compiler/tests/PPCCodeGeneratorTest.st
changeset 503 ff58cd9f1f3c
parent 491 82b272c7dc37
parent 502 1e45d3c96ec5
child 504 0fb1f0799fc1
equal deleted inserted replaced
501:e29bd90f388e 503:ff58cd9f1f3c
   435     self assert: parser fail: ''.
   435     self assert: parser fail: ''.
   436 !
   436 !
   437 
   437 
   438 testInlinePluggableNode
   438 testInlinePluggableNode
   439    "Sadly, on Smalltalk/X blocks cannot be inlined because
   439    "Sadly, on Smalltalk/X blocks cannot be inlined because
   440 		 the VM does not provide enough information to map
   440 				 the VM does not provide enough information to map
   441 		 it back to source code. Very bad indeed!!"          
   441 				 it back to source code. Very bad indeed!!"          
   442 		((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
   442 				((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
   443 			self skipIf: true description: 'Blocks cannot be inlined due to a lack of proper VM support'.
   443 						self skipIf: true description: 'Blocks cannot be inlined due to a lack of proper VM support'.
   444 		].
   444 				].
   445 
   445 
   446 		node := PPCSequenceNode new
   446 				node := PPCSequenceNode new
   447 				children: { 
   447 								children: { 
   448 						PPCPluggableNode new block: [ :ctx | ctx next ]; markForInline; yourself. 
   448 												PPCPluggableNode new block: [ :ctx | ctx next ]; markForInline; yourself. 
   449 						$a asParser asCompilerNode }.
   449 												$a asParser asCompilerNode }.
   450 		
   450 				
   451 		self compileTree: node.
   451 				self compileTree: node.
   452 		
   452 				
   453 		self assert: parser class methodDictionary size = 2.
   453 				self assert: parser class methodDictionary size = 2.
   454 		self assert: parser parse: 'ba' to: #($b $a).
   454 				self assert: parser parse: 'ba' to: #($b $a).
   455 !
   455 !
   456 
   456 
   457 testLiteralNode
   457 testLiteralNode
   458     node := PPCLiteralNode new
   458     node := PPCLiteralNode new
   459         literal: 'foo';
   459         literal: 'foo';
   915     self assert: parser parse: 'a' to: #( $a nil ) end: 1.
   915     self assert: parser parse: 'a' to: #( $a nil ) end: 1.
   916 
   916 
   917     "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   917     "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   918 !
   918 !
   919 
   919 
       
   920 testSequenceOptInlined1
       
   921     | a b bOpt |
       
   922 
       
   923     a := $a asParser asCompilerNode.
       
   924     b := $b asParser asCompilerNode.
       
   925     bOpt := PPCOptionalNode new
       
   926                 child:  b ;
       
   927                 markForInline;
       
   928                 yourself.
       
   929     node := PPCSequenceNode new
       
   930         children: { a . bOpt };
       
   931         yourself.
       
   932     self compileTree: node.
       
   933     
       
   934     self assert: parser parse: 'ab' to: #($a $b ) end: 2.
       
   935     self assert: parser parse: 'a' to: #( $a nil ) end: 1.
       
   936 
       
   937     "Created: / 22-05-2015 / 11:47:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   938 !
       
   939 
       
   940 testSequenceOptInlined2
       
   941     | a b bOpt |
       
   942 
       
   943     a := $a asParser asCompilerNode.
       
   944     a markForInline.
       
   945     b := $b asParser asCompilerNode.
       
   946     b markForInline.
       
   947     bOpt := PPCOptionalNode new
       
   948                 child:  b ;
       
   949                 markForInline;
       
   950                 yourself.
       
   951     node := PPCSequenceNode new
       
   952         children: { a . bOpt };
       
   953         yourself.
       
   954     self compileTree: node.
       
   955     
       
   956     self assert: parser parse: 'ab' to: #($a $b ) end: 2.
       
   957     self assert: parser parse: 'a' to: #( $a nil ) end: 1.
       
   958 
       
   959     "Created: / 22-05-2015 / 11:47:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   960 !
       
   961 
   920 testStarAnyNode
   962 testStarAnyNode
   921     arguments cacheFirstFollow: false.
   963     arguments cacheFirstFollow: false.
   922     node := PPCStarAnyNode new 
   964     node := PPCStarAnyNode new 
   923         child: PPCNilNode new; 
   965         child: PPCNilNode new; 
   924         yourself.
   966         yourself.