]> gitweb.factorcode.org Git - factor.git/commitdiff
HSV>RGB color conversion, much other stuff
authorSlava Pestov <slava@factorcode.org>
Tue, 12 Oct 2004 01:40:12 +0000 (01:40 +0000)
committerSlava Pestov <slava@factorcode.org>
Tue, 12 Oct 2004 01:40:12 +0000 (01:40 +0000)
README.txt
TODO.FACTOR.txt
contrib/irc.factor
library/platform/native/boot-stage2.factor
library/sdl/hsv.factor [new file with mode: 0644]
native/factor.h

index 5f484065823ee554ed39dc5c9f063255d504df7d..39ed48d2f89673a8e6de2f8297ff15a54a15869b 100644 (file)
@@ -103,9 +103,6 @@ a list. Note that it uses 'call' to execute the given quotation:
 : 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
     ] [
@@ -223,3 +220,43 @@ The 'with-stream' word is implemented by pushing a new namespace on the
 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:)
index 1a7836886c94ed6d32e2b7f93fe441e78805ab83..734dfe27ad7b0971095edd11b2212d5cfdb3ec64 100644 (file)
@@ -4,43 +4,23 @@ FFI:
 - 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
index 255784b150e658a5c6bbccdc9c5ddee09d10cd96..e680f196f6058238c54b9ae489cba229d4213981 100644 (file)
@@ -148,5 +148,5 @@ USE: unparser
     "Factor" "realname" set
     "factorbot" "nick" set
     "irc.freenode.net" 6667 <client> [
-        [ "#factor" ] irc
+        [ "#concatenative" ] irc
     ] with-stream ;
index 8f2f7cb952c8950b844a87a72431ed0fb63b4b49..c6dd71fbe3963486197a79fdb63906d375ae3379 100644 (file)
@@ -160,6 +160,8 @@ cpu "x86" = [
         "/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
diff --git a/library/sdl/hsv.factor b/library/sdl/hsv.factor
new file mode 100644 (file)
index 0000000..9b03b84
--- /dev/null
@@ -0,0 +1,36 @@
+! 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 ;
index 9472616a4b583c6c7702ede97d6ef839ea390195..aa8525b5f9a25a0068c23791ffd189cea918b1b2 100644 (file)
@@ -45,7 +45,7 @@ typedef unsigned short CHAR;
 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