mirror of
https://gitlab.cs.washington.edu/fidelp/frustration.git
synced 2024-12-25 21:58:11 +01:00
user-callable return-stack juggling words that work correctly
This commit is contained in:
parent
3aa9c06fd3
commit
72dae5a249
1 changed files with 27 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
use std::io;
|
||||
//use std::process;
|
||||
use std::process;
|
||||
use std::convert::TryInto;
|
||||
|
||||
//const CORE_SIZE: usize = 65408
|
||||
|
@ -56,7 +56,7 @@ struct TableEntry {
|
|||
immediate: bool
|
||||
}
|
||||
|
||||
const PRIMITIVES: [TableEntry; 21] = [
|
||||
const PRIMITIVES: [TableEntry; 24] = [
|
||||
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},
|
||||
|
@ -68,15 +68,18 @@ const PRIMITIVES: [TableEntry; 21] = [
|
|||
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: from_r_ , name: Some(ShortName {bytes: *b"r> ", length: 2}), 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},
|
||||
TableEntry {f: load , name: Some(ShortName {bytes: *b"@ ", length: 1}), immediate: false},
|
||||
TableEntry {f: mul , name: Some(ShortName {bytes: *b"* ", length: 1}), immediate: false},
|
||||
TableEntry {f: ret_ , name: Some(ShortName {bytes: *b"ret", length: 3}), immediate: false},
|
||||
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: to_r_ , name: Some(ShortName {bytes: *b">r ", length: 2}), immediate: false},
|
||||
TableEntry {f: word , name: Some(ShortName {bytes: *b"wor", length: 4}), immediate: false}
|
||||
];
|
||||
|
||||
|
@ -237,11 +240,25 @@ fn to_r(c: &mut Core, val: u16) {
|
|||
c.trs += 1;
|
||||
}
|
||||
|
||||
fn to_r_(c: &mut Core) {
|
||||
let r1 = from_r(c);
|
||||
let r2 = pop(c);
|
||||
to_r(c, r2);
|
||||
to_r(c, r1);
|
||||
}
|
||||
|
||||
fn from_r(c: &mut Core) -> u16 {
|
||||
c.trs -= 1;
|
||||
return c.rstack[c.trs];
|
||||
}
|
||||
|
||||
fn from_r_(c: &mut Core) {
|
||||
let r1 = from_r(c);
|
||||
let r2 = from_r(c);
|
||||
to_r(c, r1);
|
||||
push(c, r2);
|
||||
}
|
||||
|
||||
fn call(c: &mut Core) {
|
||||
to_r(c, c.ip);
|
||||
c.ip = pop(c);
|
||||
|
@ -249,9 +266,17 @@ fn call(c: &mut Core) {
|
|||
|
||||
// note: this is an inline primitive, not a dict entry
|
||||
fn ret(c: &mut Core) {
|
||||
if c.trs == 0 {
|
||||
std::process::exit(0);
|
||||
}
|
||||
c.ip = from_r(c);
|
||||
}
|
||||
|
||||
fn ret_(c: &mut Core) {
|
||||
_ = from_r(c);
|
||||
ret(c);
|
||||
}
|
||||
|
||||
// --- Inner interpreter ---
|
||||
|
||||
fn fetch(c: &mut Core) -> u16 {
|
||||
|
|
Loading…
Reference in a new issue