def emit(self): else_label = UniqueLabel.get('else') end_if_label = UniqueLabel.get('end_if') return asm_lines(self.condition.emit(), ' cmp ${}, %eax'.format(Bool.false), ' je {}'.format(else_label), self.if_branch.emit(), ' jmp {}'.format(end_if_label), '{}:'.format(else_label), self.else_branch.emit(), '{}:'.format(end_if_label))
def emit_function_header(fname): s = asm_lines(' .text', ' .globl scheme_entry', ' .type scheme_entry, @function', '{0}:'.format(fname)) return s
def compile_program(p): e = expr.run(p) return asm_lines(emit_function_header('scheme_entry'), e.emit(), ' ret')
def emit(self): return asm_lines(self.arg.emit(), self.emit_self())
def emit_self(self): # emit() is never called on FxLogNot and Inc, hence they don't need an argument return asm_lines(FxLogNot(None).emit_self(), Inc(None).emit_self())
def emit_self(self): return asm_lines(' cmp ${}, %al'.format(Bool.false), to_bool_asm)
def emit_self(self): return asm_lines('shrl $2, %eax', ' notl %eax', 'shll $2, %eax')
def emit_self(self): return asm_lines(' cmp ${}, %al'.format(Char.tag), to_bool_asm)
def emit_self(self): return asm_lines(' or ${}, %al'.format(0b01000000), ' cmp ${}, %al'.format(Bool.true), to_bool_asm)
def emit_self(self): return asm_lines(' test %eax, %eax', to_bool_asm)
def emit_self(self): return asm_lines(' and ${}, %al'.format(Fixnum.mask), ' cmp ${}, %al'.format(Fixnum.tag), to_bool_asm)
class FixnumToChar(Primitive): call_name = 'f2c' def emit_self(self): return """ shll ${}, %eax orl ${}, %eax""".format(Char.shift - Fixnum.shift, Char.tag) class CharToFixnum(Primitive): call_name = 'c2f' def emit_self(self): return """ shrl ${}, %eax""".format(Char.shift - Fixnum.shift) to_bool_asm = asm_lines(' sete %al', ' movzbl %al, %eax', ' sal ${}, %al'.format(Bool.bit), ' or ${}, %al'.format(Bool.false)) class IsFixnum(Primitive): call_name = 'fixnum?' def emit_self(self): return asm_lines(' and ${}, %al'.format(Fixnum.mask), ' cmp ${}, %al'.format(Fixnum.tag), to_bool_asm) class IsZero(Primitive): call_name = 'zero?' def emit_self(self): return asm_lines(' test %eax, %eax',