Skip to content

Instantly share code, notes, and snippets.



Created Jan 31, 2012
What would you like to do?
Draft of a VM for a game modeling language
This is the virtual machine for a pure OO language based on game creation.
It is, at essence, a stack machine. There are no registers.
Instructions only have one argument, which can be an integer or a string.
Function arguments are pushed in reverse order, C-style. (e.g. x(1,2,3) is 3 2 1 x on the stack)
Methods always have at least one argument -- "self", which is just the current object.
sys_init ; initialize system stuff
; x <- Object()
load_global "Object"
construct_object ; basically new()
load_attr "__init__" ; load up the constructor
call_function 1 ; call the constructor with self
store_local "x" ; store it in x
; x is Circle(5)
load_global "Circle"
load_attr "__init__"
load_const 5
load_local "x"
call_function 2
pop ; unused return value
; on sys:init do
; sys.print "hi"
; end
load_global "sys"
load_event "init"
register_event 0 ; no args (pushes the event back onto the stack)
register_event_ptr 0xdeadbabe (ptr to the function body)
at PC 0xdeadbabe:
; pop args (here we have self, which is sys, but we're too lazy for that)
load_const "hi"
load_global "sys"
load_attr "print"
call_function 1
push_nil ; return value
return ; return from function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.