Initial commit

This commit is contained in:
Ryan 2017-06-10 11:25:13 -04:00
commit ec13f75d67
6 changed files with 1322 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

37
AICM.lua Normal file
View File

@ -0,0 +1,37 @@
AICM={}
AICM.functions={
getAICMVersion=function(self)
return "1.0.0"
end,
}
function AICM:InitSyntax(obj,name)
obj:debug("Now using the Artificial Intelligence Communication module!")
obj.OnExtendedBlock(self.blockModule)
obj.OnCustomSyntax(self.syntaxModule)
obj:define(self.functions)
end
AICM.syntaxModule=function(self,line)
pVars,mStr=line:match("p%((.-)%)(.+)")
if pVars then
local vRef,vars=pVars:match("(.-):(.+)")
if vars:find(",") then
vars={unpack(vars:split(","))}
else
vars={vars}
end
tab={self:varExists(vRef):match(mStr)} -- self:varExists allows for all internal structures to just work
for i=1,#tab do
if vars[i] then
self._variables[vars[i]]=tab[i]
end
end
self:p() -- requried to progress the script
return {
text=line,
Type="AICMModule"
}
end
end
AICM.blockModule=function(obj,name,t,chunk,filename)
--
end

71
EBIM.lua Normal file
View File

@ -0,0 +1,71 @@
EBIM={}
EBIM.functions={
getEBIMVersion=function(self)
return "1.0.0"
end,
}
EBIM.registry={}
function EBIM:registerEBlock(name,func)
self.registry[name]=func
end
function EBIM:InitSyntax(obj,name)
obj:debug("Now using the Extended Block Interface module!")
obj.OnExtendedBlock(self.blockModule)
obj.OnCustomSyntax(self.syntaxModule)
obj:define(self.functions)
end
EBIM.syntaxModule=function(self,line)
local cmd,args=line:match("(.-) (.+):")
if cmd then
local goal=nil
local _tab={}
for i=self.pos+1,#self._cblock do
if self._cblock[i]=="end"..cmd then
goal=i
break
else
table.insert(_tab,self._cblock[i])
end
end
if goal==nil then
self:pushError("'end"..cmd.."' Expected to close '"..cmd.."'")
end
if EBIM.registry[cmd] then
EBIM.registry[cmd](self,args,_tab)
self.pos=goal+1
else
self:pushError("Unknown command: "..cmd)
end
return {
Type="EBIM-Data",
text=cmd.." Block"
}
else
return
end
end
EBIM.blockModule=function(obj,name,t,chunk,filename)
--print(">: ",obj,name,t,chunk,filename)
end
EBIM:registerEBlock("string",function(self,args,tab)
local str={}
for i=1,#tab do
table.insert(str,tab[i])
end
self:setVariable(args,table.concat(str,"\n"))
end)
EBIM:registerEBlock("list",function(self,args,tab)
local str={}
for i=1,#tab do
table.insert(str,self:varExists(tab[i]))
end
self:setVariable(args,str)
end)
EBIM:registerEBlock("dict",function(self,args,tab)
local str={}
for i=1,#tab do
local a,b=tab[i]:match("(.-):%s*(.+)")
str[a]=self:varExists(b)
end
self:setVariable(args,str)
end)

44
bytecode.lua Normal file
View File

@ -0,0 +1,44 @@
-- In an attempt to speed up my library I will use a virtual machine that runs bytecode
compiler={}
compiler.cmds={ -- list of all of the commands
EVAL="\01", -- evaluate
SPLT="\02", -- split
TRIM="\03", -- trim
VEXT="\04", -- variable exists
ILST="\05", -- is a list
LSTR="\06", -- load string
FCAL="\07", -- Function call
SVAR="\08", -- set variable
LOAD="\09", -- load file
LAOD="\10", -- _load file
DEFN="\11", -- define external functions
HCBK="\12", -- Has c Block
CMBT="\13", -- combine truths
SETB="\14", -- set block
STRT="\15", -- start
PERR="\16", -- push error
PROG="\17", -- progress
PHED="\18", -- parse header
SSLT="\19", -- split string
NEXT="\20", -- next
-- Needs refining... One step at a time right!
}
function compiler:compile(filename) -- compiles the code into bytecode
-- First we load the code but don't run it
local engine=parseManager:load(filename)
-- This captures all of the methods and important info. This also ensures that the compiler and interperter stay in sync!
local bytecodeheader=bin.new() -- header will contain the order of blocks and important flags
local bytecode=bin.newDataBuffer() -- lets leave it at unlimited size because we don't know how long it will need to be
local functions={} -- will be populated with the important methods that must be preloaded
local prebytecode={} -- this contains bytecode that has yet to be sterilized
for blockname,blockdata in pairs(engine._chunks) do
-- lets get some variables ready
local code,_type,nextblock,filename=blockdata[1],blockdata[2],blockdata.next,blockdata.file
-- note nextblock may be nil on 2 condidions. The first is when the leaking flag is disabled and the other is when the block in question was the last block defined
local lines=bin._lines(code)
print("\n["..blockname.."]\n")
for i=1,#lines do
print(lines[i])
end
end
end

1158
init.lua Normal file

File diff suppressed because it is too large Load Diff

10
interpreter.lua Normal file
View File

@ -0,0 +1,10 @@
engine={}
function engine:init(bytecodeFile)
self.code=bin.load(bytecodeFile).data
end
--[[OP-CODES
]]
function engine:run(assessors)
--
end