Mercurial > repos > rhope
comparison 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 |
comparison
equal
deleted
inserted
replaced
47:6202b866d72c | 48:a24eb366195c |
---|---|
1 | |
2 | |
3 Compile Number Method[backend, op, type:out] | |
4 { | |
5 name <- [[[op]Index[0]]Append["@"]]Append[type] | |
6 backend func <- [op]Index[1] | |
7 type inst <- Type Instance[type] | |
8 func <- [[[[backend]Create Function[name,("a","b"), ("out"), "rhope"] | |
9 ]Set Input Type[type inst, 0] | |
10 ]Set Input Type[type inst, 1] | |
11 ]Set Output Type[type inst, 0] | |
12 | |
13 ,ina <- [[func]Copy["a"] | |
14 ]Read Field["a", "Num"] | |
15 { ,inb <- [~]Read Field["b", "Num"] | |
16 { ,outa <- [~]Write Field["a", "Num"] | |
17 { after op <- [ | |
18 [backend func]Do[ | |
19 [ | |
20 [ | |
21 [ | |
22 [()]Append[~] | |
23 ]Append[ina] | |
24 ]Append[inb] | |
25 ]Append[outa] ] | |
26 ]Index[0] }}} | |
27 | |
28 out <- [backend]Store Function[ [[after op]Move["a","out"]]Release["b"] ] | |
29 | |
30 } | |
31 | |
32 Compile Number Comp Method[backend, op, type:out] | |
33 { | |
34 name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] | |
35 backend func <- [op]Index[1] | |
36 type inst <- Type Instance[type] | |
37 func <- [[[[[[ [backend]Create Function[name,("a","b"), ("out"), "rhope"] | |
38 ]Set Input Type[type inst, 0] | |
39 ]Set Input Type[type inst, 1] | |
40 ]Set Output Type[Type Instance["Boolean"], 0] | |
41 ]Register Constant["Blueprint_Boolean", Type Instance["Boolean"]] | |
42 ]Call["Build", [()]Append[Constant["Blueprint_Boolean"]]] | |
43 ]Move[Result[0], "out"] | |
44 | |
45 ,ina <- [func]Read Field["a", "Num"] | |
46 { ,inb <- [~]Read Field["b", "Num"] | |
47 { ,outa <- [~]Write Field["out", "Val"] | |
48 { after op <- [ | |
49 [backend func]Do[ | |
50 [ | |
51 [ | |
52 [ | |
53 [()]Append[~] | |
54 ]Append[ina] | |
55 ]Append[inb] | |
56 ]Append[outa] ] | |
57 ]Index[0] }}} | |
58 | |
59 out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ] | |
60 | |
61 } | |
62 | |
63 _Generate Number Methods[backend, type:out] | |
64 { | |
65 opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) | |
66 compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual")) | |
67 | |
68 Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] | |
69 { out <- Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] } | |
70 } | |
71 | |
72 Generate Number Methods[backend:out] | |
73 { | |
74 numtypes <- ("Int8","Int16","Int32","UInt8","UInt16","UInt32") | |
75 | |
76 out <- Fold["_Generate Number Methods", backend, numtypes] | |
77 } | |
78 | |
79 Register Number Method[program, method, type, outtype:out] | |
80 { | |
81 name <- [[method]Append["@"]]Append[type] | |
82 Print[["Regsiter Number Method: "]Append[name]] | |
83 out <- [[program]Register Worker[name, "rhope", 2, 1] | |
84 ]Bind Worker[name, | |
85 [[[[[NWorker["rhope"] | |
86 ]Inputs <<[("left","right")] | |
87 ]Input Types <<[ [[()]Append[ Type Instance[type]]]Append[Type Instance[type]] ] | |
88 ]Outputs <<[("out")] | |
89 ]Output Types <<[ [()]Append[Type Instance[outtype]] ] | |
90 ]Builtin? <<[Yes] | |
91 ] | |
92 } | |
93 | |
94 _Register Number Methods[program,type:out] | |
95 { | |
96 Print[["_Regsiter Number Methods: "]Append[type]] | |
97 methods <- ("+", "-", "*", "/", "LShift", "RShift") | |
98 compmethods <- ("<", ">", "=", "<=", ">=", "!=") | |
99 register <- ["Register Number Method"]Set Input[2, type] | |
100 Fold[[register]Set Input[3, type], program, methods] | |
101 { out <- Fold[[register]Set Input[3, "Boolean"], ~, compmethods] } | |
102 } | |
103 | |
104 Register Number Methods[program:out] | |
105 { | |
106 numtypes <- ("Int8","Int16","Int32","UInt8","UInt16","UInt32") | |
107 out <- Fold["_Register Number Methods", program, numtypes] | |
108 } | |
109 |