Created
December 12, 2012 07:47
-
-
Save anonymous/4265878 to your computer and use it in GitHub Desktop.
mruby_ccのコンパイル結果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 0 | |
while i < 1000000000 | |
5 * 1.7 | |
i += 1 | |
end | |
puts i | |
==================== | |
mrb_value rb_main(mrb_state *mrb, mrb_value self) { | |
mrb_value *regs = NULL; | |
int ai = mrb->arena_idx; | |
jmp_buf *prev_jmp = (jmp_buf *)mrb->jmp; | |
struct RProc *proc = mrb->ci->proc; | |
mrb_callinfo *ci = mrb->ci; | |
int cioff = mrb->ci - mrb->cibase; | |
// I have to set up my own stack | |
mrb->ci->nregs = 4 + 2; | |
if (ci->argc < 0) { | |
stack_extend(mrb, (4 < 3) ? 3 : 4, 3); | |
} | |
else { | |
stack_extend(mrb, 4, ci->argc+2); | |
} | |
//mrb->ci->proc = proc; | |
regs = mrb->stack; | |
regs[0] = self; | |
// ["OP_LOADI", 1, 255, 127] | |
L_RB_MAIN_0: | |
{ | |
/* A Bx R(A) := sBx */ | |
SET_INT_VALUE(regs[1], 0); | |
NEXT; | |
} | |
// ["OP_JMP", 0, 256, 6] | |
L_RB_MAIN_1: | |
goto L_RB_MAIN_8; | |
// ["OP_LOADI", 2, 256, 4] | |
L_RB_MAIN_2: | |
{ | |
/* A Bx R(A) := sBx */ | |
SET_INT_VALUE(regs[2], 5); | |
NEXT; | |
} | |
// ["OP_LOADL", 3, 0, 0] | |
L_RB_MAIN_3: | |
{ | |
/* A Bx R(A) := Pool(Bx) */ | |
regs[3] = mrb_float_value(1.7); | |
NEXT; | |
} | |
// ["OP_MUL", 2, 0, 1] | |
L_RB_MAIN_4: | |
{ | |
/* A B C R(A) := R(A)*R(A+1) (Syms[B]=:*,C=1)*/ | |
int a = 2; | |
/* need to check if op is overridden */ | |
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { | |
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): | |
{ | |
mrb_int x, y, z; | |
x = mrb_fixnum(regs[a]); | |
y = mrb_fixnum(regs[a+1]); | |
z = x * y; | |
if (x != 0 && z/x != y) { | |
SET_FLT_VALUE(regs[a], (mrb_float)x * (mrb_float)y); | |
} | |
else { | |
SET_INT_VALUE(regs[a], z); | |
} | |
} | |
break; | |
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT): | |
{ | |
mrb_int x = mrb_fixnum(regs[a]); | |
mrb_float y = mrb_float(regs[a+1]); | |
SET_FLT_VALUE(regs[a], (mrb_float)x * y); | |
} | |
break; | |
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM): | |
OP_MATH_BODY(*,attr_f,attr_i); | |
break; | |
case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT): | |
OP_MATH_BODY(*,attr_f,attr_f); | |
break; | |
default: | |
regs[a] = mrb_funcall_with_block(mrb, regs[a], mrb_intern(mrb, "*"), 1, ®s[a+1], mrb_nil_value()); | |
} | |
NEXT; | |
} | |
// ["OP_MOVE", 2, 1, 0] | |
L_RB_MAIN_5: | |
{ | |
/* A B R(A) := R(B) */ | |
regs[2] = regs[1]; | |
NEXT; | |
} | |
// ["OP_ADDI", 2, 1, 1] | |
L_RB_MAIN_6: | |
{ | |
/* A B C R(A) := R(A)+C (Syms[B]=:+)*/ | |
int a = 2; | |
/* need to check if + is overridden */ | |
switch (mrb_type(regs[a])) { | |
case MRB_TT_FIXNUM: | |
{ | |
mrb_int x = regs[a].attr_i; | |
mrb_int y = 1; | |
mrb_int z = x + y; | |
if (((x < 0) ^ (y < 0)) == 0 && (x < 0) != (z < 0)) { | |
/* integer overflow */ | |
SET_FLT_VALUE(regs[a], (mrb_float)x + (mrb_float)y); | |
break; | |
} | |
regs[a].attr_i = z; | |
} | |
break; | |
case MRB_TT_FLOAT: | |
regs[a].attr_f += 1; | |
break; | |
default: | |
SET_INT_VALUE(regs[a+1], 1); | |
regs[a] = mrb_funcall_with_block(mrb, regs[a], mrb_intern(mrb, "+"), 1, ®s[a+1], mrb_nil_value()); | |
} | |
NEXT; | |
} | |
// ["OP_MOVE", 1, 2, 0] | |
L_RB_MAIN_7: | |
{ | |
/* A B R(A) := R(B) */ | |
regs[1] = regs[2]; | |
NEXT; | |
} | |
// ["OP_MOVE", 2, 1, 0] | |
L_RB_MAIN_8: | |
{ | |
/* A B R(A) := R(B) */ | |
regs[2] = regs[1]; | |
NEXT; | |
} | |
// ["OP_LOADL", 3, 0, 1] | |
L_RB_MAIN_9: | |
{ | |
/* A Bx R(A) := Pool(Bx) */ | |
regs[3] = mrb_fixnum_value(1000000000); | |
NEXT; | |
} | |
// ["OP_LT", 2, 2, 1] | |
L_RB_MAIN_10: | |
{ | |
/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/ | |
int a = 2; OP_CMP(<); | |
NEXT; | |
} | |
// ["OP_JMPIF", 2, 255, 118] | |
L_RB_MAIN_11: | |
{ | |
/* A sBx if R(A) pc+=sBx */ | |
if (mrb_test(regs[2])) { | |
goto L_RB_MAIN_2; | |
} | |
NEXT; | |
} | |
// ["OP_LOADSELF", 2, 0, 0] | |
L_RB_MAIN_12: | |
{ | |
/* A R(A) := self */ | |
regs[2] = regs[0]; | |
NEXT; | |
} | |
// ["OP_MOVE", 3, 1, 0] | |
L_RB_MAIN_13: | |
{ | |
/* A B R(A) := R(B) */ | |
regs[3] = regs[1]; | |
NEXT; | |
} | |
// ["OP_SEND", 2, 3, 1] | |
L_RB_MAIN_14: | |
{ | |
int a = 2; | |
int n = 1; | |
mrb_callinfo *prev_ci = mrb->ci - mrb->cibase; | |
mrb_value ret; | |
ret = mrbb_send_r(mrb, mrb_intern(mrb, "puts"), n, ®s, a, 0); | |
if (mrb->ci->proc == -1) { | |
//cipush(mrb); | |
return ret; | |
} | |
regs[a] = ret; | |
mrb->arena_idx = ai; // TODO do we need (because of break;)? | |
NEXT; | |
} | |
// ["OP_STOP", 0, 0, 0] | |
L_RB_MAIN_15: | |
{ | |
/* stop VM */ | |
if (mrb->exc) { | |
printf("OP_STOP reached with Exception:\n"); | |
mrb_p(mrb, mrb_obj_value(mrb->exc)); | |
} | |
/* L_STOP: | |
{ | |
int n = mrb->ci->eidx; | |
while (n--) { | |
ecall(mrb, n); | |
} | |
} | |
mrb->jmp = prev_jmp; | |
if (mrb->exc) { | |
return mrb_obj_value(mrb->exc); | |
} | |
return regs[irep->nlocals];*/ | |
} | |
return mrb_nil_value(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment