|
|
@ -8,7 +8,7 @@ use crate::asm::parse::arg_parser::TokenParser; |
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_label_str, parse_rd, parse_reg_alias, parse_value}; |
|
|
|
use crate::asm::parse::parse_data::{parse_constant_name, parse_label, parse_label_str, parse_rd, parse_reg_alias, parse_value}; |
|
|
|
use crate::asm::parse::sexp_expect::{expect_any_string_atom}; |
|
|
|
use crate::asm::parse::sexp_expect::{expect_any_string_atom}; |
|
|
|
use crate::asm::patches::ErrWithPos; |
|
|
|
use crate::asm::patches::ErrWithPos; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp}; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp, SleepUnit}; |
|
|
|
use crate::module::ParseRes; |
|
|
|
use crate::module::ParseRes; |
|
|
|
use crate::utils::A; |
|
|
|
use crate::utils::A; |
|
|
|
|
|
|
|
|
|
|
@ -24,9 +24,24 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
BuiltinOp::Halt |
|
|
|
BuiltinOp::Halt |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"sleep" => { |
|
|
|
"uslp" => { |
|
|
|
BuiltinOp::Sleep { |
|
|
|
BuiltinOp::Sleep { |
|
|
|
micros: args.next_rd()?, |
|
|
|
count: args.next_rd()?, |
|
|
|
|
|
|
|
unit_us: SleepUnit::Usec, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"mslp" => { |
|
|
|
|
|
|
|
BuiltinOp::Sleep { |
|
|
|
|
|
|
|
count: args.next_rd()?, |
|
|
|
|
|
|
|
unit_us: SleepUnit::Msec, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sslp" => { |
|
|
|
|
|
|
|
BuiltinOp::Sleep { |
|
|
|
|
|
|
|
count: args.next_rd()?, |
|
|
|
|
|
|
|
unit_us: SleepUnit::Sec, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -126,7 +141,7 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
BuiltinOp::Routine(parse_routine_name(name.0, &name.1)?) |
|
|
|
BuiltinOp::Routine(parse_routine_name(name.0, &name.1)?) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"skip" => { |
|
|
|
"s" => { |
|
|
|
BuiltinOp::Skip(args.next_rd()?) |
|
|
|
BuiltinOp::Skip(args.next_rd()?) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -168,14 +183,14 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"sst" => { |
|
|
|
"stf" => { |
|
|
|
BuiltinOp::StoreStatus { |
|
|
|
BuiltinOp::StoreFlags { |
|
|
|
dst: args.next_wr()?, |
|
|
|
dst: args.next_wr()?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"sld" => { |
|
|
|
"ldf" => { |
|
|
|
BuiltinOp::LoadStatus { |
|
|
|
BuiltinOp::LoadFlags { |
|
|
|
src: args.next_rd()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -224,7 +239,9 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
match op { |
|
|
|
match op { |
|
|
|
BuiltinOp::Nop => sexp::list(&[A("nop")]), |
|
|
|
BuiltinOp::Nop => sexp::list(&[A("nop")]), |
|
|
|
BuiltinOp::Halt => sexp::list(&[A("halt")]), |
|
|
|
BuiltinOp::Halt => sexp::list(&[A("halt")]), |
|
|
|
BuiltinOp::Sleep { micros } => sexp::list(&[A("sleep"), A(micros)]), |
|
|
|
BuiltinOp::Sleep { count: micros, unit_us: SleepUnit::Sec } => sexp::list(&[A("sslp"), A(micros)]), |
|
|
|
|
|
|
|
BuiltinOp::Sleep { count: micros, unit_us: SleepUnit::Msec } => sexp::list(&[A("mslp"), A(micros)]), |
|
|
|
|
|
|
|
BuiltinOp::Sleep { count: micros, unit_us: SleepUnit::Usec } => sexp::list(&[A("uslp"), A(micros)]), |
|
|
|
BuiltinOp::Label(label) => sexp::list(&[A(label)]), |
|
|
|
BuiltinOp::Label(label) => sexp::list(&[A(label)]), |
|
|
|
BuiltinOp::Jump(label) => sexp::list(&[A("j"), A(label)]), |
|
|
|
BuiltinOp::Jump(label) => sexp::list(&[A("j"), A(label)]), |
|
|
|
BuiltinOp::FarLabel(label) => sexp::list(&[A("far"), A(label)]), |
|
|
|
BuiltinOp::FarLabel(label) => sexp::list(&[A("far"), A(label)]), |
|
|
@ -248,7 +265,7 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
BuiltinOp::Routine(name) => sexp::list(&[A("routine"), A(name)]), |
|
|
|
BuiltinOp::Routine(name) => sexp::list(&[A("routine"), A(name)]), |
|
|
|
BuiltinOp::Skip(n) => sexp::list(&[A("skip"), A(n)]), |
|
|
|
BuiltinOp::Skip(n) => sexp::list(&[A("s"), A(n)]), |
|
|
|
BuiltinOp::Barrier { kind, msg } => { |
|
|
|
BuiltinOp::Barrier { kind, msg } => { |
|
|
|
let mut inner = vec![]; |
|
|
|
let mut inner = vec![]; |
|
|
|
match kind { |
|
|
|
match kind { |
|
|
@ -279,8 +296,8 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
} |
|
|
|
} |
|
|
|
BuiltinOp::Delete(obj) => sexp::list(&[A("del"), A(obj)]), |
|
|
|
BuiltinOp::Delete(obj) => sexp::list(&[A("del"), A(obj)]), |
|
|
|
BuiltinOp::Move { dst, src } => sexp::list(&[A("ld"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Move { dst, src } => sexp::list(&[A("ld"), A(dst), A(src)]), |
|
|
|
BuiltinOp::StoreStatus { dst } => sexp::list(&[A("sst"), A(dst)]), |
|
|
|
BuiltinOp::StoreFlags { dst } => sexp::list(&[A("stf"), A(dst)]), |
|
|
|
BuiltinOp::LoadStatus { src } => sexp::list(&[A("sld"), A(src)]) |
|
|
|
BuiltinOp::LoadFlags { src } => sexp::list(&[A("ldf"), A(src)]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -302,26 +319,28 @@ mod test { |
|
|
|
// jump is translated to a skip
|
|
|
|
// jump is translated to a skip
|
|
|
|
("(nop)", "(nop)"), |
|
|
|
("(nop)", "(nop)"), |
|
|
|
("(halt)", "(halt)"), |
|
|
|
("(halt)", "(halt)"), |
|
|
|
("(sleep 1000)", "(sleep 1000)"), |
|
|
|
("(uslp 1000)", "(uslp 1000)"), |
|
|
|
("(sleep 1_0_0_0)", "(sleep 1000)"), |
|
|
|
("(uslp 1_0_0_0)", "(uslp 1000)"), |
|
|
|
("(sleep ' ')", "(sleep 32)"), |
|
|
|
("(uslp ' ')", "(uslp 32)"), |
|
|
|
("(sleep '\\n')", "(sleep 10)"), |
|
|
|
("(uslp '\\n')", "(uslp 10)"), |
|
|
|
("(sleep 0b111)", "(sleep 7)"), |
|
|
|
("(uslp 0b111)", "(uslp 7)"), |
|
|
|
("(sleep 0xab_cd)", "(sleep 43981)"), |
|
|
|
("(uslp 0xab_cd)", "(uslp 43981)"), |
|
|
|
("(sleep #ab_cd)", "(sleep 43981)"), |
|
|
|
("(uslp #ab_cd)", "(uslp 43981)"), |
|
|
|
|
|
|
|
("(mslp 1000)", "(mslp 1000)"), |
|
|
|
|
|
|
|
("(sslp 1000)", "(sslp 1000)"), |
|
|
|
("(:x)", "(:x)"), |
|
|
|
("(:x)", "(:x)"), |
|
|
|
("(j :x)", "(j :x)"), |
|
|
|
("(j :x)", "(j :x)"), |
|
|
|
("(:#7)", "(:#7)"), |
|
|
|
("(:#7)", "(:#7)"), |
|
|
|
("(j :#7)", "(j :#7)"), |
|
|
|
("(j :#7)", "(j :#7)"), |
|
|
|
("(fj :x)", "(fj :x)"), |
|
|
|
("(fj :x)", "(fj :x)"), |
|
|
|
("(skip 0)", "(skip 0)"), |
|
|
|
("(s 0)", "(s 0)"), |
|
|
|
("(skip r0)", "(skip r0)"), |
|
|
|
("(s r0)", "(s r0)"), |
|
|
|
("(sym banana r0)(unsym banana)(sym banana r1)(skip banana)", "(skip r1)"), |
|
|
|
("(sym banana r0)(unsym banana)(sym banana r1)(s banana)", "(s r1)"), |
|
|
|
("(def foo 123)(skip foo)", "(skip 123)"), |
|
|
|
("(def foo 123)(s foo)", "(s 123)"), |
|
|
|
("(def foo 123)(undef foo)(def foo 444)(skip foo)", "(skip 444)"), |
|
|
|
("(def foo 123)(undef foo)(def foo 444)(s foo)", "(s 444)"), |
|
|
|
("(def foo -777)(def bar foo)(skip bar)", "(skip -777)"), |
|
|
|
("(def foo -777)(def bar foo)(s bar)", "(s -777)"), |
|
|
|
("(skip -10)", "(skip -10)"), |
|
|
|
("(s -10)", "(s -10)"), |
|
|
|
("(skip -10000)", "(skip -10000)"), |
|
|
|
("(s -10000)", "(s -10000)"), |
|
|
|
("(call funcname)", "(call funcname)"), |
|
|
|
("(call funcname)", "(call funcname)"), |
|
|
|
("(call funcname 13)", "(call funcname 13)"), |
|
|
|
("(call funcname 13)", "(call funcname 13)"), |
|
|
|
("(sym haf r0)\ |
|
|
|
("(sym haf r0)\ |
|
|
@ -348,8 +367,8 @@ mod test { |
|
|
|
("(ld r0 r0)", "(ld r0 r0)"), |
|
|
|
("(ld r0 r0)", "(ld r0 r0)"), |
|
|
|
("(ld r0 156)", "(ld r0 156)"), |
|
|
|
("(ld r0 156)", "(ld r0 156)"), |
|
|
|
("(ld _ -32767)", "(ld _ -32767)"), |
|
|
|
("(ld _ -32767)", "(ld _ -32767)"), |
|
|
|
("(sst r0)", "(sst r0)"), |
|
|
|
("(stf r0)", "(stf r0)"), |
|
|
|
("(sld r0)", "(sld r0)"), |
|
|
|
("(ldf r0)", "(ldf r0)"), |
|
|
|
("(far :label)", "(far :label)"), |
|
|
|
("(far :label)", "(far :label)"), |
|
|
|
("(del @r5)", "(del @r5)"), |
|
|
|
("(del @r5)", "(del @r5)"), |
|
|
|
("(sym cat r0)(del @cat)", "(del @r0)"), |
|
|
|
("(sym cat r0)(del @cat)", "(del @r0)"), |
|
|
|