diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 13 | ||||
-rw-r--r-- | src/interp/compiler.boot | 2 | ||||
-rw-r--r-- | src/interp/g-opt.boot | 35 | ||||
-rw-r--r-- | src/interp/nruncomp.boot | 6 |
4 files changed, 39 insertions, 17 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 9bf35886..aaa16ebf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,18 @@ 2011-12-07 Gabriel Dos Reis <gdr@cs.tamu.edu> + * interp/g-opt.boot (tranformIF!): New. + (optimize!): Likewise. Abstract from optimizeFunctionDef. + (optimize): New. + (optimizeFunctionDef): Use optimize!. + (simplifyVMForm): Do not call optIF2COND. + (optIF2COND): Remove. + * interp/compiler.boot (compHasFormat): Use optimize! in lieu of + simplifyVMForm. + * interp/nruncomp.boot (NRTencode): Use optimize. + (NRTsetVector4a): Likewise. + +2011-12-07 Gabriel Dos Reis <gdr@cs.tamu.edu> + * interp/g-opt.boot: %writeString, %writeNewline and %writeLine are side-effect full. (removeSeq!): Tidy. Skip side-effectfree statements. diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot index 14dd801c..959d3b84 100644 --- a/src/interp/compiler.boot +++ b/src/interp/compiler.boot @@ -1373,7 +1373,7 @@ compHasFormat(pred is ["has",olda,b],e) == mkList [MKQ op,mkList [mkTypeForm type for type in sig]]] b is ["Join",:l] or b is ["CATEGORY",.,:l] => ["AND",:[compHasFormat(["has",olda,c],e) for c in l]] - isCategoryForm(b,e) => ["HasCategory",a,simplifyVMForm mkTypeForm b] + isCategoryForm(b,e) => ["HasCategory",a,optimize! mkTypeForm b] stackAndThrow('"Second argument to %1b must be a category, or a signature or an attribute",["has"]) --% IF diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot index 1813d18e..0b972171 100644 --- a/src/interp/g-opt.boot +++ b/src/interp/g-opt.boot @@ -253,6 +253,27 @@ inlineLocals! x == walkWith!(x,function f) where x x +++ Transform an IF-expression into a tower of %when-form. +transformIF! x == walkWith!(x,function f) where + f x == + x is ['IF,p,s1,s2] => + s2 is '%noBranch => resetTo(x,['%when,[p,s1]]) + s1 is '%noBranch => resetTo(x,['%when,[['%not,p],s2]]) + s2 is ['%when,:.] => resetTo(x,['%when,[p,s1],:s2.args]) + resetTo(x,['%when,[p,s1],['%otherwise,s2]]) + x + +++ Transform an intermediate form (output of the elaborator) to +++ a lower intermediate form, applying several transformations +++ generaly intended to improve quality and efficiency. +optimize! x == + simplifyVMForm transformIF! removeSeq! inlineLocals! + groupTranscients! reduceXLAM! x + +++ A non-mutating version of `optimize!'. +optimize x == + optimize! copyTree x + optimizeFunctionDef(def) == if $reportOptimization then sayBrightlyI bright '"Original LISP code:" @@ -260,8 +281,7 @@ optimizeFunctionDef(def) == expr := copyTree second def changeVariableDefinitionToStore(expr.absBody,expr.absParms) - expr := simplifyVMForm removeSeq! inlineLocals! - groupTranscients! reduceXLAM! expr + expr := optimize! expr if $reportOptimization then sayBrightlyI bright '"Intermediate VM code:" @@ -302,8 +322,6 @@ simplifyVMForm x == symbol? x.op and abstractionOperator? x.op => x.absBody := groupVariableDefinitions simplifyVMForm x.absBody x - if x.op is 'IF then - resetTo(x,optIF2COND x) for args in tails x.args repeat args.first := simplifyVMForm first args opt := subrname x.op has OPTIMIZE => resetTo(x,FUNCALL(opt,x)) @@ -491,15 +509,6 @@ EqualBarGensym(x,y) == x isnt [.,:.] or y isnt [.,:.] => false fn(first x,first y) and fn(rest x,rest y) ---Called early, to change IF to conditional form - -optIF2COND ["IF",a,b,c] == - b is "%noBranch" => ['%when,[['%not,a],c]] - c is "%noBranch" => ['%when,[a,b]] - c is ["IF",:.] => ['%when,[a,b],:rest optIF2COND c] - c is ['%when,:p] => ['%when,[a,b],:p] - ['%when,[a,b],['%otherwise,c]] - ++ Determine whether the symbol `g' is the name of a temporary that ++ can be replaced in the form `x', if it is of linear usage and not ++ the name of a program point. The latter occurs when %leave forms diff --git a/src/interp/nruncomp.boot b/src/interp/nruncomp.boot index cb78812a..852e5729 100644 --- a/src/interp/nruncomp.boot +++ b/src/interp/nruncomp.boot @@ -114,14 +114,14 @@ NRTencode(db,x,y) == encode(db,x,y,true) where encode(db,x,compForm,firstTime) = [op,:[encode(db,y,z,false) for y in x.args for z in compForm.args]] -- enumeration constants are like field names, they do not need -- to be encoded. - ['%eval,NRTreplaceAllLocalReferences(db,copyTree simplifyVMForm compForm)] + ['%eval,NRTreplaceAllLocalReferences(db,optimize compForm)] symbolMember?(x,$formalArgList) => v := $FormalMapVariableList.(symbolPosition(x,$formalArgList)) firstTime => ["local",v] v x is "$$" => x compForm is [.,:.] => - ['%eval,NRTreplaceAllLocalReferences(db,copyTree simplifyVMForm compForm)] + ['%eval,NRTreplaceAllLocalReferences(db,optimize compForm)] quote compForm --------------FUNCTIONS CALLED DURING CAPSULE FUNCTION COMPILATION------------- @@ -550,7 +550,7 @@ reverseCondlist cl == NRTsetVector4a(sig,form,cond) == sig is '$ => domainList := - [simplifyVMForm COPY comp(d,$EmptyMode,$e).expr or d + [optimize comp(d,$EmptyMode,$e).expr or d for d in categoryPrincipals $domainShell] $uncondList := append(domainList,$uncondList) if isCategoryForm(form,$e) then $uncondList := [form,:$uncondList] |