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 State = require("State")
local wordinfo = require("ForthWordInfo") local WordInfo = require("WordInfo")
local ForthDictionary = {}
local type Dictionary = record
global type Dictionary = record
contents: {string: WordInfo} contents: {string: WordInfo}
end end
@ -18,4 +16,4 @@ end
return ForthDictionary return Dictionary

View File

@ -1,8 +1,5 @@
local ForthStack = {}
local type Stack = record
global type Stack = record
contents: {any} contents: {any}
top: number top: number
push: function(Stack, any) push: function(Stack, any)
@ -27,25 +24,5 @@ end
-- operations -- 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 Stack
return ForthStack

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} dataStacks: {Stack}
compilerStack: Stack compilerStack: Stack
activeDataStack: Stack activeDataStack: Stack
@ -34,17 +33,8 @@ function State:changeActiveDataStack(stackIndex: number)
self.activeDataStack = self.dataStacks[stackIndex] self.activeDataStack = self.dataStacks[stackIndex]
end 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 = {} local type WordInfo = record
global type WordInfo = record
func: function(State) func: function(State)
immediate: boolean immediate: boolean
end end
@ -12,9 +9,6 @@ function WordInfo:new(funct: State, imm: boolean): WordInfo
return setmetatable({func = funct, immediate = imm} as WordInfo, wordi_mt) return setmetatable({func = funct, immediate = imm} as WordInfo, wordi_mt)
end end
return WordInfo
local s = State:new()
print(s)
return ForthWordInfo