From 337ef0a5b57f780c5b31971a8add400ca07e2098 Mon Sep 17 00:00:00 2001 From: Gabriel Barreto Date: Thu, 4 Jan 2024 18:13:57 -0300 Subject: [PATCH] LEM tag own file and tests --- src/cli/repl/meta_cmd.rs | 2 +- src/cli/repl/mod.rs | 2 +- src/cli/zstore.rs | 2 +- src/coprocessor/mod.rs | 2 +- src/lem/interpreter.rs | 3 +- src/lem/macros.rs | 8 +- src/lem/mod.rs | 207 +----------------------- src/lem/tag.rs | 252 ++++++++++++++++++++++++++++++ src/proof/tests/nova_tests_lem.rs | 2 +- src/tag.rs | 12 +- 10 files changed, 274 insertions(+), 218 deletions(-) create mode 100644 src/lem/tag.rs diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index 9b986a99d0..50764616bb 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -20,7 +20,7 @@ use crate::{ multiframe::MultiFrame, pointers::{Ptr, RawPtr, ZPtr}, store::expect_ptrs, - Tag, + tag::Tag, }, package::{Package, SymbolRef}, proof::{ diff --git a/src/cli/repl/mod.rs b/src/cli/repl/mod.rs index 724d9d22a4..071469e61d 100644 --- a/src/cli/repl/mod.rs +++ b/src/cli/repl/mod.rs @@ -28,7 +28,7 @@ use crate::{ multiframe::MultiFrame, pointers::{Ptr, RawPtr}, store::Store, - Tag, + tag::Tag, }, parser, proof::{nova::NovaProver, Prover, RecursiveSNARKTrait}, diff --git a/src/cli/zstore.rs b/src/cli/zstore.rs index 1513d27f02..96a0ebad8d 100644 --- a/src/cli/zstore.rs +++ b/src/cli/zstore.rs @@ -278,7 +278,7 @@ mod tests { lem::{ pointers::Ptr, store::{intern_ptrs, Store}, - Tag, + tag::Tag, }, tag::{ContTag, ExprTag, Op1, Op2}, }; diff --git a/src/coprocessor/mod.rs b/src/coprocessor/mod.rs index beb97360d8..a3be4afd8f 100644 --- a/src/coprocessor/mod.rs +++ b/src/coprocessor/mod.rs @@ -113,7 +113,7 @@ pub(crate) mod test { use super::*; use crate::circuit::gadgets::constraints::{alloc_equal, mul}; - use crate::lem::{pointers::RawPtr, Tag as LEMTag}; + use crate::lem::{pointers::RawPtr, tag::Tag as LEMTag}; use crate::tag::{ExprTag, Tag}; use std::marker::PhantomData; diff --git a/src/lem/interpreter.rs b/src/lem/interpreter.rs index 10858b0035..a656a86122 100644 --- a/src/lem/interpreter.rs +++ b/src/lem/interpreter.rs @@ -5,8 +5,9 @@ use super::{ pointers::{Ptr, RawPtr}, slot::{SlotData, Val}, store::{fetch_ptrs, intern_ptrs, Store}, + tag::Tag, var_map::VarMap, - Block, Ctrl, Func, Op, Tag, Var, + Block, Ctrl, Func, Op, Var, }; use crate::{ diff --git a/src/lem/macros.rs b/src/lem/macros.rs index 7e16a6a720..bac1d1e748 100644 --- a/src/lem/macros.rs +++ b/src/lem/macros.rs @@ -30,16 +30,16 @@ macro_rules! lit { #[macro_export] macro_rules! tag { ( Expr::$tag:ident ) => { - $crate::lem::Tag::Expr($crate::tag::ExprTag::$tag) + $crate::lem::tag::Tag::Expr($crate::tag::ExprTag::$tag) }; ( Cont::$tag:ident ) => { - $crate::lem::Tag::Cont($crate::tag::ContTag::$tag) + $crate::lem::tag::Tag::Cont($crate::tag::ContTag::$tag) }; ( Op1::$tag:ident ) => { - $crate::lem::Tag::Op1($crate::tag::Op1::$tag) + $crate::lem::tag::Tag::Op1($crate::tag::Op1::$tag) }; ( Op2::$tag:ident ) => { - $crate::lem::Tag::Op2($crate::tag::Op2::$tag) + $crate::lem::tag::Tag::Op2($crate::tag::Op2::$tag) }; } diff --git a/src/lem/mod.rs b/src/lem/mod.rs index e8b0b1ff72..f6986c4bb1 100644 --- a/src/lem/mod.rs +++ b/src/lem/mod.rs @@ -68,23 +68,19 @@ mod path; pub mod pointers; mod slot; pub mod store; +pub mod tag; mod var_map; use anyhow::{bail, Result}; use indexmap::IndexMap; -use serde::{Deserialize, Serialize}; use std::sync::Arc; #[cfg(test)] mod tests; -use crate::{ - field::LurkField, - symbol::Symbol, - tag::{ContTag, ExprTag, Op1, Op2, Tag as TagTrait}, -}; +use crate::{field::LurkField, symbol::Symbol}; -use self::{pointers::Ptr, slot::SlotsCounter, store::Store, var_map::VarMap}; +use self::{pointers::Ptr, slot::SlotsCounter, store::Store, tag::Tag, var_map::VarMap}; pub type AString = Arc; @@ -103,203 +99,6 @@ pub struct Func { #[derive(Debug, PartialEq, Clone, Eq, Hash)] pub struct Var(AString); -/// The LEM `Tag` is a wrapper around other types that are used as tags -#[derive(Copy, Debug, PartialEq, Clone, Eq, Hash, Serialize, Deserialize)] -pub enum Tag { - Expr(ExprTag), - Cont(ContTag), - Op1(Op1), - Op2(Op2), -} - -impl TryFrom for Tag { - type Error = anyhow::Error; - - fn try_from(val: u16) -> Result { - if let Ok(tag) = ExprTag::try_from(val) { - Ok(Tag::Expr(tag)) - } else if let Ok(tag) = ContTag::try_from(val) { - Ok(Tag::Cont(tag)) - } else if let Ok(tag) = Op1::try_from(val) { - Ok(Tag::Op1(tag)) - } else if let Ok(tag) = Op2::try_from(val) { - Ok(Tag::Op2(tag)) - } else { - bail!("Invalid u16 for Tag: {val}") - } - } -} - -impl From for u16 { - fn from(val: Tag) -> Self { - match val { - Tag::Expr(tag) => tag.into(), - Tag::Cont(tag) => tag.into(), - Tag::Op1(tag) => tag.into(), - Tag::Op2(tag) => tag.into(), - } - } -} - -impl TagTrait for Tag { - fn from_field(f: &F) -> Option { - Self::try_from(f.to_u16()?).ok() - } - - fn to_field(&self) -> F { - Tag::to_field(self) - } -} - -impl Tag { - #[inline] - pub fn to_field(&self) -> F { - match self { - Self::Expr(tag) => tag.to_field(), - Self::Cont(tag) => tag.to_field(), - Self::Op1(tag) => tag.to_field(), - Self::Op2(tag) => tag.to_field(), - } - } - - pub fn pos(i: usize) -> Option { - match i { - 0 => Some(Self::Expr(ExprTag::Nil)), - 1 => Some(Self::Expr(ExprTag::Cons)), - 2 => Some(Self::Expr(ExprTag::Sym)), - 3 => Some(Self::Expr(ExprTag::Fun)), - 4 => Some(Self::Expr(ExprTag::Num)), - 5 => Some(Self::Expr(ExprTag::Thunk)), - 6 => Some(Self::Expr(ExprTag::Str)), - 7 => Some(Self::Expr(ExprTag::Char)), - 8 => Some(Self::Expr(ExprTag::Comm)), - 9 => Some(Self::Expr(ExprTag::U64)), - 10 => Some(Self::Expr(ExprTag::Key)), - 11 => Some(Self::Expr(ExprTag::Cproc)), - 12 => Some(Self::Cont(ContTag::Outermost)), - 13 => Some(Self::Cont(ContTag::Call0)), - 14 => Some(Self::Cont(ContTag::Call)), - 15 => Some(Self::Cont(ContTag::Call2)), - 16 => Some(Self::Cont(ContTag::Tail)), - 17 => Some(Self::Cont(ContTag::Error)), - 18 => Some(Self::Cont(ContTag::Lookup)), - 19 => Some(Self::Cont(ContTag::Unop)), - 20 => Some(Self::Cont(ContTag::Binop)), - 21 => Some(Self::Cont(ContTag::Binop2)), - 22 => Some(Self::Cont(ContTag::If)), - 23 => Some(Self::Cont(ContTag::Let)), - 24 => Some(Self::Cont(ContTag::LetRec)), - 25 => Some(Self::Cont(ContTag::Dummy)), - 26 => Some(Self::Cont(ContTag::Terminal)), - 27 => Some(Self::Cont(ContTag::Emit)), - 28 => Some(Self::Cont(ContTag::Cproc)), - 29 => Some(Self::Op1(Op1::Car)), - 30 => Some(Self::Op1(Op1::Cdr)), - 31 => Some(Self::Op1(Op1::Atom)), - 32 => Some(Self::Op1(Op1::Emit)), - 33 => Some(Self::Op1(Op1::Open)), - 34 => Some(Self::Op1(Op1::Secret)), - 35 => Some(Self::Op1(Op1::Commit)), - 36 => Some(Self::Op1(Op1::Num)), - 37 => Some(Self::Op1(Op1::Comm)), - 38 => Some(Self::Op1(Op1::Char)), - 39 => Some(Self::Op1(Op1::Eval)), - 40 => Some(Self::Op1(Op1::U64)), - 41 => Some(Self::Op2(Op2::Sum)), - 42 => Some(Self::Op2(Op2::Diff)), - 43 => Some(Self::Op2(Op2::Product)), - 44 => Some(Self::Op2(Op2::Quotient)), - 45 => Some(Self::Op2(Op2::Equal)), - 46 => Some(Self::Op2(Op2::NumEqual)), - 47 => Some(Self::Op2(Op2::Less)), - 48 => Some(Self::Op2(Op2::Greater)), - 49 => Some(Self::Op2(Op2::LessEqual)), - 50 => Some(Self::Op2(Op2::GreaterEqual)), - 51 => Some(Self::Op2(Op2::Cons)), - 52 => Some(Self::Op2(Op2::StrCons)), - 53 => Some(Self::Op2(Op2::Begin)), - 54 => Some(Self::Op2(Op2::Hide)), - 55 => Some(Self::Op2(Op2::Modulo)), - 56 => Some(Self::Op2(Op2::Eval)), - _ => None, - } - } - - pub fn index(&self) -> usize { - match self { - Self::Expr(ExprTag::Nil) => 0, - Self::Expr(ExprTag::Cons) => 1, - Self::Expr(ExprTag::Sym) => 2, - Self::Expr(ExprTag::Fun) => 3, - Self::Expr(ExprTag::Num) => 4, - Self::Expr(ExprTag::Thunk) => 5, - Self::Expr(ExprTag::Str) => 6, - Self::Expr(ExprTag::Char) => 7, - Self::Expr(ExprTag::Comm) => 8, - Self::Expr(ExprTag::U64) => 9, - Self::Expr(ExprTag::Key) => 10, - Self::Expr(ExprTag::Cproc) => 11, - Self::Cont(ContTag::Outermost) => 12, - Self::Cont(ContTag::Call0) => 13, - Self::Cont(ContTag::Call) => 14, - Self::Cont(ContTag::Call2) => 15, - Self::Cont(ContTag::Tail) => 16, - Self::Cont(ContTag::Error) => 17, - Self::Cont(ContTag::Lookup) => 18, - Self::Cont(ContTag::Unop) => 19, - Self::Cont(ContTag::Binop) => 20, - Self::Cont(ContTag::Binop2) => 21, - Self::Cont(ContTag::If) => 22, - Self::Cont(ContTag::Let) => 23, - Self::Cont(ContTag::LetRec) => 24, - Self::Cont(ContTag::Dummy) => 25, - Self::Cont(ContTag::Terminal) => 26, - Self::Cont(ContTag::Emit) => 27, - Self::Cont(ContTag::Cproc) => 28, - Self::Op1(Op1::Car) => 29, - Self::Op1(Op1::Cdr) => 30, - Self::Op1(Op1::Atom) => 31, - Self::Op1(Op1::Emit) => 32, - Self::Op1(Op1::Open) => 33, - Self::Op1(Op1::Secret) => 34, - Self::Op1(Op1::Commit) => 35, - Self::Op1(Op1::Num) => 36, - Self::Op1(Op1::Comm) => 37, - Self::Op1(Op1::Char) => 38, - Self::Op1(Op1::Eval) => 39, - Self::Op1(Op1::U64) => 40, - Self::Op2(Op2::Sum) => 41, - Self::Op2(Op2::Diff) => 42, - Self::Op2(Op2::Product) => 43, - Self::Op2(Op2::Quotient) => 44, - Self::Op2(Op2::Equal) => 45, - Self::Op2(Op2::NumEqual) => 46, - Self::Op2(Op2::Less) => 47, - Self::Op2(Op2::Greater) => 48, - Self::Op2(Op2::LessEqual) => 49, - Self::Op2(Op2::GreaterEqual) => 50, - Self::Op2(Op2::Cons) => 51, - Self::Op2(Op2::StrCons) => 52, - Self::Op2(Op2::Begin) => 53, - Self::Op2(Op2::Hide) => 54, - Self::Op2(Op2::Modulo) => 55, - Self::Op2(Op2::Eval) => 56, - } - } -} - -impl std::fmt::Display for Tag { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use Tag::{Cont, Expr, Op1, Op2}; - match self { - Expr(tag) => write!(f, "expr.{}", tag), - Cont(tag) => write!(f, "cont.{}", tag), - Op1(tag) => write!(f, "op1.{}", tag), - Op2(tag) => write!(f, "op2.{}", tag), - } - } -} - /// LEM literals #[derive(Debug, PartialEq, Clone, Eq, Hash)] pub enum Lit { diff --git a/src/lem/tag.rs b/src/lem/tag.rs new file mode 100644 index 0000000000..76c2e4f9ad --- /dev/null +++ b/src/lem/tag.rs @@ -0,0 +1,252 @@ +use anyhow::{bail, Result}; +use serde::{Deserialize, Serialize}; + +use crate::{ + field::LurkField, + tag::{ContTag, ExprTag, Op1, Op2, Tag as TagTrait}, +}; + +/// The LEM `Tag` is a wrapper around other types that are used as tags +#[derive(Copy, Debug, PartialEq, Clone, Eq, Hash, Serialize, Deserialize)] +pub enum Tag { + Expr(ExprTag), + Cont(ContTag), + Op1(Op1), + Op2(Op2), +} + +impl TryFrom for Tag { + type Error = anyhow::Error; + + fn try_from(val: u16) -> Result { + if let Ok(tag) = ExprTag::try_from(val) { + Ok(Tag::Expr(tag)) + } else if let Ok(tag) = ContTag::try_from(val) { + Ok(Tag::Cont(tag)) + } else if let Ok(tag) = Op1::try_from(val) { + Ok(Tag::Op1(tag)) + } else if let Ok(tag) = Op2::try_from(val) { + Ok(Tag::Op2(tag)) + } else { + bail!("Invalid u16 for Tag: {val}") + } + } +} + +impl From for u16 { + fn from(val: Tag) -> Self { + match val { + Tag::Expr(tag) => tag.into(), + Tag::Cont(tag) => tag.into(), + Tag::Op1(tag) => tag.into(), + Tag::Op2(tag) => tag.into(), + } + } +} + +impl TagTrait for Tag { + fn from_field(f: &F) -> Option { + Self::try_from(f.to_u16()?).ok() + } + + fn to_field(&self) -> F { + Tag::to_field(self) + } +} + +impl Tag { + #[inline] + pub fn to_field(&self) -> F { + match self { + Self::Expr(tag) => tag.to_field(), + Self::Cont(tag) => tag.to_field(), + Self::Op1(tag) => tag.to_field(), + Self::Op2(tag) => tag.to_field(), + } + } + + pub fn pos(i: usize) -> Option { + match i { + 0 => Some(Self::Expr(ExprTag::Nil)), + 1 => Some(Self::Expr(ExprTag::Cons)), + 2 => Some(Self::Expr(ExprTag::Sym)), + 3 => Some(Self::Expr(ExprTag::Fun)), + 4 => Some(Self::Expr(ExprTag::Num)), + 5 => Some(Self::Expr(ExprTag::Thunk)), + 6 => Some(Self::Expr(ExprTag::Str)), + 7 => Some(Self::Expr(ExprTag::Char)), + 8 => Some(Self::Expr(ExprTag::Comm)), + 9 => Some(Self::Expr(ExprTag::U64)), + 10 => Some(Self::Expr(ExprTag::Key)), + 11 => Some(Self::Expr(ExprTag::Cproc)), + 12 => Some(Self::Cont(ContTag::Outermost)), + 13 => Some(Self::Cont(ContTag::Call0)), + 14 => Some(Self::Cont(ContTag::Call)), + 15 => Some(Self::Cont(ContTag::Call2)), + 16 => Some(Self::Cont(ContTag::Tail)), + 17 => Some(Self::Cont(ContTag::Error)), + 18 => Some(Self::Cont(ContTag::Lookup)), + 19 => Some(Self::Cont(ContTag::Unop)), + 20 => Some(Self::Cont(ContTag::Binop)), + 21 => Some(Self::Cont(ContTag::Binop2)), + 22 => Some(Self::Cont(ContTag::If)), + 23 => Some(Self::Cont(ContTag::Let)), + 24 => Some(Self::Cont(ContTag::LetRec)), + 25 => Some(Self::Cont(ContTag::Dummy)), + 26 => Some(Self::Cont(ContTag::Terminal)), + 27 => Some(Self::Cont(ContTag::Emit)), + 28 => Some(Self::Cont(ContTag::Cproc)), + 29 => Some(Self::Op1(Op1::Car)), + 30 => Some(Self::Op1(Op1::Cdr)), + 31 => Some(Self::Op1(Op1::Atom)), + 32 => Some(Self::Op1(Op1::Emit)), + 33 => Some(Self::Op1(Op1::Open)), + 34 => Some(Self::Op1(Op1::Secret)), + 35 => Some(Self::Op1(Op1::Commit)), + 36 => Some(Self::Op1(Op1::Num)), + 37 => Some(Self::Op1(Op1::Comm)), + 38 => Some(Self::Op1(Op1::Char)), + 39 => Some(Self::Op1(Op1::Eval)), + 40 => Some(Self::Op1(Op1::U64)), + 41 => Some(Self::Op2(Op2::Sum)), + 42 => Some(Self::Op2(Op2::Diff)), + 43 => Some(Self::Op2(Op2::Product)), + 44 => Some(Self::Op2(Op2::Quotient)), + 45 => Some(Self::Op2(Op2::Equal)), + 46 => Some(Self::Op2(Op2::NumEqual)), + 47 => Some(Self::Op2(Op2::Less)), + 48 => Some(Self::Op2(Op2::Greater)), + 49 => Some(Self::Op2(Op2::LessEqual)), + 50 => Some(Self::Op2(Op2::GreaterEqual)), + 51 => Some(Self::Op2(Op2::Cons)), + 52 => Some(Self::Op2(Op2::StrCons)), + 53 => Some(Self::Op2(Op2::Begin)), + 54 => Some(Self::Op2(Op2::Hide)), + 55 => Some(Self::Op2(Op2::Modulo)), + 56 => Some(Self::Op2(Op2::Eval)), + _ => None, + } + } + + pub fn index(&self) -> usize { + match self { + Self::Expr(ExprTag::Nil) => 0, + Self::Expr(ExprTag::Cons) => 1, + Self::Expr(ExprTag::Sym) => 2, + Self::Expr(ExprTag::Fun) => 3, + Self::Expr(ExprTag::Num) => 4, + Self::Expr(ExprTag::Thunk) => 5, + Self::Expr(ExprTag::Str) => 6, + Self::Expr(ExprTag::Char) => 7, + Self::Expr(ExprTag::Comm) => 8, + Self::Expr(ExprTag::U64) => 9, + Self::Expr(ExprTag::Key) => 10, + Self::Expr(ExprTag::Cproc) => 11, + Self::Cont(ContTag::Outermost) => 12, + Self::Cont(ContTag::Call0) => 13, + Self::Cont(ContTag::Call) => 14, + Self::Cont(ContTag::Call2) => 15, + Self::Cont(ContTag::Tail) => 16, + Self::Cont(ContTag::Error) => 17, + Self::Cont(ContTag::Lookup) => 18, + Self::Cont(ContTag::Unop) => 19, + Self::Cont(ContTag::Binop) => 20, + Self::Cont(ContTag::Binop2) => 21, + Self::Cont(ContTag::If) => 22, + Self::Cont(ContTag::Let) => 23, + Self::Cont(ContTag::LetRec) => 24, + Self::Cont(ContTag::Dummy) => 25, + Self::Cont(ContTag::Terminal) => 26, + Self::Cont(ContTag::Emit) => 27, + Self::Cont(ContTag::Cproc) => 28, + Self::Op1(Op1::Car) => 29, + Self::Op1(Op1::Cdr) => 30, + Self::Op1(Op1::Atom) => 31, + Self::Op1(Op1::Emit) => 32, + Self::Op1(Op1::Open) => 33, + Self::Op1(Op1::Secret) => 34, + Self::Op1(Op1::Commit) => 35, + Self::Op1(Op1::Num) => 36, + Self::Op1(Op1::Comm) => 37, + Self::Op1(Op1::Char) => 38, + Self::Op1(Op1::Eval) => 39, + Self::Op1(Op1::U64) => 40, + Self::Op2(Op2::Sum) => 41, + Self::Op2(Op2::Diff) => 42, + Self::Op2(Op2::Product) => 43, + Self::Op2(Op2::Quotient) => 44, + Self::Op2(Op2::Equal) => 45, + Self::Op2(Op2::NumEqual) => 46, + Self::Op2(Op2::Less) => 47, + Self::Op2(Op2::Greater) => 48, + Self::Op2(Op2::LessEqual) => 49, + Self::Op2(Op2::GreaterEqual) => 50, + Self::Op2(Op2::Cons) => 51, + Self::Op2(Op2::StrCons) => 52, + Self::Op2(Op2::Begin) => 53, + Self::Op2(Op2::Hide) => 54, + Self::Op2(Op2::Modulo) => 55, + Self::Op2(Op2::Eval) => 56, + } + } +} + +impl std::fmt::Display for Tag { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use Tag::{Cont, Expr, Op1, Op2}; + match self { + Expr(tag) => write!(f, "expr.{}", tag), + Cont(tag) => write!(f, "cont.{}", tag), + Op1(tag) => write!(f, "op1.{}", tag), + Op2(tag) => write!(f, "op2.{}", tag), + } + } +} + +#[cfg(test)] +pub(crate) mod tests { + use super::*; + use crate::tag::{CONT_TAG_INIT, EXPR_TAG_INIT, OP1_TAG_INIT, OP2_TAG_INIT}; + + #[test] + fn pos_index_roundtrip() { + let mut i = 0; + while let Some(tag) = Tag::pos(i) { + let j = tag.index(); + assert_eq!(i, j); + i += 1; + } + + let mut i = EXPR_TAG_INIT; + while let Ok(expr_tag) = ExprTag::try_from(i) { + let tag = Tag::Expr(expr_tag); + let tag_2 = Tag::pos(tag.index()).unwrap(); + assert_eq!(tag, tag_2); + i += 1; + } + + let mut i = CONT_TAG_INIT; + while let Ok(cont_tag) = ContTag::try_from(i) { + let tag = Tag::Cont(cont_tag); + let tag_2 = Tag::pos(tag.index()).unwrap(); + assert_eq!(tag, tag_2); + i += 1; + } + + let mut i = OP1_TAG_INIT; + while let Ok(op1_tag) = Op1::try_from(i) { + let tag = Tag::Op1(op1_tag); + let tag_2 = Tag::pos(tag.index()).unwrap(); + assert_eq!(tag, tag_2); + i += 1; + } + + let mut i = OP2_TAG_INIT; + while let Ok(op2_tag) = Op2::try_from(i) { + let tag = Tag::Op2(op2_tag); + let tag_2 = Tag::pos(tag.index()).unwrap(); + assert_eq!(tag, tag_2); + i += 1; + } + } +} diff --git a/src/proof/tests/nova_tests_lem.rs b/src/proof/tests/nova_tests_lem.rs index b0ed617390..74499a580a 100644 --- a/src/proof/tests/nova_tests_lem.rs +++ b/src/proof/tests/nova_tests_lem.rs @@ -6,7 +6,7 @@ use crate::{ eval::lang::{Coproc, Lang}, lem::{ store::{intern_ptrs, Store}, - Tag, + tag::Tag, }, num::Num, proof::nova::C1LEM, diff --git a/src/tag.rs b/src/tag.rs index cb2a8c2686..dc2b0eb207 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -20,6 +20,7 @@ pub trait Tag: } } +pub(crate) const EXPR_TAG_INIT: u16 = 0b0000_0000_0000_0000; /// A tag for expressions. Note that ExprTag, ContTag, Op1, Op2 all live in the same u16 namespace #[derive( Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize_repr, Deserialize_repr, TryFromRepr, @@ -27,7 +28,7 @@ pub trait Tag: #[cfg_attr(not(target_arch = "wasm32"), derive(Arbitrary))] #[repr(u16)] pub enum ExprTag { - Nil = 0b0000_0000_0000_0000, + Nil = EXPR_TAG_INIT, Cons, Sym, Fun, @@ -89,6 +90,7 @@ impl Tag for ExprTag { } } +pub(crate) const CONT_TAG_INIT: u16 = 0b0001_0000_0000_0000; /// A tag for continuations. Note that ExprTag, ContTag, Op1, Op2 all live in the same u16 namespace #[derive( Serialize_repr, Deserialize_repr, Debug, Copy, Clone, PartialEq, Eq, Hash, TryFromRepr, @@ -96,7 +98,7 @@ impl Tag for ExprTag { #[cfg_attr(not(target_arch = "wasm32"), derive(Arbitrary))] #[repr(u16)] pub enum ContTag { - Outermost = 0b0001_0000_0000_0000, + Outermost = CONT_TAG_INIT, Call0, Call, Call2, @@ -168,6 +170,7 @@ impl fmt::Display for ContTag { } } +pub(crate) const OP1_TAG_INIT: u16 = 0b0010_0000_0000_0000; #[derive( Copy, Clone, @@ -183,7 +186,7 @@ impl fmt::Display for ContTag { #[cfg_attr(not(target_arch = "wasm32"), derive(Arbitrary))] #[repr(u16)] pub enum Op1 { - Car = 0b0010_0000_0000_0000, + Car = OP1_TAG_INIT, Cdr, Atom, Emit, @@ -297,6 +300,7 @@ impl fmt::Display for Op1 { } } +pub(crate) const OP2_TAG_INIT: u16 = 0b0011_0000_0000_0000; #[derive( Copy, Clone, @@ -312,7 +316,7 @@ impl fmt::Display for Op1 { #[cfg_attr(not(target_arch = "wasm32"), derive(Arbitrary))] #[repr(u16)] pub enum Op2 { - Sum = 0b0011_0000_0000_0000, + Sum = OP2_TAG_INIT, Diff, Product, Quotient,