surround routines by far jump across

floats
Ondřej Hruška 4 years ago
parent e0cc1973ba
commit b06ef50acd
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 8
      crsn/src/asm/instr/flatten.rs
  2. 2
      crsn/src/runtime/program.rs
  3. 11
      examples/proc_skip.csn
  4. 1
      examples/stacks.csn

@ -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)
}

@ -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]
}

@ -0,0 +1,11 @@
(
(ld r0 1)
; the procedure is surrounded by a jump and a label
(proc foo
(nop)
(ret)
)
(ld r0 2)
)

@ -11,5 +11,4 @@
(cmp r1 1 (ne? (fault)))
(drop @r0)
(halt)
)

Loading…
Cancel
Save