1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 PPAbstractParserTest subclass:#PPCCodeGeneratorTest |
5 PPAbstractParserTest subclass:#PPCCodeGeneratorTest |
6 instanceVariableNames:'visitor node result compiler parser context configuration options' |
6 instanceVariableNames:'visitor node result parser context compiler options' |
7 classVariableNames:'' |
7 classVariableNames:'' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Tests-Visitors' |
9 category:'PetitCompiler-Tests-Visitors' |
10 ! |
10 ! |
11 |
11 |
12 |
12 |
13 !PPCCodeGeneratorTest methodsFor:'generating'! |
13 !PPCCodeGeneratorTest methodsFor:'generating'! |
14 |
14 |
15 compileTree: root |
15 compileTree: root |
16 parser := configuration compile: root. |
16 parser := compiler compile: root. |
17 |
17 |
18 ! ! |
18 ! ! |
19 |
19 |
20 !PPCCodeGeneratorTest methodsFor:'running'! |
20 !PPCCodeGeneratorTest methodsFor:'running'! |
21 |
21 |
22 context |
22 context |
23 ^ context := PPCProfilingContext new |
23 ^ context := PPCProfilingContext new |
24 ! |
24 ! |
25 |
25 |
26 setUp |
26 setUp |
27 options := PPCCompilationOptions default |
27 options := (PPCCompilationOptions default) |
28 tokenize: false; |
28 tokenize:false; |
29 profile: true; |
29 profile:true; |
30 yourself. |
30 yourself. |
31 |
31 compiler := PPCCompiler new passes:{ |
32 configuration := PPCConfiguration new passes: |
32 PPCCacheFirstFollowPass. |
33 { |
33 PPCCheckingVisitor. |
34 PPCCacheFirstFollowPass. |
34 PPCUniversalCodeGenerator |
35 PPCCheckingVisitor . |
35 }. |
36 PPCUniversalCodeGenerator . |
36 compiler options:options. |
37 }. |
|
38 configuration options: options. |
|
39 |
37 |
40 "Modified: / 04-09-2015 / 16:22:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
38 "Modified: / 04-09-2015 / 16:22:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
41 ! |
39 ! |
42 |
40 |
43 tearDown |
41 tearDown |
926 |
924 |
927 "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
925 "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
928 ! |
926 ! |
929 |
927 |
930 testStarAnyNode |
928 testStarAnyNode |
931 configuration removePass: PPCCacheFirstFollowPass. |
929 compiler removePass: PPCCacheFirstFollowPass. |
932 node := PPCStarAnyNode new |
930 node := PPCStarAnyNode new |
933 child: PPCNilNode new; |
931 child: PPCNilNode new; |
934 yourself. |
932 yourself. |
935 self compileTree: node. |
933 self compileTree: node. |
936 |
934 |
940 |
938 |
941 "Modified: / 04-09-2015 / 14:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
939 "Modified: / 04-09-2015 / 14:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
942 ! |
940 ! |
943 |
941 |
944 testStarCharSetPredicateNode |
942 testStarCharSetPredicateNode |
945 configuration removePass: PPCCacheFirstFollowPass. |
943 compiler removePass: PPCCacheFirstFollowPass. |
946 node := PPCStarCharSetPredicateNode new |
944 node := PPCStarCharSetPredicateNode new |
947 predicate: (PPCharSetPredicate on: [:e | e = $a ]); |
945 predicate: (PPCharSetPredicate on: [:e | e = $a ]); |
948 child: PPCSentinelNode new; |
946 child: PPCSentinelNode new; |
949 yourself. |
947 yourself. |
950 |
948 |
958 |
956 |
959 "Modified: / 04-09-2015 / 14:47:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
957 "Modified: / 04-09-2015 / 14:47:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
960 ! |
958 ! |
961 |
959 |
962 testStarMessagePredicateNode |
960 testStarMessagePredicateNode |
963 configuration removePass: PPCCacheFirstFollowPass. |
961 compiler removePass: PPCCacheFirstFollowPass. |
964 node := PPCStarMessagePredicateNode new |
962 node := PPCStarMessagePredicateNode new |
965 message: #isLetter; |
963 message: #isLetter; |
966 child: PPCSentinelNode new; |
964 child: PPCSentinelNode new; |
967 yourself. |
965 yourself. |
968 |
966 |
1037 |
1035 |
1038 node := PPCTokenStarMessagePredicateNode new |
1036 node := PPCTokenStarMessagePredicateNode new |
1039 message: #isLetter; |
1037 message: #isLetter; |
1040 child: PPCSentinelNode new; |
1038 child: PPCSentinelNode new; |
1041 yourself. |
1039 yourself. |
1042 configuration removePass: PPCCacheFirstFollowPass. |
1040 compiler removePass: PPCCacheFirstFollowPass. |
1043 options guards: false. |
1041 options guards: false. |
1044 self compileTree: node. |
1042 self compileTree: node. |
1045 |
1043 |
1046 self assert: parser class methodDictionary size = 1. |
1044 self assert: parser class methodDictionary size = 1. |
1047 |
1045 |
1064 child: PPCSentinelNode new; |
1062 child: PPCSentinelNode new; |
1065 yourself. |
1063 yourself. |
1066 node := PPCForwardNode new |
1064 node := PPCForwardNode new |
1067 child: starNode; |
1065 child: starNode; |
1068 yourself. |
1066 yourself. |
1069 configuration removePass: PPCCacheFirstFollowPass. |
1067 compiler removePass: PPCCacheFirstFollowPass. |
1070 self compileTree: node. |
1068 self compileTree: node. |
1071 |
1069 |
1072 self assert: parser class methodDictionary size = 2. |
1070 self assert: parser class methodDictionary size = 2. |
1073 |
1071 |
1074 self assert: parser parse: ' a' to: parser end: 3. |
1072 self assert: parser parse: ' a' to: parser end: 3. |
1086 markForInline; |
1084 markForInline; |
1087 yourself. |
1085 yourself. |
1088 node := PPCForwardNode new |
1086 node := PPCForwardNode new |
1089 child: starNode; |
1087 child: starNode; |
1090 yourself. |
1088 yourself. |
1091 configuration removePass: PPCCacheFirstFollowPass. |
1089 compiler removePass: PPCCacheFirstFollowPass. |
1092 self compileTree: node. |
1090 self compileTree: node. |
1093 |
1091 |
1094 self assert: parser class methodDictionary size = 1. |
1092 self assert: parser class methodDictionary size = 1. |
1095 |
1093 |
1096 self assert: parser parse: ' a' to: context end: 3. |
1094 self assert: parser parse: ' a' to: context end: 3. |