Initial add of original old code circa 2012
This commit is contained in:
parent
39ac95807d
commit
5ff8534b96
1 changed files with 55 additions and 0 deletions
55
vm.pb
Normal file
55
vm.pb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue