comparison testc_c.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
children 5a08705f7610
comparison
equal deleted inserted replaced
91:bcdc326b3d6e 92:e73a93fb5de1
1 Import cbackend_c.rhope
2 Import number_c.rhope
3 Import boolean.rhope
4
5 //Dummy versions of nworker methods so the code in number_c.rhope will compile
6 Register Worker[prog,name,convention,inputs,outputs:out]
7 {
8 out <- prog
9 }
10
11 Bind Worker[prog,name,worker:out]
12 {
13 out <- prog
14 }
15
16 Blueprint NWorker
17 {
18 Inputs
19 Input Types
20 Outputs
21 Output Types
22 Builtin?
23 }
24
25 NWorker[convention:out]
26 {
27 out <- convention
28 }
29
30 Main[]
31 {
32 prog <- [[C Program[]]Generate Number Methods]Generate Boolean Methods
33 base <- [[[[[[[[[prog]Create Function["Fib",("n"),("out"),"rhope"]
34 ]Allocate Var["work1", Type Instance["Any Type"]]
35 ]Allocate Var["work2", Type Instance["Any Type"]]
36 ]Register Constant["const_1", 1]
37 ]Register Constant["const_2", 2]
38 ]Set Null["out"]
39 ]Method Call["<", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_2"]]]]
40 ]Move[Result[0], "work1"]
41 ]Method Call["If", [()]Append["work1"]]
42 {Print["base done"] }
43
44 stream1 <- [[[base]Instruction Stream
45 ]Release[Result[0]]
46 ]Move[AddRef[Constant["const_1"]], "out"]
47 {Print["stream1 done"]}
48
49
50
51 [[[[[[[[[[base]Instruction Stream
52 ]Release[Result[0]]
53 ]Method Call["-", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_1"]]]]
54 ]Move[Result[0], "work1"]
55 ]Method Call["-", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_2"]]]]
56 ]Move[Result[0], "work2"]
57 ]Call["Fib", ("work1")]
58 ]Move[Result[0], "work1"]
59 ]Call["Fib", ("work2")]
60 ]Move[Result[0], "work2"]
61 {
62 stream3 <- [[[~]Instruction Stream
63 ]Release["n"]
64 ]Method Call["+", ("work1","work2")]
65 stream2 <- [~]Do If[NotCond["out"], stream3]
66 {Print["stream2 done"]}
67 }
68
69
70 func <- [[[base
71 ]Do If[Result[0], stream1]
72 ]Do If[Result[1], stream2]
73 ]Release["n"]
74 {Print["func done"] }
75
76 main <- [[[[prog]Create Function["Main", (), ("out"), "rhope"]
77 ]Register Constant["const_30", 30]
78 ]Call["Fib", [()]Append[Constant["const_30"]]]
79 ]Move[Result[0], "out"]
80
81 Print[
82 [[[prog]Store Function[func]
83 ]Store Function[main]
84 ]Text
85 ]
86
87 }
88