diff --git a/README.md b/README.md index 0a85d8a..a43d4d0 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,5 @@ main() { increment(3) PRINT $counter, -> $link - } ``` diff --git a/example.forge b/example.forge new file mode 100644 index 0000000..7cfcae6 --- /dev/null +++ b/example.forge @@ -0,0 +1,21 @@ +init() { + + $link -> $counter + +} + +increment(x) { + + ADD $counter, %x, $counter + MOV $counter, %r + +} + +main() { + + increment(5) + increment(3) + + PRINT $counter, -> $link + +} \ No newline at end of file diff --git a/examples/emulator.rs b/examples/emulator.rs index 263bca8..17172b9 100644 --- a/examples/emulator.rs +++ b/examples/emulator.rs @@ -1,7 +1,11 @@ +use std::path::Path; + use archforge::runtime::Runtime; fn main() { let mut runtime = Runtime::new(); + runtime.execute_script(Path::new("example.forge")); + runtime.call_function("main", vec![]); } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 65552c3..0708179 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -116,9 +116,7 @@ fn parse_operand(pair: Pair) -> Operand { match pair.as_rule() { Rule::number => Operand::Number(pair.as_str().parse().unwrap()), - Rule::global_reg | Rule::local_reg => Operand::Reg(parse_reg(pair)), - - Rule::reg => Operand::Reg(parse_reg(pair.into_inner().next().unwrap())), + Rule::reg | Rule::global_reg | Rule::local_reg => Operand::Reg(parse_reg(pair)), Rule::pointer_expr => { let inner = pair.into_inner().next().unwrap(); @@ -135,6 +133,8 @@ fn parse_reg(pair: Pair) -> Reg { Rule::local_reg => Reg::Local(pair.as_str()[1..].to_string()), + Rule::reg => parse_reg(pair.into_inner().next().unwrap()), + _ => unreachable!(), } }