Skip to content

Commit

Permalink
Merge pull request #40 from aDotInTheVoid/complex-values
Browse files Browse the repository at this point in the history
Complex values infrastructure
  • Loading branch information
aDotInTheVoid authored May 3, 2021
2 parents 1c27dad + 5f9362c commit 440f09f
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 158 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fs-err = "2.5.0"
lalrpop-util = { version = "0.19.5", features = ["lexer"] }
regex = "1.4.6"
serde = { version = "1.0.125", features = ["derive"] }
slotmap = { version = "1.0.3", features = ["serde"] }

[build-dependencies]
lalrpop = "0.19.5"
Expand Down
24 changes: 22 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use std::collections::HashMap;

use crate::value::Value;
use slotmap::SlotMap;

use crate::ast::{Function, Spanned};
use crate::value::{BigValue, HeapKey, Value};

// Scope only sticks around for the duration of a function call, wheras env
// exists for the duration Of a program. Both of these will neeed to be
// signifagently changed when we do GC and RR, so try not to make it too
// hard to do that.

#[derive(Debug, Default)]
pub struct Scope<'a> {
vars: Vec<HashMap<&'a str, Value>>,
pub(crate) vars: Vec<HashMap<&'a str, Value>>,
}

#[derive(Debug, Default)]
pub(crate) struct Env<'a> {
pub(crate) functions: HashMap<&'a str, &'a Spanned<Function<'a>>>,
pub(crate) heap: SlotMap<HeapKey, BigValue>,
}

impl<'a> Scope<'a> {
Expand Down Expand Up @@ -53,3 +67,9 @@ impl<'a> Scope<'a> {
self.vars.pop().unwrap();
}
}

impl<'a> Env<'a> {
pub fn add_to_heap(&mut self, v: BigValue) -> HeapKey {
self.heap.insert(v)
}
}
Loading

0 comments on commit 440f09f

Please sign in to comment.