feat(tazjin/rlox): Intern all string constants

This is again a step closer to the book, but there are some notable
differences:

* Only constants encountered by the compiler are interned, all other
  string operations (well, concatenation) happen with heap objects.

* OpReturn will always ensure that a returned string value is newly
  heap allocated and does not reference the interner.

Change-Id: If4f04309446e01b8ff2db51094e9710d465dbc50
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2582
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2021-03-02 13:11:21 +02:00 committed by tazjin
parent bcea8e0d16
commit 432e7a7ddd
4 changed files with 65 additions and 19 deletions

View file

@ -27,7 +27,7 @@ impl crate::Lox for Interpreter {
&mut self,
code: String,
) -> Result<Self::Value, Vec<Self::Error>> {
let chunk = compiler::compile(&code)?;
vm::interpret(chunk).map_err(|e| vec![e])
let (strings, chunk) = compiler::compile(&code)?;
vm::interpret(strings, chunk).map_err(|e| vec![e])
}
}