" I am CodeGen suited for the needs of standard (universal) code generator. " Class { #name : 'PPCUniversalCodeGen', #superclass : 'PPCCodeGen', #category : 'PetitCompiler-Compiler-Codegen' } { #category : 'memoization' } PPCUniversalCodeGen >> remember: node to: variableName [ self memoizationStrategy remember: node to: variableName. "options analyzeContext ifFalse: [ self codeAssign: 'context remember.' to: variableName. ^ self ]. (node changesContext) ifFalse: [ self codeAssign: 'context lwRemember.' to: variableName. ] ifTrue: [ node isIndentPush ifTrue: [ self codeAssign: 'context lwRemember.' to: variableName. ] ifFalse: [ (node isSequenceNode and: [node children allButLast noneSatisfy: [:e | e changesContext ]]) ifTrue: [ ""it is only the last child that changes context..."" self codeAssign: 'context lwRemember.' to: variableName. ] ifFalse: [ self codeAssign: 'context remember.' to: variableName. ]. ] ] " ] { #category : 'memoization' } PPCUniversalCodeGen >> restore: node from: variableName [ ^ self memoizationStrategy restore: node from: variableName. " self flag: 'JK: refactor!'. options analyzeContext ifFalse: [ self code: 'context restore: ', mementoName, '.'. ^ self ]. node changesContext ifFalse: [ self code: 'context lwRestore: ', mementoName, '.'. ] ifTrue: [ node isIndentPush ifTrue: [ self assert: node isSequenceNode not. self code: 'context lwRestore: ', mementoName, '.'. self code: 'context indentStack pop.'. ] ifFalse: [ self code: 'context restore: ', mementoName, '.'. ] ] " ] { #category : 'memoization' } PPCUniversalCodeGen >> restoreSequence: node child: child from: variableName [ self assert: node isSequenceNode. self memoizationStrategy restoreSequenceNode: node child: child from: variableName " self flag: 'JK: refactor'. options analyzeContext ifFalse: [ self code: 'context restore: ', mementoName, '.'. ^ self ]. node changesContext ifFalse: [ self restore: node from: mementoName ] ifTrue: [ node isIndentPush ifTrue: [ | push | self code: 'context lwRestore: ', mementoName, '.'. push := (node children detect: [:e | e isIndentPush]). (node children indexOf: child) > (node children indexOf: push) ifTrue: [ self code: 'context indentStack pop.'. ] ] ifFalse: [ (node children allButLast noneSatisfy: [:e | e changesContext ]) ifTrue: [ ""it is only the last child that changes context..."" self code: 'context lwRestore: ', mementoName, '.'. ] ifFalse: [ self restore: node from: mementoName ] ] ] " ]