annotate cbackend.rhope @ 34:df038cef648b

More work on supporting user defined types in the C backend
author Mike Pavone <pavone@retrodev.com>
date Wed, 30 Sep 2009 01:25:03 -0400
parents 3b47a8538df2
children 3498713c3dc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
1 Import extendlib.rhope
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
2 Import backendutils.rhope
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 Blueprint Blueprint Def
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 Name
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 Fixed Size
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 Fields
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 Methods
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 Blueprint Def[name]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 out <- [[[[Build["Blueprint Def"]]Name <<[name]]Fixed Size <<[0]]Fields <<[()]]Methods <<[New@Dictionary[]]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
17 Blueprint C Method Registry
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
18 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
19 Lookup
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
20 Next ID
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
21 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
22
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
23 C Method Registry[:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
24 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
25 builtins <- [[[[[[[[[[[[[New@Dictionary[]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
26 ]Set["+", "METHOD_ADD"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
27 ]Set["-", "METHOD_SUB"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
28 ]Set["/", "METHOD_DIV"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
29 ]Set["*", "METHOD_MUL"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
30 ]Set["LShift", "METHOD_LSHIFT"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
31 ]Set["RShift", "METHOD_RSHIFT"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
32 ]Set["=", "METHOD_EQUALS"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
33 ]Set[">", "METHOD_GREATER"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
34 ]Set["<", "METHOD_LESS"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
35 ]Set["If", "METHOD_IF"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
36 ]Set["Set Missing Field", "METHOD_SETFIELDMISSING"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
37 ]Set["Get Missing Field", "METHOD_GETFIELDMISSING"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
38 ]Set["Missing Method", "METHOD_MISSING"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
39 out <- [[Build["C Method Registry"]]Lookup <<[builtins]]Next ID<<[0]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
40
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
41 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
42
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
43 Register Method@C Method Registry[reg,method:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
44 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
45 [[reg]Lookup >>]Index[method]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
46 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
47 out <- reg
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
48 }{
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
49 method ID <- [reg]Next ID>>
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
50 new lookup <- [[reg]Lookup >>]Set[method, ["METHOD_FIRST_USER+"]Append[method ID]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
51 out <- [[reg]Lookup <<[new lookup]]Next ID <<[[method ID]+[1]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
52 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
53 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
54
20
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
55 Method ID@C Method Registry[reg,method:out,notfound]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
56 {
20
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
57 out,notfound <- [[reg]Lookup >>]Index[method]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
58 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
59
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
60 Blueprint C Field Registry
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
61 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
62 Lookup
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
63 Next ID
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
64 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
65
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
66 C Field Registry[:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
67 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
68 out <- [[Build["C Field Registry"]]Lookup <<[New@Dictionary[]]]Next ID<<[0]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
69
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
70 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
71
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
72 Register Field@C Field Registry[reg,field:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
73 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
74 [[reg]Lookup >>]Index[field]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
75 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
76 out <- reg
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
77 }{
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
78 field ID <- [reg]Next ID>>
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
79 new lookup <- [[reg]Lookup >>]Set[field, field ID]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
80 out <- [[reg]Lookup <<[new lookup]]Next ID <<[[field ID]+[1]]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
81 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
82 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
83
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
84 Field ID@C Field Registry[reg,field:out,notfound]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
85 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
86 out,notfound <- [[reg]Lookup >>]Index[field]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
87 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
88
33
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
89 Blueprint C Type
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
90 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
91 Name
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
92 Fields
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
93 Methods
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
94 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
95
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
96 C Type[name:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
97 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
98 out <- [[[Build["C Type"]]Name <<[name]]Fields <<[()]]Methods <<[()]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
99 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
100
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
101 Add Field@C Type[ctype,name,type:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
102 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
103 out <- [ctype]Fields <<[ [[ctype]Fields >>]Append[ [[()]Append[name]]Append[type] ] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
104 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
105
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
106 Add Method@C Type[ctype,name:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
107 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
108 out <- [ctype]Methods <<[ [[ctype]Methods >>]Append[name] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
109 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
110
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
111 Register Methods@C Type[ctype,method reg:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
112 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
113 out <- Fold["Register Method", method reg, [ctype]Methods >>]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
114 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
115
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
116 Register Fields@C Type[ctype,field reg:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
117 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
118 out <- Fold["Register Field", field reg, [ctype]Fields >>]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
119 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
120
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
121 Rhope Type to C[typename,naked:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
122 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
123 If[[typename] = ["Any Type"]]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
124 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
125 ctype <- "struct object"
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
126 }{
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
127 ctype <- ["t_"]Append[Escape Rhope Name[typename]]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
128 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
129 If[naked]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
130 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
131 out <- Val[ctype]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
132 }{
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
133 out <- [ctype]Append[" * "]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
134 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
135 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
136
33
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
137 _Type Def C Type[text,field:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
138 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
139 name <- [field]Index[0]
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
140 type <- ["\n\t"]Append[Rhope Type to C[[field]Index[1], No]]
33
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
141 out <- [[[text]Append[type]]Append[Escape Rhope Name[name]]]Append[";"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
142 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
143
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
144 Type Def@C Type[ctype:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
145 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
146 out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
147 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
148
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
149 _Type Init C[type name,method reg,text,method:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
150 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
151 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["));"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
152 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
153
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
154 Type Init@C Type[ctype,id,method reg,field reg:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
155 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
156 //TODO: Handle function pointers for build/copy/destroy funcs
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
157 start <- [["\tbp = register_type_byid("]Append[id]]Append[ [[", sizeof("]Append[["t_"]Append[Escape Rhope Name[ [ctype]Name >> ]]]]Append["), NULL, NULL, NULL);"] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
158 out <- Fold[[["_Type Init C"]Set Input[0, [ctype]Name >>]]Set Input[1, method reg], start, [ctype]Methods >>]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
159 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
160
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
161 Blueprint C Type Registry
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
162 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
163 Lookup
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
164 Definitions
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
165 Next ID
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
166 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
167
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
168 C Type Registry[:out]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
169 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
170 out <- [[[Build["C Type Registry"]]Lookup << [
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
171 [[[[[[[[[[[[[[[[New@Dictionary[]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
172 ]Set["UInt8", "TYPE_UINT8"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
173 ]Set["UInt16", "TYPE_UINT16"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
174 ]Set["UInt32", "TYPE_UINT32"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
175 ]Set["UInt64", "TYPE_UINT64"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
176 ]Set["Int8", "TYPE_INT8"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
177 ]Set["Int16", "TYPE_INT16"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
178 ]Set["Int32", "TYPE_INT32"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
179 ]Set["Int64", "TYPE_INT64"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
180 ]Set["Yes No", "TYPE_BOOLEAN"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
181 ]Set["Float32", "TYPE_FLOAT32"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
182 ]Set["Float64", "TYPE_FLOAT64"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
183 ]Set["Real Number", "TYPE_FLOAT64"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
184 ]Set["Array", "TYPE_ARRAY"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
185 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
186 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
187 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
188 ]Definitions << [New@Dictionary[]]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
189 ]Next ID <<[0]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
190 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
191
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
192 _Type Defs C[text,def:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
193 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
194 out <- [[text]Append["\n\n"]]Append[[def]Type Def]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
195 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
196
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
197 Type Defs@C Type Registry[reg:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
198 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
199 out <- Fold["_Type Defs C", "", [reg]Definitions >>]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
200 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
201
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
202 _Type Inits C[reg,method reg,field reg,text,def,name:out]
33
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
203 {
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
204 out <- [[text]Append["\n\n"]]Append[ [def]Type Init[[reg]Type ID[name], method reg, field reg] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
205 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
206
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
207 Type Inits@C Type Registry[reg,method reg,field reg:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
208 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
209 out <- Fold[[[["_Type Inits C"]Set Input[0, reg]]Set Input[1, method reg]]Set Input[2, field reg], "", [reg]Definitions >>]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
210 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
211
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
212 Register Type@C Type Registry[reg,def:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
213 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
214 name <- [def]Name >>
33
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
215 [[reg]Lookup >>]Index[name]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
216 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
217 out <- reg
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
218 }{
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
219 out <- [[[reg]Lookup <<[ [[reg]Lookup >>]Set[name, ["TYPE_FIRST_USER+"]Append[[reg]Next ID >>]] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
220 ]Definitions <<[ [[reg]Definitions >>]Set[name, def] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
221 ]Next ID <<[ [[reg]Next ID >>]+[1] ]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
222 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
223 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
224
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
225 Type ID@C Type Registry[reg,name:out,notfound]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
226 {
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
227 out,notfound <- [[reg]Lookup >>]Index[name]
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
228 }
3b47a8538df2 Started adding support for user defined types to C backend
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
229
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
230 Blueprint C Function
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
231 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
232 Name
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
233 Inputs
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
234 Outputs
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
235 Convention
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
236 Variables
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
237 Statements
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
238 Method Registry
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
239 Constants
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
240 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
241
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 C Function[name,inputs,outputs,convention:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 {
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
244 out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
245 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
246
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
247 C Function With Registry[name,inputs,outputs,convention,registry:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
248 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
249 out <- [[[[[[[[Build["C Function"]
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 ]Name <<[name]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 ]Inputs <<[inputs]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
252 ]Outputs <<[outputs]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
253 ]Convention <<[convention]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
254 ]Variables <<[New@Dictionary[]]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
255 ]Statements <<[()]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
256 ]Method Registry <<[registry]
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
257 ]Constants <<[New@Dictionary[]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
258 }
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
259
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
260 Register Constant@C Function[func,name,constant:out]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
261 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
262 Print["Register Constant"]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
263 Print[name]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
264 Print[constant]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
265 out <- [func]Constants <<[ [[func]Constants >>]Set[name, constant] ]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
266 { Print["Got register constant output"] }
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
268
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
269 Allocate Var@C Function[func,name,type:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
270 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
271 out <- [func]Variables <<[ [[func]Variables >>]Set[name,type] ]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
272 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
274 Add Statement@C Function[func,statement:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
275 {
12
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
276 out <- [func]Statements <<[ [[func]Statements >>]Append[["\t"]Append[[statement]Append[";\n"]]] ]
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
277 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
279 Add Raw Line@C Function[func,line:out]
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
280 {
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
281 out <- [func]Statements <<[ [[func]Statements >>]Append[["\t"]Append[[line]Append["\n"]]] ]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
282 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
283
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
284 Add Operator Statement@C Function[func,psource1,psource2,pdest,op:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
285 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
286 source1 <- [psource1]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
287 source2 <- [psource2]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
288 dest <- [pdest]Make Op[func]
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
289 out <- [func]Add Statement[[[[[dest]Append[" = "]]Append[source1]]Append[op]]Append[source2]]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
290 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
291
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
292 Add@C Function[func,source1,source2,dest:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
293 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
294 out <- [func]Add Operator Statement[source1,source2,dest," + "]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
295 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 Sub@C Function[func,source1,source2,dest:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
298 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
299 out <- [func]Add Operator Statement[source1,source2,dest," - "]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
300 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
301
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
302 Multiply@C Function[func,source1,source2,dest:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
303 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
304 out <- [func]Add Operator Statement[source1,source2,dest," * "]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
305 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
306
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
307 Divide@C Function[func,source1,source2,dest:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
308 {
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
309 out <- [func]Add Operator Statement[source1,source2,dest," / "]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
310 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
311
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
312 Move@C Function[func,psource,pdest:out]
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
313 {
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
314 source <- [psource]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
315 dest <- [pdest]Make Op[func]
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
316 out <- [func]Add Statement[[[dest]Append[" = "]]Append[source]]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
317 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
318
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
319 AddRef@C Function[func,psource,pdest:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
320 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
321 source <- [psource]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
322 dest <- [pdest]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
323 out <- [func]Add Statement[[[[dest]Append[" = add_ref("]]Append[source]]Append[")"]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
324 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
325
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
326 Release@C Function[func,psource:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
327 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
328 source <- [psource]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
329 out <- [func]Add Statement[[["release_ref("]Append[source]]Append[")"]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
330 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
331
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
332 Set Null@C Function[func,pdest:out]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
333 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
334 dest <- [pdest]Make Op[func]
18
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
335 out <- [func]Add Statement[[dest]Append[" = NULL"]]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
336 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
337
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
338 Lookup Constant@C Function[func,const:out]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
339 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
340 out <- [["add_ref(_const_"]Append[Escape Rhope Name[const]]]Append[")"]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
341 }
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
342
18
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
343 _Function Arg C[func,val,inputnum:out]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
344 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
345 out <- [func]Add Statement[
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
346 [[["call->params["
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
347 ]Append[inputnum]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
348 ]Append["] = "]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
349 ]Append[val]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
350 ]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
351 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
352
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
353 Method Call@C Function[func,method,args:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
354 {
18
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
355 out <- [func]Func Base[[[func]Method Registry >>]Method ID[method],args, "MCall"]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
356 }
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
357
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
358 Call@C Function[func,name,args:out]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
359 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
360 out <- [func]Func Base[Escape Rhope Name[name],args, "Call"]
18
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
361 }
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
362
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
363 Func Base@C Function[func,tocall,args,type:out]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
364 {
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
365 rargs <- Map[args, ["Make Op"]Set Input[1, func]]
18
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
366 out <- [Fold["_Function Arg C", func, rargs]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
367 ]Add Raw Line[[[[[ [type]Append["("] ]Append[tocall]]Append[", "]]Append[ [rargs]Length ]]Append[")"]]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
368 }
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
369
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
370 Tail Method Call@C Function[func,method,args:out]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
371 {
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
372 out <- [func]Func Base[[[func]Method Registry >>]Method ID[method],args, "TMCall"]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
373 }
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
374
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
375 Tail Call@C Function[func,name,args:out]
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
376 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
377 out <- [func]Func Base[Escape Rhope Name[name],args, "TCall"]
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
378 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
379
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
380 Resolve@C Function[func,op:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
381 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
382 [[func]Inputs >>]Find[op]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
383 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
384 out <- [["cdata->params["]Append[~]]Append["]"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
385 }{
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
386 out <- ["locals->"]Append[Escape Rhope Name[op]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
387 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
388 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
389
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
390 Instruction Stream@C Function[func:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
391 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
392 out <- [func]Statements <<[()]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
393 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
394
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
395 _If C[func, statement:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
396 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
397 out <- [func]Statements <<[ [[func]Statements >>]Append[ ["\t"]Append[statement] ] ]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
398 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
399
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
400 Do If@C Function[func,condition,stream:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
401 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
402 cond <- [condition]Make Op[func]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
403 out <- [Fold["_If C", [[func
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
404 ]Add Raw Line[ [["if("]Append[cond]]Append[")"] ]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
405 ]Add Raw Line["{"], [stream]Statements >>]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
406 ]Add Raw Line["}"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
407
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
408 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
409
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
410 Result Reference@C Function[func,output:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
411 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
412 out <- [["call->params["]Append[output]]Append["]"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
413 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
414
21
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
415 If Null Else@C Function[func,left,right:out]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
416 {
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
417 out <- [[[[[["("
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
418 ]Append[left]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
419 ]Append[" ? "]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
420 ]Append[left]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
421 ]Append[" : "]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
422 ]Append[right]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
423 ]Append[")"]
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
424 }
e9272f7ebd26 Limited compilation from dataflow graph to C backend
Mike Pavone <pavone@retrodev.com>
parents: 20
diff changeset
425
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
426 Init Outputs@C Function[func:out]
12
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
427 {
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
428 If[[[[func]Outputs >>]Length ] > [0]]
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
429 {
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
430 out <- [["\tlocals->"]Append[ [[func]Outputs >>]Join[" = NULL;\n\tlocals->"] ]]Append[" = NULL;\n"]
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
431 }{
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
432 out <- ""
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
433 }
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
434 }
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
435
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
436 _Release Inputs[string,inputname,inputnum:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
437 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
438 out <- [[[string
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
439 ]Append["\trelease_ref(cdata->params["]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
440 ]Append[inputnum]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
441 ]Append["]);\n"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
442 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
443
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
444 Release Inputs@C Function[func:out]
12
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
445 {
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
446 If[[[[func]Inputs >>]Length ] > [0]]
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
447 {
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
448 out <- Fold["_Release Inputs", "", [func]Inputs >>]
12
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
449 }{
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
450 out <- ""
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
451 }
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
452 }
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
453
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
454 _Set Outputs C[string,inputname,inputnum:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
455 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
456 out <- [string]Append[[[ [ ["\tRet("]Append[inputnum] ]Append[", locals->"]]Append[inputname]]Append[")\n"]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
457 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
458
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
459 Set Outputs@C Function[func:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
460 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
461 If[[[[func]Outputs >>]Length ] > [0]]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
462 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
463 out <- Fold["_Set Outputs C", "", [func]Outputs >>]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
464 }{
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
465 out <- ""
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
466 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
467 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
468 _Output Defs C[string,varname:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
469 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
470 out <- [[[string]Append["\tobject *"]]Append[Escape Rhope Name[varname]]]Append[";\n"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
471 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
472 _Var Defs C[string,type,varname:out]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
473 {
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
474 out <- [[[string]Append["\tobject *"]]Append[Escape Rhope Name[varname]]]Append[";\n"]
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
475 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
476
18
ea991f95ae1f C backend working well enough to generate Fib test
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
477
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
478 Definitions@C Function[func:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
479 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
480 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] > [0]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
481 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
482 out <- [[[Fold["_Output Defs C", Fold["_Var Defs C","typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} l_"]]Append[Escape Rhope Name[[func]Name >>]]]Append[";\n"]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
483 }{
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
484 out <- ""
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
485 }
2
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
486 }
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
487
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
488 Text@C Function[func:out]
73e978d590c7 Adding WIP compiler code
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
489 {
12
31f8182f3433 Finished fib test and did some small work on the c backend
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
490 cname <- Escape Rhope Name[[func]Name >>]
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
491 If[ [[func]Convention >>] = ["rhope"] ]
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
492 {
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
493 If[ [[[func]Variables >>]Length] = [0] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
494 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
495 out <- [[[[[["FuncNoLocals("
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
496 ]Append[cname]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
497 ]Append[",\n\tNumParams "]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
498 ]Append[ [[func]Inputs >>]Length ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
499 ]Append[",\n\tCallSpace 32)\n\n"]//TODO: Fill in with calculated callspace value
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
500 ]Append[ [[func]Statements >>]Join[""] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
501 ]Append["EndFunc"]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
502 }{
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
503 out <- [[[[[[[[["Func("
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
504 ]Append[cname]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
505 ]Append[",\n\tNumParams "]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
506 ]Append[ [[func]Inputs >>]Length ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
507 ]Append[",\n\tCallSpace 32,\n\t"]//TODO: Fill in with calculated callspace value
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
508 ]Append[["l_"]Append[cname]]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
509 ]Append[")\n\n"]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
510 ]Append[ [[func]Statements >>]Join[""] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
511 ]Append[[func]Set Outputs]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
512 ]Append["EndFunc"]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
513 }
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
514 }{
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
515 //TODO: We need to store input and output types somewhere so we can reference them here
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
516 out <- "oops"
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
517 }
14
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
518 }
69dfca29565f C backend close to being useable
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
519
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
520 Blueprint C Program
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
521 {
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
522 Functions
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
523 Method Registry
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
524 Field Registry
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
525 Type Registry
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
526 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
527
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
528 C Program[:out]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
529 {
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
530 out <- [[[[Build["C Program"]]Functions <<[New@Dictionary[]]]Method Registry <<[C Method Registry[]]]Type Registry <<[C Type Registry[]]]Field Registry <<[C Field Registry[]]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
531 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
532
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
533 Register Type@C Program[program,def:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
534 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
535 out <- [[[program]Type Registry <<[ [[program]Type Registry >>]Register Type[def] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
536 ]Method Registry <<[ [def]Register Methods[[program]Method Registry >>] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
537 ]Field Registry <<[ [def]Register Fields[[program]Field Registry >>] ]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
538 }
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
539
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
540 Create Type@C Program[program,name:out]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
541 {
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
542 out <- C Type[name]
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
543 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
544
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
545 Create Function@C Program[program,name,inputs,outputs,convention:out]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
546 {
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
547 out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
548 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
549
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
550 Store Function@C Program[program,func:out]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
551 {
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
552 out <- [program]Functions <<[ [[program]Functions >>]Set[ [func]Name >>, func] ]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
553 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
554
20
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
555 Method?@C Program[program,funcname:is,isnot]
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
556 {
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
557 is,isnot <- [[program]Method Registry >>]Method ID[funcname]
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
558 }
b715532225c0 Differentiate between method and normal calls in dataflow graph compiler
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
559
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
560 _Defs C Program[text,func:out]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
561 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
562 def <- [func]Definitions
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
563 If[[def]=[""]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
564 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
565 out <- text
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
566 }{
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
567 out <- [text]Append[[def]Append["\n\n"]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
568 }
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
569 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
570
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
571 _Text C Program[text,func:out]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
572 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
573 out <- [text]Append[[[func]Text]Append["\n\n"]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
574 }
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
575
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
576 Combine Consts[consts,func:out]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
577 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
578 out <- Combine[[func]Constants >>, consts]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
579 }
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
580
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
581 _Consts C Program[text,value,name:out]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
582 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
583 out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name]]]Append[";\n"] ]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
584 }
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
585
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
586 _Set Consts C Program[text,value,name:out]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
587 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
588 //TODO: Support more constant types
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
589 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]]
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
590 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
591
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
592 Text@C Program[program:out]
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
593 {
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
594 constants <- Fold["Combine Consts", New@Dictionary[], [program]Functions >>]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
595 headers <- "#include <stdio.h>
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
596 #include \"builtin.h\"
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
597 #include \"object.h\"
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
598 #include \"context.h\"
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
599 #include \"func.h\"
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
600 #include \"integer.h\"\n\n"
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
601 out <- [[[[[[headers
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
602 ]Append[[[program]Type Registry >>]Type Defs]
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
603 ]Append[Fold["_Text C Program",
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
604 Fold["_Consts C Program",
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
605 Fold["_Defs C Program", "", [program]Functions >>],
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
606 constants
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
607 ], [program]Functions >>]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
608 ]Append["int main(int argc, char **argv)
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
609 {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
610 returntype ret;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
611 calldata *cdata;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
612 context * ct;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
613 register_builtin_types();\n\n"]
34
df038cef648b More work on supporting user defined types in the C backend
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
614 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
30
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
615 ]Append[Fold["_Set Consts C Program", "", constants]]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
616 ]Append["
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
617 ct = new_context();
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
618 cdata = alloc_cdata(ct, 0);
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
619 cdata->num_params = 0;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
620 cdata->resume = 0;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
621 ret = f_Main(cdata);
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
622 while(ret == TAIL_RETURN)
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
623 ret = cdata->tail_func(cdata);
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
624 if(ret == EXCEPTION_RETURN) {
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
625 puts(\"Exception!\");
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
626 return -1;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
627 }
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
628 return 0;
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
629 }\n\n"]
914ad38f9b59 Compiler now works for some simple programs
Mike Pavone <pavone@retrodev.com>
parents: 21
diff changeset
630
19
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
631 }
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
632
90c20dc3f4e5 Initial work on compiling dataflow graphs to a backend
Mike Pavone <pavone@retrodev.com>
parents: 18
diff changeset
633