Mercurial > repos > rhope
annotate runtime/func_raw.h @ 189:d0e3a13c1bd9 default tip
Remove old calculator example
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 07 Oct 2011 00:24:04 -0700 |
parents | ba35ab624ec2 |
children |
rev | line source |
---|---|
186
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 typedef struct { |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 int num_ret; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 object ** retvals; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 } returntype; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 typedef returntype (*rhope_func)(int, object **); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #define DispatchEntry(name) f_ ## name, |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #define ResumeEntry(num,name) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #define ResEnum(num,name) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #define DispatchVar rhope_func func_lookup[] = { DispatchEntries }; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define EndEntry |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #define EndThreadEntry |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #define DISPATCH |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 #define lv(func,var) lv_ ## var |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #define lvar(type, name) type lv_ ## name; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define my_params(num) params[num] |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #define child_params(num) call_params[num] |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 #define my_outputs(num) retvals[num] |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 #define result(num) callret.retvals[num] |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #define numresults callret.num_ret |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 #define LocalsType(def,func) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 #define Func(name, numparams, numret) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 returntype f_ ## name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 ldec_ ## name;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 static object * retvals[numret];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 object * call_params[32];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 int idx, vcparam_offset, last_vcparam;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 returntype callret,retinfo = {numret, &retvals};\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 for(idx = numparams; idx < num_params; ++idx)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 release_ref(params[idx]); num_params = numparams; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 #define FuncNoLocals(name, numparams, numret) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 returntype f_ ## name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 object * call_params[32];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 static object * retvals[numret];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 int idx, vcparam_offset, last_vcparam;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 returntype callret,retinfo = {numret, &retvals};\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 for(idx = numparams; idx < num_params; ++idx)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 release_ref(params[idx]); num_params = numparams; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 #define Param(num,convtypeid) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 if(get_blueprint(params[num])->type_id != convtypeid)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 printf("uh oh, need conversion from type %d to type %d for param %d and that's not implemented yet!", get_blueprint(params[num])->type_id, convtypeid, num);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 exit(1);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 } |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 #define CopiedParam(num,convtypeid) Param(num,convtypeid) params[num] = copy_object(params[num]); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 #define Ret(num,val) retvals[num] = (object *)(val); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 #define NumRet(num) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 #define EndFunc(name) return retinfo;} |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 #define EndFuncNoLocals return retinfo;} |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 #define MethodImpl(name,type_name,mytype_id,numparams,numret) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 returntype f_ ## name ## AT_ ## type_name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 if (num_params < 1)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 printf("Direct call to %s@%s had no arguments!", #name, #type_name);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 printf("%d\n", *((char *)0));\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 exit(1);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 if(get_blueprint(params[0])->type_id != mytype_id)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 printf("uh oh, need conversion from type %d to %s(%d) for %s and that's not implemented yet!\n", get_blueprint(params[0])->type_id, #type_name, mytype_id, #name);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 exit(1);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 return m_ ## name ## AT_ ## type_name(num_params, params);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 returntype m_ ## name ## AT_ ## type_name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 ldec_ ## name ## AT_ ## type_name;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 static object * retvals[numret];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 object * call_params[32];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 int idx, vcparam_offset, last_vcparam;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 returntype callret,retinfo = {numret, &retvals};\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 for(idx = numparams; idx < num_params; ++idx)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 release_ref(params[idx]); num_params = numparams; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 #define MethodImplNoLocals(name,type_name,mytype_id,numparams,numret) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 returntype f_ ## name ## AT_ ## type_name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 if (num_params < 1)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 printf("Direct call to %s@%s had no arguments!", #name, #type_name);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 exit(1);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 if(get_blueprint(params[0])->type_id != mytype_id)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 printf("uh oh, need conversion from type %d to %s(%d) for %s and that's not implemented yet!\n", get_blueprint(params[0])->type_id, #type_name, mytype_id, #name);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 exit(1);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 return m_ ## name ## AT_ ## type_name(num_params, params);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 returntype m_ ## name ## AT_ ## type_name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 static object * retvals[numret];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 object * call_params[32];\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 int idx, vcparam_offset, last_vcparam;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 returntype callret,retinfo = {numret, &retvals};\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 for(idx = numparams; idx < num_params; ++idx)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 release_ref(params[idx]); num_params = numparams; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 #define Method(name) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 returntype f_ ## name(int num_params, object ** params) {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 switch(get_blueprint(params[0])->type_id)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 { |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 #define EndMethod(mname) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 default:\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 printf("Type ");\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 fwrite( ((t_Array *)((t_String *)get_blueprint(params[0])->name)->payload.Buffer)+1, 1, ((t_Array *)((t_String *)get_blueprint(params[0])->name)->payload.Buffer)->payload.Length, stdout);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 printf("(%d) does not implement method %s\n", get_blueprint(params[0])->type_id, #mname);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 printf("%d\n", *((char *)0));\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 exit(1);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 } |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 #define MethodDispatch(type_id,name,type_name) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 case type_id:\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 return m_ ## name ## AT_ ## type_name(num_params, params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 #define FuncDef(name) returntype f_ ## name(int num_params, object ** params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 #define MethodDef(name) returntype f_ ## name(int num_params, object ** params); returntype m_ ## name(int num_params, object ** params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 #define PrepCall(callspace) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 #define SetParam(num,value) call_params[num] = value; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 #define VCRePrepCall(func,numparams,lastnumparams) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 vcparam_offset = 0;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 last_vcparam = -1; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 #define VCPrepCall(func,numparams) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 vcparam_offset = 0;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 last_vcparam = -1; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 #define VCSetParam(func,num,value) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 while((num+vcparam_offset) < ((t_Worker *)func)->payload.Size && ((object **)(((t_Worker *)func)+1))[num+vcparam_offset])\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 call_params[num+vcparam_offset] = add_ref(((object **)(((t_Worker *)func)+1))[num+vcparam_offset]);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 ++vcparam_offset;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 call_params[num+vcparam_offset] = value;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 last_vcparam = num+vcparam_offset; |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 #define ValCall(tocall,numparams,resumeto,myname)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 last_vcparam++;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 while(last_vcparam < ((t_Worker *)tocall)->payload.Size)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 if (((object **)(((t_Worker *)tocall)+1))[last_vcparam]) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 call_params[last_vcparam] = add_ref(((object **)(((t_Worker *)tocall)+1))[last_vcparam]);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 ++last_vcparam;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 callret = func_lookup[((t_Worker *)tocall)->payload.Index](numparams + ((t_Worker *)tocall)->payload.Count, &call_params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 #define ValCallNoLocals(tocall,numparams,resumeto,myname)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 last_vcparam++;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 while(last_vcparam < ((t_Worker *)tocall)->payload.Size)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 {\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 if (((object **)(((t_Worker *)tocall)+1))[last_vcparam]) \ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 call_params[last_vcparam] = add_ref(((object **)(((t_Worker *)tocall)+1))[last_vcparam]);\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 ++last_vcparam;\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 }\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 callret = func_lookup[((t_Worker *)tocall)->payload.Index](numparams + ((t_Worker *)tocall)->payload.Count, &call_params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 #define ValCallPostlude(resumeto,myname) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 #define ValCallNoLocalsPostlude(resumeto,myname) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 #define Call(tocall, numparams, resumeto, myname)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 callret = f_ ## tocall(numparams, &call_params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 #define CallNoLocals(tocall, numparams, resumeto, myname)\ |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 callret = f_ ## tocall(numparams, &call_params); |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 #define FreeCall |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 #define FreeCallMethod(myname,mytype) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 #define TPrepCall(callspace) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 #define TCall(tocall, numparams) |
ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 |