+ compile_extern_method_to_c(v)
+ end
+ end
+
+ fun compile_extern_method_to_c(v: I2CCompilerVisitor)
+ do
+ var ename = method.extern_name.as(not null)#"{method.module.name}_{method.local_class.name}_{method.local_class.name}_{method.name}_{method.signature.arity}"
+ var sig = method.signature
+ assert exprs.length == sig.arity + 1
+
+ var regs = v.registers(exprs)
+
+ var args = new Array[String]
+ args.add(sig.recv.unboxtype(regs[0]))
+ for i in [0..sig.arity[ do
+ args.add(sig[i].unboxtype(regs[i+1]))
+ end
+ var s = "{ename}({args.join(", ")})"
+
+ if need_result then s = sig.return_type.boxtype(s)
+ var w = new_result(v)
+ w.add(s)
+ end
+
+ fun compile_intern_method_to_c(v: I2CCompilerVisitor)
+ do
+ var sig = method.signature
+ assert exprs.length == sig.arity + 1
+ var c = method.local_class.name
+ var n = method.name
+ var regs = v.registers(exprs)
+ var s: nullable String = null
+ if c == once "Int".to_symbol then
+ if n == once "object_id".to_symbol then
+ s = regs[0]
+ else if n == once "unary -".to_symbol then
+ s = "TAG_Int(-UNTAG_Int({regs[0]}))"
+ else if n == once "output".to_symbol then
+ s = "printf(\"%ld\\n\", UNTAG_Int({regs[0]}));"
+ else if n == once "ascii".to_symbol then
+ s = "TAG_Char(UNTAG_Int({regs[0]}))"
+ else if n == once "succ".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})+1)"
+ else if n == once "prec".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})-1)"
+ else if n == once "to_f".to_symbol then
+ s = "BOX_Float((float)UNTAG_Int({regs[0]}))"
+ else if n == once "+".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})+UNTAG_Int({regs[1]}))"
+ else if n == once "-".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})-UNTAG_Int({regs[1]}))"
+ else if n == once "*".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})*UNTAG_Int({regs[1]}))"
+ else if n == once "/".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})/UNTAG_Int({regs[1]}))"
+ else if n == once "%".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})%UNTAG_Int({regs[1]}))"
+ else if n == once "<".to_symbol then
+ s = "TAG_Bool(UNTAG_Int({regs[0]})<UNTAG_Int({regs[1]}))"
+ else if n == once ">".to_symbol then
+ s = "TAG_Bool(UNTAG_Int({regs[0]})>UNTAG_Int({regs[1]}))"
+ else if n == once "<=".to_symbol then
+ s = "TAG_Bool(UNTAG_Int({regs[0]})<=UNTAG_Int({regs[1]}))"
+ else if n == once ">=".to_symbol then
+ s = "TAG_Bool(UNTAG_Int({regs[0]})>=UNTAG_Int({regs[1]}))"
+ else if n == once "lshift".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})<<UNTAG_Int({regs[1]}))"
+ else if n == once "rshift".to_symbol then
+ s = "TAG_Int(UNTAG_Int({regs[0]})>>UNTAG_Int({regs[1]}))"
+ else if n == once "==".to_symbol then
+ s = "TAG_Bool(({regs[0]})==({regs[1]}))"
+ else if n == once "!=".to_symbol then
+ s = "TAG_Bool(({regs[0]})!=({regs[1]}))"
+ end
+ else if c == once "Float".to_symbol then
+ if n == once "object_id".to_symbol then
+ s = "TAG_Int((bigint)UNBOX_Float({regs[0]}))"
+ else if n == once "unary -".to_symbol then
+ s = "BOX_Float(-UNBOX_Float({regs[0]}))"
+ else if n == once "output".to_symbol then
+ s = "printf(\"%f\\n\", UNBOX_Float({regs[0]}));"
+ else if n == once "to_i".to_symbol then
+ s = "TAG_Int((bigint)UNBOX_Float({regs[0]}))"
+ else if n == once "+".to_symbol then
+ s = "BOX_Float(UNBOX_Float({regs[0]})+UNBOX_Float({regs[1]}))"
+ else if n == once "-".to_symbol then
+ s = "BOX_Float(UNBOX_Float({regs[0]})-UNBOX_Float({regs[1]}))"
+ else if n == once "*".to_symbol then
+ s = "BOX_Float(UNBOX_Float({regs[0]})*UNBOX_Float({regs[1]}))"
+ else if n == once "/".to_symbol then
+ s = "BOX_Float(UNBOX_Float({regs[0]})/UNBOX_Float({regs[1]}))"
+ else if n == once "<".to_symbol then
+ s = "TAG_Bool(UNBOX_Float({regs[0]})<UNBOX_Float({regs[1]}))"
+ else if n == once ">".to_symbol then
+ s = "TAG_Bool(UNBOX_Float({regs[0]})>UNBOX_Float({regs[1]}))"
+ else if n == once "<=".to_symbol then
+ s = "TAG_Bool(UNBOX_Float({regs[0]})<=UNBOX_Float({regs[1]}))"
+ else if n == once ">=".to_symbol then
+ s = "TAG_Bool(UNBOX_Float({regs[0]})>=UNBOX_Float({regs[1]}))"
+ end
+ else if c == once "Char".to_symbol then
+ if n == once "object_id".to_symbol then
+ s = "TAG_Int(UNTAG_Char({regs[0]}))"
+ else if n == once "unary -".to_symbol then
+ s = "TAG_Char(-UNTAG_Char({regs[0]}))"
+ else if n == once "output".to_symbol then
+ s = "printf(\"%c\", (unsigned char)UNTAG_Char({regs[0]}));"
+ else if n == once "ascii".to_symbol then
+ s = "TAG_Int((unsigned char)UNTAG_Char({regs[0]}))"
+ else if n == once "succ".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})+1)"
+ else if n == once "prec".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})-1)"
+ else if n == once "to_i".to_symbol then
+ s = "TAG_Int(UNTAG_Char({regs[0]})-'0')"
+ else if n == once "+".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})+UNTAG_Char({regs[1]}))"
+ else if n == once "-".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})-UNTAG_Char({regs[1]}))"
+ else if n == once "*".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})*UNTAG_Char({regs[1]}))"
+ else if n == once "/".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})/UNTAG_Char({regs[1]}))"
+ else if n == once "%".to_symbol then
+ s = "TAG_Char(UNTAG_Char({regs[0]})%UNTAG_Char({regs[1]}))"
+ else if n == once "<".to_symbol then
+ s = "TAG_Bool(UNTAG_Char({regs[0]})<UNTAG_Char({regs[1]}))"
+ else if n == once ">".to_symbol then
+ s = "TAG_Bool(UNTAG_Char({regs[0]})>UNTAG_Char({regs[1]}))"
+ else if n == once "<=".to_symbol then
+ s = "TAG_Bool(UNTAG_Char({regs[0]})<=UNTAG_Char({regs[1]}))"
+ else if n == once ">=".to_symbol then
+ s = "TAG_Bool(UNTAG_Char({regs[0]})>=UNTAG_Char({regs[1]}))"
+ else if n == once "==".to_symbol then
+ s = "TAG_Bool(({regs[0]})==({regs[1]}))"
+ else if n == once "!=".to_symbol then
+ s = "TAG_Bool(({regs[0]})!=({regs[1]}))"
+ end
+ else if c == once "Bool".to_symbol then
+ if n == once "object_id".to_symbol then
+ s = "TAG_Int(UNTAG_Bool({regs[0]}))"
+ else if n == once "unary -".to_symbol then
+ s = "TAG_Bool(-UNTAG_Bool({regs[0]}))"
+ else if n == once "output".to_symbol then
+ s = "(void)printf(UNTAG_Bool({regs[0]})?\"true\\n\":\"false\\n\");"
+ else if n == once "ascii".to_symbol then
+ s = "TAG_Bool(UNTAG_Bool({regs[0]}))"
+ else if n == once "to_i".to_symbol then
+ s = "TAG_Int(UNTAG_Bool({regs[0]}))"
+ else if n == once "==".to_symbol then
+ s = "TAG_Bool(({regs[0]})==({regs[1]}))"
+ else if n == once "!=".to_symbol then
+ s = "TAG_Bool(({regs[0]})!=({regs[1]}))"