Objs replace Values
* Obj is now a trait instead of a struct * Value enum is gone, replaced with individual structs that implement Obj * All instances where a Value was used, a Gc<(dyn Obj + 'static)> takes its place. ObjPtr is shorthand for this. * A __str__ method for objects is implemented for a couple builtin types as a proof-of-concept * println and print builtin functions are implemented using this interface There's still a lot to do, mostly with interned values. For example, whenever a new string object is created, a new __str__ function object is created each time, rather than reusing the first one that was created. Stuff like that. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::object::{QuoteTable, Value};
|
||||
use crate::object::*;
|
||||
use crate::scope::*;
|
||||
use crate::syn::ast::*;
|
||||
use crate::vm::inst::*;
|
||||
@@ -66,7 +66,7 @@ impl<'s> Compile<'s> {
|
||||
let quote =
|
||||
self.quote_table
|
||||
.insert(expr.span().clone(), locals, stmts.clone(), compiled);
|
||||
let inst = Inst::PushValue(Value::Quote(quote));
|
||||
let inst = Inst::PushValue(QuoteObj::new(quote).into_gc());
|
||||
vec![SpInst::new(expr.span().clone(), inst)]
|
||||
}
|
||||
}
|
||||
@@ -74,9 +74,9 @@ impl<'s> Compile<'s> {
|
||||
|
||||
fn compile_atom(&mut self, atom: &SpAtom) -> Vec<SpInst> {
|
||||
let inst = match atom.inner() {
|
||||
Atom::Float(f) => Inst::PushValue(Value::Float(*f)),
|
||||
Atom::Int(i) => Inst::PushValue(Value::Int(*i)),
|
||||
Atom::Str(s) => Inst::PushValue(Value::Str(s.clone())),
|
||||
Atom::Float(f) => Inst::PushValue(FloatObj::new(*f).into_gc()),
|
||||
Atom::Int(i) => Inst::PushValue(IntObj::new(*i).into_gc()),
|
||||
Atom::Str(s) => Inst::PushValue(StrObj::new(s.clone()).into_gc()),
|
||||
Atom::Assign(text) => {
|
||||
let word = self.scope_stack.insert_local(text);
|
||||
Inst::Store(word)
|
||||
|
||||
Reference in New Issue
Block a user