]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Thu, 22 Jan 2009 03:57:53 +0000 (21:57 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Thu, 22 Jan 2009 03:57:53 +0000 (21:57 -0600)
16 files changed:
basis/alien/c-types/c-types-tests.factor
basis/alien/syntax/syntax.factor
basis/furnace/utilities/utilities.factor
basis/heaps/heaps-tests.factor
basis/http/client/client.factor
basis/http/http-tests.factor
basis/http/http.factor
basis/http/server/cgi/cgi.factor
basis/http/server/server.factor
basis/refs/refs-docs.factor
core/sequences/sequences-docs.factor
core/slots/slots.factor
vm/factor.c
vm/image.c
vm/os-unix.h
vm/os-windows.h

index 31542b2699eb94224500aa3c5fe181e47d4f9fa0..40171f56e7917bda2b0916c6c1903f61672ca30d 100644 (file)
@@ -8,10 +8,6 @@ sequences system libc alien.strings io.encodings.utf8 ;
 
 [ { "blah" 123 } ] [ { "blah" xyz } expand-constants ] unit-test
 
-: foo ( -- n ) &: fdafd [ 123 ] unless* ;
-
-[ 123 ] [ foo ] unit-test
-
 [ -1 ] [ -1 <char> *char ] unit-test
 [ -1 ] [ -1 <short> *short ] unit-test
 [ -1 ] [ -1 <int> *int ] unit-test
index a02d2f3cb46e66de39a27d216d4da805e8800c26..bed454e81d1625aac2b335f83c9c1291904ef782 100644 (file)
@@ -4,7 +4,7 @@ USING: accessors arrays alien alien.c-types alien.structs
 alien.arrays alien.strings kernel math namespaces parser
 sequences words quotations math.parser splitting grouping
 effects assocs combinators lexer strings.parser alien.parser 
-fry vocabs.parser ;
+fry vocabs.parser words.constant ;
 IN: alien.syntax
 
 : DLL" lexer get skip-blank parse-string dlopen parsed ; parsing
@@ -31,10 +31,11 @@ IN: alien.syntax
 
 : C-ENUM:
     ";" parse-tokens
-    dup length
-    [ [ create-in ] dip 1quotation define ] 2each ;
+    [ [ create-in ] dip define-constant ] each-index ;
     parsing
 
+: address-of ( name library -- value )
+    load-library dlsym [ "No such symbol" throw ] unless* ;
+
 : &:
-    scan "c-library" get
-    '[ _ _ load-library dlsym ] over push-all ; parsing
+    scan "c-library" get '[ _ _ address-of ] over push-all ; parsing
index 7f71a131eda164a1103ccc882516bc9380c5b2fe..f84519b9c189769a1d214004296aad3c2c0890d9 100644 (file)
@@ -96,11 +96,7 @@ M: object modify-form drop ;
     dup method>> {
         { "GET" [ url>> query>> ] }
         { "HEAD" [ url>> query>> ] }
-        { "POST" [
-            post-data>>
-            dup content-type>> "application/x-www-form-urlencoded" =
-            [ content>> ] [ drop f ] if
-        ] }
+        { "POST" [ post-data>> params>> ] }
     } case ;
 
 : referrer ( -- referrer/f )
index 8fa6a274e7e65aa4cae36b22eb1d111fbea3bda3..7e780cbe5ef674cf56b22a4aef1335d362306143 100644 (file)
@@ -32,10 +32,8 @@ IN: heaps.tests
 
 : random-alist ( n -- alist )
     [
-        [
-            32 random-bits dup number>string swap set
-        ] times
-    ] H{ } make-assoc ;
+        drop 32 random-bits dup number>string
+    ] H{ } map>assoc ;
 
 : test-heap-sort ( n -- ? )
     random-alist dup >alist sort-keys swap heap-sort = ;
index fc6e296a4f04694504a6e7c5cf3c0ac540d39b0e..f2c0a862ebb05c3a9705e1f4965aef6664d82008 100644 (file)
@@ -25,7 +25,7 @@ IN: http.client
     dup header>> >hashtable
     over url>> host>> [ over url>> url-host "host" pick set-at ] when
     over post-data>> [
-        [ raw>> length "content-length" pick set-at ]
+        [ data>> length "content-length" pick set-at ]
         [ content-type>> "content-type" pick set-at ]
         bi
     ] when*
@@ -36,19 +36,35 @@ GENERIC: >post-data ( object -- post-data )
 
 M: post-data >post-data ;
 
-M: string >post-data utf8 encode "application/octet-stream" <post-data> ;
+M: string >post-data
+    utf8 encode
+    "application/octet-stream" <post-data>
+        swap >>data ;
 
-M: byte-array >post-data "application/octet-stream" <post-data> ;
+M: byte-array >post-data
+    "application/octet-stream" <post-data>
+        swap >>data ;
 
-M: assoc >post-data assoc>query ascii encode "application/x-www-form-urlencoded" <post-data> ;
+M: assoc >post-data
+    "application/x-www-form-urlencoded" <post-data>
+        swap >>params ;
 
 M: f >post-data ;
 
+: normalize-post-data ( request -- request )
+    dup post-data>> [
+        dup params>> [
+            assoc>query ascii encode >>data
+        ] when* drop
+    ] when* ;
+
 : unparse-post-data ( request -- request )
-    [ >post-data ] change-post-data ;
+    [ >post-data ] change-post-data
+    normalize-post-data ;
 
 : write-post-data ( request -- request )
-    dup method>> [ "POST" = ] [ "PUT" = ] bi or [ dup post-data>> raw>> write ] when ; 
+    dup method>> [ "POST" = ] [ "PUT" = ] bi or
+    [ dup post-data>> data>> write ] when ; 
 
 : write-request ( request -- )
     unparse-post-data
index 92a296c2d3ef6f225a2bf88192cf9f1c2aec0df2..6fa23b4b1f8722fa37cde832050a18bdf5cff70f 100644 (file)
@@ -35,7 +35,7 @@ blah
         { method "POST" }
         { version "1.1" }
         { header H{ { "some-header" "1; 2" } { "content-length" "4" } { "content-type" "application/octet-stream" } } }
-        { post-data T{ post-data { content "blah" } { raw "blah" } { content-type "application/octet-stream" } } }
+        { post-data T{ post-data { data "blah" } { content-type "application/octet-stream" } } }
         { cookies V{ } }
     }
 ] [
index b29f5222db4c771564fac76c0d044b8373a71e27..c85cfc9c410249910a32d679ec5aed7e0073942e 100755 (executable)
@@ -213,14 +213,11 @@ body ;
     raw-response new
         "1.1" >>version ;
 
-TUPLE: post-data raw content content-type form-variables uploaded-files ;
+TUPLE: post-data data params content-type content-encoding ;
 
-: <post-data> ( form-variables uploaded-files raw content-type -- post-data )
+: <post-data> ( content-type -- post-data )
     post-data new
-        swap >>content-type
-        swap >>raw
-        swap >>uploaded-files
-        swap >>form-variables ;
+        swap >>content-type ;
 
 : parse-content-type-attributes ( string -- attributes )
     " " split harvest [ "=" split1 [ >lower ] dip ] { } map>assoc ;
index 0c2f639cba947edbed08273bd309f70d00045c3b..959642b706fea44ac8a95b0d6e3ca6a29f06bea0 100644 (file)
@@ -34,7 +34,7 @@ IN: http.server.cgi
         request get "accept" header "HTTP_ACCEPT" set\r
 \r
         post-request? [\r
-            request get post-data>> raw>>\r
+            request get post-data>> data>>\r
             [ "CONTENT_TYPE" set ]\r
             [ length number>string "CONTENT_LENGTH" set ]\r
             bi\r
@@ -54,7 +54,7 @@ IN: http.server.cgi
     swap '[\r
         binary encode-output\r
         _ output-stream get swap <cgi-process> binary <process-stream> [\r
-            post-request? [ request get post-data>> raw>> write flush ] when\r
+            post-request? [ request get post-data>> data>> write flush ] when\r
             input-stream get swap (stream-copy)\r
         ] with-stream\r
     ] >>body ;\r
index 1c516e90517d905be6f14c56efe9af617aead905..c328e1d6a384f5cd1ccab4e0233e02f7da5a6866 100755 (executable)
@@ -55,18 +55,17 @@ ERROR: no-boundary ;
 : read-content ( request -- bytes )
     "content-length" header string>number read ;
 
-: parse-content ( request content-type -- form-variables uploaded-files raw )
-    {
-        { "multipart/form-data" [ read-multipart-data f ] }
-        { "application/x-www-form-urlencoded" [ read-content [ f f ] dip ] }
-        [ drop read-content [ f f ] dip ]
+: parse-content ( request content-type -- post-data )
+    [ <post-data> swap ] keep {
+        { "multipart/form-data" [ read-multipart-data assoc-union >>params ] }
+        { "application/x-www-form-urlencoded" [ read-content query>assoc >>params ] }
+        [ drop read-content >>data ]
     } case ;
 
 : read-post-data ( request -- request )
     dup method>> "POST" = [
         dup dup "content-type" header
-        [ ";" split1 drop parse-content ] keep
-        <post-data> >>post-data
+        ";" split1 drop parse-content >>post-data
     ] when ;
 
 : extract-host ( request -- request )
index 0034b7e566df7be2462f36053b2eb0464dd1c540..b6f222cce98c6062f8f1da3d2c2b5f43fd729f4e 100644 (file)
@@ -14,7 +14,7 @@ ARTICLE: "refs" "References to assoc entries"
 "References to values:"
 { $subsection value-ref }
 { $subsection <value-ref> }
-"References are used by the inspector." ;
+"References are used by the UI inspector." ;
 
 ABOUT: "refs"
 
index 1aeed75470d0d28c8b8dfdd8f406fc70e3ff4e09..ea7cf829c461ce7f278c87ead2d2669a9b01fd15 100644 (file)
@@ -1096,7 +1096,7 @@ HELP: set-fourth
 
 HELP: replicate
 { $values
-     { "seq" sequence } { "quot" quotation }
+     { "seq" sequence } { "quot" { $quotation "( -- elt )" } }
      { "newseq" sequence } }
 { $description "Calls the quotation for every element of the sequence in order. However, the element is not passed to the quotation -- it is dropped, and the quotation produces an element of its own that is collected into a sequence of the same class as the input sequence." }
 { $examples 
index 99766cadc218b2d289fe129b569ef816378bc8cf..f166378d9d20aa3a3a747a4e97272d00c38e5cc6 100644 (file)
@@ -1,9 +1,9 @@
-! Copyright (C) 2005, 2008 Slava Pestov.
+! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays byte-arrays kernel kernel.private math namespaces
 make sequences strings words effects generic generic.standard
 classes classes.algebra slots.private combinators accessors
-words sequences.private assocs alien quotations ;
+words sequences.private assocs alien quotations hashtables ;
 IN: slots
 
 TUPLE: slot-spec name offset class initial read-only ;
@@ -86,7 +86,7 @@ ERROR: bad-slot-value value class ;
     ] [ ] make ;
 
 : writer-props ( slot-spec -- assoc )
-    [ "writing" set ] H{ } make-assoc ;
+    "writing" associate ;
 
 : define-writer ( class slot-spec -- )
     [ name>> writer-word ] [ writer-quot ] [ writer-props ] tri
index b3020e31712c88b0a81b003763f39833fd85c40b..d9042c945563a854a3b149dc9df24ea554b72c25 100755 (executable)
@@ -53,8 +53,7 @@ INLINE bool factor_arg(const F_CHAR* str, const F_CHAR* arg, CELL* value)
 void init_parameters_from_args(F_PARAMETERS *p, int argc, F_CHAR **argv)
 {
        default_parameters(p);
-       const F_CHAR *executable_path = vm_executable_path();
-       p->executable_path = executable_path ? executable_path : argv[0];
+       p->executable_path = argv[0];
 
        int i = 0;
 
@@ -106,6 +105,11 @@ void init_factor(F_PARAMETERS *p)
        /* OS-specific initialization */
        early_init();
 
+       const F_CHAR *executable_path = vm_executable_path();
+
+       if(executable_path)
+               p->executable_path = executable_path;
+
        if(p->image_path == NULL)
                p->image_path = default_image_path();
 
index 5f4492e537ed698558a642809404178dc7b4f3b8..f7ecd34aa882d9377cae3e0787af1b09e9e684b6 100755 (executable)
@@ -112,7 +112,10 @@ bool save_image(const F_CHAR *filename)
        FILE* file;
        F_HEADER h;
 
+       F_CHAR temporary_filename[] = STRING_LITERAL("##saving-factor-image##");
+
        file = OPEN_WRITE(filename);
+       //file = OPEN_WRITE(temporary_filename);
        if(file == NULL)
        {
                print_string("Cannot open image file: "); print_native_string(filename); nl();
@@ -164,6 +167,16 @@ bool save_image(const F_CHAR *filename)
        }
 
        return true;
+
+       if(MOVE_FILE_FAILS(temporary_filename, filename))
+       {
+               print_string("Failed to rename tempoarary image file: "); print_string(strerror(errno)); nl();
+               //if(DELETE_FILE_FAILS(temporary_filename))
+                       //print_string("Failed to clean up temporary image file: "); print_string(strerror(errno)); nl();
+               return false;
+       }
+
+       return true;
 }
 
 void primitive_save_image(void)
index d2f34b4bc4c26d50a1c419ce436619ac3c833d8e..9f911acdedd506809ae7422fcb136c2543858e7c 100755 (executable)
@@ -22,6 +22,8 @@ typedef char F_SYMBOL;
 #define STRCMP strcmp
 #define STRNCMP strncmp
 #define STRDUP strdup
+#define MOVE_FILE_FAILS(old,new) (rename((old),(new)) < 0)
+#define DELETE_FILE_FAILS(old) (unlink((old)) < 0)
 
 #define FIXNUM_FORMAT "%ld"
 #define CELL_FORMAT "%lu"
index a9c3f6d803aa3ee4b23495884abe1dcde693b09b..beec7ad37c59d052766ffc62adcbb69a836f3508 100755 (executable)
@@ -19,6 +19,8 @@ typedef wchar_t F_CHAR;
 #define STRCMP wcscmp
 #define STRNCMP wcsncmp
 #define STRDUP _wcsdup
+#define MOVE_FILE_FAILS(old,new) (MoveFile((old),(new)) == 0)
+#define DELETE_FILE_FAILS(old) (DeleteFile((old)) == 0)
 
 #ifdef WIN64
        #define CELL_FORMAT "%Iu"