crappy code
This commit is contained in:
parent
c5833e094e
commit
f432c05216
|
@ -1,34 +1,16 @@
|
||||||
local CoreWords = require("CoreWords")
|
|
||||||
local ds = require("DataStructures")
|
|
||||||
local istream = require("InputStream")
|
local istream = require("InputStream")
|
||||||
local Stack, Dictionary, WordInfo, Environment = ds.Stack, ds.Dictionary, ds.WordInfo, ds.Environment
|
|
||||||
local helpers = require("CoreHelpers")
|
local helpers = require("CoreHelpers")
|
||||||
local interpreters = require("Interpreters")
|
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 standardInputRefill = helpers.standardInputRefill
|
||||||
local innerInterpreter, outerInterpreter = interpreters.inner, interpreters.outer
|
local oneReadInputStream = helpers.oneReadInputStream
|
||||||
|
local fileStream = helpers.fileStream
|
||||||
|
|
||||||
|
|
||||||
|
--interpreters.start(fileStream("codetest.txt"))
|
||||||
|
|
||||||
|
|
||||||
|
interpreters.start(istream:new(standardInputRefill))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,30 @@ local ds = require("DataStructures")
|
||||||
local Stack, Dictionary, WordInfo, Environment = ds.Stack, ds.Dictionary, ds.WordInfo, ds.Environment
|
local Stack, Dictionary, WordInfo, Environment = ds.Stack, ds.Dictionary, ds.WordInfo, ds.Environment
|
||||||
local helpers = require("CoreHelpers")
|
local helpers = require("CoreHelpers")
|
||||||
local isNumber, skipWhitespace, parseToken = helpers.isNumber, helpers.skipWhitespace, helpers.parseToken
|
local isNumber, skipWhitespace, parseToken = helpers.isNumber, helpers.skipWhitespace, helpers.parseToken
|
||||||
|
local istream = require("InputStream")
|
||||||
|
local CoreWords = require("CoreWords")
|
||||||
|
local Pointer = ds.Pointer
|
||||||
local type Interpreters = record
|
local type Interpreters = record
|
||||||
inner: function(Environment)
|
inner: function(Environment)
|
||||||
outer: function(Environment)
|
outer: function(Environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Interpreters.start(input: istream)
|
||||||
|
local machineEnvironment = Environment:new()
|
||||||
|
machineEnvironment.activeInputStream = input
|
||||||
|
machineEnvironment.activeDataStack = Stack:new()
|
||||||
|
machineEnvironment.returnStack = Stack:new()
|
||||||
|
|
||||||
|
table.insert(machineEnvironment.dictionaries, CoreWords)
|
||||||
|
local interpreterInstructions = {}
|
||||||
|
table.insert(interpreterInstructions, Interpreters.outer)
|
||||||
|
table.insert(interpreterInstructions, helpers.reset)
|
||||||
|
local startPointer = Pointer:new()
|
||||||
|
startPointer.referant = interpreterInstructions
|
||||||
|
machineEnvironment.instructionPointer = startPointer
|
||||||
|
Interpreters.inner(machineEnvironment)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Interpreters.outer(env: Environment)
|
function Interpreters.outer(env: Environment)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
1 2 + .
|
||||||
|
55 2 + .
|
||||||
|
77 2 - .
|
||||||
|
10 DUP * .
|
||||||
|
78 1 - 5 * .
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue