Пример #1
0
import sys
sys.path.append("..")
from gridcontrol.engine.ffi import GridControlFFI

def fake_ffi(vm, args):
	return 0

if __name__ == "__main__":
	if len(sys.argv) > 1:
		fn = sys.argv[1]
	else:
		fn = "code.gridlang"

	with open(fn) as fh:
		code = fh.read()
	c = GridLangParser.parse(code, constants=GridControlFFI.CONSTANTS)

	vm = None
	data = None

	while 1:
		if vm is not None:
			data = vm.freeze()
		vm = GridLangVM()
		vm.ffi = fake_ffi
		vm.set_code(c)
		if data is not None:
			vm.thaw(data)
		if vm.run(10):
			break
		
Пример #2
0
def parse(cs):
	c = GridLangParser.parse(cs)
	return c
Пример #3
0
import signal

if __name__ == "__main__":
	if len(sys.argv) > 2:
		cmd = sys.argv[1]
		fn = sys.argv[2]
	elif len(sys.argv) > 1:
		cmd = 'run'
		fn = sys.argv[1]
	else:
		sys.exit("What file should I operate on?")

	with open(fn) as fh:
		code = fh.read()
		try:
			c = GridLangParser.parse(code)
		except GridLangParseException as e:
			sys.exit(e)
	
	if cmd == 'parse':
		c.print_code()
	else:
		vm = GridLangVM()
		vm.set_code(c)
		def sigint_handler(signal, frame):
			print ""
			print "SIGINT caught"
			vm.output_traceback()
			sys.exit(0)
		signal.signal(signal.SIGINT, sigint_handler)
		vm.run()