compiler/PPCGuard.st
changeset 464 f6d77fee9811
parent 459 4751c407bb40
child 515 b5316ef15274
equal deleted inserted replaced
459:4751c407bb40 464:f6d77fee9811
     4 
     4 
     5 Object subclass:#PPCGuard
     5 Object subclass:#PPCGuard
     6 	instanceVariableNames:'classification id message'
     6 	instanceVariableNames:'classification id message'
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Core'
     9 	category:'PetitCompiler-Guards'
    10 !
    10 !
    11 
    11 
    12 !PPCGuard class methodsFor:'as yet unclassified'!
    12 !PPCGuard class methodsFor:'as yet unclassified'!
    13 
    13 
    14 on: aPPCNode
    14 on: aPPCNode
    15     ^ self new
    15     ^ self new
    16         initializeFor: aPPCNode;
    16         initializeFor: aPPCNode;
       
    17         yourself
       
    18 !
       
    19 
       
    20 on: aPPCNode id: id
       
    21     ^ self new
       
    22         initializeFor: aPPCNode;
       
    23         id: id;
    17         yourself
    24         yourself
    18 ! !
    25 ! !
    19 
    26 
    20 !PPCGuard methodsFor:'accessing'!
    27 !PPCGuard methodsFor:'accessing'!
    21 
    28 
    60 compileCharacter: compiler
    67 compileCharacter: compiler
    61     self assert: (classification select: [ :e | e ]) size = 1.
    68     self assert: (classification select: [ :e | e ]) size = 1.
    62     
    69     
    63     classification keysAndValuesDo: [ :index :value | value ifTrue: [  
    70     classification keysAndValuesDo: [ :index :value | value ifTrue: [  
    64         (index > 32 and: [ index < 127 ]) ifTrue: [ 
    71         (index > 32 and: [ index < 127 ]) ifTrue: [ 
    65             compiler add: '(context peek = ', (Character value: index) storeString, ')'
    72             compiler add: '(context peek == ', (Character value: index) storeString, ')'
    66         ] ifFalse: [ 
    73         ] ifFalse: [ 
    67             id := compiler idFor: (Character value: index) prefixed: #character.
    74             id := compiler idFor: (Character value: index) prefixed: #character.
    68             compiler addConstant: (Character value: index) as: id.
    75             compiler addConstant: (Character value: index) as: id.
    69             compiler add: '(context peek = ', id, ')'.
    76             compiler add: '(context peek = ', id, ')'.
    70      		] 
    77      		] 
   110 
   117 
   111 compileGuard: compiler
   118 compileGuard: compiler
   112     self assert: self makesSense description: 'No Guard could be compiled'.
   119     self assert: self makesSense description: 'No Guard could be compiled'.
   113     self assert: id notNil.
   120     self assert: id notNil.
   114     
   121     
   115     
       
   116     self message ifNotNil: [ ^ self compileMessage: compiler ].
   122     self message ifNotNil: [ ^ self compileMessage: compiler ].
   117     self testAny ifTrue: [ ^ self compileAny: compiler ].
   123     self testAny ifTrue: [ ^ self compileAny: compiler ].
   118     self testSingleCharacter ifTrue: [ ^ self compileCharacter: compiler ].
   124     self testSingleCharacter ifTrue: [ ^ self compileCharacter: compiler ].
   119     
   125     
   120     ^ self compileArray: compiler
   126     ^ self compileArray: compiler