diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index e23d2103e7..97180792af 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,22 +1,20 @@ -contains ==> contains? - -.s: needs nreverse - -{...} vectors -better .s +- prettyprint-1 +- {...} vectors +- better .s +- parsing should be parsing +- telnetd: listening on a socket +- vocab inspecting ==> worddef>list, assumes . on a list works +- need hashtable inspection too +- describe-word +- clone-sbuf +- contains ==> contains? +- telnetd: send errors on socket +- native 'see' + native: -- .s shows fixnums as chars - partition, sort -- describe-word -- need hashtable inspection too -- clone-sbuf -- parsing should be parsing -- inspector: - sort - partition -- vocab inspecting ==> worddef>list, assumes . on a list works +- inspector: sort + interactive: @@ -62,6 +60,7 @@ better .s + httpd: +- use catch - httpd: don't flush so much - log with date - log user agent diff --git a/build.xml b/build.xml index e6ed93c30f..81dd7086dc 100644 --- a/build.xml +++ b/build.xml @@ -21,18 +21,11 @@ compress="true" > - - - - - - - @@ -40,7 +33,6 @@ - diff --git a/library/platform/native/cross-compiler.factor b/library/platform/native/cross-compiler.factor index 1e20bd85f7..f9d1e8295b 100644 --- a/library/platform/native/cross-compiler.factor +++ b/library/platform/native/cross-compiler.factor @@ -50,8 +50,10 @@ DEFER: str= DEFER: str-hashcode IN: io-internals +DEFER: open-file DEFER: read-line-8 DEFER: write-8 +DEFER: close IN: words DEFER: @@ -131,8 +133,10 @@ IN: cross-compiler eq? getenv setenv + open-file read-line-8 write-8 + close garbage-collection save-image datastack diff --git a/library/platform/native/errors.factor b/library/platform/native/errors.factor index d7ecb4333c..7dae9eadb0 100644 --- a/library/platform/native/errors.factor +++ b/library/platform/native/errors.factor @@ -76,6 +76,6 @@ DEFER: default-error-handler : init-errors ( -- ) 64 set-catchstack* - [ 1 exit* ] >c + [ 1 exit* ] >c ( last resort ) [ default-error-handler ] >c [ throw ] 5 setenv ( kernel calls on error ) ; diff --git a/library/platform/native/parse-stream.factor b/library/platform/native/parse-stream.factor index 4b0bc128b7..e7fa5f66d9 100644 --- a/library/platform/native/parse-stream.factor +++ b/library/platform/native/parse-stream.factor @@ -39,7 +39,7 @@ USE: streams "line-number" succ@ ; : (parse-stream) ( -- ) - next-line [ (parse) (parse-stream) ] when* ; + next-line [ print (parse-stream) ] when* ; : parse-stream ( name stream -- ) [ @@ -52,3 +52,9 @@ USE: streams "parse-stream" get fclose rethrow ] catch ] bind ; + +: parse-file ( file -- code ) + "r" parse-stream ; + +: run-file ( file -- ) + parse-file call ; diff --git a/library/platform/native/prettyprint.factor b/library/platform/native/prettyprint.factor index d594a036d4..ff586c5f60 100644 --- a/library/platform/native/prettyprint.factor +++ b/library/platform/native/prettyprint.factor @@ -35,9 +35,14 @@ USE: vocabularies USE: words : see ( word -- ) + !!! Ugh! intern dup compound? [ 0 swap dup word-parameter - prettyprint-:; + [ + [ prettyprint-: ] dip prettyprint-word + dup prettyprint-newline + ] dip + prettyprint-list prettyprint-; prettyprint-newline ] [ dup primitive? [ diff --git a/library/platform/native/stream.factor b/library/platform/native/stream.factor index a97c8b0f65..c94bd2c8d1 100644 --- a/library/platform/native/stream.factor +++ b/library/platform/native/stream.factor @@ -26,8 +26,10 @@ ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IN: streams +USE: combinators USE: io-internals USE: kernel +USE: stack USE: namespaces : ( in out -- stream ) @@ -41,7 +43,15 @@ USE: namespaces [ "out" get write-8 ] "fwrite" set ( -- string ) [ "in" get read-line-8 ] "freadln" set + ( -- ) + [ + "in" get [ close ] when* + "out" get [ close ] when* + ] "fclose" set ] extend ; +: ( path mode -- stream ) + open-file dup ; + : init-stdio ( -- ) stdin stdout "stdio" set ; diff --git a/native/factor.h b/native/factor.h index 42ef0456c7..e4f6f4cefb 100644 --- a/native/factor.h +++ b/native/factor.h @@ -1,6 +1,7 @@ #ifndef __FACTOR_H__ #define __FACTOR_H__ +#include #include #include #include diff --git a/native/io.c b/native/io.c index 4eb765e051..38ed04ac79 100644 --- a/native/io.c +++ b/native/io.c @@ -9,6 +9,17 @@ void init_io(void) #define LINE_SIZE 80 +void primitive_open_file(void) +{ + char* mode = to_c_string(untag_string(env.dt)); + char* path = to_c_string(untag_string(dpop())); + printf("fopen %s %s\n",path,mode); + FILE* file = fopen(path,mode); + if(file == 0) + printf("error %d\n",errno); + env.dt = handle(file); +} + /* read a line of ASCII text. */ void primitive_read_line_8(void) { @@ -56,3 +67,9 @@ void primitive_write_8(void) for(i = 0; i < strlen; i++) putc(string_nth(str,i),file); } + +void primitive_close(void) +{ + HANDLE* h = untag_handle(env.dt); + fclose((FILE*)h->object); +} diff --git a/native/io.h b/native/io.h index b0d3db6e38..a2396c2f22 100644 --- a/native/io.h +++ b/native/io.h @@ -1,3 +1,5 @@ void init_io(void); +void primitive_open_file(void); void primitive_read_line_8(void); void primitive_write_8(void); +void primitive_close(void); diff --git a/native/primitives.c b/native/primitives.c index 0b2c2f1320..3ff545a804 100644 --- a/native/primitives.c +++ b/native/primitives.c @@ -68,16 +68,18 @@ XT primitives[] = { primitive_eq, /* 64 */ primitive_getenv, /* 65 */ primitive_setenv, /* 66 */ - primitive_read_line_8, /* 67 */ - primitive_write_8, /* 68 */ - primitive_gc, /* 69 */ - primitive_save_image, /* 70 */ - primitive_datastack, /* 71 */ - primitive_callstack, /* 72 */ - primitive_set_datastack, /* 73 */ - primitive_set_callstack, /* 74 */ - primitive_handlep, /* 75 */ - primitive_exit /* 76 */ + primitive_open_file, /* 67 */ + primitive_read_line_8, /* 68 */ + primitive_write_8, /* 69 */ + primitive_close, /* 70 */ + primitive_gc, /* 71 */ + primitive_save_image, /* 72 */ + primitive_datastack, /* 73 */ + primitive_callstack, /* 74 */ + primitive_set_datastack, /* 75 */ + primitive_set_callstack, /* 76 */ + primitive_handlep, /* 77 */ + primitive_exit /* 78 */ }; CELL primitive_to_xt(CELL primitive) diff --git a/native/primitives.h b/native/primitives.h index e52d49e23c..e7a48cf6b5 100644 --- a/native/primitives.h +++ b/native/primitives.h @@ -1,5 +1,5 @@ extern XT primitives[]; -#define PRIMITIVE_COUNT 77 +#define PRIMITIVE_COUNT 79 CELL primitive_to_xt(CELL primitive);