Mercurial > repos > rhope
annotate test/test.c @ 138:1411de6050e1
First stab at transaction data structures, needs work
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 16 Nov 2010 21:53:18 -0500 |
parents | 31f8182f3433 |
children |
rev | line source |
---|---|
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include "builtin.h" |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "object.h" |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "integer.h" |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
5 #include "context.h" |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
6 #include "func.h" |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
7 |
11
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
8 FuncNoLocals(Main, |
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
9 NumParams 0, |
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
10 CallSpace 2) |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
11 call->params[0] = make_Int32(2); |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
12 call->params[1] = make_Int32(3); |
11
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
13 MCall(METHOD_ADD, 2) |
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
14 |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
15 call->params[1] = make_Int32(1); |
11
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
16 MCall(METHOD_SUB, 2) |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
17 Ret(0,call->params[0]) |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
18 EndFunc |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
19 |
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 int main(int argc, char ** argv) |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 { |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 returntype ret; |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
24 calldata *cdata; |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
25 context * ct; |
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 register_builtin_types(); |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
27 ct = new_context(); |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
28 cdata = alloc_cdata(ct, 1); |
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
29 cdata->num_params = 0; |
11
3021dac0d8f5
Stack unwind is so close I can almost taste it
Mike Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
30 cdata->resume = 0; |
12
31f8182f3433
Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
31 ret = f_Main(cdata); |
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 while(ret == TAIL_RETURN) |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
33 ret = cdata->tail_func(cdata); |
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 if(ret == EXCEPTION_RETURN) { |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 puts("Exception!"); |
8
8d74ef7fa357
Improved helper macros and added separate Rhope stack in runtime
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
36 return -1; |
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } |
12
31f8182f3433
Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
38 printf("Result: %d\n", ((t_Int32 *)cdata->params[0])->num); |
7
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 return 0; |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 } |
d61550e2c001
Added current work on new runtime
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |