From 053f3c09a23df7c865323bc8ed44e9b89883c95f Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Fri, 9 Sep 2022 14:54:23 +0200 Subject: [PATCH] Add pick word --- henceforth/examples/test.fth | 3 +- henceforth/src/lib/compiler/instruction.rs | 67 +++++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/henceforth/examples/test.fth b/henceforth/examples/test.fth index 302576a..9994f74 100644 --- a/henceforth/examples/test.fth +++ b/henceforth/examples/test.fth @@ -1 +1,2 @@ -1 2 over debug \ No newline at end of file +1 2 debug +1 pick debug diff --git a/henceforth/src/lib/compiler/instruction.rs b/henceforth/src/lib/compiler/instruction.rs index 5f011b5..3ec7704 100644 --- a/henceforth/src/lib/compiler/instruction.rs +++ b/henceforth/src/lib/compiler/instruction.rs @@ -162,7 +162,57 @@ impl compiler::Compilable for Instruct arg: None, }, ]), - Instruction::Pick => Ok(vec![]), + Instruction::Pick => Ok(vec![ + hence::parser::ast::Node::Call { + name: "tsr".to_string(), + arg: Some(hence::arg::Arg::Variable("CORE_REG_SP".to_string())), + }, + hence::parser::ast::Node::Call { + name: "tlr".to_string(), + arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())), + }, + hence::parser::ast::Node::MacroCall { + name: "std_ld".to_string(), + args: vec![], + }, + hence::parser::ast::Node::Call { + name: "tlr".to_string(), + arg: Some(hence::arg::Arg::Variable("CORE_REG_B".to_string())), + }, + hence::parser::ast::Node::MacroCall { + name: "std_alu".to_string(), + args: vec![hence::arg::Arg::Variable("CORE_ALU_SUB".to_string())], + }, + hence::parser::ast::Node::Call { + name: "tlr".to_string(), + arg: Some(hence::arg::Arg::Variable("CORE_REG_A".to_string())), + }, + hence::parser::ast::Node::MacroCall { + name: "std_rset".to_string(), + args: vec![ + hence::arg::Arg::Variable("CORE_REG_B".to_string()), + hence::arg::Arg::BinaryExpression { + left: Box::new(hence::arg::Arg::Variable( + "CORE_MEM_PRG_END".to_string(), + )), + right: Box::new(hence::arg::Arg::Number(2)), + op: hence::arg::BinaryExpressionOperator::Sub, + }, + ], + }, + hence::parser::ast::Node::MacroCall { + name: "std_alu".to_string(), + args: vec![hence::arg::Arg::Variable("CORE_ALU_ADD".to_string())], + }, + hence::parser::ast::Node::Call { + name: "get".to_string(), + arg: None, + }, + hence::parser::ast::Node::Call { + name: "tls".to_string(), + arg: None, + }, + ]), Instruction::Dup => Ok(vec![ hence::parser::ast::Node::Call { name: "tss".to_string(), @@ -246,7 +296,20 @@ impl compiler::Compilable for Instruct Instruction::I => Ok(vec![]), Instruction::J => Ok(vec![]), Instruction::Tuck => Ok(vec![]), - Instruction::Fetch => Ok(vec![]), + Instruction::Fetch => Ok(vec![ + hence::parser::ast::Node::MacroCall { + name: "std_ld".to_string(), + args: vec![], + }, + hence::parser::ast::Node::Call { + name: "get".to_string(), + arg: None, + }, + hence::parser::ast::Node::Call { + name: "tls".to_string(), + arg: None, + }, + ]), Instruction::FetchPrint => Ok(vec![]), Instruction::Store => Ok(vec![]), Instruction::PlusStore => Ok(vec![]),