implement code hygiene fixes

This commit is contained in:
Starfflame 2021-05-11 01:55:13 -05:00
parent ca797f9e49
commit d86cec723e
5 changed files with 18 additions and 53 deletions

6
CoreWords.tl Normal file
View File

@ -0,0 +1,6 @@
local Dict = require("Dictionary")
local Stack = require("Stack")

View File

@ -1,10 +1,8 @@
local state = require("ForthState")
local wordinfo = require("ForthWordInfo")
local ForthDictionary = {}
local State = require("State")
local WordInfo = require("WordInfo")
global type Dictionary = record
local type Dictionary = record
contents: {string: WordInfo}
end
@ -18,4 +16,4 @@ end
return ForthDictionary
return Dictionary

View File

@ -1,8 +1,5 @@
local ForthStack = {}
global type Stack = record
local type Stack = record
contents: {any}
top: number
push: function(Stack, any)
@ -27,25 +24,5 @@ end
-- operations
function ForthStack.add(stack: Stack)
local a: any =stack:pop()
local b: any=stack:pop()
if a is number and b is number then
local c=a+b
stack:push(c)
else
error("invalid operands for add operation!")
end
end
function ForthStack.dot(s: Stack)
print(s:pop())
end
local s = Stack:new()
s:push(1)
s:push(4)
ForthStack.add(s)
print(ForthStack.dot(s))
return ForthStack
return Stack

View File

@ -1,10 +1,9 @@
local ForthStack = require("ForthStack")
local Stack = require("Stack")
local ForthState = {}
global type State = record
local type State = record
dataStacks: {Stack}
compilerStack: Stack
activeDataStack: Stack
@ -34,17 +33,8 @@ function State:changeActiveDataStack(stackIndex: number)
self.activeDataStack = self.dataStacks[stackIndex]
end
local state = State:new()
local stck = Stack:new()
stck:push(1)
stck:push(2)
stck:push(8)
state:addDataStack(stck)
ForthStack.add(state.dataStacks[1])
print(ForthStack.dot(state.dataStacks[1]))
return ForthState
return State

View File

@ -1,9 +1,6 @@
local state = require("ForthState")
local State = require("State")
local ForthWordInfo = {}
global type WordInfo = record
local type WordInfo = record
func: function(State)
immediate: boolean
end
@ -12,9 +9,6 @@ function WordInfo:new(funct: State, imm: boolean): WordInfo
return setmetatable({func = funct, immediate = imm} as WordInfo, wordi_mt)
end
local s = State:new()
print(s)
return ForthWordInfo
return WordInfo