Massive changes to this.
Now compiles code then runs it! Total engine overhaul
This commit is contained in:
parent
f1c7fde65d
commit
f180fef6fb
@ -1,37 +0,0 @@
|
||||
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
|
||||
@ -1,71 +0,0 @@
|
||||
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)
|
||||
@ -1,44 +0,0 @@
|
||||
-- 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
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,10 +0,0 @@
|
||||
engine={}
|
||||
function engine:init(bytecodeFile)
|
||||
self.code=bin.load(bytecodeFile).data
|
||||
end
|
||||
--[[OP-CODES
|
||||
|
||||
]]
|
||||
function engine:run(assessors)
|
||||
--
|
||||
end
|
||||
310
parseManager/standardDefine.lua
Normal file
310
parseManager/standardDefine.lua
Normal file
@ -0,0 +1,310 @@
|
||||
parseManager:define{
|
||||
print=function(self,...)
|
||||
print(...)
|
||||
end,
|
||||
error=function(self,msg)
|
||||
self:pushError(msg,"\2")
|
||||
end,
|
||||
QUIT=function()
|
||||
os.exit()
|
||||
end,
|
||||
JUMP=function(self,block)
|
||||
if self.chunks[block] then
|
||||
self.chunks[block].pos=1
|
||||
self.currentChunk=self.chunks[block]
|
||||
else
|
||||
self:pushError("Attempt to jump to a non existing block:","\2")
|
||||
end
|
||||
end,
|
||||
SKIP=function(self,n)
|
||||
if type(n)~="number" then self:pushError("Number expected got: "..type(n),"SKIP( ? )") end
|
||||
self.currentChunk.pos=self.currentChunk.pos+n
|
||||
end,
|
||||
GOTO=function(self,label)
|
||||
if self.currentChunk.labels[label] then
|
||||
self.currentChunk.pos=self.currentChunk.labels[label]
|
||||
else
|
||||
self:pushError("Attempt to goto a non existing label:","\2")
|
||||
end
|
||||
end,
|
||||
GOTOE=function(self,label)
|
||||
local chunks=self.chunks
|
||||
for i,v in pairs(chunks) do
|
||||
if chunks[i].labels[label] then
|
||||
self.currentChunk=chunks[i]
|
||||
self.currentChunk.pos=chunks[i].labels[label]
|
||||
return
|
||||
end
|
||||
end
|
||||
self:pushError("Attempt to goto a non existing label:","\2")
|
||||
end,
|
||||
ADD=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return self.lastCall+a
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return a+b
|
||||
else
|
||||
self:pushError("Invalid Arguments!","ADD("..tostring(a)..","..tostring(b)..")")
|
||||
end
|
||||
end,
|
||||
SUB=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return self.lastCall-a
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return a-b
|
||||
else
|
||||
self:pushError("Invalid Arguments!","SUB("..tostring(a)..","..tostring(b)..")")
|
||||
end
|
||||
end,
|
||||
MUL=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return self.lastCall*a
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return a*b
|
||||
else
|
||||
self:pushError("Invalid Arguments!","MUL("..tostring(a)..","..tostring(b)..")")
|
||||
end
|
||||
end,
|
||||
DIV=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return self.lastCall/a
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return a/b
|
||||
else
|
||||
self:pushError("Invalid Arguments!","DIV("..tostring(a)..","..tostring(b)..")")
|
||||
end
|
||||
end,
|
||||
POW=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return self.lastCall^a
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return a^b
|
||||
else
|
||||
self:pushError("Invalid Arguments!","POW("..tostring(a)..","..tostring(b)..")")
|
||||
end
|
||||
end,
|
||||
sqrt=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.sqrt(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.sqrt(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
cos=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.cos(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.cos(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
sin=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.sin(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.sin(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
tan=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.tan(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.tan(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
log=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.log(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.log(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
acos=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.acos(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.acos(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
tanh=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.tanh(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.tanh(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
deg=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.deg(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.deg(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
cosh=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.cosh(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.cosh(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
sinh=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.sinh(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.sinh(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
randomseed=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.randomseed(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.randomseed(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
ceil=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.ceil(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.ceil(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
floor=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.floor(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.floor(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
rad=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.rad(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.rad(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
abs=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.abs(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.abs(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
asin=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.asin(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.asin(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
log10=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.log10(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.log10(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
atan2=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.atan2(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.atan2(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
exp=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.exp(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.exp(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
atan=function(self,a)
|
||||
if type(self.lastCall)=="number" then
|
||||
return math.atan(self.lastCall)
|
||||
elseif type(a)=="number" then
|
||||
return math.atan(a)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
max=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return max(self.lastCall,a)
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return max(a,b)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
mod=function(self,a,b)
|
||||
if type(self.lastCall)=="number" and type(a)=="number" then
|
||||
return mod(self.lastCall,a)
|
||||
elseif type(a)=="number" and type(b)=="number" then
|
||||
return mod(a,b)
|
||||
else
|
||||
self:pushError("Invalid Arguments!","\2")
|
||||
end
|
||||
end,
|
||||
COMPARE=function(self,v1,v2,sym)
|
||||
if sym==nil then self:pushError("Unexpected Error has occured!",":(") end
|
||||
if sym=="==" then
|
||||
if v1==v2 then return 1 else return 0 end
|
||||
elseif sym==">=" then
|
||||
if v1>=v2 then return 1 else return 0 end
|
||||
elseif sym=="<=" then
|
||||
if v1<=v2 then return 1 else return 0 end
|
||||
elseif sym==">" then
|
||||
if v1>v2 then return 1 else return 0 end
|
||||
elseif sym=="<" then
|
||||
if v1<v2 then return 1 else return 0 end
|
||||
elseif sym=="~=" or sym=="!=" then
|
||||
if v1~=v2 then return 1 else return 0 end
|
||||
else
|
||||
self:pushError("Invalid Symbol!",sym)
|
||||
end
|
||||
end,
|
||||
CSIM=function(self,i)
|
||||
if i==0 then
|
||||
self.methods.SKIP(self,1)
|
||||
end
|
||||
end,
|
||||
print=function(self,...)
|
||||
print(...)
|
||||
end
|
||||
}
|
||||
@ -1,10 +1,13 @@
|
||||
-- 감사합니다
|
||||
ENTRY START
|
||||
[START]{
|
||||
a=10>1 -- bit shift
|
||||
a=10>1
|
||||
b=10<1
|
||||
"test: $a$ $b$"
|
||||
test["name"]="Ryan"
|
||||
name=test["name"]
|
||||
"Hi $test[name]$! $name$"
|
||||
testfunc("hello",(5!),15@1)
|
||||
test("hello",sqrt(5!),(15@1)/2)
|
||||
}
|
||||
[@:construct]{ -- get % out of 100
|
||||
ret=l/(r/100)
|
||||
@ -29,6 +32,9 @@ ENTRY START
|
||||
return(ret)
|
||||
::end::
|
||||
}
|
||||
[test:function(a,b,c)]{
|
||||
"$a$ $b$ $c$"
|
||||
}
|
||||
-- You dont have too many symbols left to use though. For now a symbol is only 1 char long so you are limited
|
||||
[fact:function(n)]{
|
||||
count=1
|
||||
@ -46,7 +52,7 @@ ENTRY START
|
||||
--Bind the fact function to the symbol '!'
|
||||
[!:construct]{
|
||||
env=fact(l)
|
||||
ret=ret<-env
|
||||
ret=env["ret"]
|
||||
return(ret)
|
||||
}
|
||||
[NOVAR]{
|
||||
|
||||
32
parsetest3.txt
Normal file
32
parsetest3.txt
Normal file
@ -0,0 +1,32 @@
|
||||
ENABLE leaking
|
||||
[TEST]{
|
||||
"Jump was successful!"
|
||||
--GOTO("HERE")
|
||||
}
|
||||
[START]{
|
||||
"Test 1:"
|
||||
t=15
|
||||
test=2*100
|
||||
"test = $test$"
|
||||
c=5
|
||||
::HERE::
|
||||
a,b="sdf",true
|
||||
"a,b,c = $a$ $b$ $c$"
|
||||
food="yum"
|
||||
test=true
|
||||
stop=21
|
||||
"food = $food$"
|
||||
"test = $test$"
|
||||
"stop = $stop$"
|
||||
"Test 2:"
|
||||
count=0
|
||||
::loop::
|
||||
"Count = $count$"
|
||||
count=count+1
|
||||
if count>10 then GOTO("end")|GOTO("loop")
|
||||
::end::
|
||||
"Done!"
|
||||
QUIT()
|
||||
}
|
||||
|
||||
-- (count==stop and name=="bob") ? GOTO(end) : GOTO(loop)
|
||||
7
test.lua
7
test.lua
@ -2,7 +2,6 @@ package.path="?/init.lua;lua/?/init.lua;lua/?.lua;"..package.path
|
||||
require("bin")
|
||||
require("multi.all")
|
||||
require("parseManager")
|
||||
--~ require("Library")
|
||||
require("bit")
|
||||
parseManager:define({
|
||||
rshift=function(self,a,b)
|
||||
@ -12,11 +11,11 @@ parseManager:define({
|
||||
return bit.lshift(a,b)
|
||||
end,
|
||||
testfunc=function(self,a,b,c)
|
||||
print("> "..tostring(a).." "..tostring(b).." "..tostring(c))
|
||||
print(tostring(a).." "..tostring(b).." "..tostring(c))
|
||||
end
|
||||
})
|
||||
test=parseManager:load("parsetest2.txt")
|
||||
t=test:start()
|
||||
test=parseManager:load("parsetest3.txt")
|
||||
t=test:start("START")
|
||||
while true do
|
||||
if t.Type=="text" then
|
||||
print(t.text)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user