|
|
@ -11,6 +11,7 @@ use crate::asm::patches::ErrWithPos; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp, SleepUnit, LdsValue}; |
|
|
|
use crate::builtin::defs::{Barrier, BuiltinOp, SleepUnit, LdsValue}; |
|
|
|
use crate::module::ParseRes; |
|
|
|
use crate::module::ParseRes; |
|
|
|
use crate::utils::A; |
|
|
|
use crate::utils::A; |
|
|
|
|
|
|
|
use crate::asm::data::{Rd, RdData, RdObj}; |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> { |
|
|
|
pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> { |
|
|
|
let pcx = args.pcx; |
|
|
|
let pcx = args.pcx; |
|
|
@ -183,35 +184,35 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"ld" => { |
|
|
|
"ld" => { |
|
|
|
BuiltinOp::Move { |
|
|
|
BuiltinOp::Load { |
|
|
|
dst: args.next_wr()?, |
|
|
|
dst: args.next_wr()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"ld32" => { |
|
|
|
"ld32" => { |
|
|
|
BuiltinOp::Move32 { |
|
|
|
BuiltinOp::Load32 { |
|
|
|
dst: args.next_rdwr()?, |
|
|
|
dst: args.next_rdwr()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"ld16" => { |
|
|
|
"ld16" => { |
|
|
|
BuiltinOp::Move16 { |
|
|
|
BuiltinOp::Load16 { |
|
|
|
dst: args.next_rdwr()?, |
|
|
|
dst: args.next_rdwr()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"ld8" => { |
|
|
|
"ld8" => { |
|
|
|
BuiltinOp::Move8 { |
|
|
|
BuiltinOp::Load8 { |
|
|
|
dst: args.next_rdwr()?, |
|
|
|
dst: args.next_rdwr()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"ldn" => { |
|
|
|
"ldn" => { |
|
|
|
BuiltinOp::MoveMultiple { |
|
|
|
BuiltinOp::LoadMultiple { |
|
|
|
dst: args.next_wr()?, |
|
|
|
dst: args.next_wr()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
src: args.next_rd()?, |
|
|
|
count: args.next_rd()?, |
|
|
|
count: args.next_rd()?, |
|
|
@ -225,6 +226,22 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
Sexp::Atom(Atom::QS(s), _) => { |
|
|
|
Sexp::Atom(Atom::QS(s), _) => { |
|
|
|
LdsValue::Chars(s) |
|
|
|
LdsValue::Chars(s) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tok @ Sexp::Atom(Atom::S(_), _) => { |
|
|
|
|
|
|
|
let pos = tok.pos().clone(); |
|
|
|
|
|
|
|
match parse_rd(tok, args.pcx)? { |
|
|
|
|
|
|
|
Rd(RdData::ImmObject(v)) => { |
|
|
|
|
|
|
|
LdsValue::Handle(RdObj::Imm(v)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Rd(RdData::RegObject(r)) => { |
|
|
|
|
|
|
|
LdsValue::Handle(RdObj::Reg(r)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_ => { |
|
|
|
|
|
|
|
return Err(CrsnError::Parse( |
|
|
|
|
|
|
|
"Expected a handle, quoted string, or a tuple of values".into(), |
|
|
|
|
|
|
|
pos)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
Sexp::List(list, _) => { |
|
|
|
Sexp::List(list, _) => { |
|
|
|
let mut vals = vec![]; |
|
|
|
let mut vals = vec![]; |
|
|
|
for v in list { |
|
|
|
for v in list { |
|
|
@ -233,11 +250,13 @@ pub(crate) fn parse_op<'a>(op_pos: &SourcePosition, keyword: &str, mut args: Tok |
|
|
|
LdsValue::Values(vals) |
|
|
|
LdsValue::Values(vals) |
|
|
|
} |
|
|
|
} |
|
|
|
other => { |
|
|
|
other => { |
|
|
|
return Err(CrsnError::Parse("Expected quoted string or a tuple of values".into(), other.pos().clone())); |
|
|
|
return Err(CrsnError::Parse( |
|
|
|
|
|
|
|
"Expected a handle, quoted string, or a tuple of values".into(), |
|
|
|
|
|
|
|
other.pos().clone())); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BuiltinOp::MoveSequence { dst, value } |
|
|
|
BuiltinOp::LoadSequence { dst, value } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
"xch" => { |
|
|
|
"xch" => { |
|
|
@ -359,15 +378,15 @@ 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::Load { dst, src } => sexp::list(&[A("ld"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Move32 { dst, src } => sexp::list(&[A("ld32"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Load32 { dst, src } => sexp::list(&[A("ld32"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Move16 { dst, src } => sexp::list(&[A("ld16"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Load16 { dst, src } => sexp::list(&[A("ld16"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Move8 { dst, src } => sexp::list(&[A("ld8"), A(dst), A(src)]), |
|
|
|
BuiltinOp::Load8 { dst, src } => sexp::list(&[A("ld8"), A(dst), A(src)]), |
|
|
|
BuiltinOp::MoveMultiple { dst, src, count } => sexp::list(&[A("ldn"), A(dst), A(src), A(count)]), |
|
|
|
BuiltinOp::LoadMultiple { dst, src, count } => sexp::list(&[A("ldn"), A(dst), A(src), A(count)]), |
|
|
|
BuiltinOp::Exchange { a, b } => sexp::list(&[A("xch"), A(a), A(b)]), |
|
|
|
BuiltinOp::Exchange { a, b } => sexp::list(&[A("xch"), A(a), A(b)]), |
|
|
|
BuiltinOp::StoreFlags { dst } => sexp::list(&[A("stf"), A(dst)]), |
|
|
|
BuiltinOp::StoreFlags { dst } => sexp::list(&[A("stf"), A(dst)]), |
|
|
|
BuiltinOp::LoadFlags { src } => sexp::list(&[A("ldf"), A(src)]), |
|
|
|
BuiltinOp::LoadFlags { src } => sexp::list(&[A("ldf"), A(src)]), |
|
|
|
BuiltinOp::MoveSequence { dst, value } => { |
|
|
|
BuiltinOp::LoadSequence { dst, value } => { |
|
|
|
match value { |
|
|
|
match value { |
|
|
|
LdsValue::Values(vals) => { |
|
|
|
LdsValue::Values(vals) => { |
|
|
|
let mut vals: Vec<_> = vals.iter().map(A).collect(); |
|
|
|
let mut vals: Vec<_> = vals.iter().map(A).collect(); |
|
|
@ -378,6 +397,9 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp { |
|
|
|
LdsValue::Chars(str) => { |
|
|
|
LdsValue::Chars(str) => { |
|
|
|
sexp::list(&[A("lds"), A(dst), atom_qs(str)]) |
|
|
|
sexp::list(&[A("lds"), A(dst), atom_qs(str)]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
LdsValue::Handle(h) => { |
|
|
|
|
|
|
|
sexp::list(&[A("lds"), A(dst), A(h)]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|