]> gitweb.factorcode.org Git - factor.git/commitdiff
continuations: faster with-datastack
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 3 Apr 2010 23:10:21 +0000 (19:10 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 3 Apr 2010 23:10:21 +0000 (19:10 -0400)
core/continuations/continuations-docs.factor
core/continuations/continuations.factor

index 371068026943a05f1125930c53841a2d169550bc..8775e599a6cdc19f207a911beeac9e04353c27be 100644 (file)
@@ -235,7 +235,7 @@ HELP: save-error
 $low-level-note ;
 
 HELP: with-datastack
-{ $values { "stack" sequence } { "quot" quotation } { "newstack" sequence } }
+{ $values { "stack" sequence } { "quot" quotation } { "new-stack" sequence } }
 { $description "Executes the quotation with the given data stack contents, and outputs the new data stack after the word returns. The input sequence is not modified; a new sequence is produced. Does not affect the data stack in surrounding code, other than consuming the two inputs and pushing the output." }
 { $examples
     { $example "USING: continuations math prettyprint ;" "{ 3 7 } [ + ] with-datastack ." "{ 10 }" }
index cfceb1f71574ba1e3e69a2ef4fc8ecea9df6738e..196a12d0d2765fce3f71222683dd72a2bef0382c 100644 (file)
@@ -1,10 +1,17 @@
-! Copyright (C) 2003, 2009 Slava Pestov.
+! Copyright (C) 2003, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays vectors kernel kernel.private sequences
 namespaces make math splitting sorting quotations assocs
 combinators combinators.private accessors words ;
 IN: continuations
 
+: with-datastack ( stack quot -- new-stack )
+    [
+        [ [ datastack ] dip swap [ { } like set-datastack ] dip ] dip
+        swap [ call datastack ] dip
+        swap [ set-datastack ] dip
+    ] (( stack quot -- new-stack )) call-effect-unsafe ;
+
 SYMBOL: error
 SYMBOL: error-continuation
 SYMBOL: error-thread
@@ -90,14 +97,6 @@ SYMBOL: return-continuation
 : return ( -- * )
     return-continuation get continue ;
 
-: with-datastack ( stack quot -- newstack )
-    [
-        [
-            [ [ { } like set-datastack ] dip call datastack ] dip
-            continue-with
-        ] (( stack quot continuation -- * )) call-effect-unsafe
-    ] callcc1 2nip ;
-
 GENERIC: compute-restarts ( error -- seq )
 
 <PRIVATE