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