forth-stuff/ForthMachine.tl

35 lines
1.2 KiB
Plaintext

local CoreWords = require("CoreWords")
local ds = require("DataStructures")
local istream = require("InputStream")
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
local reset = helpers.reset
local Pointer = ds.Pointer
local standardInputRefill = helpers.standardInputRefill
local innerInterpreter, outerInterpreter = interpreters.inner, interpreters.outer
local machineEnvironment = Environment:new()
local standardInputStream = istream:new(standardInputRefill)
machineEnvironment.activeInputStream = standardInputStream
machineEnvironment.activeDataStack = Stack:new()
machineEnvironment.returnStack = Stack:new()
table.insert(machineEnvironment.dictionaries, CoreWords)
local interpreterInstructions = {}
table.insert(interpreterInstructions, outerInterpreter)
table.insert(interpreterInstructions, reset)
local startPointer = Pointer:new()
startPointer.referant = interpreterInstructions
machineEnvironment.instructionPointer = startPointer
innerInterpreter(machineEnvironment)