Mercurial > repos > rhope
diff test/test.c @ 8:8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 13 May 2009 23:37:19 -0400 |
parents | d61550e2c001 |
children | 3021dac0d8f5 |
line wrap: on
line diff
--- a/test/test.c Wed May 13 00:47:40 2009 -0400 +++ b/test/test.c Wed May 13 23:37:19 2009 -0400 @@ -2,32 +2,50 @@ #include "builtin.h" #include "object.h" #include "integer.h" +#include "context.h" +#include "func.h" + +FuncNoLocals(Main,0) + call = alloc_cdata(cdata->ct,2); + call->params[0] = make_Int32(2); + call->params[1] = make_Int32(3); + call->num_params = 2; + ret = call_method(METHOD_ADD, call); + while(ret == TAIL_RETURN) + ret = call->tail_func(call); + if(ret == EXCEPTION_RETURN) { + Ret(0,call->params[0]); + return ret; + } + call->params[1] = make_Int32(1); + ret = call_method(METHOD_SUB, call); + while(ret == TAIL_RETURN) + ret = call->tail_func(call); + if(ret == EXCEPTION_RETURN) { + Ret(0,call->params[0]); + return ret; + } + Ret(0,call->params[0]) +EndFunc + int main(int argc, char ** argv) { returntype ret; - calldata cdata; + calldata *cdata; + context * ct; register_builtin_types(); - cdata.params[0] = make_Int32(2); - cdata.params[1] = make_Int32(3); - cdata.num_params = 2; - ret = call_method(METHOD_ADD, &cdata); + ct = new_context(); + cdata = alloc_cdata(ct, 1); + cdata->num_params = 0; + ret = _f_Main(cdata); while(ret == TAIL_RETURN) - ret = cdata.tail_func(&cdata); + ret = cdata->tail_func(cdata); if(ret == EXCEPTION_RETURN) { puts("Exception!"); - exit(-1); + return -1; } - printf("After METHOD_ADD: %d\n", ((_t_Int32 *)cdata.params[0])->num); - cdata.params[1] = make_Int32(1); - ret = call_method(METHOD_SUB, &cdata); - while(ret == TAIL_RETURN) - ret = cdata.tail_func(&cdata); - if(ret == EXCEPTION_RETURN) { - puts("Exception!"); - exit(-1); - } - printf("After METHOD_ADD: %d\n", ((_t_Int32 *)cdata.params[0])->num); + printf("Result: %d\n", ((_t_Int32 *)cdata->params[0])->num); return 0; }