diff -r b2f2f15cef26 -r 7e08b31e0dae compiler/tests/PPCNodeCompilingTest.st --- a/compiler/tests/PPCNodeCompilingTest.st Wed Nov 19 10:52:37 2014 +0000 +++ b/compiler/tests/PPCNodeCompilingTest.st Mon Nov 24 00:09:23 2014 +0000 @@ -92,33 +92,29 @@ ! testCompileChoice - tree := PPCChoiceNode new - children: { #digit asParser asCompilerNode. #letter asParser asCompilerNode }; - yourself. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 4. - - self assert: parser parse: '1' to: $1. - self assert: parser parse: 'a' to: $a. - self assert: parser fail: '_'. - - "Modified: / 06-11-2014 / 00:48:30 / Jan Vrany " + tree := PPCChoiceNode new + children: { #digit asParser asCompilerNode. #letter asParser asCompilerNode }; + yourself. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 4. + + self assert: parser parse: '1' to: $1. + self assert: parser parse: 'a' to: $a. + self assert: parser fail: '_'. ! testCompileLiteral - tree := PPCLiteralNode new - literal: 'foo'; - yourself. - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'foo' to: 'foo'. - self assert: parser parse: 'foobar' to: 'foo' end: 3. - self assert: parser fail: 'boo'. - - "Modified: / 06-11-2014 / 00:48:35 / Jan Vrany " + tree := PPCLiteralNode new + literal: 'foo'; + yourself. + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'foo' to: 'foo'. + self assert: parser parse: 'foobar' to: 'foo' end: 3. + self assert: parser fail: 'boo'. ! testCompileLiteral2 @@ -153,51 +149,45 @@ ! testCompileNotCharSetPredicate - tree := PPCNotCharSetPredicateNode new - predicate: (PPCharSetPredicate on: [ :e | e = $a ]); - yourself. - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'b' to: nil end: 0. - self assert: context invocationCount = 2. - - self assert: parser fail: 'a'. - self assert: parser parse: '' to: nil end: 0. - - "Modified: / 06-11-2014 / 00:48:43 / Jan Vrany " + tree := PPCNotCharSetPredicateNode new + predicate: (PPCharSetPredicate on: [ :e | e = $a ]); + yourself. + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'b' to: nil end: 0. + self assert: context invocationCount = 2. + + self assert: parser fail: 'a'. + self assert: parser parse: '' to: nil end: 0. ! testCompileNotLiteral - tree := PPCNotLiteralNode new - literal: 'foo'; - yourself. - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'bar' to: nil end: 0. - self assert: context invocationCount = 2. - - self assert: parser fail: 'foo'. - self assert: parser parse: '' to: nil end: 0. - - "Modified: / 06-11-2014 / 00:48:46 / Jan Vrany " + tree := PPCNotLiteralNode new + literal: 'foo'; + yourself. + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'bar' to: nil end: 0. + self assert: context invocationCount = 2. + + self assert: parser fail: 'foo'. + self assert: parser parse: '' to: nil end: 0. ! testCompileNotMessagePredicate - tree := PPCNotMessagePredicateNode new - message: #isDigit; - yourself. - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'a' to: nil end: 0. - self assert: context invocationCount = 2. - - self assert: parser fail: '1'. - self assert: parser parse: '' to: nil end: 0. - - "Modified: / 06-11-2014 / 00:48:49 / Jan Vrany " + tree := PPCNotMessagePredicateNode new + message: #isDigit; + yourself. + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'a' to: nil end: 0. + self assert: context invocationCount = 2. + + self assert: parser fail: '1'. + self assert: parser parse: '' to: nil end: 0. ! testCompileOptional @@ -256,7 +246,7 @@ ! testCompileStarAny - tree := PPCStarAnyNode new. + tree := PPCStarAnyNode new child: PPCNilNode new; yourself. parser := self compileTree: tree. self assert: parser parse: 'abc' to: #($a $b $c). @@ -265,34 +255,36 @@ ! testCompileStarCharSetPredicate - tree := PPCStarCharSetPredicateNode new - predicate: (PPCharSetPredicate on: [:e | e = $a ]); - yourself. - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'aaa1' to: #( $a $a $a) end: 3. - self assert: context invocationCount = 2. - self assert: parser parse: 'bba' to: #() end: 0. - self assert: context invocationCount = 2. - - "Modified: / 06-11-2014 / 00:48:55 / Jan Vrany " + tree := PPCStarCharSetPredicateNode new + predicate: (PPCharSetPredicate on: [:e | e = $a ]); + "I have to put something here" + child: PPCNilNode new; + yourself. + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'aaa1' to: #( $a $a $a) end: 3. + self assert: context invocationCount = 2. + self assert: parser parse: 'bba' to: #() end: 0. + self assert: context invocationCount = 2. + ! testCompileStarMessagePredicate - tree := PPCStarMessagePredicateNode new - message: #isLetter; - yourself. - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'abc1' to: #( $a $b $c) end: 3. - self assert: context invocationCount = 2. - - self assert: parser parse: '123a' to: #() end: 0. - self assert: context invocationCount = 2. - - "Modified: / 06-11-2014 / 00:48:58 / Jan Vrany " + tree := PPCStarMessagePredicateNode new + message: #isLetter; + "I have to add something here" + child: PPCNilNode new; + yourself. + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'abc1' to: #( $a $b $c) end: 3. + self assert: context invocationCount = 2. + + self assert: parser parse: '123a' to: #() end: 0. + self assert: context invocationCount = 2. + ! testCompileSymbolAction @@ -353,21 +345,19 @@ ! testCompileTokenStarMessagePredicate - - tree := PPCTokenStarMessagePredicateNode new message: #isLetter. - parser := self compileTree: tree params: {#guards -> false}. - - self assert: parser class methodDictionary size = 2. - - self assert: parser parse: 'foo' to: parser. - self assert: context invocationCount = 2. - self assert: context lwRememberCount = 0. - self assert: context lwRestoreCount = 0. - self assert: context rememberCount = 0. - - self assert: parser parse: 'foo123' to: parser end: 3. - - "Modified: / 06-11-2014 / 00:49:01 / Jan Vrany " + + tree := PPCTokenStarMessagePredicateNode new message: #isLetter; child: PPCNilNode new; yourself. + parser := self compileTree: tree params: {#guards -> false}. + + self assert: parser class methodDictionary size = 2. + + self assert: parser parse: 'foo' to: parser. + self assert: context invocationCount = 2. + self assert: context lwRememberCount = 0. + self assert: context lwRestoreCount = 0. + self assert: context rememberCount = 0. + + self assert: parser parse: 'foo123' to: parser end: 3. ! ! !PPCNodeCompilingTest methodsFor:'tests - guard'! @@ -422,98 +412,84 @@ !PPCNodeCompilingTest methodsFor:'tests - inlining'! testInlineAny - tree := PPCSequenceNode new - children: { PPCInlineAnyNode new. $a asParser asCompilerNode }. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 3. - self assert: parser parse: '.a' to: #($. $a). - - "Modified: / 06-11-2014 / 01:12:25 / Jan Vrany " + tree := PPCSequenceNode new + children: { PPCInlineAnyNode new. $a asParser asCompilerNode }. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 3. + self assert: parser parse: '.a' to: #($. $a). ! testInlineCharSetPredicate - tree := PPCPlusNode new - child: (PPCInlineCharSetPredicateNode new - predicate: (PPCharSetPredicate on: [ :e | e = $a ]); - yourself); - yourself. - - parser := self compileTree: tree. + tree := PPCPlusNode new + child: (PPCInlineCharSetPredicateNode new + predicate: (PPCharSetPredicate on: [ :e | e = $a ]); + yourself); + yourself. + + parser := self compileTree: tree. - self assert: parser class methodDictionary size = 2. - self assert: parser parse: 'a' to: #($a). - self assert: parser fail: 'b'. - - "Modified: / 06-11-2014 / 01:12:29 / Jan Vrany " + self assert: parser class methodDictionary size = 2. + self assert: parser parse: 'a' to: #($a). + self assert: parser fail: 'b'. ! testInlineCharacter - tree := PPCSequenceNode new - children: { PPCInlineCharacterNode new character: $b . $a asParser asCompilerNode }. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 3. - self assert: parser parse: 'ba' to: #($b $a). - - "Modified: / 06-11-2014 / 01:12:32 / Jan Vrany " + tree := PPCSequenceNode new + children: { PPCInlineCharacterNode new character: $b . $a asParser asCompilerNode }. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 3. + self assert: parser parse: 'ba' to: #($b $a). ! testInlineLiteral - tree := PPCSequenceNode new - children: { PPCInlineLiteralNode new literal: 'foo'. $a asParser asCompilerNode }. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 3. - self assert: parser parse: 'fooa' to: #('foo' $a). - - "Modified: / 06-11-2014 / 01:12:34 / Jan Vrany " + tree := PPCSequenceNode new + children: { PPCInlineLiteralNode new literal: 'foo'. $a asParser asCompilerNode }. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 3. + self assert: parser parse: 'fooa' to: #('foo' $a). ! testInlineNil - tree := PPCSequenceNode new - children: { PPCInlineNilNode new . $a asParser asCompilerNode }. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 3. - self assert: parser parse: 'a' to: #(nil $a). - - "Modified: / 06-11-2014 / 01:12:37 / Jan Vrany " + tree := PPCSequenceNode new + children: { PPCInlineNilNode new . $a asParser asCompilerNode }. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 3. + self assert: parser parse: 'a' to: #(nil $a). ! testInlineNotLiteral - tree := PPCSequenceNode new - children: { PPCInlineNotLiteralNode new literal: 'foo'. $a asParser asCompilerNode }. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 3. - self assert: parser parse: 'a' to: #(nil $a). - - "Modified: / 06-11-2014 / 01:12:40 / Jan Vrany " + tree := PPCSequenceNode new + children: { PPCInlineNotLiteralNode new literal: 'foo'. $a asParser asCompilerNode }. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 3. + self assert: parser parse: 'a' to: #(nil $a). ! testInlinePluggable - "Sadly, on Smalltalk/X blocks cannot be inlined because - the VM does not provide enough information to map - it back to source code. Very bad indeed!!" - ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ - self skipIf: true description: 'Blocks cannot be inlined due to a lack of proper VM support'. - ]. + "Sadly, on Smalltalk/X blocks cannot be inlined because + the VM does not provide enough information to map + it back to source code. Very bad indeed!!" + ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ + self skipIf: true description: 'Blocks cannot be inlined due to a lack of proper VM support'. + ]. - tree := PPCSequenceNode new - children: { PPCInlinePluggableNode new block: [ :ctx | ctx next ]. $a asParser asCompilerNode }. - - parser := self compileTree: tree. - - self assert: parser class methodDictionary size = 3. - self assert: parser parse: 'ba' to: #($b $a). - - "Modified: / 06-11-2014 / 01:48:07 / Jan Vrany " + tree := PPCSequenceNode new + children: { PPCInlinePluggableNode new block: [ :ctx | ctx next ]. $a asParser asCompilerNode }. + + parser := self compileTree: tree. + + self assert: parser class methodDictionary size = 3. + self assert: parser parse: 'ba' to: #($b $a). ! ! !PPCNodeCompilingTest class methodsFor:'documentation'!