Mercurial > repos > rhope
diff number.rhope @ 48:a24eb366195c
Fixed some bugs introduced in previous commit and moved definition of integer methods out of runtime and into the compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 02 Mar 2010 00:18:49 -0500 |
parents | |
children | 3e20ed8959c4 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/number.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -0,0 +1,109 @@ + + +Compile Number Method[backend, op, type:out] +{ + name <- [[[op]Index[0]]Append["@"]]Append[type] + backend func <- [op]Index[1] + type inst <- Type Instance[type] + func <- [[[[backend]Create Function[name,("a","b"), ("out"), "rhope"] + ]Set Input Type[type inst, 0] + ]Set Input Type[type inst, 1] + ]Set Output Type[type inst, 0] + + ,ina <- [[func]Copy["a"] + ]Read Field["a", "Num"] + { ,inb <- [~]Read Field["b", "Num"] + { ,outa <- [~]Write Field["a", "Num"] + { after op <- [ + [backend func]Do[ + [ + [ + [ + [()]Append[~] + ]Append[ina] + ]Append[inb] + ]Append[outa] ] + ]Index[0] }}} + + out <- [backend]Store Function[ [[after op]Move["a","out"]]Release["b"] ] + +} + +Compile Number Comp Method[backend, op, type:out] +{ + name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] + backend func <- [op]Index[1] + type inst <- Type Instance[type] + func <- [[[[[[ [backend]Create Function[name,("a","b"), ("out"), "rhope"] + ]Set Input Type[type inst, 0] + ]Set Input Type[type inst, 1] + ]Set Output Type[Type Instance["Boolean"], 0] + ]Register Constant["Blueprint_Boolean", Type Instance["Boolean"]] + ]Call["Build", [()]Append[Constant["Blueprint_Boolean"]]] + ]Move[Result[0], "out"] + + ,ina <- [func]Read Field["a", "Num"] + { ,inb <- [~]Read Field["b", "Num"] + { ,outa <- [~]Write Field["out", "Val"] + { after op <- [ + [backend func]Do[ + [ + [ + [ + [()]Append[~] + ]Append[ina] + ]Append[inb] + ]Append[outa] ] + ]Index[0] }}} + + out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ] + +} + +_Generate Number Methods[backend, type:out] +{ + opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) + compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual")) + + Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] + { out <- Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] } +} + +Generate Number Methods[backend:out] +{ + numtypes <- ("Int8","Int16","Int32","UInt8","UInt16","UInt32") + + out <- Fold["_Generate Number Methods", backend, numtypes] +} + +Register Number Method[program, method, type, outtype:out] +{ + name <- [[method]Append["@"]]Append[type] + Print[["Regsiter Number Method: "]Append[name]] + 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]] ] + ]Builtin? <<[Yes] + ] +} + +_Register Number Methods[program,type:out] +{ + Print[["_Regsiter Number Methods: "]Append[type]] + methods <- ("+", "-", "*", "/", "LShift", "RShift") + compmethods <- ("<", ">", "=", "<=", ">=", "!=") + register <- ["Register Number Method"]Set Input[2, type] + Fold[[register]Set Input[3, type], program, methods] + { out <- Fold[[register]Set Input[3, "Boolean"], ~, compmethods] } +} + +Register Number Methods[program:out] +{ + numtypes <- ("Int8","Int16","Int32","UInt8","UInt16","UInt32") + out <- Fold["_Register Number Methods", program, numtypes] +} +