Add the start of array impl
* Array syntax * Array compilation * ArrayBegin and ArrayEnd inst * mod obj::array Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -70,6 +70,15 @@ impl<'s> Compile<'s> {
|
|||||||
let inst = Inst::PushValue(QuoteObj::new(quote));
|
let inst = Inst::PushValue(QuoteObj::new(quote));
|
||||||
vec![SpInst::new(expr.span().clone(), inst)]
|
vec![SpInst::new(expr.span().clone(), inst)]
|
||||||
}
|
}
|
||||||
|
Expr::Array(stmts) => {
|
||||||
|
self.scope_stack.push_scope();
|
||||||
|
let mut compiled = self.compile(stmts.clone());
|
||||||
|
let _locals = self.scope_stack.pop_scope().unwrap();
|
||||||
|
// Add prefix and suffix to the compiled items
|
||||||
|
compiled.insert(0, SpInst::new(expr.span().clone(), Inst::BeginArray));
|
||||||
|
compiled.push(SpInst::new(expr.span().clone(), Inst::EndArray));
|
||||||
|
compiled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
0
src/obj/array.rs
Normal file
0
src/obj/array.rs
Normal file
@@ -1,5 +1,6 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
pub mod array;
|
||||||
pub mod bool;
|
pub mod bool;
|
||||||
pub mod builtin;
|
pub mod builtin;
|
||||||
pub mod float;
|
pub mod float;
|
||||||
@@ -8,6 +9,7 @@ pub mod quote;
|
|||||||
pub mod str;
|
pub mod str;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
pub use crate::obj::array::*;
|
||||||
pub use crate::obj::bool::*;
|
pub use crate::obj::bool::*;
|
||||||
pub use crate::obj::builtin::*;
|
pub use crate::obj::builtin::*;
|
||||||
pub use crate::obj::float::*;
|
pub use crate::obj::float::*;
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ pub enum Expr {
|
|||||||
|
|
||||||
/// A quoted expression list.
|
/// A quoted expression list.
|
||||||
Quote(Vec<SpStmt>),
|
Quote(Vec<SpStmt>),
|
||||||
|
|
||||||
|
/// A list of statements that create the items of an array.
|
||||||
|
Array(Vec<SpStmt>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single, finite value.
|
/// A single, finite value.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ apply = @{ "!" }
|
|||||||
assign = { ":" ~ word }
|
assign = { ":" ~ word }
|
||||||
atom = { float | int | assign | word | str | apply }
|
atom = { float | int | assign | word | str | apply }
|
||||||
quote = { "[" ~ stmt* ~ "]" }
|
quote = { "[" ~ stmt* ~ "]" }
|
||||||
|
array = { "{" ~ stmt* ~ "}" }
|
||||||
expr = { atom | quote }
|
expr = { atom | quote }
|
||||||
include = { "%include" ~ str }
|
include = { "%include" ~ str }
|
||||||
stmt = { include | expr }
|
stmt = { include | expr }
|
||||||
|
|||||||
@@ -81,6 +81,11 @@ fn parse_expr(source: &Rc<String>, pair: Pair<Rule>) -> Result<SpExpr> {
|
|||||||
.map(|pair| parse_stmt(source, pair.into_inner().next().unwrap()))
|
.map(|pair| parse_stmt(source, pair.into_inner().next().unwrap()))
|
||||||
.collect::<Result<Vec<_>>>()?,
|
.collect::<Result<Vec<_>>>()?,
|
||||||
),
|
),
|
||||||
|
Rule::array => Expr::Array(
|
||||||
|
pair.into_inner()
|
||||||
|
.map(|pair| parse_stmt(source, pair.into_inner().next().unwrap()))
|
||||||
|
.collect::<Result<Vec<_>>>()?,
|
||||||
|
),
|
||||||
rule => unreachable!("{:?}", rule),
|
rule => unreachable!("{:?}", rule),
|
||||||
};
|
};
|
||||||
let span = Span {
|
let span = Span {
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ pub enum Inst {
|
|||||||
//Dup,
|
//Dup,
|
||||||
/// Applies the top stack value, which should be a macro.
|
/// Applies the top stack value, which should be a macro.
|
||||||
Call,
|
Call,
|
||||||
|
|
||||||
|
/// Begin creating a new array object.
|
||||||
|
BeginArray,
|
||||||
|
|
||||||
|
/// End creating a new array object.
|
||||||
|
EndArray,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SpInst = Spanned<Inst>;
|
pub type SpInst = Spanned<Inst>;
|
||||||
|
|||||||
@@ -295,6 +295,12 @@ impl Machine {
|
|||||||
let value = self.stack_pop()?;
|
let value = self.stack_pop()?;
|
||||||
value.call(Some(inst.span().clone()), self)?;
|
value.call(Some(inst.span().clone()), self)?;
|
||||||
}
|
}
|
||||||
|
Inst::BeginArray => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
Inst::EndArray => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update this frame's PC
|
// Update this frame's PC
|
||||||
|
|||||||
Reference in New Issue
Block a user