further development of VM (added separate code stack)
--HG-- branch : mung
This commit is contained in:
parent
d3f845144e
commit
b11356b0c3
2 changed files with 59 additions and 1 deletions
24
langdoc.txt
Executable file
24
langdoc.txt
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
simple program:
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
arg = "message";
|
||||||
|
send(#7407, arg);
|
||||||
|
suspend(1.0);
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
bytecode:
|
||||||
|
|
||||||
|
startblock 1
|
||||||
|
stack_literal_int 1
|
||||||
|
exit_true 1
|
||||||
|
stack_literal_str "message"
|
||||||
|
set_var arg
|
||||||
|
discard_stack 1
|
||||||
|
get_var arg
|
||||||
|
stack_literal_obj #7407
|
||||||
|
call_builtin send
|
||||||
|
discard_stack 1
|
||||||
|
stack_literal_float 1.0
|
||||||
|
call_builtin suspend
|
||||||
|
discard_stack 1
|
||||||
|
endblock 1
|
36
language.py
36
language.py
|
@ -7,11 +7,19 @@ class VirtualMachine(object):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.active_task_id = None
|
self.active_task_id = None
|
||||||
self.sleepytime = None
|
self.sleepytime = None
|
||||||
|
self.codestack = []
|
||||||
self.stack = []
|
self.stack = []
|
||||||
self.contexts = []
|
self.contexts = []
|
||||||
self.tasks = {}
|
self.tasks = {}
|
||||||
self.task_sequence = []
|
self.task_sequence = []
|
||||||
self.ticks_used = 0
|
self.ticks_used = 0
|
||||||
|
self.exception_thrown = None
|
||||||
|
|
||||||
|
def pop_code(self):
|
||||||
|
return self.code_stack.pop()
|
||||||
|
|
||||||
|
def push_code(self, code):
|
||||||
|
self.code_stack.append(code)
|
||||||
|
|
||||||
def pop(self, count=1):
|
def pop(self, count=1):
|
||||||
return [uncoerce(self.stack.pop()) for x in range(count)]
|
return [uncoerce(self.stack.pop()) for x in range(count)]
|
||||||
|
@ -52,11 +60,29 @@ class VirtualMachine(object):
|
||||||
self.stack = task[1]
|
self.stack = task[1]
|
||||||
self.contexts = task[2]
|
self.contexts = task[2]
|
||||||
self.ticks_used = task[3]
|
self.ticks_used = task[3]
|
||||||
|
self.exception_thrown = None
|
||||||
|
|
||||||
def get_next_task(self):
|
def get_next_task(self):
|
||||||
heapq.heappop(self.task_sequence)
|
heapq.heappop(self.task_sequence)
|
||||||
|
|
||||||
def run_active_task
|
def uncaught_exception(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run_active_task(self):
|
||||||
|
task_id = self.active_task_id
|
||||||
|
while task_id == self.active_task_id and self.code_stack and self.exception_thrown == None:
|
||||||
|
nextop = self.pop_code()
|
||||||
|
nextop.execute(self)
|
||||||
|
|
||||||
|
if self.exception_thrown != None:
|
||||||
|
self.uncaught_exception()
|
||||||
|
self.finished_start_next()
|
||||||
|
|
||||||
|
if task_id == self.active_task_id:
|
||||||
|
self.finished_start_next()
|
||||||
|
|
||||||
|
self.finished_start_next
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.sleepytime = None
|
self.sleepytime = None
|
||||||
|
@ -112,6 +138,14 @@ class CallBuiltin(CodeOp):
|
||||||
funcname, = vm.pop(1)
|
funcname, = vm.pop(1)
|
||||||
builtin_map[funcname](vm)
|
builtin_map[funcname](vm)
|
||||||
|
|
||||||
|
class DiscardStack(CodeOp):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
def execute(self, vm):
|
||||||
|
count, = vm.pop(1)
|
||||||
|
vm.pop(count)
|
||||||
|
|
||||||
|
|
||||||
class StartContext(CodeOp):
|
class StartContext(CodeOp):
|
||||||
def execute(self, vm):
|
def execute(self, vm):
|
||||||
vm.push_context()
|
vm.push_context()
|
||||||
|
|
Loading…
Add table
Reference in a new issue