add a print builtin/opcode
This commit is contained in:
parent
c497b90a16
commit
bf2b16c30f
|
@ -76,6 +76,7 @@ pub enum Op {
|
|||
At,
|
||||
|
||||
Not,
|
||||
Print,
|
||||
// Inc,
|
||||
// Dec,
|
||||
// Gt,
|
||||
|
@ -169,6 +170,7 @@ impl std::fmt::Display for Op {
|
|||
EmptyString => "empty_string",
|
||||
ConcatStrings => "concat_strings",
|
||||
Stringify => "stringify",
|
||||
Print => "print",
|
||||
|
||||
Eq => "eq",
|
||||
Add => "add",
|
||||
|
@ -214,7 +216,7 @@ impl Chunk {
|
|||
| PanicIfNoMatch | ResetMatch | GetKey | PanicNoWhen | PanicNoMatch | TypeOf
|
||||
| Duplicate | Decrement | Truncate | Noop | LoadTuple | LoadList | Eq | Add | Sub
|
||||
| Mult | Div | Unbox | BoxStore | Assert | Get | At | Not | Panic | EmptyString
|
||||
| ConcatStrings | Stringify | MatchType | Return | Match => {
|
||||
| ConcatStrings | Stringify | MatchType | Return | Match | Print => {
|
||||
println!("{i:04}: {op}")
|
||||
}
|
||||
Constant | MatchConstant => {
|
||||
|
@ -277,6 +279,7 @@ fn get_builtin(name: &str, arity: usize) -> Option<Op> {
|
|||
("get", 2) => Some(Op::Get),
|
||||
("at", 2) => Some(Op::At),
|
||||
("not", 1) => Some(Op::Not),
|
||||
("print!", 1) => Some(Op::Print),
|
||||
|
||||
_ => None,
|
||||
}
|
||||
|
@ -859,7 +862,6 @@ impl Compiler {
|
|||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
// TODO: implement longer synthetic expressions
|
||||
for (term, _) in rest {
|
||||
match term {
|
||||
Keyword(str) => {
|
||||
|
|
|
@ -76,9 +76,11 @@ pub fn run(src: &'static str) {
|
|||
pub fn main() {
|
||||
env::set_var("RUST_BACKTRACE", "1");
|
||||
let src = "
|
||||
fn foo () -> fn () -> fn () -> #{:foo :bar}
|
||||
fn bang! () -> print! (:bang)
|
||||
|
||||
foo () () () :foo
|
||||
bang! ()
|
||||
bang! ()
|
||||
bang! ()
|
||||
";
|
||||
run(src);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user