comparison test/fib.c @ 11:3021dac0d8f5

Stack unwind is so close I can almost taste it
author Mike Pavone <pavone@retrodev.com>
date Tue, 19 May 2009 23:29:55 -0400
parents
children 31f8182f3433
comparison
equal deleted inserted replaced
10:0f2c4ee070fe 11:3021dac0d8f5
1 #include <stdio.h>
2 #include "builtin.h"
3 #include "object.h"
4 #include "integer.h"
5 #include "context.h"
6 #include "func.h"
7
8 typedef struct
9 {
10 object * work1;
11 object * work2;
12 } fib_t;
13
14 object * const_1;
15 object * const_2;
16
17 Func(Fib,
18 NumParams 1,
19 CallSpace 2,
20 fib_t);
21
22 MCall(METHOD_SUB,
23 EndFunc
24
25 FuncNoLocals(Main,
26 NumParams 0,
27 CallSpace 2)
28
29 call->params[0] = make_Int32(2);
30 call->params[1] = make_Int32(3);
31 call->num_params = 2;
32 call->resume = 0;
33 ret = call_method(METHOD_ADD, call);
34 while(ret == TAIL_RETURN)
35 ret = call->tail_func(call);
36 if(ret == EXCEPTION_RETURN) {
37 Ret(0,call->params[0]);
38 return ret;
39 }
40 call->params[1] = make_Int32(1);
41 call->resume = 0;
42 ret = call_method(METHOD_SUB, call);
43 while(ret == TAIL_RETURN)
44 ret = call->tail_func(call);
45 if(ret == EXCEPTION_RETURN) {
46 Ret(0,call->params[0]);
47 return ret;
48 }
49 Ret(0,call->params[0])
50 EndFunc
51
52
53 int main(int argc, char ** argv)
54 {
55 returntype ret;
56 calldata *cdata;
57 context * ct;
58 register_builtin_types();
59 ct = new_context();
60 cdata = alloc_cdata(ct, 1);
61 cdata->num_params = 0;
62 cdata->resume = 0;
63
64 const_1 = make_Int32(1);
65 const_2 = make_Int32(2);
66 ret = _f_Main(cdata);
67 while(ret == TAIL_RETURN)
68 ret = cdata->tail_func(cdata);
69 if(ret == EXCEPTION_RETURN) {
70 puts("Exception!");
71 return -1;
72 }
73 printf("Result: %d\n", ((_t_Int32 *)cdata->params[0])->num);
74 return 0;
75 }
76