From 5ff8534b969f5ec68be3f10135668f18d1796aa1 Mon Sep 17 00:00:00 2001 From: kake26 Date: Tue, 30 Aug 2022 17:31:14 -0500 Subject: [PATCH 1/3] Initial add of original old code circa 2012 --- vm.pb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 vm.pb diff --git a/vm.pb b/vm.pb new file mode 100644 index 0000000..8b2f0d0 --- /dev/null +++ b/vm.pb @@ -0,0 +1,55 @@ +; vm + +Structure opi +code.l +args.s +EndStructure + +; In theory this is a byte code interpreter +; Also mad science and may not work + + +Procedure writeblock (fid, *opco.opi) +; used by compile to write compiled code to file + WriteByte(fid, *opco\code) + WriteLong(fid, Len(*opco\args)) + WriteData(fid, @*opco\args, Len(*opco\args)) +EndProcedure + +Procedure readblock (fid, *opci.opi) +; should not need to be explained + *opci\code = ReadByte(fid) + *opci\args = Space(ReadLong(fid)) + ReadData(fid, @*opci\args, Len(*opci\args)) +EndProcedure + +;for demo purposes we hard wire the code + +opcobj.opi\code = $01 +opcobj.opi\args = "Hi world" + +; now write bytecode to file + +OpenFile(0,"test.byc") +writeblock(0, opcobj) +CloseFile(0) + +; now read + +OpenFile(1,"test.byc") +readblock(1, opcoobj.opi) +CloseFile(1) + +;run + +Select opcoobj\code + +Case $01 : MessageRequester("ouput",opcoobj\args) + +EndSelect + +; IDE Options = PureBasic 4.61 (Windows - x86) +; CursorPosition = 3 +; Folding = - +; EnableXP +; Executable = ..\Desktop\vm.exe \ No newline at end of file From 93555b630707b746b3cf87bcca9d1687c5ae87e4 Mon Sep 17 00:00:00 2001 From: kake26 Date: Tue, 30 Aug 2022 17:33:39 -0500 Subject: [PATCH 2/3] Update to recent 2022 version, adjusted for newer compiler version --- test.byc | Bin 0 -> 636 bytes vm.pb | 51 ++++++++++++++++++++++++++++++++++++++-------- vm2.pb | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 test.byc create mode 100644 vm2.pb diff --git a/test.byc b/test.byc new file mode 100644 index 0000000000000000000000000000000000000000..b65a55e76dc0c34e6102f9dfac487a1528836079 GIT binary patch literal 636 zcmZ9J-BH6p420JVg_w89Py6=xl8SFh zFG{L)(ov;a^%^zn9lR#i@eSZaq|pSbI2&z12hKAY&YQ>?$e2-b+_64#47k^kJ<&tx(mnA7RL3Sz%>pgq6wyb9YbY>d+GV~6X!$xrQ+_ZkY2-c6~4B?{_CiY z$~|g}OM9F2M1NV`ozC>RLC0RQ+eBq|RN=9MZ|;`6SrbuD((k*dz5>00%)M4xkUe;& z6O59)880n!&Q3hTb@;wcVo$w~(8`ta&MM~8Ftx;M7h3-(Hd13i+x;3huY|j7y literal 0 HcmV?d00001 diff --git a/vm.pb b/vm.pb index 8b2f0d0..7fb3404 100644 --- a/vm.pb +++ b/vm.pb @@ -12,8 +12,9 @@ EndStructure Procedure writeblock (fid, *opco.opi) ; used by compile to write compiled code to file WriteByte(fid, *opco\code) - WriteLong(fid, Len(*opco\args)) - WriteData(fid, @*opco\args, Len(*opco\args)) + WriteLong(fid, MemorySize(@*opco\args));Len(*opco\args)) + WriteData(fid, @*opco\args, MemorySize(@*opco\args));Len(*opco\args)*2) using memorysize to make it work over a decade later because unicode + EndProcedure Procedure readblock (fid, *opci.opi) @@ -21,35 +22,69 @@ Procedure readblock (fid, *opci.opi) *opci\code = ReadByte(fid) *opci\args = Space(ReadLong(fid)) ReadData(fid, @*opci\args, Len(*opci\args)) + EndProcedure ;for demo purposes we hard wire the code opcobj.opi\code = $01 -opcobj.opi\args = "Hi world" +opcobj.opi\args = "Bacon ipsum dolor amet beef kevin turducken pork loin, jerky short loin sirloin alcatra doner." ; now write bytecode to file OpenFile(0,"test.byc") + +Debug("Before write " + Loc(0)) + writeblock(0, opcobj) +Debug("After write " + Loc(0)) + +opcobjj.opi\code = $02 +opcobjj.opi\args = "Hamburger pork chop pork, t-bone buffalo shank biltong fatback ham. Tail pork porchetta cupim, tenderloin jowl bacon bresaola alcatra strip steak andouille short ribs flank spare ribs chislic." + +writeblock(0, opcobjj) + +Debug("After write 2 " + Loc(0)) + CloseFile(0) ; now read OpenFile(1,"test.byc") + +Debug("Before read " + Loc(1)) + readblock(1, opcoobj.opi) + +Debug("After read " + Loc(1)) + +readblock(1, opcoobjj.opi) + +Debug("After read2 " + Loc(1)) + CloseFile(1) ;run Select opcoobj\code -Case $01 : MessageRequester("ouput",opcoobj\args) - + Case $01 : MessageRequester("ouput",opcoobj\args) + EndSelect -; IDE Options = PureBasic 4.61 (Windows - x86) -; CursorPosition = 3 +;Debug(opcoobjj\args) + +Select opcoobjj\code + + Case $02: MessageRequester("ouput",opcoobjj\args) + + Default + MessageRequester("ouput",opcoobjj\args) + +EndSelect +; IDE Options = PureBasic 6.00 LTS (Linux - x64) +; CursorPosition = 42 +; FirstLine = 11 ; Folding = - ; EnableXP -; Executable = ..\Desktop\vm.exe \ No newline at end of file +; Executable = vm \ No newline at end of file diff --git a/vm2.pb b/vm2.pb new file mode 100644 index 0000000..5a05ced --- /dev/null +++ b/vm2.pb @@ -0,0 +1,60 @@ +; vm + +Structure opi +code.l +args.s +dat.s +EndStructure + +; In theory this is a byte code interpreter +; Also mad science and may not work + + +Procedure writeblock (fid, *opco.opi) +; used by compile to write compiled code to file + WriteByte(fid, *opco\code) + WriteLong(fid, Len(*opco\args)) + WriteData(fid, @*opco\args, MemorySize(@*opco\args)) + WriteLong(fid, Len(*opco\dat)) + WriteData(fid, @*opco\dat, MemorySize(@*opco\dat)) + +EndProcedure + +Procedure readblock (fid, *opci.opi) +; should not need to be explained + *opci\code = ReadByte(fid) + *opci\args = Space(ReadLong(fid)) + ReadData(fid, @*opci\args, MemorySize(@*opci\args)) + *opci\dat = Space(ReadLong(fid)) + ReadData(fid, @*opci\dat, MemorySize(@*opci\dat)) +EndProcedure + +;for demo purposes we hard wire the code + +opcobj.opi\code = $01 +opcobj.opi\args = "Hi world" +opcobj.opi\dat = "Bye world!" + +; now write bytecode to file + +OpenFile(0,"test.byc") +writeblock(0, opcobj) +CloseFile(0) + +; now read + +OpenFile(1,"test.byc") +readblock(1, opcoobj.opi) +CloseFile(1) + +;run + +Select opcoobj\code + +Case $01 : MessageRequester("ouput",opcoobj\dat) + +EndSelect +; IDE Options = PureBasic 6.00 LTS (Linux - x64) +; CursorPosition = 35 +; Folding = - +; EnableXP \ No newline at end of file From 78ae5664da5d1f0d92b4b7f98438aa33e8537107 Mon Sep 17 00:00:00 2001 From: kake26 Date: Tue, 30 Aug 2022 20:55:07 -0500 Subject: [PATCH 3/3] Read me update --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3f5931..b55aede 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # vmbc -A bytecode compiler and VM. Based on very old code thats been dusted off. \ No newline at end of file +A bytecode compiler and VM. Based on very old code thats been dusted off. I'm not sure exactly what I will use this for just yet, but it is interesting to dabble with this again. + +# Notes + +This program is written in PureBasic and will require it to be compiled from source. Currently, this is more of a proof of concept type thing and I'll figure out how to make this even better. I'm not sure what its current encarnation will be used for however, that remains to be seen for now.