compiler/tests/PPCCodeGeneratorTest.st
changeset 535 a8feb0f47574
parent 534 a949c4fe44df
child 537 fb212e14d1f4
equal deleted inserted replaced
534:a949c4fe44df 535:a8feb0f47574
    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         profile: true.
    28                 tokenize: false; 
    29         
    29                 profile: true;
    30     configuration := PPCPluggableConfiguration on: [ :_self | 
    30                 yourself.
    31         options cacheFirstFollow ifTrue:[ 
    31         
    32             _self runPass: PPCCacheFirstFollowPass.
    32     configuration := PPCConfiguration new passes:
    33         ].
    33             {
    34         _self runPass: PPCCheckingVisitor.
    34                 PPCCacheFirstFollowPass.
    35         _self runPass: PPCUniversalCodeGenerator.
    35                 PPCCheckingVisitor .
    36         _self generateParser.
    36                 PPCUniversalCodeGenerator .
    37     ].
    37             }.
    38     configuration options: options.
    38     configuration options: options.
    39 
    39 
    40     "Modified: / 04-09-2015 / 10:31:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    40     "Modified: / 04-09-2015 / 16:22:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    41 !
    41 !
    42 
    42 
    43 tearDown
    43 tearDown
    44     | class |
    44     | class |
    45 
    45 
   926 
   926 
   927     "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   927     "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   928 !
   928 !
   929 
   929 
   930 testStarAnyNode
   930 testStarAnyNode
   931     options cacheFirstFollow: false.
   931     configuration removePass: PPCCacheFirstFollowPass.
   932     node := PPCStarAnyNode new 
   932     node := PPCStarAnyNode new 
   933         child: PPCNilNode new; 
   933         child: PPCNilNode new; 
   934         yourself.
   934         yourself.
   935     self compileTree: node.
   935     self compileTree: node.
   936     
   936     
   937     self assert: parser parse: 'abc' to: #($a $b $c).
   937     self assert: parser parse: 'abc' to: #($a $b $c).
   938     self assert: parser parse: 'a' to: #($a).
   938     self assert: parser parse: 'a' to: #($a).
   939     self assert: parser parse: '' to: #().
   939     self assert: parser parse: '' to: #().
       
   940 
       
   941     "Modified: / 04-09-2015 / 14:47:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   940 !
   942 !
   941 
   943 
   942 testStarCharSetPredicateNode
   944 testStarCharSetPredicateNode
   943     options cacheFirstFollow: false.
   945     configuration removePass: PPCCacheFirstFollowPass.
   944     node := PPCStarCharSetPredicateNode new
   946     node := PPCStarCharSetPredicateNode new
   945         predicate: (PPCharSetPredicate on: [:e | e = $a ]);
   947         predicate: (PPCharSetPredicate on: [:e | e = $a ]);
   946         child: PPCSentinelNode new;
   948         child: PPCSentinelNode new;
   947         yourself.
   949         yourself.
   948     
   950     
   951     self assert: parser class methodDictionary size = 1.
   953     self assert: parser class methodDictionary size = 1.
   952     self assert: parser parse: 'aaa1' to: #( $a $a $a) end: 3.
   954     self assert: parser parse: 'aaa1' to: #( $a $a $a) end: 3.
   953     self assert: context invocationCount = 1.
   955     self assert: context invocationCount = 1.
   954     self assert: parser parse: 'bba' to: #() end: 0.
   956     self assert: parser parse: 'bba' to: #() end: 0.
   955     self assert: context invocationCount = 1.
   957     self assert: context invocationCount = 1.
   956     
   958 
       
   959     "Modified: / 04-09-2015 / 14:47:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   957 !
   960 !
   958 
   961 
   959 testStarMessagePredicateNode
   962 testStarMessagePredicateNode
   960     options cacheFirstFollow: false.
   963     configuration removePass: PPCCacheFirstFollowPass.
   961     node := PPCStarMessagePredicateNode new
   964     node := PPCStarMessagePredicateNode new
   962         message: #isLetter;
   965         message: #isLetter;
   963         child: PPCSentinelNode new;
   966         child: PPCSentinelNode new;
   964         yourself.
   967         yourself.
   965     
   968     
   969     self assert: parser parse: 'abc1' to: #( $a $b $c) end: 3.
   972     self assert: parser parse: 'abc1' to: #( $a $b $c) end: 3.
   970     self assert: context invocationCount = 1.
   973     self assert: context invocationCount = 1.
   971     
   974     
   972     self assert: parser parse: '123a' to: #() end: 0.
   975     self assert: parser parse: '123a' to: #() end: 0.
   973     self assert: context invocationCount = 1.
   976     self assert: context invocationCount = 1.
   974     
   977 
       
   978     "Modified: / 04-09-2015 / 14:48:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   975 !
   979 !
   976 
   980 
   977 testStarNode
   981 testStarNode
   978     node := PPCStarNode new
   982     node := PPCStarNode new
   979         child: ($a asParser asCompilerNode);
   983         child: ($a asParser asCompilerNode);
  1033     
  1037     
  1034     node := PPCTokenStarMessagePredicateNode new 
  1038     node := PPCTokenStarMessagePredicateNode new 
  1035         message: #isLetter; 
  1039         message: #isLetter; 
  1036         child: PPCSentinelNode new; 
  1040         child: PPCSentinelNode new; 
  1037         yourself.
  1041         yourself.
  1038     options cacheFirstFollow: false.
  1042     configuration removePass: PPCCacheFirstFollowPass.
  1039     options guards: false.	
  1043     options guards: false.      
  1040     self compileTree: node.
  1044     self compileTree: node.
  1041     
  1045     
  1042     self assert: parser class methodDictionary size = 1.
  1046     self assert: parser class methodDictionary size = 1.
  1043     
  1047     
  1044     self assert: parser parse: 'foo' to: parser.
  1048     self assert: parser parse: 'foo' to: parser.
  1046     self assert: context lwRememberCount  = 0.
  1050     self assert: context lwRememberCount  = 0.
  1047     self assert: context lwRestoreCount  = 0.
  1051     self assert: context lwRestoreCount  = 0.
  1048     self assert: context rememberCount = 0.
  1052     self assert: context rememberCount = 0.
  1049     
  1053     
  1050     self assert: parser parse: 'foo123' to: parser end: 3.
  1054     self assert: parser parse: 'foo123' to: parser end: 3.
       
  1055 
       
  1056     "Modified: / 04-09-2015 / 14:48:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1051 !
  1057 !
  1052 
  1058 
  1053 testTokenStarSeparatorNode
  1059 testTokenStarSeparatorNode
  1054     
  1060     
  1055     | starNode |
  1061     | starNode |
  1058         child: PPCSentinelNode new; 
  1064         child: PPCSentinelNode new; 
  1059         yourself.
  1065         yourself.
  1060     node := PPCForwardNode new
  1066     node := PPCForwardNode new
  1061         child: starNode;
  1067         child: starNode;
  1062         yourself.
  1068         yourself.
  1063     options cacheFirstFollow: false.
  1069     configuration removePass: PPCCacheFirstFollowPass.
  1064     self compileTree: node.
  1070     self compileTree: node.
  1065     
  1071     
  1066     self assert: parser class methodDictionary size = 2.
  1072     self assert: parser class methodDictionary size = 2.
  1067     
  1073     
  1068     self assert: parser parse: '   a' to: parser end: 3.
  1074     self assert: parser parse: '   a' to: parser end: 3.
  1069     self assert: context invocationCount = 2.
  1075     self assert: context invocationCount = 2.
  1070     
  1076 
       
  1077     "Modified: / 04-09-2015 / 14:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1071 !
  1078 !
  1072 
  1079 
  1073 testTokenStarSeparatorNode2
  1080 testTokenStarSeparatorNode2
  1074     
  1081     
  1075     | starNode |
  1082     | starNode |
  1078         child: PPCSentinelNode new; 
  1085         child: PPCSentinelNode new; 
  1079         markForInline;
  1086         markForInline;
  1080         yourself.
  1087         yourself.
  1081     node := PPCForwardNode new
  1088     node := PPCForwardNode new
  1082         child: starNode;
  1089         child: starNode;
  1083         yourself.	
  1090         yourself.       
  1084     options cacheFirstFollow: false.
  1091     configuration removePass: PPCCacheFirstFollowPass.
  1085     self compileTree: node.
  1092     self compileTree: node.
  1086     
  1093     
  1087     self assert: parser class methodDictionary size = 1.
  1094     self assert: parser class methodDictionary size = 1.
  1088     
  1095     
  1089     self assert: parser parse: '   a' to: context end: 3.
  1096     self assert: parser parse: '   a' to: context end: 3.
  1090     self assert: context invocationCount = 1.
  1097     self assert: context invocationCount = 1.
  1091     
  1098 
       
  1099     "Modified: / 04-09-2015 / 14:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1092 !
  1100 !
  1093 
  1101 
  1094 testTrimNode
  1102 testTrimNode
  1095     node := PPCTrimNode new
  1103     node := PPCTrimNode new
  1096         child: #letter asParser asCompilerNode;
  1104         child: #letter asParser asCompilerNode;