# HG changeset patch # User Mike Pavone # Date 1254981158 14400 # Node ID d2f9b0a9403ddf59203fa88479b82c1d1e5d8106 # Parent 7f05bbe82f24091bcabe4a2b163199d2b3ad251c Initial experiment with goto and switch diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/bool.c --- a/runtime/bool.c Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/bool.c Thu Oct 08 01:52:38 2009 -0400 @@ -6,19 +6,3 @@ t_Boolean * val_yes; t_Boolean * val_no; -#define lval ((t_Boolean *)(cdata->params[0]))->val - -MethodNoLocals(If,Boolean, - NumParams 1, - CallSpace 1) - - Param(0, TYPE_BOOLEAN) - - if(lval) - { - Ret(1, NULL) - } else { - Ret(1, cdata->params[0]); - Ret(0, NULL) - } -EndFunc diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/bool.h --- a/runtime/bool.h Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/bool.h Thu Oct 08 01:52:38 2009 -0400 @@ -12,6 +12,5 @@ extern t_Boolean * val_yes; extern t_Boolean * val_no; -MethodDef(If,Boolean) #endif //BOOL_H_ diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/builtin.c --- a/runtime/builtin.c Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/builtin.c Thu Oct 08 01:52:38 2009 -0400 @@ -12,26 +12,26 @@ { case TYPE_INT32: bp = register_type_byid(TYPE_INT32, sizeof(int32_t), NULL, NULL, NULL); - add_method(bp, METHOD_ADD, MethodName(_PL_,Int32)); +/* add_method(bp, METHOD_ADD, MethodName(_PL_,Int32)); add_method(bp, METHOD_SUB, MethodName(_MN_,Int32)); add_method(bp, METHOD_MUL, MethodName(_TM_,Int32)); add_method(bp, METHOD_DIV, MethodName(_DV_,Int32)); add_method(bp, METHOD_LSHIFT, MethodName(LShift,Int32)); add_method(bp, METHOD_RSHIFT, MethodName(RShift,Int32)); add_method(bp, METHOD_LESS, MethodName(_LT_,Int32)); - add_method(bp, METHOD_GREATER, MethodName(_GT_,Int32)); + add_method(bp, METHOD_GREATER, MethodName(_GT_,Int32)); */ break; case TYPE_BOOLEAN: bp = register_type_byid(TYPE_BOOLEAN, sizeof(int32_t), NULL, NULL, NULL); - add_method(bp, METHOD_IF, MethodName(If,Boolean)); + //add_method(bp, METHOD_IF, MethodName(If,Boolean)); val_yes = (t_Boolean *)new_object(TYPE_BOOLEAN); val_yes->val = 1; val_no = (t_Boolean *)new_object(TYPE_BOOLEAN); val_no->val = 0; break; - case TYPE_BLUEPRINT: +/* case TYPE_BLUEPRINT: bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL); - break; + break;*/ } } @@ -42,17 +42,3 @@ register_builtin_type(i); } -//TODO: Remove this when it's possible to write Print in Rhope -FuncNoLocals(Print, - NumParams 1, - CallSpace 0) - - if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32)) - { - printf("%d\n", ((t_Int32 *)(cdata->params[0]))->num); - } else { - puts("Don't know how to print this type"); - } - release_ref(cdata->params[0]); - Ret(0, make_Int32(0)) -EndFunc diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/builtin.h --- a/runtime/builtin.h Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/builtin.h Thu Oct 08 01:52:38 2009 -0400 @@ -47,7 +47,4 @@ void register_builtin_types(); void register_builtin_type(uint32_t type); -//TODO: Remove this when it's possible to write Print in Rhope -FuncDef(Print) - #endif //_BUILTIN_H_ diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/context.c --- a/runtime/context.c Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/context.c Thu Oct 08 01:52:38 2009 -0400 @@ -18,7 +18,6 @@ context * c = malloc(sizeof(context)); c->stack_begin = new_stack(); c->current_stack = c->stack_begin; - c->unwind = NULL; return c; } @@ -51,12 +50,11 @@ return ret; } -calldata * alloc_cdata(context * ct, uint32_t num_params) +calldata * alloc_cdata(context * ct, calldata * lastframe, uint32_t num_params) { - calldata * out = alloc_stack(ct, sizeof(calldata)+(num_params-1)*sizeof(object *)); - if(out) - out->ct = ct; - return out; + calldata * retval = (calldata *)(((char *)alloc_stack(ct, sizeof(calldata)+(num_params-1)*sizeof(object *))) + sizeof(object *)*(num_params-1)); + retval->lastframe = lastframe; + return retval; } void free_stack(context * ct, void * data) diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/context.h --- a/runtime/context.h Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/context.h Thu Oct 08 01:52:38 2009 -0400 @@ -14,20 +14,14 @@ char data[STACK_CHUNK_SIZE]; } stackchunk; -typedef struct { - rhope_func func; - struct calldata *params; -} unwind_cell; - typedef struct context { stackchunk *stack_begin; stackchunk *current_stack; - unwind_cell *unwind; } context; stackchunk * new_stack(); context * new_context(); void * alloc_stack(context * ct, uint32_t size); -struct calldata * alloc_cdata(context * ct, uint32_t num_params); +struct calldata * alloc_cdata(context * ct, struct calldata * lastframe, uint32_t num_params); void free_stack(context * ct, void * data); #endif //_CONTEXT_H_ diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/fib.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/fib.c Thu Oct 08 01:52:38 2009 -0400 @@ -0,0 +1,308 @@ +#include +#include "builtin.h" +#include "object.h" +#include "context.h" +#include "func.h" +#include "integer.h" +#include "bool.h" + +typedef enum { + FUNC__LT_, + FUNC__LT__AT_Int32, + FUNC__MN_, + FUNC__MN__AT_Int32, + FUNC__PL_, + FUNC__PL__AT_Int32, + FUNC_Fib, + FUNC_If, + FUNC_If_AT_Yes_SP_No, + FUNC_Main, + FUNC_Print, + END +} funcids; + +typedef struct { + struct object *____result__0__0; + struct object *____result__0__1; + struct object *____result__10__0; + struct object *____result__11__0; + struct object *____result__1__0; + struct object *____result__5__0; + struct object *____result__6__0; + struct object *____result__7__0; + struct object *out; +} lt_Fib; + +typedef struct { + struct object *____result__0__0; + struct object *____result__1__0; +} lt_Main; + +object * _const_Whole_SP_Number__1; +object * _const_Whole_SP_Number__2; +object * _const_Whole_SP_Number__30; + +void rhope(uint32_t func) +{ + uint16_t resume,idx; + context * ct; + calldata * cdata, *temp_cdata; +FuncDef(Fib) +FuncDef(Main) + + ct = new_context(); + cdata = alloc_cdata(ct, NULL, 0); + cdata->num_params = 0; + cdata->func = END; + resume = 0; +_dispatch: +switch(func) +{ +Method(_LT_) + MethodDispatch(TYPE_INT32,_LT_,Int32) +EndMethod + +MethodImplNoLocals(_LT_,Int32,TYPE_INT32, + NumParams 2) + + Param(1, TYPE_INT32) + + if(((t_Int32 *)cdata->params[0])->num < ((t_Int32 *)cdata->params[-1])->num) + { + release_ref(cdata->params[0]); + Ret(0, Yes) + } else { + release_ref(cdata->params[0]); + Ret(0, No) + } + + release_ref(cdata->params[-1]); +EndFuncNoLocals + +Method(_MN_) + MethodDispatch(TYPE_INT32,_MN_,Int32) +EndMethod + +MethodImplNoLocals(_MN_,Int32,TYPE_INT32, + NumParams 2) + + Param(1, TYPE_INT32) + + cdata->params[0] = copy_object(cdata->params[0]); + ((t_Int32 *)cdata->params[0])->num -= ((t_Int32 *)cdata->params[-1])->num; + + release_ref(cdata->params[-1]); +EndFuncNoLocals + +Method(_PL_) + MethodDispatch(TYPE_INT32,_PL_,Int32) +EndMethod + +MethodImplNoLocals(_PL_,Int32,TYPE_INT32, + NumParams 2) + + Param(1, TYPE_INT32) + + cdata->params[0] = copy_object(cdata->params[0]); + ((t_Int32 *)cdata->params[0])->num += ((t_Int32 *)cdata->params[-1])->num; + + release_ref(cdata->params[-1]); +EndFuncNoLocals + +Func(Fib, + NumParams 1) + lv_Fib->____result__0__0 = NULL; + lv_Fib->____result__0__1 = NULL; + lv_Fib->____result__1__0 = NULL; + lv_Fib->____result__5__0 = NULL; + lv_Fib->____result__6__0 = NULL; + lv_Fib->____result__7__0 = NULL; + lv_Fib->____result__10__0 = NULL; + lv_Fib->____result__11__0 = NULL; + lv_Fib->out = NULL; + + PrepCall(2) + SetParam(0, add_ref(cdata->lastframe->params[0])) + SetParam(1, add_ref(_const_Whole_SP_Number__2)) + Call(_LT_, + NumParams 2, 1, Fib) + lv_Fib->____result__1__0 = cdata->params[0]; + FreeCall + + PrepCall(2) + SetParam(0, add_ref(lv_Fib->____result__1__0)) + Call(If, + NumParams 1, 2, Fib) + lv_Fib->____result__0__0 = cdata->params[0]; + lv_Fib->____result__0__1 = cdata->params[-1]; + FreeCall + + if(lv_Fib->____result__0__1) + { + PrepCall(2) + SetParam(0, add_ref(cdata->lastframe->params[0])) + SetParam(1, add_ref(_const_Whole_SP_Number__1)) + Call(_MN_, + NumParams 2, 3, Fib) + lv_Fib->____result__7__0 = cdata->params[0]; + FreeCall + } + if(lv_Fib->____result__0__1) + { + PrepCall(2) + SetParam(0, add_ref(cdata->lastframe->params[0])) + SetParam(1, add_ref(_const_Whole_SP_Number__2)) + Call(_MN_, + NumParams 2, 4, Fib) + lv_Fib->____result__11__0 = cdata->params[0]; + FreeCall + } + if(lv_Fib->____result__0__0) + { + lv_Fib->out = add_ref(_const_Whole_SP_Number__1); + } + if(lv_Fib->____result__0__1) + { + PrepCall(1) + SetParam(0, add_ref(lv_Fib->____result__7__0)) + Call(Fib, + NumParams 1, 5, Fib) + lv_Fib->____result__6__0 = cdata->params[0]; + FreeCall + } + if(lv_Fib->____result__0__1) + { + PrepCall(1) + SetParam(0, add_ref(lv_Fib->____result__11__0)) + Call(Fib, + NumParams 1, 6, Fib) + lv_Fib->____result__10__0 = cdata->params[0]; + FreeCall + } + if(lv_Fib->____result__0__1) + { + PrepCall(2) + SetParam(0, add_ref(lv_Fib->____result__6__0)) + SetParam(1, add_ref(lv_Fib->____result__10__0)) + Call(_PL_, + NumParams 2, 7, Fib) + lv_Fib->____result__5__0 = cdata->params[0]; + FreeCall + } + if(lv_Fib->____result__0__1) + { + lv_Fib->out = add_ref(lv_Fib->____result__5__0); + } + if(lv_Fib->____result__0__0) + { + release_ref(lv_Fib->____result__0__0); + } + if(lv_Fib->____result__0__1) + { + release_ref(lv_Fib->____result__0__1); + } + if(lv_Fib->____result__1__0) + { + release_ref(lv_Fib->____result__1__0); + } + if(lv_Fib->____result__5__0) + { + release_ref(lv_Fib->____result__5__0); + } + if(lv_Fib->____result__6__0) + { + release_ref(lv_Fib->____result__6__0); + } + if(lv_Fib->____result__7__0) + { + release_ref(lv_Fib->____result__7__0); + } + if(lv_Fib->____result__10__0) + { + release_ref(lv_Fib->____result__10__0); + } + if(lv_Fib->____result__11__0) + { + release_ref(lv_Fib->____result__11__0); + } + release_ref(cdata->params[0]); + Ret(0, lv_Fib->out) +EndFunc(Fib) + +Method(If) + MethodDispatch(TYPE_BOOLEAN,If,Yes_SP_No) +EndMethod + +MethodImplNoLocals(If,Yes_SP_No,TYPE_BOOLEAN, + NumParams 1) + + if(((t_Boolean *)(cdata->params[0]))->val) + { + Ret(1, NULL) + } else { + Ret(1, cdata->params[0]); + Ret(0, NULL) + } +EndFuncNoLocals + +Func(Main, + NumParams 0) + + lv_Main->____result__0__0 = NULL; + lv_Main->____result__1__0 = NULL; + + PrepCall(1) + SetParam(0, add_ref(_const_Whole_SP_Number__30)) + Call(Fib, + NumParams 1, 1, Main) + lv_Main->____result__1__0 = cdata->params[0]; + FreeCall + + PrepCall(1) + SetParam(0, add_ref(lv_Main->____result__1__0)) + Call(Print, + NumParams 1, 2, Main) + lv_Main->____result__0__0 = cdata->params[0]; + FreeCall + + if(lv_Main->____result__0__0) + { + release_ref(lv_Main->____result__0__0); + } + if(lv_Main->____result__1__0) + { + release_ref(lv_Main->____result__1__0); + } +EndFunc(Main) + +FuncNoLocals(Print, + NumParams 1) + + if(get_blueprint(cdata->params[0])->type_id == TYPE_INT32) + { + printf("%d\n", ((t_Int32 *)(cdata->params[0]))->num); + } else { + puts("Don't know how to print this type"); + } + release_ref(cdata->params[0]); + Ret(0, make_Int32(0)) +EndFuncNoLocals + +case END: + return; +} +_exception: + puts("whoops, exception!"); +} + +int main(int argc, char ** argv) +{ + register_builtin_types(); + + _const_Whole_SP_Number__1 = make_Int32(1); + _const_Whole_SP_Number__2 = make_Int32(2); + _const_Whole_SP_Number__30 = make_Int32(30); + + rhope(FUNC_Main); + return 0; +} diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/func.h --- a/runtime/func.h Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/func.h Thu Oct 08 01:52:38 2009 -0400 @@ -15,183 +15,134 @@ #define MethodName(name,type) f_ ## name ## _AT_ ## type -#define Func(name,numparams,callspace,localtype) \ - returntype f_ ## name (calldata * cdata)\ - {\ - localtype *locals;\ - calldata *call;\ - returntype ret;\ - int idx;\ - if(cdata->resume)\ - {\ - call = cdata->call;\ - locals = cdata->locals;\ - }\ - switch(cdata->resume)\ + +#define Func(name,numparams) \ + case FUNC_ ## name:\ +f_ ## name:\ + switch(resume)\ {\ case 0:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ - release_ref(cdata->params[idx]); cdata->num_params = numparams;\ - cdata->num_params = numparams;\ - cdata->call = call = alloc_cdata(cdata->ct, callspace);\ - cdata->locals = locals = alloc_stack(cdata->ct, sizeof(localtype)); + release_ref(cdata->params[0-idx]); cdata->num_params = numparams;\ + lv_ ## name = alloc_stack(ct, sizeof(lt_ ## name)); + -#define FuncNoLocals(name,numparams,callspace) \ - returntype f_ ## name (calldata * cdata)\ - {\ - calldata *call;\ - returntype ret;\ - int idx;\ - if(cdata->resume)\ - call = cdata->locals;\ - switch(cdata->resume)\ +#define FuncNoLocals(name,numparams) \ + case FUNC_ ## name:\ +f_ ## name:\ + switch(resume)\ {\ case 0:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ - release_ref(cdata->params[idx]);\ - cdata->num_params = numparams;\ - cdata->locals = call = alloc_cdata(cdata->ct, callspace); + release_ref(cdata->params[0-idx]); cdata->num_params = numparams;\ -#define EndFunc \ - free_stack(cdata->ct, call);\ - return NORMAL_RETURN;\ - }\ - } +#define EndFunc(name) \ + free_stack(ct, lv_ ## name);\ + func = cdata->func;\ + resume = cdata->resume;\ + goto _dispatch;\ + } + +#define EndFuncNoLocals \ + func = cdata->func;\ + resume = cdata->resume;\ + goto _dispatch;\ + } -#define Method(name,type,numparams,callspace,localtype) \ - returntype MethodName(name,type) (calldata * cdata)\ - {\ - localtype *locals;\ - calldata *call;\ - returntype ret;\ - int idx;\ - if(cdata->resume)\ - {\ - call = cdata->call;\ - locals = cdata->locals;\ - }\ - switch(cdata->resume)\ +#define Method(name) \ + case FUNC_ ## name:\ +f_ ## name:\ + if (cdata->num_params < 1)\ + goto _exception;\ + switch(get_blueprint(cdata->params[0])->type_id)\ + { + +#define EndMethod \ + default:\ + goto _exception;\ + } + + +#define MethodDispatch(type_id,name,type_name) \ + case type_id:\ + goto m_ ## name ## _AT_ ## type_name; + +#define MethodImpl(name,type_name,mytype_id,numparams) \ + case FUNC_ ## name ## _AT_ ## type_name:\ +f_ ## name ## _AT_ ## type_name:\ + switch(resume)\ {\ case 0:\ + if (cdata->num_params < 1)\ + goto _exception;\ + if(get_blueprint(cdata->params[0])->type_id != mytype_id)\ + {\ + puts("uh oh, need conversion and that's not implemented yet!");\ + exit(1);\ + }\ +m_ ## name ## _AT_ ## type_name:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ - release_ref(cdata->params[idx]); cdata->num_params = numparams;\ - cdata->num_params = numparams;\ - cdata->call = call = alloc_cdata(cdata->ct, callspace);\ - cdata->locals = locals = alloc_stack(cdata->ct, sizeof(localtype)); - -#define MethodNoLocals(name,type,numparams,callspace) \ - returntype MethodName(name,type) (calldata * cdata)\ - {\ - calldata *call;\ - returntype ret;\ - int idx;\ - if(cdata->resume)\ - call = cdata->locals;\ - switch(cdata->resume)\ + release_ref(cdata->params[0-idx]); cdata->num_params = numparams;\ + lv_ ## name ## _AT_ ## type_name = alloc_stack(ct, sizeof(lt_ ## name ## _AT_ ## type_name)); + + +#define MethodImplNoLocals(name,type_name,mytype_id,numparams) \ + case FUNC_ ## name ## _AT_ ## type_name:\ +f_ ## name ## _AT_ ## type_name:\ + switch(resume)\ {\ case 0:\ + if (cdata->num_params < 1)\ + goto _exception;\ + if(get_blueprint(cdata->params[0])->type_id != mytype_id)\ + {\ + puts("uh oh, need conversion and that's not implemented yet!");\ + exit(1);\ + }\ +m_ ## name ## _AT_ ## type_name:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ - release_ref(cdata->params[idx]);\ - cdata->num_params = numparams;\ - cdata->locals = call = alloc_cdata(cdata->ct, callspace); - + release_ref(cdata->params[0-idx]); cdata->num_params = numparams; + #define NumParams #define CallSpace #define Param(num,convtypeid) \ - call->params[0] = cdata->params[num];\ - call->resume = 0;\ - ret = coerce_value(convtypeid, call);\ - while(ret == TAIL_RETURN)\ - ret = call->tail_func(call);\ - if(ret == EXCEPTION_RETURN)\ + if(get_blueprint(cdata->params[0-num])->type_id != convtypeid)\ {\ - for(idx = 0; idx < cdata->num_params; ++idx)\ - if(idx != num && cdata->params[idx])\ - release_ref(cdata->params[idx]);\ - cdata->params[0] = call->params[0];\ - free_stack(cdata->ct, call);\ - return ret;\ - }\ - cdata->params[num] = call->params[0]; + puts("uh oh, need conversion and that's not implemented yet!");\ + exit(1);\ + } #define CopiedParam(num,convtypeid) Param(num,convtypeid) cdata->params[num] = copy_object(cdata->params[num]); -#define Ret(num,val) cdata->params[num] = (object *)(val); -#define Return return NORMAL_RETURN; +#define Ret(num,val) cdata->params[0-num] = (object *)(val); #define Exception -#define FuncDef(name) returntype f_ ## name (calldata * cdata); -#define MethodDef(name,type) returntype MethodName(name,type) (calldata * cdata); +#define FuncDef(name) lt_ ## name * lv_ ## name; +#define MethodDef(name) lt_ ## name ## _AT_ ## type_name * lv_ ## name ## _AT_ ## type_name; + + +#define PrepCall(callspace) cdata = alloc_cdata(ct, cdata, callspace); -#define Call(func, numparams)\ - call->num_params = numparams;\ - call->resume = 0;\ - ret = f_ ## func (call);\ - while(ret == TAIL_RETURN)\ - ret = call->tail_func(call);\ - if(ret == EXCEPTION_RETURN)\ - {\ - for(idx = 0; idx < cdata->num_params; ++idx)\ - if(cdata->params[idx])\ - release_ref(cdata->params[idx]);\ - cdata->params[0] = call->params[0];\ - free_stack(cdata->ct, call);\ - return ret;\ - } - -#define MCall(methodid, numparams)\ - call->num_params = numparams;\ - call->resume = 0;\ - ret = call_method(methodid, call);\ - while(ret == TAIL_RETURN)\ - ret = call->tail_func(call);\ - if(ret == EXCEPTION_RETURN)\ - {\ - for(idx = 0; idx < cdata->num_params; ++idx)\ - if(cdata->params[idx])\ - release_ref(cdata->params[idx]);\ - cdata->params[0] = call->params[0];\ - free_stack(cdata->ct, call);\ - return ret;\ - } +#define SetParam(num,value) cdata->params[0-num] = value; + +#define Call(tocall, numparams, resumeto, myname)\ + cdata->func = FUNC_ ## myname;\ + cdata->resume = resumeto;\ + cdata->num_params = numparams;\ + resume = 0;\ + goto f_ ## tocall;\ + case resumeto:\ + lv_ ## myname = (lt_ ## myname *)(cdata->lastframe+1); -#define GFieldCall(fieldid)\ - call->num_params = 1;\ - call->resume = 0;\ - ret = get_field(fieldid, call);\ - while(ret == TAIL_RETURN)\ - ret = call->tail_func(call);\ - if(ret == EXCEPTION_RETURN)\ - {\ - for(idx = 0; idx < cdata->num_params; ++idx)\ - if(cdata->params[idx])\ - release_ref(cdata->params[idx]);\ - cdata->params[0] = call->params[0];\ - free_stack(cdata->ct, call);\ - return ret;\ - } - -#define SFieldCall(fieldid)\ - call->num_params = 2;\ - call->resume = 0;\ - ret = set_field(fieldid, call);\ - while(ret == TAIL_RETURN)\ - ret = call->tail_func(call);\ - if(ret == EXCEPTION_RETURN)\ - {\ - for(idx = 0; idx < cdata->num_params; ++idx)\ - if(cdata->params[idx])\ - release_ref(cdata->params[idx]);\ - cdata->params[0] = call->params[0];\ - free_stack(cdata->ct, call);\ - return ret;\ - } +#define FreeCall\ + temp_cdata = cdata->lastframe;\ + free_stack(ct, cdata);\ + cdata = temp_cdata; -#define TMCall(methodid, numparams)\ - free_stack(cdata->ct, call);\ - cdata->num_params = numparams;\ - cdata->resume = 0;\ - ret = call_method(methodid, cdata);\ - return ret; +#define FreeCallMethod(myname,mytype)\ + temp_cdata = cdata->lastframe;\ + free_stack(ct, cdata);\ + cdata = temp_cdata;\ + lv_ ## myname ## _AT_ ## type_name = (lt_ ## myname ## _AT_ ## type_name *)(cdata+1); #define TCall(func, numparams)\ free_stack(cdata->ct, call);\ diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/integer.c --- a/runtime/integer.c Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/integer.c Thu Oct 08 01:52:38 2009 -0400 @@ -3,117 +3,6 @@ #include "context.h" #include "bool.h" -#define left ((t_Int32 *)cdata->params[0]) -#define right ((t_Int32 *)cdata->params[1]) - -MethodNoLocals(_PL_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num += right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_MN_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num -= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_TM_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num *= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_DV_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num /= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(LShift,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num <<= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(RShift,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num <<= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_LT_,Int32, - NumParams 2, - CallSpace 1) - - Param(0, TYPE_INT32) - Param(1, TYPE_INT32) - - if(left->num < right->num) - { - release_ref(cdata->params[0]); - Ret(0, Yes) - } else { - release_ref(cdata->params[0]); - Ret(0, No) - } - release_ref(cdata->params[1]); -EndFunc - -MethodNoLocals(_GT_,Int32, - NumParams 2, - CallSpace 1) - - Param(0, TYPE_INT32) - Param(1, TYPE_INT32) - - if(left->num > right->num) - { - release_ref(cdata->params[0]); - Ret(0, Yes) - } else { - release_ref(cdata->params[0]); - Ret(0, No) - } - release_ref(cdata->params[1]); -EndFunc - object * make_Int32(int32_t val) { t_Int32 * obj; diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/integer.h --- a/runtime/integer.h Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/integer.h Thu Oct 08 01:52:38 2009 -0400 @@ -8,15 +8,6 @@ int32_t num; Object(Int32) -MethodDef(_PL_,Int32) -MethodDef(_MN_,Int32) -MethodDef(_TM_,Int32) -MethodDef(_DV_,Int32) -MethodDef(LShift,Int32) -MethodDef(RShift,Int32) -MethodDef(_LT_,Int32) -MethodDef(_GT_,Int32) - object * make_Int32(int32_t val); #endif //_INTEGER_H_ diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/object.c --- a/runtime/object.c Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/object.c Thu Oct 08 01:52:38 2009 -0400 @@ -8,6 +8,7 @@ uint32_t max_registered_type = 0; uint32_t type_storage = 0; +/* returntype call_method(uint32_t methodid, calldata * params) { int i; @@ -121,7 +122,7 @@ release_ref(params->params[i]); params->params[0] = new_object(TYPE_WRONGTYPEEXCEPTION); return EXCEPTION_RETURN; -} +}*/ object * alloc_object(blueprint * bp) { @@ -275,6 +276,7 @@ bp->size = size; bp->boxed_size = size >= 0 ? size + sizeof(object) : size; bp->method_lookup = bp->getter_lookup = bp->setter_lookup = bp->convert_to = bp->convert_from = NULL; + bp->type_id = type; bp->init = init ? init : default_action; bp->copy = copy ? copy : default_action; bp->cleanup = cleanup ? cleanup : default_action; diff -r 7f05bbe82f24 -r d2f9b0a9403d runtime/object.h --- a/runtime/object.h Tue Oct 06 23:13:47 2009 -0400 +++ b/runtime/object.h Thu Oct 08 01:52:38 2009 -0400 @@ -15,6 +15,7 @@ special_func copy; special_func cleanup; struct object *name; + uint32_t type_id; uint32_t first_methodid; uint32_t last_methodid; uint32_t first_getfieldid; @@ -39,17 +40,15 @@ uint32_t size; } multisize; - +#pragma pack(push,1) typedef struct calldata { - rhope_func tail_func; - struct context *ct; - void *locals; - struct calldata *call; - uint32_t original_methodid; - uint16_t num_params; - uint16_t resume; - object *params[1]; + object *params[1]; + struct calldata *lastframe; + uint16_t num_params; + uint16_t resume; + uint32_t func; } calldata; +#pragma pack(pop) #define OBegin typedef struct { object header; #define Object(name) } t_ ## name;