add word for VALUE

This commit is contained in:
Starfflame 2021-07-19 22:15:55 -05:00
parent fa9daaebb0
commit b31e6cffab
2 changed files with 23 additions and 1 deletions

View File

@ -357,6 +357,24 @@ local function forthTo(e: Environment)
e.toMode = true e.toMode = true
end 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 function forth_local_(e: Environment)
local localName = e.activeDataStack:pop() as string local localName = e.activeDataStack:pop() as string
if localName == "" then if localName == "" then
@ -443,6 +461,8 @@ defineWord(CoreWords, "PARSE-NAME", parseName, true)
defineWord(CoreWords, "EMPTYS", emptys, true) defineWord(CoreWords, "EMPTYS", emptys, true)
defineWord(CoreWords, "\"\"", emptys, false) defineWord(CoreWords, "\"\"", emptys, false)
defineWord(CoreWords, "VALUE", forthValue, false)
defineWord(CoreWords,"<", cmplt, false) defineWord(CoreWords,"<", cmplt, false)
defineWord(CoreWords,"<=", cmplte, false) defineWord(CoreWords,"<=", cmplte, false)
defineWord(CoreWords,"=", cmpe, false) defineWord(CoreWords,"=", cmpe, false)

View File

@ -53,6 +53,7 @@ local type DataStructures = record
toMode: boolean toMode: boolean
locals: Dictionary locals: Dictionary
localBuffer: {function(integer, Environment)} localBuffer: {function(integer, Environment)}
values: {any}
end end
end end
@ -123,7 +124,8 @@ function Environment:new(input: InputStream, dict: {Dictionary} ): Environment
compileState = false, compileState = false,
currentDefinition = {}, currentDefinition = {},
locals = Dictionary:new(), locals = Dictionary:new(),
localBuffer = {} localBuffer = {},
values = {}
} as Environment, } as Environment,
state_mt) state_mt)
end end