Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/number.rhope Sat Jul 31 17:17:23 2010 -0400 +++ b/number.rhope Mon Aug 02 00:58:55 2010 -0400 @@ -76,6 +76,27 @@ out <- [backend]Store Function[ffunc] } +Compile Abs UInt Method[backend,type:out] +{ + outtype <- ["U"]Append[type] + func <- [[[[[[[[[backend]Create Function[["Abs UInt@"]Append[type], ("in"), ("out"), "rhope"] + ]Set Input Type[Type Instance[type], 0] + ]Set Output Type[Type Instance[["U"]Append[type]], 0] + ]Register Constant[["Blueprint_"]Append[outtype], Type Instance[outtype]] + ]Allocate Var["abs", Type Instance[type]] + ]Call["Build", [()]Append[ Constant[["Blueprint_"]Append[outtype]] ]] + ]Move[Result[0], "out"] + ]Call["Abs", [()]Append["in"]] + ]Move[Result[0], "abs"] + { Print["After Call to Abs"] } + + ,src <- [func]Read Field["abs", "Num"] + { ,dst <- [~]Write Field["out", "Num"] + { ffunc <- [[~]Move[src, dst]]Release["abs"] }} + + out <- [backend]Store Function[ffunc] +} + _Generate Number Methods[backend, type:out] { opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) @@ -84,7 +105,15 @@ Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] { Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] { Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] - { out <- Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] }}} + { + almost <- Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] + If[[type]Starts With["I"]] + { + out <- Compile Abs UInt Method[almost,type] + }{ + out <- Val[almost] + } + }}} } Generate Number Methods[backend:out] @@ -99,11 +128,11 @@ name <- [[method]Append["@"]]Append[type] out <- [[program]Register Worker[name, "rhope", 2, 1] ]Bind Worker[name, - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance[type]]]Append[Type Instance[type]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance[outtype]] ] + [[[[[NWorker["rhope"] + ]Inputs <<[("left","right")] + ]Input Types <<[ [[()]Append[ Type Instance[type]]]Append[Type Instance[type]] ] + ]Outputs <<[("out")] + ]Output Types <<[ [()]Append[Type Instance[outtype]] ] ]Builtin? <<[Yes] ] } @@ -153,7 +182,24 @@ Fold[[register]Set Input[3, type], program, methods] { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] { Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] - { out <- Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] }}} + { + almost <- Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] + If[[type]Starts With["I"]] + { + name <- ["Abs UInt@"]Append[type] + out <- [[almost]Register Worker[name, "rhope", 1, 1] + ]Bind Worker[name + [[[[[NWorker["rhope"] + ]Inputs <<[("in")] + ]Input Types <<[ [()]Append[Type Instance[type]] ] + ]Outputs <<[("out")] + ]Output Types <<[ [()]Append[Type Instance[["U"]Append[type]]] ] + ]Builtin? <<[Yes] + ] + }{ + out <- Val[almost] + } + }}} } Register Number Methods[program:out]