return hex(reg.value)
-def convert_to_pure_python(pcode, helper=False, filename="string"):
-
- gsc = GardenSnakeCompiler(form=None, incl_carry=False, helper=helper)
-
+def compile(pcode, form, helper, incl_carry, filename):
+ fields = {
+ "read_regs",
+ "write_regs",
+ "uninit_regs",
+ "special_regs",
+ "op_fields",
+ }
+ gsc = GardenSnakeCompiler(form=form, incl_carry=incl_carry, helper=helper)
tree = gsc.compile(pcode, mode="exec", filename=filename)
tree = ast.fix_missing_locations(tree)
- return astor.to_source(tree)
+ regs = {field:getattr(gsc.parser, field) for field in fields}
+
+ return (tree, regs)
def convert_to_python(pcode, form, incl_carry, helper=False, filename="string"):
- log("form", form)
- gsc = GardenSnakeCompiler(form=form, incl_carry=incl_carry, helper=helper)
+ (tree, regs) = compile(pcode=pcode,
+ form=form, helper=helper,
+ incl_carry=incl_carry, filename=filename)
+ return (astor.to_source(tree), regs)
- tree = gsc.compile(pcode, mode="exec", filename=filename)
- tree = ast.fix_missing_locations(tree)
- regsused = {'read_regs': gsc.parser.read_regs,
- 'write_regs': gsc.parser.write_regs,
- 'uninit_regs': gsc.parser.uninit_regs,
- 'special_regs': gsc.parser.special_regs,
- 'op_fields': gsc.parser.op_fields}
- return astor.to_source(tree), regsused
+
+def convert_to_pure_python(pcode, helper=False, filename="string"):
+ (tree, _) = compile(form=None,
+ pcode=pcode, helper=helper,
+ incl_carry=False, filename=filename)
+ return astor.to_source(tree)
def check_in_gitignore(output_file):