def meth_base_name(meth): if is_inline_meth(meth): return inline_meth_base_name(meth) if is_asm_meth(meth): return asm_meth_base_name(meth) if not pairp(meth): raise CompileError(meth, 'method must be a list') if not pairp(meth.car()): raise CompileError(meth.car(), 'method signature must be a list') return meth.caar()
def expand_seq_macros(seq): if seq.nullp(): return seq if not pairp(seq.car()): return seq if seq.car().nullp(): return seq tag = str(seq.caar()) if tag not in seq_macros: return seq return seq_macros[tag](seq)
def annotate_or_report(self, exp): self.context = (exp,) + getattr(self, 'context', ()) if self.context[0:1] == self.context[1:2]: self.context = self.context[1:] while exp not in reader.current_pos_info: if not pairp(exp): raise self exp = exp.car() info = reader.current_pos_info[exp] report_compile_error(self, file=info[0], line=info[1], char=info[2])
def scan_out_xyz(exp): if self_evaluatingp(exp): return nil if tagged_list(exp, quote_s): return nil if variablep(exp): return scan_out_xyz_variable(exp) if tagged_list(exp, set__s): return scan_out_xyz_assignment(exp) if tagged_list(exp, def_s): return scan_out_xyz_definition(exp) #if tagged_list(exp, load_module_s): return nil if tagged_list(exp, if_s): return scan_out_xyz_if(exp) if tagged_list(exp, fn_s): return scan_out_xyz_obj(fn2obj(exp)) if tagged_list(exp, bracket_s): return nil # impossible if tagged_list(exp, obj_s): return scan_out_xyz_obj(exp) if tagged_list(exp, sobj_s): return scan_out_xyz_sobj(exp) if tagged_list(exp, do_s): return scan_out_xyz_do(exp) if tagged_list(exp, inline_s): return nil if pairp(exp): return scan_out_xyz_application(exp) raise CompileError(exp, 'Unknown expression type in scan_out_xyz')
def compile_literal(exp, target, linkage, cenv, pop_all_symbol): if exp is nil: return end_with_linkage(linkage, make_ir_seq((), (target,), mov(target, nil_r)), pop_all_symbol) return compile_self_evaluating(exp, target, linkage, cenv, pop_all_symbol) if self_evaluatingp(exp) or symbolp(exp): return compile_self_evaluating(exp, target, linkage, cenv, pop_all_symbol) if pairp(exp): reg = tmp_r if reg is target: reg = val_r # this feels like a hack d = compile_literal(exp.cdr(), target, next_s, cenv, pop_all_symbol) a = compile_literal(exp.car(), reg, next_s, cenv, pop_all_symbol) return end_with_linkage(linkage, append_ir_seqs( d, preserving((target,), a, make_ir_seq((reg, target), (target,), ir.cons(target, reg, target)), pop_all_symbol)), pop_all_symbol) raise CompileError(exp, "Can't compile literal")
def compile(exp, target, linkage, cenv, pop_all_symbol, **kwargs): try: if self_evaluatingp(exp): return compile_self_evaluating(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, quote_s): return compile_quoted(exp, target, linkage, cenv, pop_all_symbol) if variablep(exp): return compile_variable(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, set__s): return compile_assignment(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, def_s): return compile_definition(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, qmark_s): return compile_qmark(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, fn_s): return compile_obj(fn2obj(exp), target, linkage, cenv, pop_all_symbol) if tagged_list(exp, bracket_s): return compile_shfn(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, obj_s): return compile_obj(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, sobj_s): return compile_sobj(exp, target, linkage, cenv, pop_all_symbol, **kwargs) if tagged_list(exp, do_s): return compile_do(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, inline_s): return compile_inline(exp) if tagged_list(exp, return_s): return compile_return(exp, target, linkage, cenv, pop_all_symbol) if tagged_list(exp, cint_s): return compile_cint(exp, target, linkage, cenv, pop_all_symbol) if tagged_list2(exp, assign_s): return compile(assign2prefix(exp, set__s), target, linkage, cenv, pop_all_symbol) if simple_macrop(exp): return compile(expand_simple_macros(exp), target, linkage, cenv, pop_all_symbol) if pairp(exp): return compile_application(exp, target, linkage, cenv, pop_all_symbol) raise CompileError(exp, 'Unknown expression type') except CompileError, err: err.annotate_or_report(exp)
def asm_meth_arity(meth): params = asm_meth_params(meth) if pairp(params): return len(params) return 0
def expand_simple_macro(exp): if not pairp(exp): return exp tag = str(exp.car()) if tag not in simple_macros: return exp return simple_macros[tag](exp)
def find(cframe, var, i): if cframe is var: return i, True if not pairp(cframe): return None, False if cframe.car() is var: return i, False return find(cframe.cdr(), var, i + 1)
def tagged_list2(exp, tag): return pairp(exp) and (not exp.nullp()) and tagged_list(exp.cdr(), tag)
def tagged_list(exp, tag): return pairp(exp) and (not exp.nullp()) and exp.car() is tag
def check(params): if params is nil: return True if pairp(params): return check(params.cdr()) return False
def meth_arity(meth): if is_inline_meth(meth): return inline_meth_arity(meth) if is_asm_meth(meth): return asm_meth_arity(meth) params = meth_params(meth) if pairp(params): return len(params) return 0
def inline_meth_arity(meth): params = inline_meth_params(meth) if pairp(params): return len(params) return 0
def inline_meth_params(meth): x = meth.caddr() if pairp(x): return x.cdr() return nil
def asm_meth_params(meth): x = meth.cadr() if pairp(x): return x.cdr() return nil
def asm_meth_base_name(meth): x = meth.cadr() if pairp(x): return x.car() return x
def inline_meth_base_name(meth): x = meth.caddr() if pairp(x): return x.car() return x