Mercurial > repos > rhope
annotate number_c.rhope @ 176:327bcf35e094
Add bytecode interpreter
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 Jun 2011 23:24:29 -0700 |
parents | fd06fb07762a |
children |
rev | line source |
---|---|
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 Compile Number Method[backend, op, type:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 name <- [[[op]Index[0]]Append["@"]]Append[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 backend func <- [op]Index[1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 type inst <- Type Instance[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 func <- [[[[backend]Create Function[name,("a","b"), ("out"), "rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 ]Set Input Type[type inst, 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 ]Set Input Type[type inst, 1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 ]Set Output Type[type inst, 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 ,ina <- [[func]Copy["a"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 ]Read Field["a", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 { ,inb <- [~]Read Field["b", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 { ,outa <- [~]Write Field["a", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 { after op <- [backend func]Call[~, ina, inb, outa] }}} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 out <- [backend]Store Function[ [[after op]Move["a","out"]]Release["b"] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
169
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
23 Compile Number Inline[func,op,type,a,b,outvar:out] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
24 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
25 ,ina <- [ |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
26 [[func]Move[a, outvar] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
27 ]Copy[outvar] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
28 ]Read Field[Cast[outvar, type], "Num"] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
29 { ,inb <- [~]Read Field[Cast[Strip Addref[b], type], "Num"] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
30 { ,outa <- [~]Write Field[Cast[outvar, type], "Num"] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
31 { out <- [op]Call[~, ina, inb, outa] }}} |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
32 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
33 |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
34 Compile Number Comp Inline[func,op,type,a,b,outvar:out] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
35 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
36 ,ina <- [ |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
37 [func]Allocate Var["compres", [Type Instance["Int32"]]Set Variant["Naked"]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
38 ]Read Field[Cast[Strip Addref[a], type], "Num"] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
39 { ,inb <- [~]Read Field[Cast[Strip Addref[b], type], "Num"] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
40 { after op <- [op]Call[~, ina, inb, "compres"] }} |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
41 |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
42 [after op]Do If["compres", [[after op]Instruction Stream]Move[Constant["Boolean_Yes"], outvar]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
43 { out <- [~]Do If[NotCond["compres"], [[after op]Instruction Stream]Move[Constant["Boolean_No"], outvar]] } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
44 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
45 |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
46 Compile Number Inline Check[func,op,type a,type b,a,b,outvar:out,no inline] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
47 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
48 opmap <- [[[[[[[[Dictionary[] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
49 ]Set["+", Add[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
50 ]Set["-", Sub[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
51 ]Set["*", Multiply[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
52 ]Set["/", Divide[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
53 ]Set["LShift", DoLShift[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
54 ]Set["RShift", DoRShift[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
55 ]Set["&", BitAnd[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
56 ]Set["|", BitOr[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
57 backend op <- [opmap]Index[op] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
58 { inline func <- Val[Compile Number Inline[?]] } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
59 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
60 comp opmap <- [[[[[[Dictionary[] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
61 ]Set["<", CompLess[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
62 ]Set[">", CompGreater[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
63 ]Set["=", CompEqual[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
64 ]Set["<=", CompLessEqual[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
65 ]Set[">=", CompGreaterEqual[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
66 ]Set["!=", CompNotEqual[?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
67 backend op, no inline <- [comp opmap]Index[op] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
68 { inline func <- Val[Compile Number Comp Inline[?]] } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
69 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
70 |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
71 |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
72 Val[backend op] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
73 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
74 signed?,int,size,no inline <- [[type a]Name >>]Partition["Int"] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
75 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
76 ,no inline <- If[[[signed?] = ["U"]] Or [[signed?] = [""]]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
77 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
78 ,no inline <- [("8","16","32","64")]Find[=[size, ?]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
79 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
80 //TODO: Do an inline type check/conversion rather than falling back on a standard call |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
81 ,no inline <- If[[type b] = [type a]] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
82 { |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
83 out <- [inline func]Call[func, backend op, type a, a, b, outvar] |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
84 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
85 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
86 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
87 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
88 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
89 } |
fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
Mike Pavone <pavone@retrodev.com>
parents:
136
diff
changeset
|
90 |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 Compile Number Comp Method[backend, op, type:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 backend func <- [op]Index[1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 type inst <- Type Instance[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 func <- [[[[[[ [backend]Create Function[name,("a","b"), ("out"), "rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 ]Set Input Type[type inst, 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 ]Set Input Type[type inst, 1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 ]Set Output Type[Type Instance["Boolean"], 0] |
122
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
100 ]Register Constant["Boolean_Yes", Yes] |
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
101 ]Register Constant["Boolean_No", No] |
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
102 ]Allocate Var["compres", [Type Instance["Int32"]]Set Variant["Naked"]] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 ,ina <- [func]Read Field["a", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 { ,inb <- [~]Read Field["b", "Num"] |
122
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
106 { after op <- [backend func]Call[~, ina, inb, "compres"] }} |
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
107 |
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
108 [after op]Do If["compres", [[after op]Instruction Stream]Move[Constant["Boolean_Yes"], "out"]] |
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
109 { after out <- [~]Do If[NotCond["compres"], [[after op]Instruction Stream]Move[Constant["Boolean_No"], "out"]] } |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 |
122
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
111 out <- [backend]Store Function[ [[after out]Release["a"]]Release["b"] ] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 Compile Conversion Method[backend,intype,outtype,prefix:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 func <- [[[[[[backend]Create Function[[prefix]Append[[[outtype]Append["@"]]Append[intype]], ("in"), ("out"), "rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 ]Set Input Type[Type Instance[intype], 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 ]Set Output Type[Type Instance[outtype], 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 ]Register Constant[["Blueprint_"]Append[outtype], Type Instance[outtype]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 ]Call["Build", [()]Append[ Constant[["Blueprint_"]Append[outtype]] ]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 ]Move[Result[0], "out"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 ,src <- [func]Read Field["in", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 { ,dst <- [~]Write Field["out", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 { ffunc <- [[~]Move[src, dst]]Release["in"] }} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 out <- [backend]Store Function[ffunc] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 Compile Abs UInt Method[backend,type:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 outtype <- ["U"]Append[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 func <- [[[[[[[[[backend]Create Function[["Abs UInt@"]Append[type], ("in"), ("out"), "rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 ]Set Input Type[Type Instance[type], 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 ]Set Output Type[Type Instance[["U"]Append[type]], 0] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 ]Register Constant[["Blueprint_"]Append[outtype], Type Instance[outtype]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 ]Allocate Var["abs", Type Instance[type]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 ]Call["Build", [()]Append[ Constant[["Blueprint_"]Append[outtype]] ]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 ]Move[Result[0], "out"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 ]Call["Abs", [()]Append["in"]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 ]Move[Result[0], "abs"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 { Print["After Call to Abs"] } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 ,src <- [func]Read Field["abs", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 { ,dst <- [~]Write Field["out", "Num"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 { ffunc <- [[~]Move[src, dst]]Release["abs"] }} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 out <- [backend]Store Function[ffunc] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 |
136
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
152 Supports Type?[backend,type:out] |
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
153 { |
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
154 [[backend]Supported Number Types]Find[=[type,?]] |
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
155 { out <- Yes } |
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
156 { out <- No } |
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
157 } |
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
158 |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 _Generate Number Methods[backend, type:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 //Old crappy parser doesn't like Worker literals in List literals, work around for now |
122
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
162 opmap <- [[[[[[[[() |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 ]Append[ [("+")]Append[Add[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 ]Append[ [("-")]Append[Sub[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 ]Append[ [("*")]Append[Multiply[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 ]Append[ [("/")]Append[Divide[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 ]Append[ [("LShift")]Append[DoLShift[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 ]Append[ [("RShift")]Append[DoRShift[?]] ] |
122
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
169 ]Append[ [("&")]Append[BitAnd[?]] ] |
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
170 ]Append[ [("|")]Append[BitOr[?]] ] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 //(("+", Add[?]), ("-", Sub[?]), ("*", Multiply[?]), ("/", Divide[?]), ("LShift", DoLShift[?]), ("RShift", DoRShift[?])) |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 compops <- [[[[[[() |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 ]Append[ [("<")]Append[CompLess[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 ]Append[ [(">")]Append[CompGreater[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 ]Append[ [("=")]Append[CompEqual[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 ]Append[ [("<=")]Append[CompLessEqual[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 ]Append[ [(">=")]Append[CompGreaterEqual[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 ]Append[ [("!=")]Append[CompNotEqual[?]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 //(("<", CompLess[?]), (">", CompGreater[?]), ("=", CompEqual[?]), ("<=", CompLessEqual[?]), (">=", CompGreaterEqual[?]), ("!=", CompNotEqual[?])) |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 Fold[Compile Number Method[?, ?, type], backend, opmap] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 { Fold[Compile Number Comp Method[?, ?, type], ~, compops] |
136
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
183 { Fold[Compile Conversion Method[?, type, ?, ""], ~, Filter[Legal Conversions[type], [backend]Supports Type?[?]]] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 { |
136
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
185 almost <- Fold[Compile Conversion Method[?, type, ?, "Trunc "], ~, Filter[Truncations[type], [backend]Supports Type?[?]]] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 If[[type]Starts With["I"]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 out <- Compile Abs UInt Method[almost,type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 }{ |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 out <- Val[almost] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 }}} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 Generate Number Methods[backend:out] |
135
18a4403fe576
Javascript backend can now produce broken output. Needs fixes plus port of standard lib
Mike Pavone <pavone@retrodev.com>
parents:
122
diff
changeset
|
196 { |
18a4403fe576
Javascript backend can now produce broken output. Needs fixes plus port of standard lib
Mike Pavone <pavone@retrodev.com>
parents:
122
diff
changeset
|
197 out <- Fold[_Generate Number Methods[?], backend, [backend]Supported Number Types] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 Register Number Method[program, method, type, outtype:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 name <- [[method]Append["@"]]Append[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 out <- [[program]Register Worker[name, "rhope", 2, 1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 ]Bind Worker[name, |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 [[[[[NWorker["rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 ]Inputs <<[("left","right")] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 ]Input Types <<[ [[()]Append[ Type Instance[type]]]Append[Type Instance[type]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 ]Outputs <<[("out")] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 ]Output Types <<[ [()]Append[Type Instance[outtype]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 ]Builtin? <<[Yes] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 Register Conversion Method[program, intype, outtype,prefix:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 name <- [prefix]Append[[[outtype]Append["@"]]Append[intype]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 out <- [[program]Register Worker[name, "rhope", 1, 1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 ]Bind Worker[name, |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 [[[[[NWorker["rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 ]Inputs <<[("in")] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 ]Input Types <<[ [()]Append[Type Instance[intype]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 ]Outputs <<[("out")] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 ]Output Types <<[ [()]Append[Type Instance[outtype]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 ]Builtin? <<[Yes] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 Legal Conversions[type:convs] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 bigger <- Map[Filter[(16,32,64), >[?, size]], String[?]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 base convs <- Map[bigger, Append["Int", ?]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 If[[type]Starts With["U"]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 [type]Slice[4] {} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 { size <- Int32[~] } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 convs <- Concatenate[base convs, Map[bigger, Append["UInt", ?]]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 }{ |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 [type]Slice[3] {} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 { size <- Int32[~] } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 convs <- Val[base convs] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 Truncations[type:truncs] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 u <- [type]Partition["Int"] {} {} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 { size <- Int32[~] } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 truncs <- Map[Map[Filter[(8,16,32), <[?, size]], String[?]] Append[[u]Append["Int"], ?]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 _Register Number Methods[program,type:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 { |
122
7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
253 methods <- ("+", "-", "*", "/", "LShift", "RShift", "&", "|") |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 compmethods <- ("<", ">", "=", "<=", ">=", "!=") |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 register <- Val[Register Number Method[?, ?, type]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 Fold[[register]Set Input[3, type], program, methods] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 { Fold[Register Conversion Method[?, type, ?, ""], ~, Legal Conversions[type]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 almost <- Fold[Register Conversion Method[?, type, ?, "Trunc "], ~, Truncations[type]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 If[[type]Starts With["I"]] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 { |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 name <- ["Abs UInt@"]Append[type] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 out <- [[almost]Register Worker[name, "rhope", 1, 1] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 ]Bind Worker[name |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 [[[[[NWorker["rhope"] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 ]Inputs <<[("in")] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 ]Input Types <<[ [()]Append[Type Instance[type]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 ]Outputs <<[("out")] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 ]Output Types <<[ [()]Append[Type Instance[["U"]Append[type]]] ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 ]Builtin? <<[Yes] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 ] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 }{ |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 out <- Val[almost] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 }}} |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 Register Number Methods[program:out] |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 { |
136
fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
281 out <- Fold[_Register Number Methods[?], program, [program]Supported Number Types] |
92
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 } |
e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 |