added captures to values
This commit is contained in:
parent
91bbdf0b37
commit
79f77cb7d9
23
src/value.rs
23
src/value.rs
|
@ -4,6 +4,7 @@ use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
fmt::{Display, Write},
|
fmt::{Display, Write},
|
||||||
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A Wisp value
|
/// A Wisp value
|
||||||
|
@ -13,7 +14,7 @@ pub enum Value<'a> {
|
||||||
Vector(Vec<Self>),
|
Vector(Vec<Self>),
|
||||||
Map(BTreeMap<Self, Self>),
|
Map(BTreeMap<Self, Self>),
|
||||||
Module(Module<'a>),
|
Module(Module<'a>),
|
||||||
Function(Function),
|
Function(Function<'a>),
|
||||||
Symbol(Symbol<'a>),
|
Symbol(Symbol<'a>),
|
||||||
Keyword(Cow<'a, str>),
|
Keyword(Cow<'a, str>),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
|
@ -24,12 +25,28 @@ pub enum Value<'a> {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Module<'a> {
|
pub struct Module<'a> {
|
||||||
members: BTreeMap<u64, Value<'a>>,
|
members: BTreeMap<u64, Rc<Value<'a>>>,
|
||||||
symbol_table: BTreeMap<String, u64>,
|
symbol_table: BTreeMap<String, u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Function {}
|
pub struct Function<'a> {
|
||||||
|
// TODO: bytecode
|
||||||
|
captures: Box<[Capture<'a>]>,
|
||||||
|
symbol_table: BTreeMap<Symbol<'a>, SymbolMapping>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum Capture<'a> {
|
||||||
|
Reference(Rc<Value<'a>>),
|
||||||
|
Owned(Value<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum SymbolMapping {
|
||||||
|
Local(u64),
|
||||||
|
Capture(u64),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Symbol<'a> {
|
pub enum Symbol<'a> {
|
||||||
|
|
Loading…
Reference in a new issue