Mercurial > repos > rhope
comparison cbackend.rhope @ 33:3b47a8538df2
Started adding support for user defined types to C backend
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Sep 2009 22:08:40 -0400 |
parents | 914ad38f9b59 |
children | df038cef648b |
comparison
equal
deleted
inserted
replaced
32:9ee9adc696e7 | 33:3b47a8538df2 |
---|---|
53 } | 53 } |
54 | 54 |
55 Method ID@C Method Registry[reg,method:out,notfound] | 55 Method ID@C Method Registry[reg,method:out,notfound] |
56 { | 56 { |
57 out,notfound <- [[reg]Lookup >>]Index[method] | 57 out,notfound <- [[reg]Lookup >>]Index[method] |
58 } | |
59 | |
60 Blueprint C Type | |
61 { | |
62 Name | |
63 Fields | |
64 Methods | |
65 } | |
66 | |
67 C Type[name:out] | |
68 { | |
69 out <- [[[Build["C Type"]]Name <<[name]]Fields <<[()]]Methods <<[()] | |
70 } | |
71 | |
72 Add Field@C Type[ctype,name,type:out] | |
73 { | |
74 out <- [ctype]Fields <<[ [[ctype]Fields >>]Append[ [[()]Append[name]]Append[type] ] ] | |
75 } | |
76 | |
77 Add Method@C Type[ctype,name:out] | |
78 { | |
79 out <- [ctype]Methods <<[ [[ctype]Methods >>]Append[name] ] | |
80 } | |
81 | |
82 _Type Def C Type[text,field:out] | |
83 { | |
84 name <- [field]Index[0] | |
85 rawtype <- [field]Index[1] | |
86 If[[rawtype] = ["Any Type"]] | |
87 { | |
88 type <- "\n\tobject * " | |
89 }{ | |
90 type <- [["\n\tt_"]Append[Escape Rhope Name[rawtype]]]Append[" * "] | |
91 } | |
92 out <- [[[text]Append[type]]Append[Escape Rhope Name[name]]]Append[";"] | |
93 } | |
94 | |
95 Type Def@C Type[ctype:out] | |
96 { | |
97 out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] | |
98 } | |
99 | |
100 _Type Init C[type name,method reg,text,method:out] | |
101 { | |
102 out <- [[text]Append[[["\n\tadd_method(bp, "]Append[ [method reg]Method ID[method] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[method]]]Append[[","]Append[Escape Rhope Name[type name]]]]]]Append["));"] | |
103 } | |
104 | |
105 Type Init@C Type[ctype,id,method reg,field reg:out] | |
106 { | |
107 //TODO: Handle function pointers for build/copy/destroy funcs | |
108 start <- [["\tbp = register_type_byid("]Append[id]]Append[ [[", sizeof("]Append[["t_"]Append[Escape Rhope Name[ [ctype]Name >> ]]]]Append["), NULL, NULL, NULL);"] ] | |
109 out <- Fold[[["_Type Init C"]Set Input[0, [ctype]Name >>]]Set Input[1, method reg], start, [ctype]Methods >>] | |
110 } | |
111 | |
112 Blueprint C Type Registry | |
113 { | |
114 Lookup | |
115 Definitions | |
116 Next ID | |
117 } | |
118 | |
119 C Type Registry[:out] | |
120 { | |
121 out <- [[[Build["C Type Registry"]]Lookup << [ | |
122 [[[[[[[[[[[[[[[[New@Dictionary[] | |
123 ]Set["UInt8", "TYPE_UINT8"] | |
124 ]Set["UInt16", "TYPE_UINT16"] | |
125 ]Set["UInt32", "TYPE_UINT32"] | |
126 ]Set["UInt64", "TYPE_UINT64"] | |
127 ]Set["Int8", "TYPE_INT8"] | |
128 ]Set["Int16", "TYPE_INT16"] | |
129 ]Set["Int32", "TYPE_INT32"] | |
130 ]Set["Int64", "TYPE_INT64"] | |
131 ]Set["Yes No", "TYPE_BOOLEAN"] | |
132 ]Set["Float32", "TYPE_FLOAT32"] | |
133 ]Set["Float64", "TYPE_FLOAT64"] | |
134 ]Set["Real Number", "TYPE_FLOAT64"] | |
135 ]Set["Array", "TYPE_ARRAY"] | |
136 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] | |
137 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] | |
138 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] | |
139 ]Definitions << [New@Dictionary[]] | |
140 ]Next ID <<[0] | |
141 } | |
142 | |
143 Register Type@C Type Registry[reg,name,def:out] | |
144 { | |
145 [[reg]Lookup >>]Index[name] | |
146 { | |
147 out <- reg | |
148 }{ | |
149 out <- [[[reg]Lookup <<[ [[reg]Lookup >>]Set[name, ["TYPE_FIRST_USER+"]Append[[reg]Next ID >>]] ] | |
150 ]Definitions <<[ [[reg]Definitions >>]Set[name, def] ] | |
151 ]Next ID <<[ [[reg]Next ID >>]+[1] ] | |
152 } | |
153 } | |
154 | |
155 Type ID@C Type Registry[reg,name:out,notfound] | |
156 { | |
157 out,notfound <- [[reg]Lookup >>]Index[name] | |
58 } | 158 } |
59 | 159 |
60 Blueprint C Function | 160 Blueprint C Function |
61 { | 161 { |
62 Name | 162 Name |