From 5bf578ba093e6fe272d132f6de2ffb57f2b0f2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Sat, 6 Feb 2021 10:02:48 +0100 Subject: intern strings and constants --- src/lib.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index cca1a58..e49e653 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,6 +162,7 @@ impl From for Value { #[derive(Clone)] pub enum Value { + Ty(Type), Blob(usize), BlobInstance(usize, Rc>>), Tuple(Rc>), @@ -178,6 +179,7 @@ pub enum Value { impl Debug for Value { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { + Value::Ty(ty) => write!(fmt, "(type {:?})", ty), Value::Blob(i) => write!(fmt, "(blob {})", i), Value::BlobInstance(i, v) => write!(fmt, "(inst {} {:?})", i, v), Value::Float(f) => write!(fmt, "(float {})", f), @@ -307,11 +309,11 @@ pub enum Op { /// /// {A, B} - Copy - {A, B, B} Copy, - /// Adds the given value to the top of the stack. + /// Adds the value indexed in the `constants-vector` to the top of the stack. /// Also links upvalues if the value is a function. /// /// {A} - Constant(B) - {A, B} - Constant(Value), + Constant(usize), /// Creates a new [Tuple] with the given size and place it on the top /// of the stack. /// @@ -326,15 +328,17 @@ pub enum Op { /// Looks up a field by the given name /// and replaces the parent with it. /// Currently only expects [Value::Blob]. + /// (name is looked up in the internal string-list) /// /// {O} - Get(F) - {O.F} - Get(String), + Get(usize), /// Looks up a field by the given name /// and replaces the current value in the object. /// Currently only expects [Value::Blob]. + /// (name is looked up in the internal string-list) /// /// {O} - Set(F) - {} - Set(String), + Set(usize), /// Adds the two top elements on the stack, /// using the function [op::add]. The result @@ -452,9 +456,10 @@ pub enum Op { /// makes sure the top value on the stack /// is of the given type, and is ment to signal /// that the "variable" is added. + /// (The type is looked up in the constants vector) /// /// Does not affect the stack. - Define(Type), + Define(usize), /// Calls "something" with the given number /// of arguments. The callable value is @@ -702,6 +707,8 @@ pub struct Prog { pub blocks: Vec>>, pub blobs: Vec>, pub functions: Vec, + pub constants: Vec, + pub strings: Vec, } #[cfg(test)] -- cgit v1.2.1 From 1c9674e1a718397e48363743eb21638e2ccd6281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Sat, 6 Feb 2021 10:07:21 +0100 Subject: make op copy --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index e49e653..b34b87e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -288,7 +288,7 @@ impl Blob { /// machine carries out when running the /// "byte-code". /// -#[derive(Debug, Clone)] +#[derive(Debug, Copy, Clone)] pub enum Op { /// This instruction should never be run. /// Finding it in a program is a critical error. -- cgit v1.2.1