Working reading
This commit is contained in:
@@ -24,6 +24,5 @@ main() {
|
|||||||
increment(3)
|
increment(3)
|
||||||
|
|
||||||
PRINT $counter, -> $link
|
PRINT $counter, -> $link
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
init() {
|
||||||
|
|
||||||
|
$link -> $counter
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
increment(x) {
|
||||||
|
|
||||||
|
ADD $counter, %x, $counter
|
||||||
|
MOV $counter, %r
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
|
||||||
|
increment(5)
|
||||||
|
increment(3)
|
||||||
|
|
||||||
|
PRINT $counter, -> $link
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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
@@ -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!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user