aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-02-06 10:02:48 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-02-06 10:02:48 +0100
commit5bf578ba093e6fe272d132f6de2ffb57f2b0f2fe (patch)
tree7b48b1a1728e8a86c7107ba4387f2ea5f8719a64 /src/lib.rs
parent98df292fe4142fcc836013341579ed4437a2a464 (diff)
downloadsylt-5bf578ba093e6fe272d132f6de2ffb57f2b0f2fe.tar.gz
intern strings and constants
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs17
1 files changed, 12 insertions, 5 deletions
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<Type> for Value {
#[derive(Clone)]
pub enum Value {
+ Ty(Type),
Blob(usize),
BlobInstance(usize, Rc<RefCell<Vec<Value>>>),
Tuple(Rc<Vec<Value>>),
@@ -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<Rc<RefCell<Block>>>,
pub blobs: Vec<Rc<Blob>>,
pub functions: Vec<RustFunction>,
+ pub constants: Vec<Value>,
+ pub strings: Vec<String>,
}
#[cfg(test)]