BETRAYED by the unified primitive/dict table, see TODOs

This commit is contained in:
psf 2022-03-26 11:24:22 -07:00
parent d40b9d17d5
commit 30cca5288e

View file

@ -173,6 +173,7 @@ fn step(c: &mut Core) {
fn inner(c: &mut Core) {
loop {
step(c);
println!("ip={} trs={}", c.ip, c.trs);
if c.trs == 0 {
break;
}
@ -185,7 +186,10 @@ fn ret(c: &mut Core) {
}
c.ip = from_r(c);
}
// TODO: i dont think this actually fixed anything, 'cos it affected both the primitive
// and the dictionary entry.
// having separate tables would probably make more sense
// lit shouldn't be a primitive anyway! just a dictionary entry.
fn ret_(c: &mut Core) {
ret(c);
ret(c);
@ -217,10 +221,11 @@ fn load(c: &mut Core) {
push(c, u16::from_le_bytes(c.ram[addr..=addr+1].try_into().unwrap()));
}
// TODO: again the nesting of primitive inside dictionary entry is acting fucky
fn lit(c: &mut Core) {
let retaddr = from_r(c) as usize;
push(c, u16::from_le_bytes(c.ram[retaddr..=retaddr+1].try_into().unwrap()));
to_r(c, retaddr as u16 + 2);
to_r(c, (retaddr as u16) + 2);
}
fn add(c: &mut Core) {
@ -275,7 +280,15 @@ fn outer(c: &mut Core, s: &str) {
None => {
let val = t.parse::<u16>();
match val {
Ok(n) => { push(c, n) }
Ok(n) => {
match(c.state) {
State::Interpreting => { push(c, n) }
State::Compiling => {
comma(c, 65530); // lit. TODO make robust
comma(c, n);
}
}
}
Err(_) => { if t != "" { println!("{}?", t) }}
}
}