: each ( list quotation -- )
#! Push each element of a proper list in turn, and apply a
#! quotation to each element.
- #!
- #! In order to compile, the quotation must consume one more
- #! value than it produces.
over [
>r uncons r> tuck >r >r call r> r> each
] [
namestack, setting the 'stdio' variable therein, and execution the given
quotation.
+* Continuations
+
+A continuation is a quotation that restores execution to the point where
+it was captured. Continuations are captured using the callcc0 and
+callcc1 words in the 'continuations' vocabulary.
+
+The word names are abbreviations for 'call with current continuation';
+the 0 or 1 refers to the arity of the continuation.
+
+Consider the phrase 'call with current continuation':
+
+- 'call' -- it calls a quotation given as a parameter...
+- 'with' -- with a value on the stack....
+- 'current continuation' -- that is a quotation that can be called
+ to restore execution at the current point.
+
+A continuation can either have arity 0 or 1. This refers to the number
+of parameters the quotation transfers from the caller stack to the
+restored point.
+
+Three very simple examples:
+
+ [ call ] callcc0 "Hello world." print
+ ^
+ ------- captured continuation restores here.
+ ==> Hello world.
+
+ [ "my-c" set ] callcc0 "Hello world." print
+ ^
+ -------- captured continuation restores here.
+ ==> Hello world.
+
+ "my-c" get call
+ ==> Hello world.
+
+Continuations are an advanced feature and are used in the implementation
+of error handling, multi-tasking, co-routines, and generators.
+
+(This is for my editor. It can be removed.
+:tabSize=4:indentSize=4:noTabs=true:)
- command line parsing cleanup\r
- > 1 ( ) inside word def\r
\r
-- when* compilation\r
+- when* compilation in jvm\r
- compile word twice; no more 'cannot compile' error!\r
- doc comments in assoc, image, inferior\r
- styles - could use some cleanup\r
- list - trim down\r
-- move quadratic and simpson to contrib\r
-- init-assembler called twice\r
- compiler: drop literal peephole optimization\r
- compiling when*\r
- compiling unless*\r
- getenv/setenv: if literal arg, compile as a load/store\r
- inline words\r
\r
-[error] SideKick$BufferChangeHandler: We have cplusplus.xml (/home/slava/jEdit/modes/) but got event for DefaultInputHandler.java (/home/slava/jEdit/org/gjt/sp/jedit/gui/)\r
-[error] SideKick$BufferChangeHandler: We have cplusplus.xml (/home/slava/jEdit/modes/) but got event for DefaultInputHandler.java (/home/slava/jEdit/org/gjt/sp/jedit/gui/)\r
-\r
[error] AWT-EventQueue-0: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 98\r
[error] AWT-EventQueue-0: at org.gjt.sp.jedit.Buffer.getLineOfOffset(Buffer.java:882)\r
[error] AWT-EventQueue-0: at errorlist.DefaultErrorSource$DefaultError.getLineNumber(Unknown Source)\r
[error] AWT-EventQueue-0: at errorlist.DefaultErrorSource.getLineErrors(Unknown Source)\r
[error] AWT-EventQueue-0: at errorlist.ErrorOverview.paintComponent(Unknown Source)\r
\r
-[error] EditBus: Exception while sending message on EditBus:\r
-[error] EditBus: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 98\r
-[error] EditBus: at org.gjt.sp.jedit.Buffer.getLineOfOffset(Buffer.java:882)\r
-[error] EditBus: at errorlist.DefaultErrorSource$DefaultError.getLineNumber(Unknown Source)\r
-[error] EditBus: at errorlist.ErrorList$ErrorCellRenderer.getTreeCellRendererComponent(Unknown Source)\r
-[error] EditBus: at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2751)\r
-\r
-[error] EditBus: Exception while sending message on EditBus:\r
-[error] EditBus: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 98\r
-[error] EditBus: at org.gjt.sp.jedit.Buffer.getLineOfOffset(Buffer.java:882)\r
-[error] EditBus: at errorlist.DefaultErrorSource$DefaultError.getLineNumber(Unknown Source)\r
-[error] EditBus: at errorlist.ErrorList$ErrorCellRenderer.getTreeCellRendererComponent(Unknown Source)\r
-[error] EditBus: at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2751)\r
-[error] EditBus: at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:475)\r
-\r
- perhaps /i should work with all numbers\r
- profiler is inaccurate: wrong word on cs\r
- buffer change handler in sidekick is screwed\r
"Factor" "realname" set
"factorbot" "nick" set
"irc.freenode.net" 6667 <client> [
- [ "#factor" ] irc
+ [ "#concatenative" ] irc
] with-stream ;
"/library/sdl/sdl.factor"
"/library/sdl/sdl-video.factor"
"/library/sdl/sdl-event.factor"
+ "/library/sdl/sdl-gfx.factor"
+ "/library/sdl/hsv.factor"
] [
dup print
run-resource
--- /dev/null
+! Contains definition of the hsv>rgb word for converting
+! Hue/Saturation/Value color values to RGB.
+
+! This thing is GPL, hsv->rgb is a translation to Common Lisp of a
+! function found in color_sys.py in Python 2.3.0
+
+! Translated to Factor by Slava Pestov.
+
+IN: sdl
+USE: combinators
+USE: kernel
+USE: lists
+USE: math
+USE: namespaces
+USE: stack
+
+: f_ ( h s v i -- f ) >r transp >r 2dup r> 6 * r> - ;
+: p ( v s x -- v p x ) >r dupd neg succ * r> ;
+: q ( v s f -- q ) * neg succ * ;
+: t_ ( v s f -- t_ ) neg succ * neg succ * ;
+
+: mod-cond ( p list -- )
+ #! Call p mod q'th entry of the list of quotations, where
+ #! q is the length of the list. The value q remains on the
+ #! stack.
+ [ dupd length mod ] keep nth call ;
+
+: hsv>rgb ( h s v -- r g b )
+ pick 6 * >fixnum [
+ [ f_ t_ p swap ( v p t ) ]
+ [ f_ q p -rot ( q v p ) ]
+ [ f_ t_ p swapd ( p v t ) ]
+ [ f_ q p rot ( p q v ) ]
+ [ f_ t_ p transp ( t p v ) ]
+ [ f_ q p ( v p q ) ]
+ ] mod-cond ;
typedef unsigned char BYTE;
/* Memory heap size */
-#define DEFAULT_ARENA (5 * 1024 * 1024)
+#define DEFAULT_ARENA (64 * 1024 * 1024)
#define COMPILE_ZONE_SIZE (5 * 1024 * 1024)
#define STACK_SIZE 16384