diff --git a/cozo-core/src/data/expr.rs b/cozo-core/src/data/expr.rs index 03a8dd45..5316f2a0 100644 --- a/cozo-core/src/data/expr.rs +++ b/cozo-core/src/data/expr.rs @@ -25,7 +25,7 @@ use crate::parse::expr::expr2bytecode; use crate::parse::SourceSpan; #[derive(Clone, PartialEq, Eq, serde_derive::Serialize, serde_derive::Deserialize, Debug)] -pub enum ExprByteCode { +pub enum Bytecode { /// push 1 Binding { var: Symbol, @@ -69,8 +69,8 @@ struct UnboundVariableError(String, #[label] SourceSpan); #[diagnostic(code(eval::tuple_too_short))] struct TupleTooShortError(String, usize, usize, #[label] SourceSpan); -pub(crate) fn eval_bytecode_pred( - bytecodes: &[ExprByteCode], +pub fn eval_bytecode_pred( + bytecodes: &[Bytecode], bindings: impl AsRef<[DataValue]>, stack: &mut Vec, span: SourceSpan, @@ -81,8 +81,8 @@ pub(crate) fn eval_bytecode_pred( } } -pub(crate) fn eval_bytecode( - bytecodes: &[ExprByteCode], +pub fn eval_bytecode( + bytecodes: &[Bytecode], bindings: impl AsRef<[DataValue]>, stack: &mut Vec, ) -> Result { @@ -94,7 +94,7 @@ pub(crate) fn eval_bytecode( } let current_instruction = &bytecodes[pointer]; match current_instruction { - ExprByteCode::Binding { var, tuple_pos, .. } => match tuple_pos { + Bytecode::Binding { var, tuple_pos, .. } => match tuple_pos { None => { bail!(UnboundVariableError(var.name.to_string(), var.span)) } @@ -115,11 +115,11 @@ pub(crate) fn eval_bytecode( pointer += 1; } }, - ExprByteCode::Const { val, .. } => { + Bytecode::Const { val, .. } => { stack.push(val.clone()); pointer += 1; } - ExprByteCode::Apply { op, arity, span } => { + Bytecode::Apply { op, arity, span } => { let frame_start = stack.len() - *arity; let args_frame = &stack[frame_start..]; let result = (op.inner)(args_frame) @@ -128,7 +128,7 @@ pub(crate) fn eval_bytecode( stack.push(result); pointer += 1; } - ExprByteCode::JumpIfFalse { jump_to, span } => { + Bytecode::JumpIfFalse { jump_to, span } => { let val = stack.pop().unwrap(); let cond = val .get_bool() @@ -139,7 +139,7 @@ pub(crate) fn eval_bytecode( pointer = *jump_to; } } - ExprByteCode::Goto { jump_to, .. } => { + Bytecode::Goto { jump_to, .. } => { pointer = *jump_to; } } @@ -228,7 +228,7 @@ struct BadEntityId(DataValue, #[label] SourceSpan); struct EvalRaisedError(#[label] SourceSpan, #[help] String); impl Expr { - pub(crate) fn compile(&self) -> Vec { + pub(crate) fn compile(&self) -> Vec { let mut collector = vec![]; expr2bytecode(self, &mut collector); collector diff --git a/cozo-core/src/parse/expr.rs b/cozo-core/src/parse/expr.rs index bb040f2b..867e6646 100644 --- a/cozo-core/src/parse/expr.rs +++ b/cozo-core/src/parse/expr.rs @@ -15,7 +15,7 @@ use pest::pratt_parser::{Op, PrattParser}; use smartstring::{LazyCompact, SmartString}; use thiserror::Error; -use crate::data::expr::{get_op, Expr, ExprByteCode}; +use crate::data::expr::{get_op, Expr, Bytecode}; use crate::data::functions::{ OP_ADD, OP_AND, OP_COALESCE, OP_CONCAT, OP_DIV, OP_EQ, OP_GE, OP_GT, OP_LE, OP_LIST, OP_LT, OP_MINUS, OP_MOD, OP_MUL, OP_NEGATE, OP_NEQ, OP_OR, OP_POW, OP_SUB, @@ -53,16 +53,16 @@ lazy_static! { #[diagnostic(code(parser::invalid_expression))] pub(crate) struct InvalidExpression(#[label] pub(crate) SourceSpan); -pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec) { +pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec) { match expr { - Expr::Binding { var, tuple_pos } => collector.push(ExprByteCode::Binding { var: var.clone(), tuple_pos: *tuple_pos }), - Expr::Const { val, span } => collector.push(ExprByteCode::Const { val: val.clone(), span: *span }), + Expr::Binding { var, tuple_pos } => collector.push(Bytecode::Binding { var: var.clone(), tuple_pos: *tuple_pos }), + Expr::Const { val, span } => collector.push(Bytecode::Const { val: val.clone(), span: *span }), Expr::Apply { op, args, span } => { let arity = args.len(); for arg in args.iter() { expr2bytecode(arg, collector); } - collector.push(ExprByteCode::Apply { op, arity, span: *span }) + collector.push(Bytecode::Apply { op, arity, span: *span }) } Expr::Cond { clauses, span } => { let mut return_jump_pos = vec![]; @@ -70,19 +70,19 @@ pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec) { // +1 expr2bytecode(cond, collector); // -1 - collector.push(ExprByteCode::JumpIfFalse { jump_to: 0, span: *span }); + collector.push(Bytecode::JumpIfFalse { jump_to: 0, span: *span }); let false_jump_amend_pos = collector.len(); // +1 in this branch expr2bytecode(val, collector); - collector.push(ExprByteCode::Goto { jump_to: 0, span: *span }); + collector.push(Bytecode::Goto { jump_to: 0, span: *span }); return_jump_pos.push(collector.len()); - collector[false_jump_amend_pos] = ExprByteCode::JumpIfFalse { + collector[false_jump_amend_pos] = Bytecode::JumpIfFalse { jump_to: collector.len() + 1, span: *span, }; } for pos in return_jump_pos { - collector[pos] = ExprByteCode::Goto { jump_to: pos, span: *span } + collector[pos] = Bytecode::Goto { jump_to: pos, span: *span } } } } diff --git a/cozo-core/src/query/ra.rs b/cozo-core/src/query/ra.rs index 75318096..fd6fff94 100644 --- a/cozo-core/src/query/ra.rs +++ b/cozo-core/src/query/ra.rs @@ -16,7 +16,7 @@ use log::{debug, error}; use miette::{bail, Diagnostic, Result}; use thiserror::Error; -use crate::data::expr::{compute_bounds, eval_bytecode, eval_bytecode_pred, Expr, ExprByteCode}; +use crate::data::expr::{compute_bounds, eval_bytecode, eval_bytecode_pred, Expr, Bytecode}; use crate::data::program::MagicSymbol; use crate::data::relation::{ColType, NullableColType}; use crate::data::symb::Symbol; @@ -60,7 +60,7 @@ pub(crate) struct UnificationRA { pub(crate) parent: Box, pub(crate) binding: Symbol, pub(crate) expr: Expr, - pub(crate) expr_bytecode: Vec, + pub(crate) expr_bytecode: Vec, pub(crate) is_multi: bool, pub(crate) to_eliminate: BTreeSet, pub(crate) span: SourceSpan, @@ -172,7 +172,7 @@ impl UnificationRA { pub(crate) struct FilteredRA { pub(crate) parent: Box, pub(crate) filters: Vec, - pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, + pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, pub(crate) to_eliminate: BTreeSet, pub(crate) span: SourceSpan, } @@ -778,7 +778,7 @@ fn invert_option_err(v: Result>) -> Option> { } fn filter_iter( - filters_bytecodes: Vec<(Vec, SourceSpan)>, + filters_bytecodes: Vec<(Vec, SourceSpan)>, it: impl Iterator>, ) -> impl Iterator> { let mut stack = vec![]; @@ -817,7 +817,7 @@ pub(crate) struct StoredRA { pub(crate) bindings: Vec, pub(crate) storage: RelationHandle, pub(crate) filters: Vec, - pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, + pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, pub(crate) span: SourceSpan, } @@ -826,7 +826,7 @@ pub(crate) struct StoredWithValidityRA { pub(crate) bindings: Vec, pub(crate) storage: RelationHandle, pub(crate) filters: Vec, - pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, + pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, pub(crate) valid_at: ValidityTs, pub(crate) span: SourceSpan, } @@ -1247,7 +1247,7 @@ pub(crate) struct TempStoreRA { pub(crate) bindings: Vec, pub(crate) storage_key: MagicSymbol, pub(crate) filters: Vec, - pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, + pub(crate) filters_bytecodes: Vec<(Vec, SourceSpan)>, pub(crate) span: SourceSpan, }