|
@@ -2,7 +2,7 @@ use super::{
|
|
|
compiler::Compiler,
|
|
|
expr::{Expr, ExprOp, Variable},
|
|
|
opcode::OpCode,
|
|
|
- parser::{parse_query, Query},
|
|
|
+ parser::parse,
|
|
|
runtime::execute,
|
|
|
value::{Value, ValueOrRef},
|
|
|
Addr, Error, Register,
|
|
@@ -13,7 +13,7 @@ use std::collections::HashMap;
|
|
|
#[derive(Debug, Clone)]
|
|
|
pub struct Filter<'a> {
|
|
|
/// Query
|
|
|
- query: Query,
|
|
|
+ expr: Option<Expr>,
|
|
|
/// List of external variables
|
|
|
variables: Vec<Variable>,
|
|
|
/// Unoptimized opcodes
|
|
@@ -29,8 +29,8 @@ pub struct Filter<'a> {
|
|
|
|
|
|
impl<'a> Filter<'a> {
|
|
|
pub fn new(code: &str) -> Result<Self, Error> {
|
|
|
- let query = parse_query(code)?;
|
|
|
- let opcodes = query.where_clause.as_ref().map_or_else(
|
|
|
+ let expr = parse(code)?;
|
|
|
+ let opcodes = expr.as_ref().map_or_else(
|
|
|
|| {
|
|
|
Ok(vec![
|
|
|
OpCode::LOAD(0.into(), true.into()),
|
|
@@ -41,7 +41,7 @@ impl<'a> Filter<'a> {
|
|
|
)?;
|
|
|
|
|
|
let instance = Self {
|
|
|
- query,
|
|
|
+ expr,
|
|
|
dbg_opcodes: opcodes.clone(),
|
|
|
opcodes: opcodes.clone(),
|
|
|
variables: opcodes
|
|
@@ -71,21 +71,7 @@ impl<'a> Filter<'a> {
|
|
|
|
|
|
self.opcodes = new_opcodes;
|
|
|
self.initial_register.clear();
|
|
|
- self.opcodes_to_execute = Compiler::resolve_label_to_addr(
|
|
|
- self.opcodes.clone(), /*
|
|
|
- self.opcodes
|
|
|
- .iter()
|
|
|
- .filter_map(|opcode| match opcode {
|
|
|
- OpCode::LOAD(addr, value) => {
|
|
|
- self.initial_register
|
|
|
- .insert(*addr, ValueOrRef::Value(value.clone()));
|
|
|
- None
|
|
|
- }
|
|
|
- _ => Some(opcode.clone()),
|
|
|
- })
|
|
|
- .collect::<Vec<_>>()*/
|
|
|
- )
|
|
|
- .unwrap();
|
|
|
+ self.opcodes_to_execute = Compiler::resolve_label_to_addr(self.opcodes.clone()).unwrap();
|
|
|
self
|
|
|
}
|
|
|
|