fix literal dataflow, other fixes

cvs
Slava Pestov 2004-11-29 02:56:58 +00:00
parent cfb85ef884
commit 46d15bc82c
23 changed files with 197 additions and 264 deletions

View File

@ -52,7 +52,7 @@
- jedit ==> jedit-word, jedit takes a file name - jedit ==> jedit-word, jedit takes a file name
- command line parsing cleanup - command line parsing cleanup
- nicer way to combine two paths - nicer way to combine two paths
- OOP - finish OOP
- ditch object paths - ditch object paths
- browser responder for word links in HTTPd; inspect responder for - browser responder for word links in HTTPd; inspect responder for
objects objects

View File

@ -63,7 +63,6 @@ USE: stdio
"/library/io/io-internals.factor" "/library/io/io-internals.factor"
"/library/io/stream-impl.factor" "/library/io/stream-impl.factor"
"/library/io/stdio.factor" "/library/io/stdio.factor"
"/library/io/extend-stream.factor"
"/library/words.factor" "/library/words.factor"
"/library/vocabularies.factor" "/library/vocabularies.factor"
"/library/syntax/parse-numbers.factor" "/library/syntax/parse-numbers.factor"

View File

@ -64,7 +64,6 @@ primitives,
"/library/io/io-internals.factor" "/library/io/io-internals.factor"
"/library/io/stream-impl.factor" "/library/io/stream-impl.factor"
"/library/io/stdio.factor" "/library/io/stdio.factor"
"/library/io/extend-stream.factor"
"/library/words.factor" "/library/words.factor"
"/library/vocabularies.factor" "/library/vocabularies.factor"
"/library/syntax/parse-numbers.factor" "/library/syntax/parse-numbers.factor"
@ -83,5 +82,6 @@ DEFER: boot
[ [
boot boot
"Good morning!" print "Good morning!" print
flush
"/library/bootstrap/boot-stage2.factor" run-resource "/library/bootstrap/boot-stage2.factor" run-resource
] boot-quot set ] boot-quot set

View File

@ -405,6 +405,6 @@ IN: image
: cross-compile-resource ( resource -- ) : cross-compile-resource ( resource -- )
[ [
! Change behavior of ; and SYMBOL: ! Change behavior of ; and SYMBOL:
[ pick USE: prettyprint . define, ] "define-hook" set [ define, ] "define-hook" set
run-resource run-resource
] with-scope ; ] with-scope ;

View File

@ -180,10 +180,10 @@ SYMBOL: boot-quot
( Words ) ( Words )
: word, ( -- pointer ) : word, ( word -- pointer )
word-tag here-as word-tag >header emit word-tag here-as >r word-tag >header emit
0 HEX: fffffff random-int emit ( hashcode ) hashcode emit ( hashcode )
0 emit ; 0 emit r> ;
! This is to handle mutually recursive words ! This is to handle mutually recursive words
@ -272,7 +272,7 @@ DEFER: '
: define, ( word primitive parameter -- ) : define, ( word primitive parameter -- )
#! Write a word definition to the image. #! Write a word definition to the image.
' >r >r dup (word+) dup emit-plist >r ' >r >r dup (word+) dup emit-plist >r
word, pool-object dup word, pool-object
r> ( -- plist ) r> ( -- plist )
r> ( primitive -- ) emit r> ( primitive -- ) emit
r> ( parameter -- ) emit r> ( parameter -- ) emit

View File

@ -83,9 +83,9 @@ init-error-handler
0 [ drop succ ] each-word unparse write " words" print 0 [ drop succ ] each-word unparse write " words" print
! "Inferring stack effects..." print "Inferring stack effects..." print
! 0 [ unit try-infer [ succ ] when ] each-word 0 [ unit try-infer [ succ ] when ] each-word
! unparse write " words have a stack effect" print unparse write " words have a stack effect" print
"Bootstrapping is complete." print "Bootstrapping is complete." print
"Now, you can run ./f factor.image" print "Now, you can run ./f factor.image" print

View File

@ -65,15 +65,17 @@ SYMBOL: delegate
: no-method : no-method
"No applicable method." throw ; "No applicable method." throw ;
: method ( selector traits -- quot ) : method ( selector traits -- traits quot )
#! Look up the method with the traits object on the stack. #! Look up the method with the traits object on the stack.
#! Returns the traits to call the method on; either the
#! original object, or one of the delegates.
2dup object-map hash* dup [ 2dup object-map hash* dup [
nip nip cdr ( method is defined ) rot drop cdr ( method is defined )
] [ ] [
drop delegate swap hash* dup [ drop delegate swap hash* dup [
cdr method ( check delegate ) cdr method ( check delegate )
] [ ] [
3drop [ no-method ] ( no delegate ) drop [ no-method ] ( no delegate )
] ifte ] ifte
] ifte ; ] ifte ;
@ -100,7 +102,7 @@ SYMBOL: delegate
#! bar method on the traits object, with the traits object #! bar method on the traits object, with the traits object
#! on the stack. #! on the stack.
CREATE CREATE
dup unit [ car over method call ] cons dup unit [ car swap method call ] cons
define-compound ; parsing define-compound ; parsing
: constructor-word ( word -- word ) : constructor-word ( word -- word )

View File

@ -38,6 +38,8 @@ USE: streams
USE: strings USE: strings
USE: unparser USE: unparser
USE: url-encoding USE: url-encoding
USE: presentation
USE: generic
: html-entities ( -- alist ) : html-entities ( -- alist )
[ [
@ -133,16 +135,20 @@ USE: url-encoding
drop call drop call
] ifte ; ] ifte ;
: html-write-attr ( string style -- ) TRAITS: html-stream
M: html-stream fwrite-attr ( str style stream -- )
[ [
[ [
[ [
[ drop chars>entities write ] span-tag [
] file-link-tag [ drop chars>entities write ] span-tag
] object-link-tag ] file-link-tag
] icon-tag ; ] object-link-tag
] icon-tag
] bind ;M
: <html-stream> ( stream -- stream ) C: html-stream ( stream -- stream )
#! Wraps the given stream in an HTML stream. An HTML stream #! Wraps the given stream in an HTML stream. An HTML stream
#! converts special characters to entities when being #! converts special characters to entities when being
#! written, and supports writing attributed strings with #! written, and supports writing attributed strings with
@ -156,11 +162,7 @@ USE: url-encoding
#! underline #! underline
#! size #! size
#! link - an object path #! link - an object path
<extend-stream> [ [ dup delegate set "stdio" set ] extend ;
[ chars>entities write ] "fwrite" set
[ chars>entities print ] "fprint" set
[ html-write-attr ] "fwrite-attr" set
] extend ;
: with-html-stream ( quot -- ) : with-html-stream ( quot -- )
[ "stdio" get <html-stream> "stdio" set call ] with-scope ; [ "stdio" get <html-stream> "stdio" set call ] with-scope ;

View File

@ -111,8 +111,8 @@ USE: hashtables
: infer-ifte ( -- ) : infer-ifte ( -- )
#! Infer effects for both branches, unify. #! Infer effects for both branches, unify.
3 ensure-d 3 ensure-d
\ drop CALL dataflow, drop pop-d dataflow-drop, pop-d
\ drop CALL dataflow, drop pop-d 2list dataflow-drop, pop-d 2list
IFTE IFTE
pop-d drop ( condition ) pop-d drop ( condition )
infer-branches ; infer-branches ;
@ -128,7 +128,7 @@ USE: hashtables
: infer-generic ( -- ) : infer-generic ( -- )
#! Infer effects for all branches, unify. #! Infer effects for all branches, unify.
2 ensure-d 2 ensure-d
\ drop CALL dataflow, drop pop-d vtable>list dataflow-drop, pop-d vtable>list
GENERIC GENERIC
peek-d drop ( dispatch ) peek-d drop ( dispatch )
infer-branches ; infer-branches ;
@ -136,7 +136,7 @@ USE: hashtables
: infer-2generic ( -- ) : infer-2generic ( -- )
#! Infer effects for all branches, unify. #! Infer effects for all branches, unify.
3 ensure-d 3 ensure-d
\ drop CALL dataflow, drop pop-d vtable>list dataflow-drop, pop-d vtable>list
2GENERIC 2GENERIC
peek-d drop ( dispatch ) peek-d drop ( dispatch )
peek-d drop ( dispatch ) peek-d drop ( dispatch )

View File

@ -89,3 +89,8 @@ SYMBOL: node-param
: dataflow, ( param op -- node ) : dataflow, ( param op -- node )
#! Add a node to the dataflow IR. #! Add a node to the dataflow IR.
<dataflow-node> dup dataflow-graph cons@ ; <dataflow-node> dup dataflow-graph cons@ ;
: dataflow-drop, ( -- )
#! Remove the top stack element and add a dataflow node
#! noting this.
\ drop CALL dataflow, [ 1 0 node-inputs ] bind ;

View File

@ -109,7 +109,8 @@ DEFER: apply-word
: apply-literal ( obj -- ) : apply-literal ( obj -- )
#! Literals are annotated with the current recursive #! Literals are annotated with the current recursive
#! state. #! state.
dup PUSH dataflow, drop recursive-state get cons push-d ; dup recursive-state get cons push-d
PUSH dataflow, [ 1 0 node-outputs ] bind ;
: apply-object ( obj -- ) : apply-object ( obj -- )
#! Apply the object's stack effect to the inferencer state. #! Apply the object's stack effect to the inferencer state.

View File

@ -31,6 +31,19 @@ USE: interpreter
USE: stack USE: stack
USE: words USE: words
USE: lists USE: lists
USE: namespaces
\ >r [
\ >r CALL dataflow, [ 1 0 node-inputs ] extend
pop-d push-r
[ 0 1 node-outputs ] bind
] "infer" set-word-property
\ r> [
\ r> CALL dataflow, [ 0 1 node-inputs ] extend
pop-r push-d
[ 1 0 node-outputs ] bind
] "infer" set-word-property
: meta-infer ( word -- ) : meta-infer ( word -- )
#! Mark a word as being partially evaluated. #! Mark a word as being partially evaluated.
@ -41,13 +54,6 @@ USE: lists
\ with-dataflow , \ with-dataflow ,
] make-list "infer" set-word-property ; ] make-list "infer" set-word-property ;
\ >r [
\ >r CALL dataflow, drop pop-d push-r
] "infer" set-word-property
\ r> [
\ r> CALL dataflow, drop pop-r push-d
] "infer" set-word-property
\ drop meta-infer \ drop meta-infer
\ dup meta-infer \ dup meta-infer
\ swap meta-infer \ swap meta-infer

View File

@ -35,6 +35,8 @@ USE: stack
USE: stdio USE: stdio
USE: streams USE: streams
USE: strings USE: strings
USE: presentation
USE: generic
! Some words for outputting ANSI colors. ! Some words for outputting ANSI colors.
@ -76,13 +78,18 @@ USE: strings
: ansi-attr-string ( string style -- string ) : ansi-attr-string ( string style -- string )
[ ansi-attrs , reset , ] make-string ; [ ansi-attrs , reset , ] make-string ;
: <ansi-stream> ( stream -- stream ) TRAITS: ansi-stream
M: ansi-stream fwrite-attr ( string style stream -- )
[
[ default-style ] unless* ansi-attr-string
delegate get fwrite
] bind ;M
C: ansi-stream ( stream -- stream )
#! Wraps the given stream in an ANSI stream. ANSI streams #! Wraps the given stream in an ANSI stream. ANSI streams
#! support the following character attributes: #! support the following character attributes:
#! bold - if not f, text is boldface. #! bold - if not f, text is boldface.
#! ansi-fg - foreground color #! ansi-fg - foreground color
#! ansi-bg - background color #! ansi-bg - background color
<extend-stream> [ [ delegate set ] extend ;
( string style -- )
[ ansi-attr-string write ] "fwrite-attr" set
] extend ;

View File

@ -1,57 +0,0 @@
! :folding=indent:collapseFolds=1:
! $Id$
!
! Copyright (C) 2004 Slava Pestov.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met:
!
! 1. Redistributions of source code must retain the above copyright notice,
! this list of conditions and the following disclaimer.
!
! 2. Redistributions in binary form must reproduce the above copyright notice,
! this list of conditions and the following disclaimer in the documentation
! and/or other materials provided with the distribution.
!
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: streams
USE: errors
USE: kernel
USE: namespaces
USE: stack
USE: stdio
USE: strings
: <extend-stream> ( stream -- stream )
#! Create a stream that wraps another stream. Override some
#! or all of the stream words.
<stream> [
"stdio" set
( -- string )
[ read ] "freadln" set
( -- string )
[ read1 ] "fread1" set
( count -- string )
[ read# ] "fread#" set
( string -- )
[ write ] "fwrite" set
( string style -- )
[ write-attr ] "fwrite-attr" set
( -- )
[ flush ] "fflush" set
( -- )
[ "stdio" get fclose ] "fclose" set
( string -- )
[ print ] "fprint" set
] extend ;

View File

@ -38,17 +38,18 @@ USE: stdio
USE: strings USE: strings
USE: namespaces USE: namespaces
USE: unparser USE: unparser
USE: generic
: <server> ( port -- stream ) TRAITS: server
M: server fclose ( stream -- )
[ "socket" get close-port ] bind ;M
C: server ( port -- stream )
#! Starts listening on localhost:port. Returns a stream that #! Starts listening on localhost:port. Returns a stream that
#! you can close with fclose, and accept connections from #! you can close with fclose, and accept connections from
#! with accept. No other stream operations are supported. #! with accept. No other stream operations are supported.
server-socket <stream> [ [ server-socket "socket" set ] extend ;C
"socket" set
( -- )
[ "socket" get close-port ] "fclose" set
] extend ;
: <client-stream> ( host port in out -- stream ) : <client-stream> ( host port in out -- stream )
<fd-stream> [ ":" swap unparse cat3 "client" set ] extend ; <fd-stream> [ ":" swap unparse cat3 "client" set ] extend ;

View File

@ -25,9 +25,6 @@
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: streams
DEFER: <extend-stream>
IN: stdio IN: stdio
USE: combinators USE: combinators
USE: errors USE: errors
@ -36,40 +33,23 @@ USE: lists
USE: namespaces USE: namespaces
USE: stack USE: stack
USE: streams USE: streams
USE: generic
USE: strings
: flush ( -- ) : flush ( -- ) "stdio" get fflush ;
"stdio" get fflush ; : read ( -- string ) "stdio" get freadln ;
: read1 ( count -- string ) "stdio" get fread1 ;
: read ( -- string ) : read# ( count -- string ) "stdio" get fread# ;
"stdio" get freadln ; : write ( string -- ) "stdio" get fwrite ;
: write-attr ( string style -- ) "stdio" get fwrite-attr ;
: read1 ( count -- string ) : print ( string -- ) "stdio" get fprint ;
"stdio" get fread1 ; : terpri ( -- ) "\n" write ;
: close ( -- ) "stdio" get fclose ;
: read# ( count -- string )
"stdio" get fread# ;
: write ( string -- )
"stdio" get fwrite ;
: write-attr ( string style -- )
#! Write an attributed string to standard output.
"stdio" get fwrite-attr ;
: write-icon ( resource -- ) : write-icon ( resource -- )
#! Write an icon. Eg, /library/icons/File.png #! Write an icon. Eg, /library/icons/File.png
"icon" swons unit "" swap write-attr ; "icon" swons unit "" swap write-attr ;
: print ( string -- )
"stdio" get fprint ;
: terpri ( -- )
#! Print a newline to standard output.
"\n" write ;
: close ( -- )
"stdio" get fclose ;
: with-stream ( stream quot -- ) : with-stream ( stream quot -- )
[ swap "stdio" set [ close rethrow ] catch ] with-scope ; [ swap "stdio" set [ close rethrow ] catch ] with-scope ;
@ -80,12 +60,13 @@ USE: streams
call "stdio" get stream>str call "stdio" get stream>str
] with-stream ; ] with-stream ;
: <stdio-stream> ( stream -- stream ) TRAITS: stdio-stream
#! We disable fclose on stdio so that various tricks like
#! with-stream can work.
<extend-stream> [
( string -- )
[ write "\n" write flush ] "fprint" set
[ ] "fclose" set M: stdio-stream fauto-flush ( -- )
] extend ; [ delegate get fflush ] bind ;M
M: stdio-stream fclose ( -- )
drop ;M
C: stdio-stream ( delegate -- stream )
[ delegate set ] extend ;C

View File

@ -37,34 +37,33 @@ USE: stack
USE: stdio USE: stdio
USE: strings USE: strings
USE: namespaces USE: namespaces
USE: generic
: <fd-stream> ( in out -- stream ) TRAITS: fd-stream
#! Create a file descriptor stream object, wrapping a pair
#! of file descriptor handles for input and output.
<stream> [
"out" set
"in" set
( str -- ) M: fd-stream fwrite-attr ( str style stream -- )
[ "out" get blocking-write ] "fwrite" set [ drop "out" get blocking-write ] bind ;M
( -- str ) M: fd-stream freadln ( stream -- str )
[ "in" get dup [ blocking-read-line ] when ] "freadln" set [ "in" get dup [ blocking-read-line ] when ] bind ;M
( count -- str ) M: fd-stream fread# ( count stream -- str )
[ [ "in" get dup [ blocking-read# ] [ nip ] ifte ] bind ;M
"in" get dup [ blocking-read# ] [ nip ] ifte
] "fread#" set
( -- ) M: fd-stream fflush ( stream -- )
[ "out" get [ blocking-flush ] when* ] "fflush" set [ "out" get [ blocking-flush ] when* ] bind ;M
( -- ) M: fd-stream fauto-flush ( stream -- )
[ drop ;M
"out" get [ dup blocking-flush close-port ] when*
"in" get [ close-port ] when* M: fd-stream fclose ( -- )
] "fclose" set [
] extend ; "out" get [ dup blocking-flush close-port ] when*
"in" get [ close-port ] when*
] bind ;M
C: fd-stream ( in out -- stream )
[ "out" set "in" set ] extend ;C
: <filecr> ( path -- stream ) : <filecr> ( path -- stream )
t f open-file <fd-stream> ; t f open-file <fd-stream> ;

View File

@ -32,72 +32,43 @@ USE: kernel
USE: namespaces USE: namespaces
USE: stack USE: stack
USE: strings USE: strings
USE: generic
! Generic functions, of sorts... GENERIC: fflush ( stream -- )
GENERIC: fauto-flush ( stream -- )
: fflush ( stream -- ) GENERIC: freadln ( stream -- string )
[ "fflush" get call ] bind ; GENERIC: fread# ( count stream -- string )
GENERIC: fwrite-attr ( string style stream -- )
: freadln ( stream -- string ) GENERIC: fclose ( stream -- )
[ "freadln" get call ] bind ;
: fread1 ( stream -- string ) : fread1 ( stream -- string )
[ "fread1" get call ] bind ; 1 swap fread# dup f-or-"" [ 0 swap str-nth ] unless ;
: fread# ( count stream -- string )
[ "fread#" get call ] bind ;
: fprint ( string stream -- ) : fprint ( string stream -- )
[ "fprint" get call ] bind ; tuck fwrite "\n" over fwrite fauto-flush ;
: fwrite ( string stream -- ) : fwrite ( string stream -- )
[ "fwrite" get call ] bind ; f swap fwrite-attr ;
: fwrite-attr ( string style stream -- ) TRAITS: string-output-stream
#! Write an attributed string to the given stream.
#! Supported keys depend on the type of stream.
[ "fwrite-attr" get call ] bind ;
: fclose ( stream -- ) M: string-output-stream fwrite-attr ( string style stream -- )
[ "fclose" get call ] bind ; [ drop "buf" get sbuf-append ] bind ;M
: <stream> ( -- stream ) M: string-output-stream fclose ( stream -- )
#! Create a stream object. drop ;M
<namespace> [
( -- string )
[ "freadln not implemented." throw ] "freadln" set
( -- string )
[
1 namespace fread# dup f-or-"" [
0 swap str-nth
] unless
] "fread1" set
( count -- string )
[ "fread# not implemented." throw ] "fread#" set
( string -- )
[ "fwrite not implemented." throw ] "fwrite" set
( string style -- )
[ drop namespace fwrite ] "fwrite-attr" set
( -- )
[ ] "fflush" set
( -- )
[ ] "fclose" set
( string -- )
[
namespace fwrite
"\n" namespace fwrite
] "fprint" set
] extend ;
: <string-output-stream> ( size -- stream ) M: string-output-stream fflush ( stream -- )
#! Creates a new stream for writing to a string buffer. drop ;M
<stream> [
<sbuf> "buf" set M: string-output-stream fauto-flush ( stream -- )
( string -- ) drop ;M
[ "buf" get sbuf-append ] "fwrite" set
] extend ;
: stream>str ( stream -- string ) : stream>str ( stream -- string )
#! Returns the string written to the given string output #! Returns the string written to the given string output
#! stream. #! stream.
[ "buf" get ] bind sbuf>str ; [ "buf" get ] bind sbuf>str ;
C: string-output-stream ( size -- stream )
#! Creates a new stream for writing to a string buffer.
[ <sbuf> "buf" set ] extend ;C

View File

@ -44,6 +44,9 @@ USE: stack
] with-string ] with-string
] unit-test ] unit-test
: html-write-attr ( string style -- string )
[ write-attr ] with-html-stream ;
[ "hello world" ] [ "hello world" ]
[ [
[ "hello world" [ ] html-write-attr ] with-string [ "hello world" [ ] html-write-attr ] with-string

View File

@ -6,7 +6,7 @@ USE: stdio
[ "ab\0\0" ] [ 4 "ab" align-string ] unit-test [ "ab\0\0" ] [ 4 "ab" align-string ] unit-test
[ { 0 } ] [ [ { 0 } ] [
[ "\0\0\0\0" emit-string ] with-minimal-image [ "\0\0\0\0" emit-chars ] with-minimal-image
] unit-test ] unit-test
[ { 6815845 7077996 7274528 7798895 7471212 6553600 } ] [ { 6815845 7077996 7274528 7798895 7471212 6553600 } ]

View File

@ -3,21 +3,38 @@ USE: namespaces
USE: streams USE: streams
USE: stdio USE: stdio
USE: test USE: test
USE: stack
USE: generic
[ "xyzzy" ] [ [ "xyzzy" write ] with-string ] unit-test [ "xyzzy" ] [ [ "xyzzy" write ] with-string ] unit-test
TRAITS: xyzzy-stream
M: xyzzy-stream fwrite-attr ( str style stream -- )
[
drop "<" delegate get fwrite
delegate get fwrite
">" delegate get fwrite
] bind ;M
M: xyzzy-stream fclose ( stream -- )
drop ;M
M: xyzzy-stream fflush ( stream -- )
drop ;M
M: xyzzy-stream fauto-flush ( stream -- )
drop ;M
C: xyzzy-stream ( stream -- stream )
[ delegate set ] extend ;C
[ [
"<xyzzy>" "<xyzzy>"
] [ ] [
[ [
[ "stdio" get <xyzzy-stream> [
"stdio" get <extend-stream> [
[ "<" write write ">" write ] "fwrite" set
[ "<" write write ">" print ] "fprint" set
] extend "stdio" set
"xyzzy" write "xyzzy" write
] with-scope ] with-stream
] with-string ] with-string
] unit-test ] unit-test

View File

@ -37,6 +37,7 @@ USE: stdio
USE: streams USE: streams
USE: strings USE: strings
USE: words USE: words
USE: generic
! Wire protocol for jEdit to evaluate Factor code. ! Wire protocol for jEdit to evaluate Factor code.
! Packets are of the form: ! Packets are of the form:
@ -71,35 +72,25 @@ USE: listener
! the client: ! the client:
! 4 bytes -- length. -1 means EOF ! 4 bytes -- length. -1 means EOF
! remaining -- input ! remaining -- input
: jedit-read ( -- str )
CHAR: r write flush read-big-endian-32 read# ;
: jedit-write-attr ( str style -- ) : jedit-write-attr ( str style -- )
CHAR: w write CHAR: w write
[ swap . . ] with-string [ swap . . ] with-string
dup str-length write-big-endian-32 dup str-length write-big-endian-32
write ; write ;
: jedit-flush ( -- ) TRAITS: jedit-stream
CHAR: f write flush ;
: <jedit-stream> ( stream -- stream ) M: jedit-stream freadln ( stream -- str )
<extend-stream> [ [ CHAR: r write flush read-big-endian-32 read# ] bind ;M
( -- str )
[ jedit-read ] "freadln" set M: jedit-stream fwrite-attr ( str style stream -- )
( str -- ) [ [ default-style ] unless* jedit-write-attr ] bind ;M
[
default-style jedit-write-attr M: jedit-stream fflush ( stream -- )
] "fwrite" set [ CHAR: f write flush ] bind ;M
( str style -- )
[ jedit-write-attr ] "fwrite-attr" set C: jedit-stream ( stream -- stream )
( string -- ) [ dup delegate set "stdio" set ] extend ;C
[
"\n" cat2 default-style jedit-write-attr
] "fprint" set
( -- )
[ jedit-flush ] "fflush" set
] extend ;
: stream-server ( -- ) : stream-server ( -- )
#! Execute this in the inferior Factor. #! Execute this in the inferior Factor.

View File

@ -29,22 +29,27 @@ void throw_error(CELL error, bool keep_stacks)
siglongjmp(toplevel,1); siglongjmp(toplevel,1);
} }
void primitive_throw(void)
{
throw_error(dpop(),true);
}
void early_error(CELL error) void early_error(CELL error)
{ {
if(userenv[BREAK_ENV] == F) if(userenv[BREAK_ENV] == F)
{ {
/* Crash at startup */ /* Crash at startup */
fprintf(stderr,"Error %ld thrown before BREAK_ENV set\n",to_fixnum(error)); if(type_of(error) == FIXNUM_TYPE)
fprintf(stderr,"Error: %ld\n",to_fixnum(error));
else if(type_of(error) == STRING_TYPE)
fprintf(stderr,"Error: %s\n",to_c_string(untag_string(error)));
fflush(stderr); fflush(stderr);
exit(1); exit(1);
} }
} }
void primitive_throw(void)
{
CELL error = dpop();
early_error(error);
throw_error(error,true);
}
void general_error(CELL error, CELL tagged) void general_error(CELL error, CELL tagged)
{ {
early_error(error); early_error(error);