diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/interp/compiler.boot | 9 | ||||
-rw-r--r-- | src/interp/g-opt.boot | 6 | ||||
-rw-r--r-- | src/interp/lisp-backend.boot | 8 |
4 files changed, 20 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index fd8f184a..126537fa 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2011-12-16 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * interp/compiler.boot (finishListCollect): New. + (compRepeatOrCollect): Use it. + * interp/g-opt.boot (optCollectVector): Likewise. + * interp/lisp-backend.boot (expandCollect): Likewise. + 2011-12-15 Gabriel Dos Reis <gdr@cs.tamu.edu> * interp/g-util.boot (prefixWalk!): New. diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot index a6c3cf02..c4428079 100644 --- a/src/interp/compiler.boot +++ b/src/interp/compiler.boot @@ -2392,6 +2392,13 @@ processInlineRequest(t,e) == --% ITERATORS --% +finishListCollect(iters,body) == + val := gensym() -- result of the list comprehension + -- Transform the body to build the list as we go. + body := ['%store,val,['%pair,body,val]] + -- Don't forget we built the result in reverse order. + ['%repeat,:iters,['%init,val,'%nil],body,['%lreverse!,val]] + compReduce(form,m,e) == compReduce1(form,m,e,$formalArgList) @@ -2495,7 +2502,7 @@ compRepeatOrCollect(form,m,e) == $loopKind = "%CollectV" => ["%CollectV",localReferenceIfThere(m',e'),:itl',body'] -- We are phasing out use of LISP macros COLLECT and REPEAT. - $loopKind = "COLLECT" => ['%collect,:itl',body'] + $loopKind = "COLLECT" => finishListCollect(itl',body') ['%repeat,:itl',body','%nil] m'' := aggr is [c,.] and c in '(List PrimitiveArray Vector) => [c,m'] diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot index 2dc0dd72..c93204bc 100644 --- a/src/interp/g-opt.boot +++ b/src/interp/g-opt.boot @@ -433,7 +433,8 @@ subrname u == nil changeLeaveToExit(s,g) == - s isnt [.,:.] or s.op in '(QUOTE %seq REPEAT COLLECT %collect %repeat) => nil + atomic? s => nil + s.op in '(QUOTE %seq REPEAT COLLECT %collect %repeat) => nil s is ['%leave, =g,:u] => (s.first := '%exit; s.rest := u) changeLeaveToExit(first s,g) changeLeaveToExit(rest s,g) @@ -789,7 +790,8 @@ optCollectVector form == systemErrorHere ["optCollectVector", iter] -- if we draw from a list, then just build a list and convert to vector. fromList => - ["homogeneousListToVector",["getVMType",eltType], ['%collect,:iters,body]] + ["homogeneousListToVector",["getVMType",eltType], + finishListCollect(iters,body)] vecSize = nil => systemErrorHere ["optCollectVector",form] -- get the actual size of the vector. vecSize := diff --git a/src/interp/lisp-backend.boot b/src/interp/lisp-backend.boot index d5581dfe..f5fcf28f 100644 --- a/src/interp/lisp-backend.boot +++ b/src/interp/lisp-backend.boot @@ -176,13 +176,7 @@ expandRepeat ['%repeat,:iters,body,ret] == ++ Generate code for list comprehension. expandCollect ['%collect,:iters,body] == - val := gensym() -- result of the list comprehension - -- Transform the body to build the list as we go. - body := ['%store,val,['%pair,body,val]] - -- Initialize the variable holding the result; expand as - -- if ordinary loop. But don't forget we built the result - -- in reverse order. - expandRepeat ['%repeat,:iters,["%init",val,nil],body,['%lreverse!,val]] + expandRepeat finishListCollect(iters,body) expandList(x is ['%list,:args]) == args := [expandToVMForm arg for arg in args] |