]> gitweb.factorcode.org Git - factor.git/commitdiff
a few bug fixes
authorSlava Pestov <slava@factorcode.org>
Thu, 28 Oct 2004 03:13:00 +0000 (03:13 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 28 Oct 2004 03:13:00 +0000 (03:13 +0000)
TODO.FACTOR.txt
contrib/dejong.factor [new file with mode: 0644]
factor/jedit/FactorPlugin.java
library/image.factor
library/inferior.factor
library/platform/native/parse-syntax.factor
library/platform/native/parser.factor
library/platform/native/words.factor
library/test/parser.factor
library/test/parsing-word.factor
library/test/test.factor

index 4cf6d494ab5f5e165bfbdcfe23d4e3c28d8150b1..73ef6a0d0c4f487866dc2c3af0580197971d573f 100644 (file)
@@ -1,5 +1,13 @@
 FFI:\r
 \r
+- wordpreview: don't show for string literals and comments\r
+- listener: use console shell api\r
+- add a socket timeout\r
+- fix error postoning -- not all errors thrown by i/o code are\r
+  postponed\r
+- file responder: don't show full path in title\r
+- quit responder breaks with multithreading\r
+\r
 + compiler/ffi:\r
 \r
 - is signed -vs- unsigned pointers an issue?\r
@@ -37,15 +45,12 @@ FFI:
 - clean up listener's action popups\r
 - accept multi-line input in listener\r
 - don't show listener on certain commands\r
-- wordpreview: don't show for string literals and comments\r
 - NPE in ErrorHighlight\r
 - some way to not have previous definitions from a source file\r
   clutter the namespace\r
 - use inferior.factor for everything not just listener\r
 - fedit broken with listener\r
 - maple-like: press enter at old commands to evaluate there\r
-- input style after clicking link\r
-- listener backspace overzealous\r
 - completion in the listener\r
 - special completion for USE:/IN:\r
 - inspector links when describe called without object path\r
@@ -54,12 +59,7 @@ FFI:
 \r
 - profiler is inaccurate: wrong word on cs\r
 - better i/o scheduler\r
-- move some s48_ functions into bignum.c\r
-- remove unused functions\r
 - >lower, >upper for strings\r
-- add a socket timeout\r
-- fix error postoning -- not all errors thrown by i/o code are\r
-  postponed\r
 - don't rehash strings on every startup\r
 \r
 + misc:\r
@@ -67,23 +67,17 @@ FFI:
 - jedit ==> jedit-word, jedit takes a file name\r
 - 'cascading' styles\r
 - command line parsing cleanup\r
-- > 1 ( ) inside word def\r
-- parsing-word test fails\r
-- doc comments in image, inferior\r
-- eval with multilien strings and #!\r
 - nicer way to combine two paths\r
 - alist -vs- assoc terminology\r
 \r
 + httpd:\r
 \r
-- file responder: don't show full path in title\r
 - wiki responder:\r
   - port to native\r
   - text styles\r
 - log with date\r
  basic authentication, using httpdAuth function from a config file\r
 - file responder; last-modified field\r
-- quit responder breaks with multithreading\r
 \r
 + java factor is going away:\r
 \r
diff --git a/contrib/dejong.factor b/contrib/dejong.factor
new file mode 100644 (file)
index 0000000..abe827d
--- /dev/null
@@ -0,0 +1,66 @@
+! DeJong attractor renderer.
+! To run this code, start your interpreter like so:
+!
+! ./f -library:sdl=libSDL.so -library:sdl-gfx=libSDL_gfx.so
+!
+! Then, enter this at the interpreter prompt:
+!
+! "contrib/dejong.factor" run-file
+
+! For details on DeJong attractors, see
+! http://www.complexification.net/gallery/machines/peterdejong/
+
+IN: dejong
+
+USE: sdl
+USE: namespaces
+USE: math
+USE: stack
+
+SYMBOL: a
+SYMBOL: b
+SYMBOL: c
+SYMBOL: d
+SYMBOL: width
+SYMBOL: height
+
+: next-x ( x y -- x ) a get * sin swap b get * cos - ;
+: next-y ( x y -- y ) swap c get * sin swap d get * cos - ;
+
+: white ( -- rgb )
+    HEX: ffffffff ;
+
+: pixel ( #{ x y } color -- )
+    >r >r surface get r> >rect r> pixelColor ;
+
+: iterate-dejong ( x y -- x y )
+    2dup next-y >r next-x r> ;
+
+: scale-dejong ( x y -- x y )
+    swap width get 4 / * width get 2 / + >fixnum
+    swap height get 4 / * height get 2 / + >fixnum ;
+
+: draw-dejong ( x0 y0 iterations -- )
+    [
+        iterate-dejong 2dup scale-dejong rect> white pixel
+    ] times 2drop ;
+
+: dejong ( -- )
+    ! Fiddle with these four values!
+    1.4 a set
+    -2.3 b set
+    2.4 c set
+    -2.1 d set
+
+    640 dup width set
+    480 dup height set
+    32 SDL_HWSURFACE SDL_SetVideoMode drop
+
+    [
+        0 0 100000 draw-dejong
+    ] with-surface
+
+    <event> event-loop
+    SDL_Quit ;
+
+dejong
index ecfdf83c32407053534919027f9c1a2603a904ba..d6a173a089219e3b37b0bb47838e935267b7192d 100644 (file)
@@ -313,7 +313,7 @@ public class FactorPlugin extends EditPlugin
 
                Buffer buffer = view.getBuffer();
                int lastUseOffset = 0;
-               boolean trailingNewline = false;
+               boolean leadingNewline = false;
 
                for(int i = 0; i < buffer.getLineCount(); i++)
                {
@@ -321,26 +321,29 @@ public class FactorPlugin extends EditPlugin
                        if(text.startsWith("IN:") || text.startsWith("USE:"))
                        {
                                lastUseOffset = buffer.getLineEndOffset(i) - 1;
+                               leadingNewline = true;
                        }
-                       else if(text.startsWith("!") || text.length() == 0)
+                       else if(text.startsWith("!"))
+                       {
+                               lastUseOffset = buffer.getLineEndOffset(i) - 1;
+                               leadingNewline = true;
+                       }
+                       else if(text.length() == 0)
                        {
                                if(i == 0)
                                        lastUseOffset = 0;
                                else
-                                       lastUseOffset = buffer.getLineEndOffset(i-1) - 1;
+                                       lastUseOffset  = buffer.getLineEndOffset(i - 1) - 1;
                        }
                        else
                        {
-                               trailingNewline = true;
                                break;
                        }
                }
 
                String decl = "USE: " + vocab;
-               if(lastUseOffset != 0)
+               if(leadingNewline)
                        decl = "\n" + decl;
-               if(trailingNewline)
-                       decl = decl + "\n";
                buffer.insert(lastUseOffset,decl);
                showStatus(view,"inserted-use",decl);
        } //}}}
@@ -377,6 +380,9 @@ public class FactorPlugin extends EditPlugin
                        return;
 
                int start = asset.start.getOffset();
+               /* Hack */
+               start = buffer.getLineStartOffset(
+                       buffer.getLineOfOffset(start));
 
                String indent = MiscUtilities.createWhiteSpace(
                        buffer.getIndentSize(),
@@ -386,7 +392,16 @@ public class FactorPlugin extends EditPlugin
                String newDef = ": " + newWord + "\n" + indent
                        + selection.trim() + " ;\n\n" ;
 
-               buffer.insert(start,newDef);
-               textArea.setSelectedText(newWord);
+               try
+               {
+                       buffer.beginCompoundEdit();
+                       
+                       buffer.insert(start,newDef);
+                       textArea.setSelectedText(newWord);
+               }
+               finally
+               {
+                       buffer.endCompoundEdit();
+               }
        } //}}}
 }
index c12e5f797f7212d745884cbc8dc41c35c60351c3..9f91b866b48cdbb2dcc9deb392dae9c38f40beb7 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+! This library allows one to generate a new set of bootstrap
+! images (boot.image.{le32,le64,be32,be64}.
+!
+! It does this by parsing the set of source files needed to
+! generate the minimal image, and writing the cons cells, words,
+! strings etc to the image file in the CFactor object memory
+! format.
+!
+! What is a bootstrap image? It basically contains enough code
+! to parse a source file. See platform/native/boot.factor --
+! It initializes the core interpreter services, and proceeds to
+! run platform/native/boot-stage2.factor.
+
 IN: namespaces
 
 ( Java Factor doesn't have this )
index 7f8f3b073c0ab61be2ba6950d3775fc9c69abf15..0549d98381bf24db83f340d50b80cf7856aa0908 100644 (file)
@@ -41,6 +41,21 @@ USE: streams
 USE: strings
 USE: styles
 
+! The purpose of this library is to allow CFactor to be embedded
+! inside the Java Factor listener in jEdit.
+!
+! Eg, in Java Factor, you could evaluate this after fixing the
+! paths accordingly:
+!
+! : (inf
+!     [
+!         "/home/slava/Factor/f"
+!         "/home/slava/Factor/factor.image"
+!         "-no-ansi"
+!     ] pipe inferior-client ;
+!
+! Details:
+!
 ! Packets have the following form:
 ! 1 byte -- type. CHAR: w: write, CHAR: r: read
 ! 4 bytes -- for write only -- length of write request
index 279b90f521b1483a37735c142e20d20faffb3a2f..b828507d84905876dc0073c6872c35b116f57fd1 100644 (file)
@@ -45,12 +45,10 @@ USE: unparser
 : CREATE ( -- word )
     scan "in" get create dup set-word
     dup f "documentation" set-word-property
-    dup f "stack-effect" set-word-property ;
-
-: remember-where ( word -- )
+    dup f "stack-effect" set-word-property
     dup "line-number" get "line" set-word-property
     dup "col"         get "col"  set-word-property
-        "file"        get "file" set-word-property ;
+    dup "file"        get "file" set-word-property ;
 
 ! \x
 : unicode-escape>ch ( -- esc )
@@ -91,7 +89,11 @@ USE: unparser
 
 : parsed-stack-effect ( parsed str -- parsed )
     over doc-comment-here? [
-        word swap "stack-effect" set-word-property
+        word stack-effect [
+            drop
+        ] [
+            word swap "stack-effect" set-word-property
+        ] ifte
     ] [
         drop
     ] ifte ;
@@ -137,17 +139,14 @@ IN: syntax
 
 : :
     #! Begin a word definition. Word name follows.
-    CREATE dup remember-where [ ]
-    "in-definition" on ; parsing
+    CREATE [ ] "in-definition" on ; parsing
 
 : ;-hook ( word def -- )
     ";-hook" get [ call ] [ define-compound ] ifte* ;
 
 : ;
     #! End a word definition.
-    "in-definition" off
-    reverse
-    ;-hook ; parsing
+    "in-definition" off reverse ;-hook ; parsing
 
 ! Symbols
 : SYMBOL: CREATE define-symbol ; parsing
index 6f0f61d8140cc5b0dad78371edcd7f3c3bfcb3eb..ccdf59df0d0fd776a6c6684123c8f5ed224f9a9a 100644 (file)
@@ -173,8 +173,14 @@ USE: unparser
 : until ( ch -- str )
     ch-search (until) ;
 
+: (until-eol) ( -- index ) 
+    "\n" ch-search dup -1 = [ drop "line" get str-length ] when ;
+
 : until-eol ( -- str )
-    "line" get str-length (until) ;
+    #! This is just a hack to get "eval" to work with multiline
+    #! strings from jEdit with EOL comments. Normally, input to
+    #! the parser is already line-tokenized.
+    (until-eol) (until) ;
 
 : next-ch ( -- ch )
     end? [ "Unexpected EOF" throw ] [ ch advance ] ifte ;
index 097d4dd4c0b861d16a7c6930e9b9fe42ced89350..3d43070c11fbe8e7ba08e6c1780cebf4e43877ae 100644 (file)
@@ -59,8 +59,8 @@ USE: stack
 
 : define-compound ( word def -- )
     over set-word-parameter
-    ( dup f "parsing" set-word-property )
-    1 swap set-word-primitive ;
+    1 over set-word-primitive
+    f "parsing" set-word-property ;
 
 : define-symbol ( word -- )
     dup dup set-word-parameter
index 72e564cf2cfe9169b10d4253575f6e0ea45d6947..c0f253d8022fc0709e3b229f0701fd1df13bf535 100644 (file)
@@ -57,3 +57,6 @@ test-word
 [ 2 ] [ "[ 1 | 2 ]" parse car cdr ] unit-test
 [ "hello" ] [ "[ 1 | \"hello\" ]" parse car cdr ] unit-test
 [ #{ 1 2 } ] [ "[ 1 | #{ 1 2 } ]" parse car cdr ] unit-test
+
+! Test EOL comments in multiline strings.
+[ [ "Hello" ] ] [ "#! This calls until-eol.\n\"Hello\"" parse ] unit-test 
index 3f68d7960fdd56498d6ce13df1cdef66e22b4f90..bbb18356e562aa39b3ad447e3db3a9c70b04922e 100644 (file)
@@ -2,6 +2,9 @@ IN: scratchpad
 
 USE: parser
 USE: test
+USE: stack
+USE: words
+USE: strings
 
 DEFER: foo
 
@@ -12,3 +15,8 @@ DEFER: foo
 ": foo 2 2 + . ;" eval
 
 [ [ foo ] ] [ "foo" parse ] unit-test
+
+! Test > 1 ( ) comment; only the first one should be used.
+[ t ] [
+    "a" ": foo ( a ) ( b ) ;" parse drop word stack-effect str-contains?
+] unit-test
index 996f758af17c5ab2a5e3a3f9c37b751c22f0d3de..652ad5736e1d4f68f118439ebe04d34d2cd86251 100644 (file)
@@ -113,7 +113,7 @@ USE: unparser
         "crashes" test
         "sbuf" test
         "threads" test
-       ! "parsing-word" test
+        "parsing-word" test
 
         cpu "x86" = [
             [