comparison number.rhope @ 92:e73a93fb5de1

Beginning of port of compiler to itself, some bugfixes and a refcount optimization
author Mike Pavone <pavone@retrodev.com>
date Mon, 02 Aug 2010 00:58:55 -0400
parents d0ce696786cc
children
comparison
equal deleted inserted replaced
91:bcdc326b3d6e 92:e73a93fb5de1
74 { ffunc <- [[~]Move[src, dst]]Release["in"] }} 74 { ffunc <- [[~]Move[src, dst]]Release["in"] }}
75 75
76 out <- [backend]Store Function[ffunc] 76 out <- [backend]Store Function[ffunc]
77 } 77 }
78 78
79 Compile Abs UInt Method[backend,type:out]
80 {
81 outtype <- ["U"]Append[type]
82 func <- [[[[[[[[[backend]Create Function[["Abs UInt@"]Append[type], ("in"), ("out"), "rhope"]
83 ]Set Input Type[Type Instance[type], 0]
84 ]Set Output Type[Type Instance[["U"]Append[type]], 0]
85 ]Register Constant[["Blueprint_"]Append[outtype], Type Instance[outtype]]
86 ]Allocate Var["abs", Type Instance[type]]
87 ]Call["Build", [()]Append[ Constant[["Blueprint_"]Append[outtype]] ]]
88 ]Move[Result[0], "out"]
89 ]Call["Abs", [()]Append["in"]]
90 ]Move[Result[0], "abs"]
91 { Print["After Call to Abs"] }
92
93 ,src <- [func]Read Field["abs", "Num"]
94 { ,dst <- [~]Write Field["out", "Num"]
95 { ffunc <- [[~]Move[src, dst]]Release["abs"] }}
96
97 out <- [backend]Store Function[ffunc]
98 }
99
79 _Generate Number Methods[backend, type:out] 100 _Generate Number Methods[backend, type:out]
80 { 101 {
81 opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) 102 opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift"))
82 compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual")) 103 compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual"))
83 104
84 Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] 105 Fold[["Compile Number Method"]Set Input[2, type], backend, opmap]
85 { Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] 106 { Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops]
86 { Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] 107 { Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]]
87 { out <- Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] }}} 108 {
109 almost <- Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]]
110 If[[type]Starts With["I"]]
111 {
112 out <- Compile Abs UInt Method[almost,type]
113 }{
114 out <- Val[almost]
115 }
116 }}}
88 } 117 }
89 118
90 Generate Number Methods[backend:out] 119 Generate Number Methods[backend:out]
91 { 120 {
92 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") 121 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")
151 compmethods <- ("<", ">", "=", "<=", ">=", "!=") 180 compmethods <- ("<", ">", "=", "<=", ">=", "!=")
152 register <- ["Register Number Method"]Set Input[2, type] 181 register <- ["Register Number Method"]Set Input[2, type]
153 Fold[[register]Set Input[3, type], program, methods] 182 Fold[[register]Set Input[3, type], program, methods]
154 { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] 183 { Fold[[register]Set Input[3, "Boolean"], ~, compmethods]
155 { Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] 184 { Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]]
156 { out <- Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] }}} 185 {
186 almost <- Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]]
187 If[[type]Starts With["I"]]
188 {
189 name <- ["Abs UInt@"]Append[type]
190 out <- [[almost]Register Worker[name, "rhope", 1, 1]
191 ]Bind Worker[name
192 [[[[[NWorker["rhope"]
193 ]Inputs <<[("in")]
194 ]Input Types <<[ [()]Append[Type Instance[type]] ]
195 ]Outputs <<[("out")]
196 ]Output Types <<[ [()]Append[Type Instance[["U"]Append[type]]] ]
197 ]Builtin? <<[Yes]
198 ]
199 }{
200 out <- Val[almost]
201 }
202 }}}
157 } 203 }
158 204
159 Register Number Methods[program:out] 205 Register Number Methods[program:out]
160 { 206 {
161 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") 207 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")