forth-stuff/ForthMachine.tl

35 lines
1.2 KiB
Plaintext
Raw Normal View History

local CoreWords = require("CoreWords")
local ds = require("DataStructures")
local istream = require("InputStream")
2021-05-14 08:29:54 +00:00
local Stack, Dictionary, WordInfo, Environment = ds.Stack, ds.Dictionary, ds.WordInfo, ds.Environment
local helpers = require("CoreHelpers")
local interpreters = require("Interpreters")
local isNumber, skipWhitespace, parseToken = helpers.isNumber, helpers.skipWhitespace, helpers.parseToken
2021-05-18 01:59:46 +00:00
local reset = helpers.reset
local Pointer = ds.Pointer
local standardInputRefill = helpers.standardInputRefill
local innerInterpreter, outerInterpreter = interpreters.inner, interpreters.outer
2021-05-12 08:32:25 +00:00
local machineEnvironment = Environment:new()
local standardInputStream = istream:new(standardInputRefill)
2021-05-14 08:29:54 +00:00
machineEnvironment.activeInputStream = standardInputStream
machineEnvironment.activeDataStack = Stack:new()
machineEnvironment.returnStack = Stack:new()
2021-05-14 08:29:54 +00:00
table.insert(machineEnvironment.dictionaries, CoreWords)
2021-05-12 08:32:25 +00:00
local interpreterInstructions = {}
table.insert(interpreterInstructions, outerInterpreter)
table.insert(interpreterInstructions, reset)
2021-05-18 01:59:46 +00:00
local startPointer = Pointer:new()
startPointer.referant = interpreterInstructions
machineEnvironment.instructionPointer = startPointer
innerInterpreter(machineEnvironment)