Mercurial > repos > rhope
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:d61550e2c001 | 8:8d74ef7fa357 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include "builtin.h" | 2 #include "builtin.h" |
3 #include "object.h" | 3 #include "object.h" |
4 #include "integer.h" | 4 #include "integer.h" |
5 #include "context.h" | |
6 #include "func.h" | |
7 | |
8 FuncNoLocals(Main,0) | |
9 call = alloc_cdata(cdata->ct,2); | |
10 call->params[0] = make_Int32(2); | |
11 call->params[1] = make_Int32(3); | |
12 call->num_params = 2; | |
13 ret = call_method(METHOD_ADD, call); | |
14 while(ret == TAIL_RETURN) | |
15 ret = call->tail_func(call); | |
16 if(ret == EXCEPTION_RETURN) { | |
17 Ret(0,call->params[0]); | |
18 return ret; | |
19 } | |
20 call->params[1] = make_Int32(1); | |
21 ret = call_method(METHOD_SUB, call); | |
22 while(ret == TAIL_RETURN) | |
23 ret = call->tail_func(call); | |
24 if(ret == EXCEPTION_RETURN) { | |
25 Ret(0,call->params[0]); | |
26 return ret; | |
27 } | |
28 Ret(0,call->params[0]) | |
29 EndFunc | |
30 | |
5 | 31 |
6 int main(int argc, char ** argv) | 32 int main(int argc, char ** argv) |
7 { | 33 { |
8 returntype ret; | 34 returntype ret; |
9 calldata cdata; | 35 calldata *cdata; |
36 context * ct; | |
10 register_builtin_types(); | 37 register_builtin_types(); |
11 cdata.params[0] = make_Int32(2); | 38 ct = new_context(); |
12 cdata.params[1] = make_Int32(3); | 39 cdata = alloc_cdata(ct, 1); |
13 cdata.num_params = 2; | 40 cdata->num_params = 0; |
14 ret = call_method(METHOD_ADD, &cdata); | 41 ret = _f_Main(cdata); |
15 while(ret == TAIL_RETURN) | 42 while(ret == TAIL_RETURN) |
16 ret = cdata.tail_func(&cdata); | 43 ret = cdata->tail_func(cdata); |
17 if(ret == EXCEPTION_RETURN) { | 44 if(ret == EXCEPTION_RETURN) { |
18 puts("Exception!"); | 45 puts("Exception!"); |
19 exit(-1); | 46 return -1; |
20 } | 47 } |
21 printf("After METHOD_ADD: %d\n", ((_t_Int32 *)cdata.params[0])->num); | 48 printf("Result: %d\n", ((_t_Int32 *)cdata->params[0])->num); |
22 cdata.params[1] = make_Int32(1); | |
23 ret = call_method(METHOD_SUB, &cdata); | |
24 while(ret == TAIL_RETURN) | |
25 ret = cdata.tail_func(&cdata); | |
26 if(ret == EXCEPTION_RETURN) { | |
27 puts("Exception!"); | |
28 exit(-1); | |
29 } | |
30 printf("After METHOD_ADD: %d\n", ((_t_Int32 *)cdata.params[0])->num); | |
31 return 0; | 49 return 0; |
32 } | 50 } |
33 | 51 |