From 3af881e1a9bf2c3c0bb580a6ddb2599ae38557b6 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Mon, 1 Apr 2019 07:45:17 -0400 Subject: [PATCH] basic bytecode to file Can now save bytecode to file. Will change in the future so dont use yet --- parseManager/init.lua | 58 ++++++++++++++++++++++++++++++- rps.dms | 10 +++--- test.dms | 50 ++++++++------------------- test.dmsc | Bin 0 -> 830 bytes test.lua | 77 ++---------------------------------------- test.luac | Bin 0 -> 1866 bytes 6 files changed, 79 insertions(+), 116 deletions(-) create mode 100644 test.dmsc create mode 100644 test.luac diff --git a/parseManager/init.lua b/parseManager/init.lua index 967aa2d..ac2ea94 100644 --- a/parseManager/init.lua +++ b/parseManager/init.lua @@ -16,6 +16,7 @@ parseManager.currentHandle=nil parseManager.currentHandleName=nil parseManager.state = {} parseManager.active = true +parseManager.usings = {} function parseManager:mainRunner(block) local t = self:next(block) if not t then return nil end @@ -105,6 +106,7 @@ function parseManager:DISABLE(fn) end function parseManager:USING(fn,name) local m = require("parseManager."..fn) + self.usings[#self.usings]={fn,name} if not m then self:pushError(fn.." was not found as an import that can be used!") else @@ -114,6 +116,52 @@ function parseManager:USING(fn,name) 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) local c = c if not c then @@ -1146,7 +1194,15 @@ function parseManager:parseHeader(data) self:pushError("Attempt to round a non number!") end 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!") return else diff --git a/rps.dms b/rps.dms index 806f303..d40b8fb 100644 --- a/rps.dms +++ b/rps.dms @@ -16,17 +16,17 @@ ENTRY START list3["s"]="scissors" ::gameloop:: cpus_mov=random(1,3) - cpus_move=$list[cpus_mov]$ + cpus_move=list[cpus_mov] 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") - a=$list2[cpus_mov]$ - b=$list3[player_move]$ + a=list2[cpus_mov] + b=list3[player_move] 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=="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) - b=$list2[cpus_mov]$ - a=$list3[player_move]$ + b=list2[cpus_mov] + 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=="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) diff --git a/test.dms b/test.dms index 929243f..71e356b 100644 --- a/test.dms +++ b/test.dms @@ -1,41 +1,19 @@ ENTRY MAIN USING extendedDefine -VERSION 4.1 //The version that nested functions was introduced +VERSION 4.1 [MAIN]{ test = [1,2,3,4,5,6,7,8,9,10] t=0 - for i = 1,10 < - "Choice Test: $test[1]$" < - "A" setGlobalVar("t",1) - "B" continue() - "C" setGlobalVar("t",3) - > - > - ::leave:: - print("t = $t$ i = $i$") -} -// [hmm:function(a,b)]{ - // return a+b -// } -// [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") -// } \ No newline at end of file + test2 = "Hello" + str = $test2[1:-2]$ + print(str) + // for i = 1,10 < + // "Choice Test: $test[1]$" < + // "A" setGlobalVar("t",1) + // "B" continue() + // "C" setGlobalVar("t",3) + // > + // > + // ::leave:: + // print("t = $t$ i = $i$") +} \ No newline at end of file diff --git a/test.dmsc b/test.dmsc new file mode 100644 index 0000000000000000000000000000000000000000..bf7f4dbfdbf805e7b8afc587ebff5dabf0e2922b GIT binary patch literal 830 zcmaJVH06P6QRhEONit+md_CQ2Rdpxeu@q{ zBt8OWdL z6DhzGG?6KIf+jKzPtcNbBfWwlT3kR7hm}#qj+KtZWohRC)*A@pI$kzg<`GPT7$lZT zEMWqQSp*|NUK{*uwq+JwgmL_TmRM81KTHKy4aXva5#Ze7oew z(2KA6987O_2HKHKIMhF1z~yyU0TAsWq~%emI~so1$4z0>58_n$pUU#Scd2~M{{TvO zQpWhG{B|r&1VsQP2;1`ZM|a$Zukc@MWwG0EsmwlB?ijtGieQ M9o0Ed-F~3H0G2$9MF0Q* literal 0 HcmV?d00001 diff --git a/test.lua b/test.lua index 9bd0a22..7f16e4e 100644 --- a/test.lua +++ b/test.lua @@ -2,11 +2,9 @@ package.path="?/init.lua;lua/?/init.lua;lua/?.lua;"..package.path local bin = require("bin") local multi = require("multi") 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()) - - ---Code would happen here anyway t=test:next() while t do if t.Type=="text" then @@ -30,7 +28,7 @@ while t do cm=tonumber(io.read()) t=test:next(nil,cm) 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() else os.exit() @@ -41,72 +39,3 @@ while t do t=test:next() 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 -]] diff --git a/test.luac b/test.luac new file mode 100644 index 0000000000000000000000000000000000000000..9b547ce010379228327383960b966637040bbab1 GIT binary patch literal 1866 zcmaJ>OHUL*5U!qW7V!OCd<9XW;v;aEg98idK@TQ+^D?{JvK{8J&dx?W(U2eq{()Je zKV^Kd7q5ErpwYyuCdL>O6Th0-bteP3$w$}sO?7p3RW&DXwVXR7q?ALni-_zSj0zD<7QaozdeqzdEBrb~*6~HC( zm=l}OJMnAYFA~kn!8TiBmEzya{TOqIAx!?flKIv5q5187?4Nxfdj}u-(f2Vs_{87) zJ~4daA(PaE??avBJ}Y*SlKa^m@s14YSELs)@?NnBizQZzG;bB?`fNvDpIwpfXI2Ys zG~>DXgVD(u0!uoQZKW-D8H*J9T?jvOg_v=>vUS9z~Ah=sgCLsNqx>odrdb zr?BBfb&}^`U7OOrPR4Z_BRiF+Jjc^%fKWYb=@0=VwpFxGvIxU#xsfKhHwhXx)osVe zDPejHzl8Lg8#uLc;5D?XY9#rYB(J3AHLGcyMyP%Ga&onn*C1)JPb&CoscYSR-00pQ zO0)u;bdW}P6zZt^F;q_XlxpDDbfg1hyBoevv#A$+Pw`Qlz3WtzOL7pVr=og*U2IqD zfvzGJ+l>%uN9bnq`*uyTH93}EqFfJxrW(Hr%5v2sIgB+5{FYbYDsZiokFeYVS2>H? zUr2p}W_mfbq`S$eFbqPt5%E6@u>-g+J@A=5@JT)J)$-uG8P*sgeCsXNHzL053!~y{w@Oi`wO5fBUS(a literal 0 HcmV?d00001