From 79f77cb7d97ccb13b13b8aae0fcb1075d064a120 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 21 Jul 2022 21:54:28 +0200 Subject: [PATCH] added captures to values --- src/value.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/value.rs b/src/value.rs index 0d785aa..c1fdd2c 100644 --- a/src/value.rs +++ b/src/value.rs @@ -4,6 +4,7 @@ use std::{ borrow::Cow, collections::BTreeMap, fmt::{Display, Write}, + rc::Rc, }; /// A Wisp value @@ -13,7 +14,7 @@ pub enum Value<'a> { Vector(Vec), Map(BTreeMap), Module(Module<'a>), - Function(Function), + Function(Function<'a>), Symbol(Symbol<'a>), Keyword(Cow<'a, str>), Bool(bool), @@ -24,12 +25,28 @@ pub enum Value<'a> { #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Module<'a> { - members: BTreeMap>, + members: BTreeMap>>, symbol_table: BTreeMap, } #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct Function {} +pub struct Function<'a> { + // TODO: bytecode + captures: Box<[Capture<'a>]>, + symbol_table: BTreeMap, SymbolMapping>, +} + +#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub enum Capture<'a> { + Reference(Rc>), + 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)] pub enum Symbol<'a> {