diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 97180792af..17f3301681 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,3 +1,7 @@ ++ native: + +- parsing: -1, HEX:, #\, | +- minimal use/in for parse-stream - prettyprint-1 - {...} vectors - better .s @@ -10,9 +14,6 @@ - contains ==> contains? - telnetd: send errors on socket - native 'see' - -+ native: - - partition, sort - inspector: sort diff --git a/library/combinators.factor b/library/combinators.factor index 62ebb6aa54..5fad275265 100644 --- a/library/combinators.factor +++ b/library/combinators.factor @@ -54,9 +54,6 @@ USE: stack #! If the quotation compiles, this combinator compiles. -rot >r >r call r> r> ; inline interpret-only -: 3dip ( a b c quot -- ) - swap >r swap >r swap >r call r> r> r> ; - : forever ( code -- ) #! The code is evaluated in an infinite loop. Typically, a #! continuation is used to escape the infinite loop. diff --git a/library/debugger.factor b/library/debugger.factor index 3db64a0f35..270a6891a9 100644 --- a/library/debugger.factor +++ b/library/debugger.factor @@ -30,6 +30,7 @@ USE: combinators USE: continuations USE: kernel USE: inspector +USE: logic USE: namespaces USE: stack USE: stdio @@ -41,8 +42,8 @@ USE: unparser : parse-dump ( error -- ) <% - "parse-name" get % ":" % - "line-number" get fixnum>str % ": " % + "parse-name" get [ "" ] unless* % ":" % + "line-number" get [ 1 ] unless* fixnum>str % ": " % error>str % %> print @@ -50,10 +51,12 @@ USE: unparser <% "pos" get " " fill % "^" % %> print ; +: in-parser? ( -- ? ) + "line" get "pos" get and ; + : default-error-handler ( error -- ) #! Print the error and return to the top level. - "parse-name" get [ parse-dump ] [ standard-dump ] ifte - terpri + in-parser? [ parse-dump ] [ standard-dump ] ifte terpri "Stacks have been reset." print ":s :r :n :c show stacks at time of error." print diff --git a/library/platform/native/kernel.factor b/library/platform/native/kernel.factor index 259ae12808..50dc6b4a7f 100644 --- a/library/platform/native/kernel.factor +++ b/library/platform/native/kernel.factor @@ -91,6 +91,10 @@ USE: words : java? f ; : native? t ; +! No compiler... +: inline ; +: interpret-only ; + !!! HACK IN: strings diff --git a/library/platform/native/parse-stream.factor b/library/platform/native/parse-stream.factor index e7fa5f66d9..ff82494179 100644 --- a/library/platform/native/parse-stream.factor +++ b/library/platform/native/parse-stream.factor @@ -31,6 +31,7 @@ USE: combinators USE: errors USE: lists USE: namespaces +USE: stack USE: stdio USE: streams @@ -39,22 +40,24 @@ USE: streams "line-number" succ@ ; : (parse-stream) ( -- ) - next-line [ print (parse-stream) ] when* ; + next-line [ (parse) (parse-stream) ] when* ; + +: [ [ - "parse-stream" set - "parse-name" set - 0 "line-number" set - f (parse-stream) nreverse + parse-stream ; + dup "r" parse-stream ; : run-file ( file -- ) parse-file call ; diff --git a/library/platform/native/parser.factor b/library/platform/native/parser.factor index f7e474c960..fc1913f84f 100644 --- a/library/platform/native/parser.factor +++ b/library/platform/native/parser.factor @@ -37,6 +37,7 @@ USE: stack USE: strings USE: words USE: vocabularies +USE: unparser ! Number parsing @@ -83,7 +84,7 @@ USE: vocabularies #! "hello world" #! #! Will call the parsing word ". - ch "\"" str-contains? ; + ch "\"!" str-contains? ; : (scan) ( -- start end ) skip-blank "pos" get @@ -130,6 +131,9 @@ USE: vocabularies : until-eol ( ch -- str ) "line" get str-length (until) ; +: next-ch ( -- ch ) + end? [ "Unexpected EOF" throw ] [ ch advance ] ifte ; + !!! Parsing words. 'builtins' is a stupid vocabulary name now !!! that it does not contain Java words anymore! @@ -142,13 +146,6 @@ IN: builtins ! Lists : [ f ; parsing : ] nreverse swons ; parsing - -! Comments -: ( ")" until drop ; parsing -: ! until-eol drop ; parsing - -! String literal -: " "\"" until swons ; parsing ! Colon defs : : @@ -160,5 +157,42 @@ IN: builtins nreverse define ; parsing ! Vocabularies +: DEFER: scan "in" get create drop ; parsing : USE: scan "use" cons@ ; parsing : IN: scan dup "use" cons@ "in" set ; parsing + +! \x +: escape ( ch -- esc ) + [ + [ #\e | #\\e ] + [ #\n | #\\n ] + [ #\r | #\\r ] + [ #\t | #\\t ] + [ #\s | #\\s ] + [ #\\s | #\\s ] + [ #\0 | #\\0 ] + [ #\\\ | #\\\ ] + [ #\\" | #\\" ] + ] assoc ; + +! String literal + +: scan-escape ( -- ) + next-ch escape dup [ % ] [ drop "Bad escape" throw ] ifte ; + +: scan-string ( -- ) + next-ch dup #\" = [ + drop + ] [ + dup #\\\ = [ drop scan-escape ] [ % ] ifte scan-string + ] ifte ; + +: " + #! Note the ugly hack to carry the new value of 'pos' from + #! the <% %> scope up to the original scope. + <% scan-string "pos" get %> swap "pos" set swons ; parsing + +! Comments +: ( ")" until drop ; parsing +: ! until-eol drop ; parsing +: #! until-eol drop ; parsing diff --git a/native/io.c b/native/io.c index 38ed04ac79..fbe0aa7ad8 100644 --- a/native/io.c +++ b/native/io.c @@ -13,10 +13,7 @@ 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); } @@ -72,4 +69,5 @@ void primitive_close(void) { HANDLE* h = untag_handle(env.dt); fclose((FILE*)h->object); + env.dt = dpop(); }