Working reading

This commit is contained in:
2026-03-13 23:50:03 +01:00
parent 0ad745c6d5
commit af5e7d26f8
4 changed files with 28 additions and 4 deletions
-1
View File
@@ -24,6 +24,5 @@ main() {
increment(3) increment(3)
PRINT $counter, -> $link PRINT $counter, -> $link
} }
``` ```
+21
View File
@@ -0,0 +1,21 @@
init() {
$link -> $counter
}
increment(x) {
ADD $counter, %x, $counter
MOV $counter, %r
}
main() {
increment(5)
increment(3)
PRINT $counter, -> $link
}
+4
View File
@@ -1,7 +1,11 @@
use std::path::Path;
use archforge::runtime::Runtime; use archforge::runtime::Runtime;
fn main() { fn main() {
let mut runtime = Runtime::new(); let mut runtime = Runtime::new();
runtime.execute_script(Path::new("example.forge"));
runtime.call_function("main", vec![]); runtime.call_function("main", vec![]);
} }
+3 -3
View File
@@ -116,9 +116,7 @@ fn parse_operand(pair: Pair<Rule>) -> Operand {
match pair.as_rule() { match pair.as_rule() {
Rule::number => Operand::Number(pair.as_str().parse().unwrap()), Rule::number => Operand::Number(pair.as_str().parse().unwrap()),
Rule::global_reg | Rule::local_reg => Operand::Reg(parse_reg(pair)), Rule::reg | Rule::global_reg | Rule::local_reg => Operand::Reg(parse_reg(pair)),
Rule::reg => Operand::Reg(parse_reg(pair.into_inner().next().unwrap())),
Rule::pointer_expr => { Rule::pointer_expr => {
let inner = pair.into_inner().next().unwrap(); let inner = pair.into_inner().next().unwrap();
@@ -135,6 +133,8 @@ fn parse_reg(pair: Pair<Rule>) -> Reg {
Rule::local_reg => Reg::Local(pair.as_str()[1..].to_string()), Rule::local_reg => Reg::Local(pair.as_str()[1..].to_string()),
Rule::reg => parse_reg(pair.into_inner().next().unwrap()),
_ => unreachable!(), _ => unreachable!(),
} }
} }