Browse Source

implement reworked variable definition behavior

feature/defvar-rework
mark 10 months ago
parent
commit
a928eeb1dd
2 changed files with 5 additions and 5 deletions
  1. +4
    -4
      dictionary.js
  2. +1
    -1
      memeforth.js

+ 4
- 4
dictionary.js View File

@@ -269,7 +269,7 @@ const fetch = state => {
*/
const defvar = state => {
let addr = 0;
let varName = state.stack.pop();
let varName = state.tokens.shift();

if (typeof varName !== "string") {
const err = new TypeError("Variable names must be strings.");
@@ -289,8 +289,8 @@ const defvar = state => {

const defArr = state => {
let startAddr = 0;
let varName = state.stack.pop();
let size = state.stack.pop();
let varName = state.tokens.shift();
let size = parseInt(state.tokens.shift());

if (typeof varName !== "string") {
const err = new TypeError("Variable names must be strings.");
@@ -685,7 +685,7 @@ const dictionary = {
SLICE: strSlice,
I: "_I @".split(" "),
SPLIT: strSplit,
JOIN: "DELIM DEFVAR DELIM ! 1 - 0 DO DELIM @ SWAP CONCAT CONCAT LOOP".split(
JOIN: "DEFVAR DELIM DELIM ! 1 - 0 DO DELIM @ SWAP CONCAT CONCAT LOOP".split(
" "
),
SPACE: [" "],


+ 1
- 1
memeforth.js View File

@@ -82,7 +82,7 @@ const doLoop = state => {

if (!state.words["_I"]) {
const oldTokens = state.tokens;
const init = `_I DEFVAR ${begin} _I !`.split(" ");
const init = `DEFVAR _I ${begin} _I !`.split(" ");
newState = state;
newState.tokens = init;
state = interpret(newState);


Loading…
Cancel
Save