mirror of
https://gitlab.cs.washington.edu/fidelp/frustration.git
synced 2024-12-25 21:58:11 +01:00
stack ops
This commit is contained in:
parent
e594cb6298
commit
3aa9c06fd3
1 changed files with 21 additions and 1 deletions
|
@ -56,7 +56,7 @@ struct TableEntry {
|
|||
immediate: bool
|
||||
}
|
||||
|
||||
const PRIMITIVES: [TableEntry; 18] = [
|
||||
const PRIMITIVES: [TableEntry; 21] = [
|
||||
TableEntry {f: ret , name: None, immediate: false},
|
||||
TableEntry {f: lit , name: None, immediate: false},
|
||||
TableEntry {f: add , name: Some(ShortName {bytes: *b"+ ", length: 1}), immediate: false},
|
||||
|
@ -65,6 +65,8 @@ const PRIMITIVES: [TableEntry; 18] = [
|
|||
TableEntry {f: create_ , name: Some(ShortName {bytes: *b"cre", length: 6}), immediate: false},
|
||||
TableEntry {f: div , name: Some(ShortName {bytes: *b"/ ", length: 1}), immediate: false},
|
||||
TableEntry {f: dot , name: Some(ShortName {bytes: *b". ", length: 1}), immediate: false},
|
||||
TableEntry {f: drop , name: Some(ShortName {bytes: *b"dro", length: 4}), immediate: false},
|
||||
TableEntry {f: dup , name: Some(ShortName {bytes: *b"dup", length: 3}), immediate: false},
|
||||
TableEntry {f: dump , name: Some(ShortName {bytes: *b"dum", length: 4}), immediate: false},
|
||||
TableEntry {f: immediate,name: Some(ShortName {bytes: *b"imm", length: 9}), immediate: false},
|
||||
TableEntry {f: lbracket, name: Some(ShortName {bytes: *b"[ ", length: 1}), immediate: true},
|
||||
|
@ -73,6 +75,7 @@ const PRIMITIVES: [TableEntry; 18] = [
|
|||
TableEntry {f: rbracket, name: Some(ShortName {bytes: *b"] ", length: 1}), immediate: false},
|
||||
TableEntry {f: store , name: Some(ShortName {bytes: *b"! ", length: 1}), immediate: false},
|
||||
TableEntry {f: sub , name: Some(ShortName {bytes: *b"- ", length: 1}), immediate: false},
|
||||
TableEntry {f: swap , name: Some(ShortName {bytes: *b"swa", length: 4}), immediate: false},
|
||||
TableEntry {f: tick , name: Some(ShortName {bytes: *b"' ", length: 1}), immediate: false},
|
||||
TableEntry {f: word , name: Some(ShortName {bytes: *b"wor", length: 4}), immediate: false}
|
||||
];
|
||||
|
@ -212,6 +215,23 @@ fn pop(c: &mut Core) -> u16 {
|
|||
return c.dstack[c.tds];
|
||||
}
|
||||
|
||||
fn dup(c: &mut Core) {
|
||||
let val = pop(c);
|
||||
push(c, val);
|
||||
push(c, val);
|
||||
}
|
||||
|
||||
fn swap(c: &mut Core) {
|
||||
let val1 = pop(c);
|
||||
let val2 = pop(c);
|
||||
push(c, val1);
|
||||
push(c, val2);
|
||||
}
|
||||
|
||||
fn drop(c: &mut Core) {
|
||||
let _ = pop(c);
|
||||
}
|
||||
|
||||
fn to_r(c: &mut Core, val: u16) {
|
||||
c.rstack[c.trs] = val;
|
||||
c.trs += 1;
|
||||
|
|
Loading…
Reference in a new issue