Skip to content

Commit

Permalink
Renames, comments, tests, simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-barrett committed Jan 2, 2024
1 parent 3d8cf69 commit cc602b2
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 120 deletions.
7 changes: 5 additions & 2 deletions src/cli/zstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ impl<F: LurkField> ZDag<F> {
*z_ptr
} else {
let tag = ptr.tag();
let z_ptr = match ptr.pay() {
let z_ptr = match ptr.raw() {
RawPtr::Atom(idx) => {
let f = store.expect_f(*idx);
let z_ptr = ZPtr::from_parts(*tag, *f);
self.0.insert(z_ptr, ZPtrType::Atom);
z_ptr
}
RawPtr::Hash3(_) => {
todo!()
// `Hash3` is currently only used for commit caches, and in particular, they
// never appear as part of expressions, since commits are not pointers, but
// field elements
unreachable!()
}
RawPtr::Hash4(idx) => {
let [a, b] = store.expect_2_ptrs(*idx);
Expand Down
26 changes: 13 additions & 13 deletions src/lem/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ impl Block {
bindings.insert_bool(tgt.clone(), a || b);
}
Op::Add(tgt, a, b) => {
let a = *bindings.get_ptr(a)?.pay();
let b = *bindings.get_ptr(b)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let b = *bindings.get_ptr(b)?.raw();
let c = if let (RawPtr::Atom(f), RawPtr::Atom(g)) = (a, b) {
let (f, g) = (store.expect_f(f), store.expect_f(g));
store.intern_atom(Tag::Expr(Num), *f + *g)
Expand All @@ -240,8 +240,8 @@ impl Block {
bindings.insert_ptr(tgt.clone(), c);
}
Op::Sub(tgt, a, b) => {
let a = *bindings.get_ptr(a)?.pay();
let b = *bindings.get_ptr(b)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let b = *bindings.get_ptr(b)?.raw();
let c = if let (RawPtr::Atom(f), RawPtr::Atom(g)) = (a, b) {
let (f, g) = (store.expect_f(f), store.expect_f(g));
store.intern_atom(Tag::Expr(Num), *f - *g)
Expand All @@ -251,8 +251,8 @@ impl Block {
bindings.insert_ptr(tgt.clone(), c);
}
Op::Mul(tgt, a, b) => {
let a = *bindings.get_ptr(a)?.pay();
let b = *bindings.get_ptr(b)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let b = *bindings.get_ptr(b)?.raw();
let c = if let (RawPtr::Atom(f), RawPtr::Atom(g)) = (a, b) {
let (f, g) = (store.expect_f(f), store.expect_f(g));
store.intern_atom(Tag::Expr(Num), *f * *g)
Expand All @@ -262,8 +262,8 @@ impl Block {
bindings.insert_ptr(tgt.clone(), c);
}
Op::Div(tgt, a, b) => {
let a = *bindings.get_ptr(a)?.pay();
let b = *bindings.get_ptr(b)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let b = *bindings.get_ptr(b)?.raw();
let c = if let (RawPtr::Atom(f), RawPtr::Atom(g)) = (a, b) {
let (f, g) = (store.expect_f(f), store.expect_f(g));
if g == &F::ZERO {
Expand All @@ -276,8 +276,8 @@ impl Block {
bindings.insert_ptr(tgt.clone(), c);
}
Op::Lt(tgt, a, b) => {
let a = *bindings.get_ptr(a)?.pay();
let b = *bindings.get_ptr(b)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let b = *bindings.get_ptr(b)?.raw();
let c = if let (RawPtr::Atom(f_idx), RawPtr::Atom(g_idx)) = (a, b) {
let f = *store.expect_f(f_idx);
let g = *store.expect_f(g_idx);
Expand All @@ -301,7 +301,7 @@ impl Block {
}
Op::Trunc(tgt, a, n) => {
assert!(*n <= 64);
let a = *bindings.get_ptr(a)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let c = if let RawPtr::Atom(f_idx) = a {
let f = *store.expect_f(f_idx);
hints.bit_decomp.push(Some(SlotData {
Expand All @@ -315,8 +315,8 @@ impl Block {
bindings.insert_ptr(tgt.clone(), c);
}
Op::DivRem64(tgt, a, b) => {
let a = *bindings.get_ptr(a)?.pay();
let b = *bindings.get_ptr(b)?.pay();
let a = *bindings.get_ptr(a)?.raw();
let b = *bindings.get_ptr(b)?.raw();
let (c1, c2) = if let (RawPtr::Atom(f), RawPtr::Atom(g)) = (a, b) {
let f = *store.expect_f(f);
let g = *store.expect_f(g);
Expand Down
24 changes: 12 additions & 12 deletions src/lem/pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,24 @@ impl RawPtr {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub struct Ptr {
tag: Tag,
pay: RawPtr,
raw: RawPtr,
}

impl Ptr {
pub fn new(tag: Tag, pay: RawPtr) -> Self {
Ptr { tag, pay }
pub fn new(tag: Tag, raw: RawPtr) -> Self {
Ptr { tag, raw }
}

pub fn tag(&self) -> &Tag {
&self.tag
}

pub fn pay(&self) -> &RawPtr {
&self.pay
pub fn raw(&self) -> &RawPtr {
&self.raw
}

pub fn parts(&self) -> (&Tag, &RawPtr) {
let Ptr { tag, pay } = self;
let Ptr { tag, raw: pay } = self;
(tag, pay)
}

Expand Down Expand Up @@ -143,34 +143,34 @@ impl Ptr {

#[inline]
pub fn cast(self, tag: Tag) -> Self {
Ptr { tag, pay: self.pay }
Ptr { tag, raw: self.raw }
}

#[inline]
pub fn get_atom(&self) -> Option<usize> {
self.pay().get_atom()
self.raw().get_atom()
}

#[inline]
pub fn get_index2(&self) -> Option<usize> {
self.pay().get_hash4()
self.raw().get_hash4()
}

#[inline]
pub fn get_index3(&self) -> Option<usize> {
self.pay().get_hash6()
self.raw().get_hash6()
}

#[inline]
pub fn get_index4(&self) -> Option<usize> {
self.pay().get_hash8()
self.raw().get_hash8()
}

#[inline]
pub fn atom(tag: Tag, idx: usize) -> Ptr {
Ptr {
tag,
pay: RawPtr::Atom(idx),
raw: RawPtr::Atom(idx),
}
}
}
Expand Down
Loading

0 comments on commit cc602b2

Please sign in to comment.