Ejemplo n.º 1
0
 def _execute_simple(self, code, data):
     result = [None]
     def getresult(val):
         result[0] = val
     vm = VirtualMachine([], getresult)
     globalns = Namespace("globals")
     ctx = BytecodeCompiler("main", code, data, namespace=globalns)
     globalns.set_func("main", ctx.mkfunc())
     vm.setglobals(globalns)
     vm.run(pass_argv=False)
     return result[0]
Ejemplo n.º 2
0
    def _execute_simple(self, code, data):
        result = [None]

        def getresult(val):
            result[0] = val

        vm = VirtualMachine([], getresult)
        globalns = Namespace("globals")
        ctx = BytecodeCompiler("main", code, data, namespace=globalns)
        globalns.set_func("main", ctx.mkfunc())
        vm.setglobals(globalns)
        vm.run(pass_argv=False)
        return result[0]
Ejemplo n.º 3
0
 def _execute_simple(self, code):
     # set up the global namespace
     globalns = Namespace("globals")
     for node in DipperParser().parse(code):
         if node.type == "Function":
             globalns.add_func(node.name, FrameCompiler(node).mkfunc())
         elif node.type == "Struct":
             globalns.add_struct(node.name, node.mkstruct())
     # set up a hacky way to extract data from the VM via a callback
     result = [None] # we need a mutable object we can put data in
     def getresult(val):
         result[0] = val
     # set up the VM
     vm = VirtualMachine([], cb=getresult, debug=False)
     vm.setglobals(globalns)
     vm.run()
     return result[0]
Ejemplo n.º 4
0
    def _execute_simple(self, code):
        # set up the global namespace
        globalns = Namespace("globals")
        for node in DipperParser().parse(code):
            if node.type == "Function":
                globalns.add_func(node.name, FrameCompiler(node).mkfunc())
            elif node.type == "Struct":
                globalns.add_struct(node.name, node.mkstruct())
        # set up a hacky way to extract data from the VM via a callback
        result = [None]  # we need a mutable object we can put data in

        def getresult(val):
            result[0] = val

        # set up the VM
        vm = VirtualMachine([], cb=getresult, debug=False)
        vm.setglobals(globalns)
        vm.run()
        return result[0]