Skip to content

Commit

Permalink
intern_syntax added
Browse files Browse the repository at this point in the history
This will allow parsing Lurk code into `Ptr<F>`
  • Loading branch information
gabriel-barrett committed Jul 28, 2023
1 parent e952578 commit 7d7d5b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lem/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,11 @@ fn apply_cont() -> Func {
return(hidden, env, continuation, makethunk)
}
Op2::Equal => {
// TODO
return (result, env, err, errctrl)
// TODO should we check whether the tags are also equal?
if evaled_arg == result {
return (t, env, continuation, makethunk)
}
return (nil, env, continuation, makethunk)
}
Op2::Sum => {
// TODO deal with U64
Expand Down Expand Up @@ -879,8 +882,8 @@ mod tests {
use blstrs::Scalar as Fr;

const NUM_INPUTS: usize = 1;
const NUM_AUX: usize = 8027;
const NUM_CONSTRAINTS: usize = 9967;
const NUM_AUX: usize = 8032;
const NUM_CONSTRAINTS: usize = 9981;
const NUM_SLOTS: SlotsCounter = SlotsCounter {
hash2: 16,
hash3: 4,
Expand Down
45 changes: 45 additions & 0 deletions src/lem/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::{
hash::PoseidonCache,
lem::Tag,
tag::ExprTag::*,
syntax::Syntax,
uint::UInt,
};
use anyhow::{bail, Result};
use dashmap::DashMap;
Expand Down Expand Up @@ -212,6 +214,49 @@ impl<F: LurkField> Store<F> {
}
}

pub fn intern_syntax(&mut self, syn: Syntax<F>) -> Ptr<F> {
match syn {
Syntax::Num(_, x) => Ptr::Leaf(Tag::Expr(Num), x.into_scalar()),
Syntax::UInt(_, UInt::U64(x)) => Ptr::Leaf(Tag::Expr(U64), x.into()),
Syntax::Char(_, x) => Ptr::Leaf(Tag::Expr(Char), (x as u64).into()),
Syntax::Symbol(_, x) => {
let path = x.path.iter().map(|s| Arc::from(s.clone())).collect();
self.intern_symbol(&Symbol::Sym(path))
},
Syntax::Keyword(_, x) => {
let path = x.path.iter().map(|s| Arc::from(s.clone())).collect();
self.intern_symbol(&Symbol::Key(path))
},
Syntax::LurkSym(_, x) => {
self.intern_symbol(&Symbol::lurk_sym(&format!("{x}")))
},
Syntax::String(_, x) => {
self.intern_string(&x)
},
Syntax::Quote(pos, x) => {
let quote = crate::symbol::Symbol::lurk_sym("quote");
let xs = vec![Syntax::Symbol(pos, quote), *x];
self.intern_syntax(Syntax::List(pos, xs))
}
Syntax::List(_, xs) => {
let mut cdr = self.intern_symbol(&Symbol::lurk_sym(&"nil"));
for x in xs.into_iter().rev() {
let car = self.intern_syntax(x);
cdr = self.intern_2_ptrs(Tag::Expr(Cons), car, cdr);
}
cdr
}
Syntax::Improper(_, xs, end) => {
let mut cdr = self.intern_syntax(*end);
for x in xs.into_iter().rev() {
let car = self.intern_syntax(x);
cdr = self.intern_2_ptrs(Tag::Expr(Cons), car, cdr);
}
cdr
}
}
}

/// Recursively hashes the children of a `Ptr` in order to obtain its
/// corresponding `ZPtr`. While traversing a `Ptr` tree, it consults the
/// cache of `Ptr`s that have already been hydrated and also populates this
Expand Down

0 comments on commit 7d7d5b9

Please sign in to comment.