Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl.test/tests/Object.sl @ 21488:6420ac0cbe3c
Add Makefile generator for building graal without mx
author | Stefan Anzinger <stefan.anzinger@oracle.com> |
---|---|
date | Tue, 26 May 2015 14:46:32 +0200 |
parents | 997bc9764a9a |
children |
rev | line source |
---|---|
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1 function main() { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
2 obj1 = new(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
3 println(obj1.x); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
4 obj1.x = 42; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
5 println(obj1.x); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
6 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
7 obj2 = new(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
8 obj2.o = obj1; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
9 println(obj2.o.x); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
10 obj2.o.y = "why"; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
11 println(obj1.y); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
12 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
13 println(mkobj().z); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
14 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
15 obj3 = new(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
16 obj3.fn = mkobj; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
17 println(obj3.fn().z); |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
18 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
19 obj4 = new(); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
20 write(obj4, 1); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
21 read(obj4); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
22 write(obj4, 2); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
23 read(obj4); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
24 write(obj4, "three"); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
25 read(obj4); |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
26 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
27 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
28 function mkobj() { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
29 newobj = new(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
30 newobj.z = "zzz"; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
31 return newobj; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
32 } |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
33 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
34 function read(obj) { |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
35 return obj.prop; |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
36 } |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
37 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
38 function write(obj, value) { |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
39 return obj.prop = value; |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
40 } |