Mercurial > repos > rhope
comparison number_c.rhope @ 169:fd06fb07762a
Basic inlining of arithmetic and comparison operations on integer types
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 08 May 2011 01:37:44 -0700 |
parents | fc3815b7462f |
children |
comparison
equal
deleted
inserted
replaced
168:d2b941f82d74 | 169:fd06fb07762a |
---|---|
16 { ,outa <- [~]Write Field["a", "Num"] | 16 { ,outa <- [~]Write Field["a", "Num"] |
17 { after op <- [backend func]Call[~, ina, inb, outa] }}} | 17 { after op <- [backend func]Call[~, ina, inb, outa] }}} |
18 | 18 |
19 out <- [backend]Store Function[ [[after op]Move["a","out"]]Release["b"] ] | 19 out <- [backend]Store Function[ [[after op]Move["a","out"]]Release["b"] ] |
20 | 20 |
21 } | |
22 | |
23 Compile Number Inline[func,op,type,a,b,outvar:out] | |
24 { | |
25 ,ina <- [ | |
26 [[func]Move[a, outvar] | |
27 ]Copy[outvar] | |
28 ]Read Field[Cast[outvar, type], "Num"] | |
29 { ,inb <- [~]Read Field[Cast[Strip Addref[b], type], "Num"] | |
30 { ,outa <- [~]Write Field[Cast[outvar, type], "Num"] | |
31 { out <- [op]Call[~, ina, inb, outa] }}} | |
32 } | |
33 | |
34 Compile Number Comp Inline[func,op,type,a,b,outvar:out] | |
35 { | |
36 ,ina <- [ | |
37 [func]Allocate Var["compres", [Type Instance["Int32"]]Set Variant["Naked"]] | |
38 ]Read Field[Cast[Strip Addref[a], type], "Num"] | |
39 { ,inb <- [~]Read Field[Cast[Strip Addref[b], type], "Num"] | |
40 { after op <- [op]Call[~, ina, inb, "compres"] }} | |
41 | |
42 [after op]Do If["compres", [[after op]Instruction Stream]Move[Constant["Boolean_Yes"], outvar]] | |
43 { out <- [~]Do If[NotCond["compres"], [[after op]Instruction Stream]Move[Constant["Boolean_No"], outvar]] } | |
44 } | |
45 | |
46 Compile Number Inline Check[func,op,type a,type b,a,b,outvar:out,no inline] | |
47 { | |
48 opmap <- [[[[[[[[Dictionary[] | |
49 ]Set["+", Add[?]] | |
50 ]Set["-", Sub[?]] | |
51 ]Set["*", Multiply[?]] | |
52 ]Set["/", Divide[?]] | |
53 ]Set["LShift", DoLShift[?]] | |
54 ]Set["RShift", DoRShift[?]] | |
55 ]Set["&", BitAnd[?]] | |
56 ]Set["|", BitOr[?]] | |
57 backend op <- [opmap]Index[op] | |
58 { inline func <- Val[Compile Number Inline[?]] } | |
59 { | |
60 comp opmap <- [[[[[[Dictionary[] | |
61 ]Set["<", CompLess[?]] | |
62 ]Set[">", CompGreater[?]] | |
63 ]Set["=", CompEqual[?]] | |
64 ]Set["<=", CompLessEqual[?]] | |
65 ]Set[">=", CompGreaterEqual[?]] | |
66 ]Set["!=", CompNotEqual[?]] | |
67 backend op, no inline <- [comp opmap]Index[op] | |
68 { inline func <- Val[Compile Number Comp Inline[?]] } | |
69 } | |
70 | |
71 | |
72 Val[backend op] | |
73 { | |
74 signed?,int,size,no inline <- [[type a]Name >>]Partition["Int"] | |
75 { | |
76 ,no inline <- If[[[signed?] = ["U"]] Or [[signed?] = [""]]] | |
77 { | |
78 ,no inline <- [("8","16","32","64")]Find[=[size, ?]] | |
79 { | |
80 //TODO: Do an inline type check/conversion rather than falling back on a standard call | |
81 ,no inline <- If[[type b] = [type a]] | |
82 { | |
83 out <- [inline func]Call[func, backend op, type a, a, b, outvar] | |
84 } | |
85 } | |
86 } | |
87 } | |
88 } | |
21 } | 89 } |
22 | 90 |
23 Compile Number Comp Method[backend, op, type:out] | 91 Compile Number Comp Method[backend, op, type:out] |
24 { | 92 { |
25 name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] | 93 name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] |