-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbc_test.txt
109 lines (105 loc) · 2.04 KB
/
bc_test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Parse Succesful!
[Abstract Syntax]
(PDefs [(DFun "main" [(ADecl "arg1"), (ADecl "arg2")] [(SExp [(EApp "N_printString" [(EString "What string? ")] )] ), (SInit "s" [(EApp "N_readString" [] )] ), (SExp [(EApp "N_printString" [(EString "How many times? ")] )] ), (SInit "k" [(EApp "N_readInt" [] )] ), (SExp [(EApp "N_printString" [(EApp "F_B" [(EId "k"), (EId "s")] )] )] ), (SReturn [(EInt 1)] )] ), (DClass "C_A" "Base" [(DFun "F_A" [] [(SInit "i" [(EInt 1)] ), (SInit "r" [(EId "s")] ), (SReturn [(EId "r")] )] )] ), (DFun "F_B" [(ADecl "k"), (ADecl "s")] [(SInit "i" [(EInt 1)] ), (SNewClass "f" "C_A" ), (SClassMember "f" [(EApp "F_A" [] )] ), (SInit "r" [(EId "s")] ), (SReturn [(EId "r")] )] )])
[Linearized Tree]
main (arg1, arg2)
{
N_printString ("What string? ");
s = N_readString ();
N_printString ("How many times? ");
k = N_readInt ();
N_printString (F_B (k, s));
return 1;
}
class C_A : Base
{
F_A ()
{
i = 1;
r = s;
return r;
}
}
F_B (k, s)
{
i = 1;
f = new C_A;
f . F_A ();
r = s;
return r;
}
BYTECODE
<BEGIN MAIN> 0 0 0
<BEGIN FUN> 0 0 0
DFUN ID 0 0
SIZE ID 0 1
ArgumentDECL ID 0 2
ArgumentDECL ID 0 3
CALL ID 0 4
STRING ID 0 5
STORE ID 0 6
CALL ID 0 7
CALL ID 0 4
STRING ID 0 8
STORE ID 0 9
CALL ID 0 10
CALL ID 0 4
CALL ID 0 11
ArgumentPASS ID 0 9
ArgumentPASS ID 0 6
RET 0 0 0
INT ID 0 12
<END FUN> 0 0 0
<BEGIN CLASS> 0 0 0
DClass ID 0 13
DClassParent ID 0 14
<BEGIN FUN> 0 0 0
DFUN ID 0 15
SIZE ID 0 16
STORE ID 0 17
INT ID 0 12
STORE ID 0 18
ArgumentPASS ID 0 6
RET 0 0 0
ArgumentPASS ID 0 18
<END FUN> 0 0 0
<END CLASS> 0 0 0
<BEGIN FUN> 0 0 0
DFUN ID 0 11
SIZE ID 0 1
ArgumentDECL ID 0 9
ArgumentDECL ID 0 6
STORE ID 0 17
INT ID 0 12
STORE ID 0 19
NEW ID 0 13
MEMBER ID 0 19
CALL ID 0 15
STORE ID 0 18
ArgumentPASS ID 0 6
RET 0 0 0
ArgumentPASS ID 0 18
<END FUN> 0 0 0
<END MAIN> 0 0 0
************************************************
CONSTANT POOL
0 16
1 12
2 1
Base 14
C_A 13
F_A 15
F_B 11
How many times? 8
N_printString 4
N_readInt 10
N_readString 7
What string? 5
arg1 2
arg2 3
f 19
i 17
k 9
main 0
r 18
s 6