diff --git a/lang/compile.py b/lang/compile.py index 14901ed..b1c21ec 100755 --- a/lang/compile.py +++ b/lang/compile.py @@ -156,7 +156,7 @@ print("not a call? line: %s" % (' '.join(line))) return None subject = parse_value(cut[0]) - if not subject: + if subject is None: print("not a subject? line: %s" % (' '.join(line))) return None verb = None @@ -165,7 +165,7 @@ args = [] for arg in cut[2:]: val = parse_value(arg) - if not val: + if val is None: print("not a arg value? line: %s" % (' '.join(line))) return None args.append(val) @@ -176,7 +176,7 @@ print("not a set? line: %s" % (' '.join(line))) return None call = parse_call(line, 4) - if not call: + if call is None: return None return ASTSet(line[1], call) @@ -185,7 +185,7 @@ print("not a return? line: %s" % (' '.join(line))) return None value = parse_value(line[1]) - if not value: + if value is None: print("not a return value? line: %s" % (' '.join(line))) return None return ASTReturn(value) @@ -195,7 +195,7 @@ print("not a jump? line: %s" % (' '.join(line))) return None jump_call = parse_call(line, 2) - if not jump_call: + if jump_call is None: print("not a jump call? line: %s" % (' '.join(line))) return None return ASTJump(jump_call) @@ -209,7 +209,7 @@ command = parse_return(line) elif instr == "Jump": command = parse_jump(line) - if not command: + if command is None: print("not a command? line: %s" % (' '.join(line))) return None return ASTCommand(command) @@ -251,7 +251,7 @@ (command, new_lines) = parse_conditional(lines) else: command = parse_command(line) - if not command: + if command is None: print("not a statement? line: %s" % (' '.join(line))) return (None, []) return (ASTStatement(command), new_lines) @@ -477,15 +477,15 @@ def generate_ir_call(ast, is_jump): final_ir = [] subject_ir = generate_ir_value(ast.subject) - if not subject_ir: + if subject_ir is None: print("Unknown subject ast node: %s" % (node)) return None - if not ast.verb: + if ast.verb is None: return subject_ir args_ir = [] for arg in ast.args: arg_ir = generate_ir_value(arg) - if not arg_ir: + if arg_ir is None: print("Unknown arg ast node: %s" % (arg)) return None args_ir = args_ir + arg_ir @@ -508,7 +508,7 @@ def generate_ir_set(ast, create): command = ast.command sub_ir = generate_ir_call(command, False) - if not sub_ir: + if sub_ir is None: print("Unknown set ast node: %s" % (node)) return None store = IRStore(ast.name, -1, create) @@ -516,7 +516,7 @@ def generate_ir_return(ast): value_ir = generate_ir_value(ast.value) - if not value_ir: + if value_ir is None: print("Unknown return ast node: %s" % (node)) return None store_ret = IRStore("Return", -1, False) @@ -532,7 +532,7 @@ sub_ir = generate_ir_return(node) elif isinstance(node, ASTJump): sub_ir = generate_ir_jump(node) - if not sub_ir: + if sub_ir is None: print("Unknown command ast node: %s" % (node)) return None return sub_ir @@ -568,7 +568,7 @@ sub_ir = generate_ir_command(node, True) elif isinstance(node, ASTJump): sub_ir = generate_ir_jump(node) - if not sub_ir: + if sub_ir is None: print("Unknown statement ast node: %s" % (node)) return None return sub_ir @@ -581,7 +581,7 @@ sub_ir = None if isinstance(node, ASTStatement): sub_ir = generate_ir_statement(node, statement_id) - if not sub_ir: + if sub_ir is None: print("Unknown function statement ast node: %s" % (node)) return None ir = ir + sub_ir @@ -599,7 +599,7 @@ sub_ir = generate_ir_metadata(node) elif isinstance(node, ASTFunction): sub_ir = generate_ir_function(node) - if not sub_ir: + if sub_ir is None: print("Unknown ast node: %s" % (node)) return None ir.append(sub_ir) @@ -661,7 +661,7 @@ def registers_allocate_func(ir): registers = find_variables(ir) - if not registers: + if registers is None: return None new_ir = replace_variables(ir, registers) name = ir.name @@ -699,7 +699,7 @@ fixups = {} for node in ir.statements: pos = len(bytes) - if not comments.get(pos): + if comments.get(pos) is None: comments[pos] = [] comments[pos].append(str(node)) if isinstance(node, IRNumber): @@ -882,23 +882,23 @@ def compile(code, id): lines = tokenize(code) - if not lines: + if lines is None: print("Failed to tokenize file") return None ast = parse_toplevel(lines, id) - if not ast: + if ast is None: print("Failed to parse file") return None ir = generate_ir(ast) - if not ir: + if ir is None: print("Failed to generate IR") return None ir_reg = registers_allocate(ir) - if not ir_reg: + if ir_reg is None: print("Failed to allocate registers") return None c_code = generate_c_file(ir_reg, code) - if not c_code: + if c_code is None: print("Failed to generate C file") return None return c_code