# bob: tests_full/test_vm_compiler.py # # Run the full tests for the compiler and VM of Bob # # Eli Bendersky ([email protected]) # This code is in the public domain #------------------------------------------------------------------------------- import sys from testcases_utils import run_all_tests sys.path.insert(0, '..') from bob.compiler import compile_code from bob.vm import BobVM from bob.bytecode import Serializer, Deserializer def vm_compiler_runner(code, ostream): codeobject = compile_code(code) # Run the code through (de+)serialization to test how that works # too # ser = Serializer().serialize_bytecode(codeobject) codeobject = Deserializer().deserialize_bytecode(ser) vm = BobVM(output_stream=ostream) vm.run(codeobject) run_all_tests(runner=vm_compiler_runner)
from bob.compiler import compile_code from bob.bytecode import Serializer def make_runner(barevm_path): def barevm_runner(code, ostream): codeobject = compile_code(code) serialized = Serializer().serialize_bytecode(codeobject) # Get a temporary filename and write the serialized codeobject # into it # fileobj, filename = tempfile.mkstemp() os.write(fileobj, serialized) os.close(fileobj) vm_proc = Popen([barevm_path, filename], stdout=PIPE) vm_output = vm_proc.stdout.read() ostream.write(vm_output) os.remove(filename) return barevm_runner if __name__ == '__main__': barevm_path = "../barevm/barevm" barevm_runner = make_runner(barevm_path) run_all_tests(barevm_runner)
#!/usr/bin/env python #------------------------------------------------------------------------------- # bob: tests_full/test_interpreter.py # # Run the full tests for the interpreter module of Bob # # Eli Bendersky ([email protected]) # This code is in the public domain #------------------------------------------------------------------------------- import sys from testcases_utils import run_all_tests sys.path.insert(0, '..') from bob.interpreter import interpret_code def interpreter_runner(code, ostream): interpret_code(code, output_stream=ostream) run_all_tests(runner=interpreter_runner)
#!/usr/bin/env python #------------------------------------------------------------------------------- # bob: tests_full/test_vm_compiler.py # # Run the full tests for the compiler and VM of Bob # # Eli Bendersky ([email protected]) # This code is in the public domain #------------------------------------------------------------------------------- import sys from testcases_utils import run_all_tests from bob.compiler import compile_code from bob.vm import BobVM from bob.bytecode import Serializer, Deserializer def vm_compiler_runner(code, ostream): codeobject = compile_code(code) # Run the code through (de+)serialization to test how that works # too # ser = Serializer().serialize_bytecode(codeobject) codeobject = Deserializer().deserialize_bytecode(ser) vm = BobVM(output_stream=ostream) vm.run(codeobject) run_all_tests(runner=vm_compiler_runner)