surround routines by far jump across

This commit is contained in:
2020-10-04 21:26:06 +02:00
parent e0cc1973ba
commit b06ef50acd
4 changed files with 18 additions and 4 deletions
+6 -2
View File
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::{AtomicU32, Ordering};
use crate::asm::data::{Rd, RdData};
use crate::asm::data::literal::{Label, Value};
@@ -63,7 +63,10 @@ impl Flatten for Vec<Box<dyn Flatten>> {
impl Flatten for Routine {
fn flatten(self: Box<Self>, label_num: &AtomicU32) -> Result<Vec<Op>, CrsnError> {
let mut ops = vec![
let skip_label = Label::Numbered(label_num.fetch_add(1, Ordering::Relaxed));
let mut ops : Vec<Op> = vec![
BuiltinOp::FarJump(skip_label.clone()).into(),
BuiltinOp::Barrier(Some(format!("Routine \"{}\" start", self.name).into())).into(),
BuiltinOp::Routine(self.name.clone()).into(),
];
@@ -71,6 +74,7 @@ impl Flatten for Routine {
ops.extend(self.body.flatten(label_num)?);
ops.push(BuiltinOp::Barrier(Some(format!("Routine \"{}\" end", self.name).into())).into());
ops.push(BuiltinOp::FarLabel(skip_label).into());
numbered_labels_to_skips(ops)
}
+1 -1
View File
@@ -50,7 +50,7 @@ impl Program {
/// Read a program instruction at address
pub fn read(&self, addr: Addr) -> &Op {
if addr.0 >= self.ops.len() as u64 {
&Op::BuiltIn(BuiltinOp::Nop)
&Op::BuiltIn(BuiltinOp::Halt)
} else {
&self.ops[addr.0 as usize]
}
+11
View File
@@ -0,0 +1,11 @@
(
(ld r0 1)
; the procedure is surrounded by a jump and a label
(proc foo
(nop)
(ret)
)
(ld r0 2)
)
-1
View File
@@ -11,5 +11,4 @@
(cmp r1 1 (ne? (fault)))
(drop @r0)
(halt)
)