basic bytecode to file
Can now save bytecode to file. Will change in the future so dont use yet
This commit is contained in:
parent
ecf3762853
commit
3af881e1a9
@ -16,6 +16,7 @@ parseManager.currentHandle=nil
|
|||||||
parseManager.currentHandleName=nil
|
parseManager.currentHandleName=nil
|
||||||
parseManager.state = {}
|
parseManager.state = {}
|
||||||
parseManager.active = true
|
parseManager.active = true
|
||||||
|
parseManager.usings = {}
|
||||||
function parseManager:mainRunner(block)
|
function parseManager:mainRunner(block)
|
||||||
local t = self:next(block)
|
local t = self:next(block)
|
||||||
if not t then return nil end
|
if not t then return nil end
|
||||||
@ -105,6 +106,7 @@ function parseManager:DISABLE(fn)
|
|||||||
end
|
end
|
||||||
function parseManager:USING(fn,name)
|
function parseManager:USING(fn,name)
|
||||||
local m = require("parseManager."..fn)
|
local m = require("parseManager."..fn)
|
||||||
|
self.usings[#self.usings]={fn,name}
|
||||||
if not m then
|
if not m then
|
||||||
self:pushError(fn.." was not found as an import that can be used!")
|
self:pushError(fn.." was not found as an import that can be used!")
|
||||||
else
|
else
|
||||||
@ -114,6 +116,52 @@ function parseManager:USING(fn,name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--[[
|
||||||
|
self.VERSION = 5
|
||||||
|
self.chunks={}
|
||||||
|
self.stats={warnings = true}
|
||||||
|
self.stack={}
|
||||||
|
self.cFuncs={}
|
||||||
|
self.mainENV={_VERSION = self.VERSION}
|
||||||
|
self.__INTERNAL = {}
|
||||||
|
self.currentENV=self.mainENV
|
||||||
|
self.entry="START"
|
||||||
|
self.methods={}
|
||||||
|
self.lastCall=nil
|
||||||
|
self.currentHandle=nil
|
||||||
|
self.currentHandleName=nil
|
||||||
|
self.state = {}
|
||||||
|
self.active = true
|
||||||
|
self.usings = {}
|
||||||
|
]]
|
||||||
|
function parseManager:compileToFile(path,topath)
|
||||||
|
local file = bin.new()
|
||||||
|
local state = self:load(path)
|
||||||
|
file:addBlock(state.VERSION)
|
||||||
|
file:addBlock(state.chunks)
|
||||||
|
file:addBlock(state.stats)
|
||||||
|
-- file:addBlock(state.cFuncs)
|
||||||
|
-- file:addBlock(state.__INTERNAL)
|
||||||
|
file:addBlock(#state.entry,1)
|
||||||
|
file:addBlock(state.entry)
|
||||||
|
file:addBlock(state.usings)
|
||||||
|
file:tofile(topath)
|
||||||
|
return state
|
||||||
|
end
|
||||||
|
function parseManager:loadCompiled(path)
|
||||||
|
local file = bin.load(path)
|
||||||
|
local c = {}
|
||||||
|
setmetatable(c,parseManager)
|
||||||
|
c.VERSION = file:getBlock("n",4)
|
||||||
|
c.chunks = file:getBlock("t")
|
||||||
|
c.stats = file:getBlock("t")
|
||||||
|
-- c.cFuncs = file:getBlock("t")
|
||||||
|
-- c.__INTERNAL = file:getBlock("t")
|
||||||
|
local size = file:getBlock("n",1)
|
||||||
|
c.entry = file:getBlock("s",size)
|
||||||
|
c.usings = file:getBlock("t")
|
||||||
|
return c
|
||||||
|
end
|
||||||
function parseManager:load(path,c)
|
function parseManager:load(path,c)
|
||||||
local c = c
|
local c = c
|
||||||
if not c then
|
if not c then
|
||||||
@ -1146,7 +1194,15 @@ function parseManager:parseHeader(data)
|
|||||||
self:pushError("Attempt to round a non number!")
|
self:pushError("Attempt to round a non number!")
|
||||||
end
|
end
|
||||||
elseif dat:find("%[") then
|
elseif dat:find("%[") then
|
||||||
if not type(self.currentENV[dat])=="table" then
|
if type(self.currentENV[dat:match("(.-)%[")])=="string" then
|
||||||
|
if dat:find(":") then
|
||||||
|
local var,inwards = dat:match("(.-)%[(.+)%]")
|
||||||
|
local ind = parseManager.split(inwards,":")
|
||||||
|
if #ind==2 then
|
||||||
|
return self.currentENV[dat:match("(.-)%[")]:sub(ind[1],ind[2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif not type(self.currentENV[dat])=="table" then
|
||||||
self:pushError("Attempt to index a non table object!")
|
self:pushError("Attempt to index a non table object!")
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
|
|||||||
10
rps.dms
10
rps.dms
@ -16,17 +16,17 @@ ENTRY START
|
|||||||
list3["s"]="scissors"
|
list3["s"]="scissors"
|
||||||
::gameloop::
|
::gameloop::
|
||||||
cpus_mov=random(1,3)
|
cpus_mov=random(1,3)
|
||||||
cpus_move=$list[cpus_mov]$
|
cpus_move=list[cpus_mov]
|
||||||
player_move = getInput("Enter 'r' 'p' or 's': ")
|
player_move = getInput("Enter 'r' 'p' or 's': ")
|
||||||
if player_move=="r" or player_move=="p" or player_move=="s" then SKIP(0)|GOTO("gameloop")
|
if player_move=="r" or player_move=="p" or player_move=="s" then SKIP(0)|GOTO("gameloop")
|
||||||
a=$list2[cpus_mov]$
|
a=list2[cpus_mov]
|
||||||
b=$list3[player_move]$
|
b=list3[player_move]
|
||||||
if player_move==cpus_move then print("We both played $b$, no one won...")|SKIP(0)
|
if player_move==cpus_move then print("We both played $b$, no one won...")|SKIP(0)
|
||||||
if cpus_move=="r" and player_move=="s" then print("I won $name$, you lose! You know $a$ beats $b$")|SKIP(0)
|
if cpus_move=="r" and player_move=="s" then print("I won $name$, you lose! You know $a$ beats $b$")|SKIP(0)
|
||||||
if cpus_move=="p" and player_move=="r" then print("I won $name$, you lose! You know $a$ beats $b$")|SKIP(0)
|
if cpus_move=="p" and player_move=="r" then print("I won $name$, you lose! You know $a$ beats $b$")|SKIP(0)
|
||||||
if cpus_move=="s" and player_move=="p" then print("I won $name$, you lose! You know $a$ beats $b$")|SKIP(0)
|
if cpus_move=="s" and player_move=="p" then print("I won $name$, you lose! You know $a$ beats $b$")|SKIP(0)
|
||||||
b=$list2[cpus_mov]$
|
b=list2[cpus_mov]
|
||||||
a=$list3[player_move]$
|
a=list3[player_move]
|
||||||
if player_move=="r" and cpus_move=="s" then print("$name$ you won wow! I guess my $b$ was no match for your $a$")|SKIP(0)
|
if player_move=="r" and cpus_move=="s" then print("$name$ you won wow! I guess my $b$ was no match for your $a$")|SKIP(0)
|
||||||
if player_move=="p" and cpus_move=="r" then print("$name$ you won wow! I guess my $b$ was no match for your $a$")|SKIP(0)
|
if player_move=="p" and cpus_move=="r" then print("$name$ you won wow! I guess my $b$ was no match for your $a$")|SKIP(0)
|
||||||
if player_move=="s" and cpus_move=="p" then print("$name$ you won wow! I guess my $b$ was no match for your $a$")|SKIP(0)
|
if player_move=="s" and cpus_move=="p" then print("$name$ you won wow! I guess my $b$ was no match for your $a$")|SKIP(0)
|
||||||
|
|||||||
50
test.dms
50
test.dms
@ -1,41 +1,19 @@
|
|||||||
ENTRY MAIN
|
ENTRY MAIN
|
||||||
USING extendedDefine
|
USING extendedDefine
|
||||||
VERSION 4.1 //The version that nested functions was introduced
|
VERSION 4.1
|
||||||
[MAIN]{
|
[MAIN]{
|
||||||
test = [1,2,3,4,5,6,7,8,9,10]
|
test = [1,2,3,4,5,6,7,8,9,10]
|
||||||
t=0
|
t=0
|
||||||
for i = 1,10 <
|
test2 = "Hello"
|
||||||
"Choice Test: $test[1]$" <
|
str = $test2[1:-2]$
|
||||||
"A" setGlobalVar("t",1)
|
print(str)
|
||||||
"B" continue()
|
// for i = 1,10 <
|
||||||
"C" setGlobalVar("t",3)
|
// "Choice Test: $test[1]$" <
|
||||||
>
|
// "A" setGlobalVar("t",1)
|
||||||
>
|
// "B" continue()
|
||||||
::leave::
|
// "C" setGlobalVar("t",3)
|
||||||
print("t = $t$ i = $i$")
|
// >
|
||||||
}
|
// >
|
||||||
// [hmm:function(a,b)]{
|
// ::leave::
|
||||||
// return a+b
|
// print("t = $t$ i = $i$")
|
||||||
// }
|
}
|
||||||
// [A1]{
|
|
||||||
// "At: 1"
|
|
||||||
// }
|
|
||||||
// [A2]{
|
|
||||||
// "At: 2"
|
|
||||||
// }
|
|
||||||
// [A3]{
|
|
||||||
// "At: 3"
|
|
||||||
// }
|
|
||||||
// [TEST]{
|
|
||||||
// newThread("TEST2")
|
|
||||||
// ::loop::
|
|
||||||
// print("Hello!")
|
|
||||||
// sleep(.5)
|
|
||||||
// GOTO("loop")
|
|
||||||
// }
|
|
||||||
// [TEST2]{
|
|
||||||
// ::loop::
|
|
||||||
// print("Hi!")
|
|
||||||
// sleep(1)
|
|
||||||
// GOTO("loop")
|
|
||||||
// }
|
|
||||||
77
test.lua
77
test.lua
@ -2,11 +2,9 @@ package.path="?/init.lua;lua/?/init.lua;lua/?.lua;"..package.path
|
|||||||
local bin = require("bin")
|
local bin = require("bin")
|
||||||
local multi = require("multi")
|
local multi = require("multi")
|
||||||
require("parseManager")
|
require("parseManager")
|
||||||
test=parseManager:load("test.dms")--load("StoryTest/init.dms")
|
test=parseManager:compileToFile("test.dms","test.dmsc")--load("StoryTest/init.dms")
|
||||||
|
--~ test = parseManager:loadCompiled("test.dmsc")
|
||||||
print(test:dump())
|
print(test:dump())
|
||||||
|
|
||||||
|
|
||||||
--Code would happen here anyway
|
|
||||||
t=test:next()
|
t=test:next()
|
||||||
while t do
|
while t do
|
||||||
if t.Type=="text" then
|
if t.Type=="text" then
|
||||||
@ -30,7 +28,7 @@ while t do
|
|||||||
cm=tonumber(io.read())
|
cm=tonumber(io.read())
|
||||||
t=test:next(nil,cm)
|
t=test:next(nil,cm)
|
||||||
elseif t.Type=="end" then
|
elseif t.Type=="end" then
|
||||||
if t.text=="leaking" then -- go directly to the block right under the current block if it exists
|
if t.text=="leaking" then
|
||||||
t=test:next()
|
t=test:next()
|
||||||
else
|
else
|
||||||
os.exit()
|
os.exit()
|
||||||
@ -41,72 +39,3 @@ while t do
|
|||||||
t=test:next()
|
t=test:next()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--[[
|
|
||||||
MAIN:
|
|
||||||
1:
|
|
||||||
Type: assign
|
|
||||||
vals:
|
|
||||||
1: 1
|
|
||||||
vars:
|
|
||||||
1: x
|
|
||||||
2:
|
|
||||||
Type: label
|
|
||||||
pos: 2
|
|
||||||
label: FORA
|
|
||||||
3:
|
|
||||||
Type: fwor
|
|
||||||
Func: print
|
|
||||||
args:
|
|
||||||
1: x
|
|
||||||
2: y
|
|
||||||
4:
|
|
||||||
Func: ADD
|
|
||||||
Type: fwr
|
|
||||||
vars:
|
|
||||||
1: x
|
|
||||||
args:
|
|
||||||
1: x
|
|
||||||
2: 1
|
|
||||||
5:
|
|
||||||
Type: assign
|
|
||||||
vals:
|
|
||||||
vars:
|
|
||||||
6:
|
|
||||||
Type: fwr
|
|
||||||
vars:
|
|
||||||
1: L$
|
|
||||||
Func: COMPARE
|
|
||||||
args:
|
|
||||||
1: x
|
|
||||||
2: 11
|
|
||||||
3: ==
|
|
||||||
7:
|
|
||||||
Type: fwor
|
|
||||||
Func: CSIM
|
|
||||||
args:
|
|
||||||
1: L$
|
|
||||||
8:
|
|
||||||
Type: fwor
|
|
||||||
Func: GOTO
|
|
||||||
args:
|
|
||||||
1: FORENDA
|
|
||||||
path: test.dms
|
|
||||||
pos: 1
|
|
||||||
11:
|
|
||||||
Type: text
|
|
||||||
text: Tests
|
|
||||||
labels:
|
|
||||||
FORA: 2
|
|
||||||
FORENDA: 10
|
|
||||||
type: BLOCK
|
|
||||||
10:
|
|
||||||
Type: label
|
|
||||||
pos: 10
|
|
||||||
label: FORENDA
|
|
||||||
name: MAIN
|
|
||||||
9:
|
|
||||||
Type: fwor
|
|
||||||
Func: GOTO
|
|
||||||
args:
|
|
||||||
1: FORA
|
|
||||||
]]
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user