20 !TCompilerExamples methodsFor:'tests'! |
20 !TCompilerExamples methodsFor:'tests'! |
21 |
21 |
22 example_if |
22 example_if |
23 | environment unit compiler| |
23 | environment unit compiler| |
24 |
24 |
25 environment := TNamespaceDefinition new. |
25 environment := TEnvironment new. |
26 unit := TSourceReader read:' |
26 unit := TSourceReader read:' |
27 nil subclass: #tBoolean |
27 nil subclass: #If |
28 category: ''tKernel-Builtins'' |
28 category: ''t-Examples'' |
29 !! |
|
30 |
|
31 nil subclass: #tSIntegerW |
|
32 category: ''tKernel-Builtins'' |
|
33 !! |
29 !! |
34 !!tSIntegerW methodsFor:''testing''!! |
30 !!If class methodsFor:''examples''!! |
35 = another <tSIntegerW> <^ tBoolean> |
31 if <^ tSIntegerW> |
36 %[:asm | |
32 true ifTrue:[ ^ 1 ] ifFalse:[ ^ 0 ] |
37 asm ret: (asm add: self _: another) |
|
38 %]. |
|
39 "Following code is actually used only in hosted environment" |
|
40 ^ self + another |
|
41 !! !! |
|
42 |
|
43 !!tSIntegerW class methodsFor:''test''!! |
|
44 threePlusFour <^ tSIntegerW> |
|
45 ^ 3 + 4 |
|
46 |
|
47 !! !! |
|
48 '. |
33 '. |
49 |
34 |
50 compiler := TCompiler new. |
35 compiler := TCompiler new. |
51 compiler compile: unit in: environment. |
36 compiler compile: unit in: environment. |
52 self halt. |
37 self halt. |
53 " |
38 " |
54 compiler context module |
39 compiler context module |
55 " |
40 " |
56 |
41 |
57 "Created: / 14-09-2015 / 12:14:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
42 "Created: / 14-09-2015 / 12:14:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
58 "Modified: / 14-09-2015 / 14:27:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
43 "Modified: / 15-09-2015 / 12:22:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
59 ! |
44 ! |
60 |
45 |
61 example_three_plus_four |
46 example_three_plus_four |
62 | environment unit compiler| |
47 | environment unit compiler| |
63 |
48 |