Mercurial > repos > rhope
comparison number.rhope @ 51:7d6a6906b648
Added integer type conversions and started on the implementation of String
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 22 Apr 2010 02:18:26 -0400 |
parents | 3e20ed8959c4 |
children | 079200bc3e75 |
comparison
equal
deleted
inserted
replaced
50:689fb73e7612 | 51:7d6a6906b648 |
---|---|
58 | 58 |
59 out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ] | 59 out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ] |
60 | 60 |
61 } | 61 } |
62 | 62 |
63 Compile Conversion Method[backend,intype,outtype,prefix:out] | |
64 { | |
65 func <- [[[[[[backend]Create Function[[prefix]Append[[[outtype]Append["@"]]Append[intype]], ("in"), ("out"), "rhope"] | |
66 ]Set Input Type[Type Instance[intype], 0] | |
67 ]Set Output Type[Type Instance[outtype], 0] | |
68 ]Register Constant[["Blueprint_"]Append[outtype], Type Instance[outtype]] | |
69 ]Call["Build", [()]Append[ Constant[["Blueprint_"]Append[outtype]] ]] | |
70 ]Move[Result[0], "out"] | |
71 | |
72 ,src <- [func]Read Field["in", "Num"] | |
73 { ,dst <- [~]Write Field["out", "Num"] | |
74 { ffunc <- [[~]Move[src, dst]]Release["in"] }} | |
75 | |
76 out <- [backend]Store Function[ffunc] | |
77 } | |
78 | |
63 _Generate Number Methods[backend, type:out] | 79 _Generate Number Methods[backend, type:out] |
64 { | 80 { |
65 opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) | 81 opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) |
66 compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual")) | 82 compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual")) |
67 | 83 |
68 Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] | 84 Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] |
69 { out <- Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] } | 85 { 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]] | |
87 { out <- Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Legal Conversions[type]] }}} | |
70 } | 88 } |
71 | 89 |
72 Generate Number Methods[backend:out] | 90 Generate Number Methods[backend:out] |
73 { | 91 { |
74 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") | 92 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") |
89 ]Output Types <<[ [()]Append[Type Instance[outtype]] ] | 107 ]Output Types <<[ [()]Append[Type Instance[outtype]] ] |
90 ]Builtin? <<[Yes] | 108 ]Builtin? <<[Yes] |
91 ] | 109 ] |
92 } | 110 } |
93 | 111 |
112 Register Conversion Method[program, intype, outtype,prefix:out] | |
113 { | |
114 name <- [prefix]Append[[[outtype]Append["@"]]Append[intype]] | |
115 Print[["Registering conversion: "]Append[name]] | |
116 out <- [[program]Register Worker[name, "rhope", 1, 1] | |
117 ]Bind Worker[name, | |
118 [[[[[NWorker["rhope"] | |
119 ]Inputs <<[("in")] | |
120 ]Input Types <<[ [()]Append[Type Instance[intype]] ] | |
121 ]Outputs <<[("out")] | |
122 ]Output Types <<[ [()]Append[Type Instance[outtype]] ] | |
123 ]Builtin? <<[Yes] | |
124 ] | |
125 } | |
126 | |
127 Legal Conversions[type:convs] | |
128 { | |
129 bigger <- Filter[(16,32,64), [">"]Set Input[1, size]] | |
130 base convs <- Map[bigger, ["Append"]Set Input[0, "Int"]] | |
131 If[[type]Starts With["U"]] | |
132 { | |
133 [type]Slice[4] {} | |
134 { size <- <String@Whole Number[~] } | |
135 convs <- Concatenate[base convs, Map[bigger, ["Append"]Set Input[0, "UInt"]]] | |
136 }{ | |
137 [type]Slice[3] {} | |
138 { size <- <String@Whole Number[~] } | |
139 convs <- Val[base convs] | |
140 } | |
141 } | |
142 | |
143 Truncations[type:truncs] | |
144 { | |
145 ,u <- [type]Get DString["Int"] | |
146 { size <- <String@Whole Number[~] } | |
147 truncs <- Map[Filter[(8,16,32), ["<"]Set Input[1, size]], ["Append"]Set Input[0, [u]Append["Int"]]] | |
148 } | |
149 | |
94 _Register Number Methods[program,type:out] | 150 _Register Number Methods[program,type:out] |
95 { | 151 { |
96 Print[["_Regsiter Number Methods: "]Append[type]] | 152 Print[["_Regsiter Number Methods: "]Append[type]] |
97 methods <- ("+", "-", "*", "/", "LShift", "RShift") | 153 methods <- ("+", "-", "*", "/", "LShift", "RShift") |
98 compmethods <- ("<", ">", "=", "<=", ">=", "!=") | 154 compmethods <- ("<", ">", "=", "<=", ">=", "!=") |
99 register <- ["Register Number Method"]Set Input[2, type] | 155 register <- ["Register Number Method"]Set Input[2, type] |
100 Fold[[register]Set Input[3, type], program, methods] | 156 Fold[[register]Set Input[3, type], program, methods] |
101 { out <- Fold[[register]Set Input[3, "Boolean"], ~, compmethods] } | 157 { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] |
158 { Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] | |
159 { out <- Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc ", ~, Truncations[type]] }}} | |
102 } | 160 } |
103 | 161 |
104 Register Number Methods[program:out] | 162 Register Number Methods[program:out] |
105 { | 163 { |
106 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") | 164 numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") |