diff --git a/src/eval.rs b/src/eval.rs index 76fb864d1..078467ab7 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -53,7 +53,7 @@ impl Engine { val: i, span: expr.span, }), - Expr::Var(v) => Err(ShellError::Unsupported(expr.span)), + Expr::Var(_) => Err(ShellError::Unsupported(expr.span)), Expr::Call(_) => Err(ShellError::Unsupported(expr.span)), Expr::ExternalCall(_, _) => Err(ShellError::Unsupported(expr.span)), Expr::Operator(_) => Err(ShellError::Unsupported(expr.span)), diff --git a/src/main.rs b/src/main.rs index 2b6c83abc..a699ae5ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use engine_q::{Engine, ParserWorkingSet, Signature, SyntaxShape}; +use engine_q::{ParserWorkingSet, Signature, SyntaxShape}; fn main() -> std::io::Result<()> { if let Some(path) = std::env::args().nth(1) { @@ -70,7 +70,7 @@ fn main() -> std::io::Result<()> { println!("{:#?}", output); println!("error: {:?}", err); - println!("working set: {:#?}", working_set); + //println!("working set: {:#?}", working_set); // println!("{}", size_of::()); diff --git a/src/parser.rs b/src/parser.rs index 2b2e06c43..3afafe391 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,7 +4,7 @@ use crate::{ lex, lite_parse, parser_state::{Type, VarId}, signature::Flag, - DeclId, Declaration, LiteBlock, ParseError, ParserWorkingSet, Signature, Span, + BlockId, DeclId, Declaration, LiteBlock, ParseError, ParserWorkingSet, Signature, Span, }; /// The syntactic shapes that values must match to be passed into a command. You can think of this as the type-checking that occurs when you call a function. @@ -129,8 +129,8 @@ pub enum Expr { ExternalCall(Vec, Vec>), Operator(Operator), BinaryOp(Box, Box, Box), //lhs, op, rhs - Subexpression(Box), - Block(Box), + Subexpression(BlockId), + Block(BlockId), List(Vec), Table(Vec, Vec>), Literal(Vec), @@ -178,9 +178,9 @@ impl Expression { } } - pub fn as_block(self) -> Option> { + pub fn as_block(self) -> Option { match self.expr { - Expr::Block(block) => Some(block), + Expr::Block(block_id) => Some(block_id), _ => None, } } @@ -796,9 +796,11 @@ impl ParserWorkingSet { let (output, err) = self.parse_block(&output); error = error.or(err); + let block_id = self.add_block(output); + ( Expression { - expr: Expr::Subexpression(Box::new(output)), + expr: Expr::Subexpression(block_id), span, }, error, @@ -1082,9 +1084,11 @@ impl ParserWorkingSet { println!("{:?} {:?}", output, error); + let block_id = self.add_block(output); + ( Expression { - expr: Expr::Block(Box::new(output)), + expr: Expr::Block(block_id), span, }, error, @@ -1423,14 +1427,12 @@ impl ParserWorkingSet { .into_iter() .map(|x| x.as_var().expect("internal error: expected parameter")) .collect::>(); - let block = call + let block_id = call .positional .remove(0) .as_block() .expect("internal error: expected block"); - let block_id = self.add_block(block); - let decl = Declaration { signature: Signature::new(name), body: Some(block_id), diff --git a/src/parser_state.rs b/src/parser_state.rs index d864903a3..8c598438e 100644 --- a/src/parser_state.rs +++ b/src/parser_state.rs @@ -1,4 +1,4 @@ -use crate::{parser::Block, Declaration, Signature, Span}; +use crate::{parser::Block, Declaration, Span}; use std::{collections::HashMap, sync::Arc}; #[derive(Debug)] @@ -7,7 +7,7 @@ pub struct ParserState { file_contents: Vec, vars: Vec, decls: Vec, - blocks: Vec>, + blocks: Vec, } #[derive(Clone, Copy, Debug)] @@ -118,7 +118,7 @@ pub struct ParserWorkingSet { pub(crate) file_contents: Vec, vars: Vec, // indexed by VarId decls: Vec, // indexed by DeclId - blocks: Vec>, // indexed by BlockId + blocks: Vec, // indexed by BlockId permanent_state: Option>, scope: Vec, } @@ -181,7 +181,7 @@ impl ParserWorkingSet { decl_id } - pub fn add_block(&mut self, block: Box) -> BlockId { + pub fn add_block(&mut self, block: Block) -> BlockId { self.blocks.push(block); self.num_blocks() - 1