2021-05-13 05:23:42 +00:00
|
|
|
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
|
2021-05-13 09:19:54 +00:00
|
|
|
local helpers = require("CoreHelpers")
|
2021-05-19 03:43:19 +00:00
|
|
|
local interpreters = require("Interpreters")
|
2021-05-13 09:19:54 +00:00
|
|
|
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
|
2021-05-19 03:43:19 +00:00
|
|
|
local standardInputRefill = helpers.standardInputRefill
|
|
|
|
local innerInterpreter, outerInterpreter = interpreters.inner, interpreters.outer
|
|
|
|
|
|
|
|
|
2021-05-12 08:32:25 +00:00
|
|
|
|
2021-05-19 03:43:19 +00:00
|
|
|
local machineEnvironment = Environment:new()
|
2021-05-13 05:23:42 +00:00
|
|
|
local standardInputStream = istream:new(standardInputRefill)
|
|
|
|
|
2021-05-14 08:29:54 +00:00
|
|
|
machineEnvironment.activeInputStream = standardInputStream
|
|
|
|
machineEnvironment.activeDataStack = Stack:new()
|
2021-05-19 03:43:19 +00:00
|
|
|
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
|
|
|
|
2021-05-19 03:43:19 +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
|
|
|
|
|
2021-05-19 03:43:19 +00:00
|
|
|
innerInterpreter(machineEnvironment)
|
2021-05-13 05:23:42 +00:00
|
|
|
|