forked from MightyPork/crsn
add "swap" instr, document buffer ops
This commit is contained in:
+17
-25
@@ -12,40 +12,32 @@ pub(crate) fn parse<'a>(_pos: &SourcePosition, keyword: &str, mut args: TokenPar
|
||||
Ok(ParseRes::ext(match keyword {
|
||||
"mkbf" => {
|
||||
let dst = args.next_wr()?;
|
||||
let len = if args.have_more() {
|
||||
args.next_rd()?
|
||||
} else {
|
||||
Rd::immediate(0)
|
||||
};
|
||||
BufOps::New { dst, value: BufValue::Zeros(len) }
|
||||
}
|
||||
|
||||
"mkbfv" => {
|
||||
let dst = args.next_wr()?;
|
||||
|
||||
let next = args.next_or_err()?;
|
||||
|
||||
match next {
|
||||
Sexp::Atom(Atom::QS(s), _) => {
|
||||
BufOps::New {
|
||||
dst,
|
||||
value: BufValue::Chars(s),
|
||||
}
|
||||
let value = match args.next() {
|
||||
None => {
|
||||
BufValue::Zeros(Rd::immediate(0))
|
||||
}
|
||||
Sexp::List(list, _) => {
|
||||
Some(tok @ Sexp::Atom(Atom::S(_), _)) |
|
||||
Some(tok @ Sexp::Atom(Atom::I(_), _)) |
|
||||
Some(tok @ Sexp::Atom(Atom::U(_), _)) => {
|
||||
BufValue::Zeros(parse_rd(tok, args.pcx)?)
|
||||
}
|
||||
Some(Sexp::Atom(Atom::QS(s), _)) => {
|
||||
BufValue::Chars(s)
|
||||
}
|
||||
Some(Sexp::List(list, _)) => {
|
||||
let mut vals = vec![];
|
||||
for v in list {
|
||||
vals.push(parse_rd(v, args.pcx)?);
|
||||
}
|
||||
BufOps::New {
|
||||
dst,
|
||||
value: BufValue::Values(vals),
|
||||
}
|
||||
BufValue::Values(vals)
|
||||
}
|
||||
other => {
|
||||
Some(other) => {
|
||||
return Err(CrsnError::Parse("Expected quoted string or a tuple of values".into(), other.pos().clone()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BufOps::New { dst, value }
|
||||
}
|
||||
|
||||
"bfrd" => {
|
||||
|
||||
Reference in New Issue
Block a user