Mercurial > repos > rhope
comparison number_c.rhope @ 122:7361d70fbba6
Improve comparison performance by using a constant rather than building a new result object each time
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 28 Oct 2010 21:04:44 -0400 |
parents | e73a93fb5de1 |
children | 18a4403fe576 |
comparison
equal
deleted
inserted
replaced
121:1af91ceaaf49 | 122:7361d70fbba6 |
---|---|
27 type inst <- Type Instance[type] | 27 type inst <- Type Instance[type] |
28 func <- [[[[[[ [backend]Create Function[name,("a","b"), ("out"), "rhope"] | 28 func <- [[[[[[ [backend]Create Function[name,("a","b"), ("out"), "rhope"] |
29 ]Set Input Type[type inst, 0] | 29 ]Set Input Type[type inst, 0] |
30 ]Set Input Type[type inst, 1] | 30 ]Set Input Type[type inst, 1] |
31 ]Set Output Type[Type Instance["Boolean"], 0] | 31 ]Set Output Type[Type Instance["Boolean"], 0] |
32 ]Register Constant["Blueprint_Boolean", Type Instance["Boolean"]] | 32 ]Register Constant["Boolean_Yes", Yes] |
33 ]Call["Build", [()]Append[Constant["Blueprint_Boolean"]]] | 33 ]Register Constant["Boolean_No", No] |
34 ]Move[Result[0], "out"] | 34 ]Allocate Var["compres", [Type Instance["Int32"]]Set Variant["Naked"]] |
35 | 35 |
36 ,ina <- [func]Read Field["a", "Num"] | 36 ,ina <- [func]Read Field["a", "Num"] |
37 { ,inb <- [~]Read Field["b", "Num"] | 37 { ,inb <- [~]Read Field["b", "Num"] |
38 { ,outa <- [~]Write Field["out", "Val"] | 38 { after op <- [backend func]Call[~, ina, inb, "compres"] }} |
39 { after op <- [backend func]Call[~, ina, inb, outa] }}} | 39 |
40 | 40 [after op]Do If["compres", [[after op]Instruction Stream]Move[Constant["Boolean_Yes"], "out"]] |
41 out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ] | 41 { after out <- [~]Do If[NotCond["compres"], [[after op]Instruction Stream]Move[Constant["Boolean_No"], "out"]] } |
42 | |
43 out <- [backend]Store Function[ [[after out]Release["a"]]Release["b"] ] | |
42 | 44 |
43 } | 45 } |
44 | 46 |
45 Compile Conversion Method[backend,intype,outtype,prefix:out] | 47 Compile Conversion Method[backend,intype,outtype,prefix:out] |
46 { | 48 { |
80 } | 82 } |
81 | 83 |
82 _Generate Number Methods[backend, type:out] | 84 _Generate Number Methods[backend, type:out] |
83 { | 85 { |
84 //Old crappy parser doesn't like Worker literals in List literals, work around for now | 86 //Old crappy parser doesn't like Worker literals in List literals, work around for now |
85 opmap <- [[[[[[() | 87 opmap <- [[[[[[[[() |
86 ]Append[ [("+")]Append[Add[?]] ] | 88 ]Append[ [("+")]Append[Add[?]] ] |
87 ]Append[ [("-")]Append[Sub[?]] ] | 89 ]Append[ [("-")]Append[Sub[?]] ] |
88 ]Append[ [("*")]Append[Multiply[?]] ] | 90 ]Append[ [("*")]Append[Multiply[?]] ] |
89 ]Append[ [("/")]Append[Divide[?]] ] | 91 ]Append[ [("/")]Append[Divide[?]] ] |
90 ]Append[ [("LShift")]Append[DoLShift[?]] ] | 92 ]Append[ [("LShift")]Append[DoLShift[?]] ] |
91 ]Append[ [("RShift")]Append[DoRShift[?]] ] | 93 ]Append[ [("RShift")]Append[DoRShift[?]] ] |
94 ]Append[ [("&")]Append[BitAnd[?]] ] | |
95 ]Append[ [("|")]Append[BitOr[?]] ] | |
92 //(("+", Add[?]), ("-", Sub[?]), ("*", Multiply[?]), ("/", Divide[?]), ("LShift", DoLShift[?]), ("RShift", DoRShift[?])) | 96 //(("+", Add[?]), ("-", Sub[?]), ("*", Multiply[?]), ("/", Divide[?]), ("LShift", DoLShift[?]), ("RShift", DoRShift[?])) |
93 compops <- [[[[[[() | 97 compops <- [[[[[[() |
94 ]Append[ [("<")]Append[CompLess[?]] ] | 98 ]Append[ [("<")]Append[CompLess[?]] ] |
95 ]Append[ [(">")]Append[CompGreater[?]] ] | 99 ]Append[ [(">")]Append[CompGreater[?]] ] |
96 ]Append[ [("=")]Append[CompEqual[?]] ] | 100 ]Append[ [("=")]Append[CompEqual[?]] ] |
171 truncs <- Map[Map[Filter[(8,16,32), <[?, size]], String[?]] Append[[u]Append["Int"], ?]] | 175 truncs <- Map[Map[Filter[(8,16,32), <[?, size]], String[?]] Append[[u]Append["Int"], ?]] |
172 } | 176 } |
173 | 177 |
174 _Register Number Methods[program,type:out] | 178 _Register Number Methods[program,type:out] |
175 { | 179 { |
176 methods <- ("+", "-", "*", "/", "LShift", "RShift") | 180 methods <- ("+", "-", "*", "/", "LShift", "RShift", "&", "|") |
177 compmethods <- ("<", ">", "=", "<=", ">=", "!=") | 181 compmethods <- ("<", ">", "=", "<=", ">=", "!=") |
178 register <- Val[Register Number Method[?, ?, type]] | 182 register <- Val[Register Number Method[?, ?, type]] |
179 Fold[[register]Set Input[3, type], program, methods] | 183 Fold[[register]Set Input[3, type], program, methods] |
180 { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] | 184 { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] |
181 { Fold[Register Conversion Method[?, type, ?, ""], ~, Legal Conversions[type]] | 185 { Fold[Register Conversion Method[?, type, ?, ""], ~, Legal Conversions[type]] |