diff --git a/CoreWords.tl b/CoreWords.tl index 5dfbf3a..a883c77 100644 --- a/CoreWords.tl +++ b/CoreWords.tl @@ -357,6 +357,24 @@ local function forthTo(e: Environment) e.toMode = true end +local function forthValue(e: Environment) + local val = e.activeDataStack:pop() as any + helpers.skipSpaces(e) + local valName = helpers.parseToken(e) + local index = #e.values + 1 + local getValue = function(e: Environment) + e.activeDataStack:push(e.values[index]) + end + local setValue = function(e: Environment) + local newValue = e.activeDataStack:pop() + e.values[index] = newValue + end + defineWord(e.dictionaries[1], valName, getValue, false, setValue) + e.values[index] = val +end + + + local function forth_local_(e: Environment) local localName = e.activeDataStack:pop() as string if localName == "" then @@ -443,6 +461,8 @@ defineWord(CoreWords, "PARSE-NAME", parseName, true) defineWord(CoreWords, "EMPTYS", emptys, true) defineWord(CoreWords, "\"\"", emptys, false) +defineWord(CoreWords, "VALUE", forthValue, false) + defineWord(CoreWords,"<", cmplt, false) defineWord(CoreWords,"<=", cmplte, false) defineWord(CoreWords,"=", cmpe, false) diff --git a/DataStructures.tl b/DataStructures.tl index b046184..8b7ef19 100644 --- a/DataStructures.tl +++ b/DataStructures.tl @@ -53,6 +53,7 @@ local type DataStructures = record toMode: boolean locals: Dictionary localBuffer: {function(integer, Environment)} + values: {any} end end @@ -123,7 +124,8 @@ function Environment:new(input: InputStream, dict: {Dictionary} ): Environment compileState = false, currentDefinition = {}, locals = Dictionary:new(), - localBuffer = {} + localBuffer = {}, + values = {} } as Environment, state_mt) end