-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.java
More file actions
211 lines (171 loc) · 6.61 KB
/
Tests.java
File metadata and controls
211 lines (171 loc) · 6.61 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
class Tests
{
public static void testast( )
{
ast.Pointer pnt = new ast.Pointer(0);
System.out. println( pnt );
ast.Tree tr1 = new ast.Bool( true );
tr1. type = new type.Bool( );
tr1. lr = 'L';
ast.Tree tr2 = new ast.Char( 'x' );
ast.Tree tr3 = new ast.Double( 100 );
System. out. println( tr2 );
tr3. lr = 'L';
tr3. type = new type. Double( );
tr3 = new ast.Select( "f", tr3 );
tr3. lr = 'R';
tr3. type = new type. Pointer( new type. Double( ));
ast.Tree tr4 = new ast.Apply( "<=", tr3, tr3 );
tr4. lr = 'R';
tr4. type = new type.Pointer( new type.Struct( "type6" ));
tr4 = new ast.Apply( "function", tr4 );
tr4. type = new type. Double( );
tr4. lr = 'L';
System.out.println( tr4 );
System.out. println( tr4. trueType( ));
System.out.println( tr4. treesize( ));
}
public static void testtype( )
{
type.StructStore structs = new type.StructStore( );
structs. insert( "struct1", new type.Field[]
{ new type.Field( "f1", new type.Struct( "list" ) ),
new type.Field( "f2", new type.Char( )),
new type.Field( "f3", new type.Double( )),
new type.Field( "f4", new type.Integer( )),
new type.Field( "f5", new type.Double( )),
new type.Field( "f6", new type.Pointer(
new type.Array( 20, new type.Struct( "x" )))) } );
structs. insert( "list",
new type.Field[] {
new type.Field( "elem", new type.Double( )),
new type.Field( "next",
new type.Pointer( new type.Struct( "list" ))) } );
structs. insert( "complex",
new type.Field[] {
new type.Field( "re", new type.Double( )),
new type.Field( "im", new type.Double( )) } );
System. out. println( structs );
System. out. println( structs. fieldtype( "struct1", 0 ));
semantic.VarStore vars = new semantic.VarStore( );
vars. push( "c1", structs, new type.Struct( "complex" ));
vars. push( "d1", structs, new type.Double( ));
vars. push( "l1", structs, new type.Struct( "list" ));
vars. push( "ll", structs, new type.Array(10, new type.Struct( "list" )));
vars. push( "d1", structs, new type.Integer( ));
vars. restore(3);
System.out.println( vars );
System.out.println( vars. contains( "d1" ));
System.out.println( vars. currentoffset( "d1" ));
System.out.println( vars. gettype( "d1" ));
}
public static void testsimulator( )
{
simulator.Memory mem = new simulator.Memory( );
simulator.Program prog = new simulator.Program( );
type.StructStore structs = new type.StructStore( );
structs. insert( "list",
new type.Field[] {
new type.Field( "elem", new type.Double( )),
new type.Field( "next",
new type.Pointer( new type.Struct( "list" ))) } );
structs. insert( "complex",
new type.Field[] {
new type.Field( "re", new type.Double( )),
new type.Field( "im", new type.Double( )) } );
try
{
// simulator.Examples.addfact( prog );
simulator.Examples.addfactrec( prog );
// simulator.Examples.addlistsum( prog );
// simulator.Examples.addcomplexsum( prog );
System.out.println( prog );
if( true )
{
Object[] data =
new Object[] { new java.lang.Integer( 5 ) };
type.Type types[] =
new type.Type[] { new type.Integer( ) };
prog. run( structs, mem,
"factrec", new type.Double( ), data, types );
}
// mem. clear( );
// int ls = new type.Struct( "list" ). sizeof( structs );
// simulator.Memory.Pointer p =
// mem. allocate( 5 * ls );
// for( int i = 0; i != 5; ++ i )
// {
// mem. store( p. plus( i * ls ), new java.lang.Double(i));
// mem. store( p. plus( i * ls + 1 ), p. plus( i * ls + 2 ));
// }
// prog. run( structs, mem, "listsum", new type.Double( ),
// new Object[] { p },
// new type.Type[] {
// new type.Pointer( new type.Struct( "list" )) } );
if( false )
{
prog. run( structs, mem,
"complexsum", new type.Struct( "complex" ),
new Object[] {
new java.lang.Double(1), new java.lang.Double(10),
new java.lang.Double(2), new java.lang.Double(20) },
new type.Type[] {
new type.Struct( "complex" ),
new type.Struct( "complex" ) } );
}
System.out.println( mem. toString( 50 ));
}
catch( simulator.Error err )
{
System.out.println( "Something went wrong: " );
System.out.println( err );
System.out.println( "\n" );
}
}
public static void testtokenizer( java.io.InputStreamReader source )
{
System.out.println( "testing the tokenizer" );
Lexer lex = new Lexer( source );
try
{
java_cup.runtime.Symbol lookahead = lex. next_token( );
while( lookahead.sym != sym. EOF )
{
System. out. println( "Read Symbol: " +
sym. terminalNames [ lookahead. sym ] +
" " + lookahead. left +
" " + lookahead. right +
" " + lookahead. value );
lookahead = lex. next_token( );
}
System.out.println( "end of file at " +
lookahead.left + " " +
lookahead. right );
}
catch( java.io.IOException io )
{
System.out.println( "Error: " + io );
}
catch( ScanError err )
{
System.out.println( "ScanError: " + err );
}
catch( java.lang.NumberFormatException err )
{
System.out.println( "NumberFormatException: " + err );
System.out.println( "this probably means that the integer is too big" );
}
}
public static void testtokenizer( java.lang.String filename )
{
try
{
System.out.println( "Reading from file " + filename );
testtokenizer( new java.io.FileReader( filename ));
}
catch( java.io.FileNotFoundException err )
{
System.out.println( "could not open file " + filename );
}
}
}