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
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)

View File

@ -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