From 3aa9c06fd37cb0e2a5c4d3aaa1a05ad24ee06420 Mon Sep 17 00:00:00 2001 From: psf Date: Sun, 27 Mar 2022 00:15:39 -0700 Subject: [PATCH] stack ops --- frustration.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/frustration.rs b/frustration.rs index 4861248..63d87ba 100644 --- a/frustration.rs +++ b/frustration.rs @@ -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;