client socket works

cvs
Slava Pestov 2004-08-18 23:22:15 +00:00
parent 73a4e3e6c5
commit 9d2af6d349
10 changed files with 48 additions and 28 deletions

View File

@ -1,11 +1,11 @@
- lineno/file for native - non-blocking client socket
- native client socket
- input style after clicking link - input style after clicking link
- fedit broken with listener - fedit broken with listener
- maple-like: press enter at old commands to evaluate there - maple-like: press enter at old commands to evaluate there
- sending ^C on socket - sending ^C on socket
- read# - read#
- enforce bottom-up in native bootstrap - enforce bottom-up in native bootstrap
- fix up native file/line info
- standalone listener input style - standalone listener input style
- add a socket timeout - add a socket timeout
- drop test in http server - drop test in http server

View File

@ -42,17 +42,17 @@ USE: unparser
: parse-dump ( error -- ) : parse-dump ( error -- )
<% <%
"error-parse-name" get [ "<interactive>" ] unless* % ":" % "error-file" get [ "<interactive>" ] unless* % ":" %
"error-line-number" get [ 1 ] unless* unparse % ": " % "error-line-number" get [ 1 ] unless* unparse % ": " %
%> write %> write
error. error.
"error-line" get print "error-line" get print
<% "error-pos" get " " fill % "^" % %> print ; <% "error-col" get " " fill % "^" % %> print ;
: in-parser? ( -- ? ) : in-parser? ( -- ? )
"error-line" get "error-pos" get and ; "error-line" get "error-col" get and ;
: error-handler-hook : error-handler-hook
#! The game overrides this. #! The game overrides this.

View File

@ -43,15 +43,15 @@ USE: vectors
#! Save the stacks and parser state for post-mortem #! Save the stacks and parser state for post-mortem
#! inspection after an error. #! inspection after an error.
namespace [ namespace [
"pos" get "col" get
"line" get "line" get
"line-number" get "line-number" get
"parse-name" get "file" get
global [ global [
"error-parse-name" set "error-file" set
"error-line-number" set "error-line-number" set
"error-line" set "error-line" set
"error-pos" set "error-col" set
"error" set "error" set
datastack >pop> "error-datastack" set datastack >pop> "error-datastack" set
callstack >pop> >pop> "error-callstack" set callstack >pop> >pop> "error-callstack" set

View File

@ -274,8 +274,9 @@ IN: cross-compiler
dup word-name "name" swons , dup word-name "name" swons ,
dup word-vocabulary "vocabulary" swons , dup word-vocabulary "vocabulary" swons ,
"parsing" swap word-property >boolean "parsing" swons , "parsing" over word-property [ t "parsing" swons , ] when
drop
,] ' ; ,] ' ;
: (worddef,) ( word primitive parameter -- ) : (worddef,) ( word primitive parameter -- )

View File

@ -63,7 +63,8 @@ USE: unparser
"restore" get bool% "," % "restore" get bool% "," %
"newView" get bool% "," % "newView" get bool% "," %
"newPlainView" get bool% "," % "newPlainView" get bool% "," %
unparse % "," % ( If the dir is not set, we don't want to send f )
dup [ unparse ] [ drop "null" ] ifte % "," %
list>bsh-array% ");\n" % %> list>bsh-array% ");\n" % %>
] bind ; ] bind ;

View File

@ -28,6 +28,7 @@
IN: jedit IN: jedit
USE: arithmetic USE: arithmetic
USE: combinators USE: combinators
USE: errors
USE: kernel USE: kernel
USE: namespaces USE: namespaces
USE: stack USE: stack
@ -35,7 +36,7 @@ USE: strings
USE: words USE: words
! Doesn't exist in native Factor. ! Doesn't exist in native Factor.
DEFER: local-jedit-line/file : local-jedit-line/file "Not supported" throw ;
: jedit-local? ( -- ? ) : jedit-local? ( -- ? )
java? [ global [ "jedit" get ] bind ] [ f ] ifte ; java? [ global [ "jedit" get ] bind ] [ f ] ifte ;
@ -59,7 +60,8 @@ DEFER: local-jedit-line/file
: word-line/file ( word -- line dir file ) : word-line/file ( word -- line dir file )
#! Note that line numbers here start from 1 #! Note that line numbers here start from 1
[ "line" get "file" get word-file ] bind ; "line" over word-property swap
"file" swap word-property word-file ;
: jedit ( word -- ) : jedit ( word -- )
intern word-line/file jedit-line/file ; intern word-line/file jedit-line/file ;

View File

@ -37,6 +37,11 @@ USE: stdio
USE: streams USE: streams
USE: strings USE: strings
! Stream parsing uses a number of variables:
! file
! line-number
! parse-stream
: next-line ( -- str ) : next-line ( -- str )
"parse-stream" get freadln "parse-stream" get freadln
"line-number" succ@ ; "line-number" succ@ ;
@ -63,9 +68,9 @@ USE: strings
: parse-stream ( name stream -- code ) : parse-stream ( name stream -- code )
#! Uses the current namespace for temporary variables. #! Uses the current namespace for temporary variables.
>r "parse-name" set f r> >r "file" set f r>
[ (parse) ] read-lines nreverse [ (parse) ] read-lines nreverse
"parse-name" off "file" off
"line-number" off ; "line-number" off ;
: parse-file ( file -- code ) : parse-file ( file -- code )

View File

@ -67,9 +67,15 @@ USE: unparser
! Colon defs ! Colon defs
: CREATE scan "in" get create ; : CREATE scan "in" get create ;
: remember-where ( word -- )
"line-number" get "line" pick set-word-property
"col" get "col" pick set-word-property
"file" get "file" pick set-word-property
drop ;
: : : :
#! Begin a word definition. Word name follows. #! Begin a word definition. Word name follows.
CREATE [ ] ; parsing CREATE dup remember-where [ ] ; parsing
: ; : ;
#! End a word definition. #! End a word definition.
@ -128,7 +134,7 @@ USE: unparser
: " : "
#! Note the ugly hack to carry the new value of 'pos' from #! Note the ugly hack to carry the new value of 'pos' from
#! the <% %> scope up to the original scope. #! the <% %> scope up to the original scope.
<% parse-string "pos" get %> swap "pos" set parsed ; parsing <% parse-string "col" get %> swap "col" set parsed ; parsing
! Char literal ! Char literal
: CHAR: ( -- ) next-word-ch parse-ch parsed ; parsing : CHAR: ( -- ) next-word-ch parse-ch parsed ; parsing

View File

@ -60,11 +60,11 @@ USE: unparser
t "parsing" word set-word-property t "parsing" word set-word-property
] unless ; parsing ] unless ; parsing
: <parsing "line" set 0 "pos" set ; : <parsing "line" set 0 "col" set ;
: parsing> "line" off "pos" off ; : parsing> "line" off "col" off ;
: end? ( -- ? ) "pos" get "line" get str-length >= ; : end? ( -- ? ) "col" get "line" get str-length >= ;
: ch ( -- ch ) "pos" get "line" get str-nth ; : ch ( -- ch ) "col" get "line" get str-nth ;
: advance ( -- ) "pos" succ@ ; : advance ( -- ) "col" succ@ ;
: skip ( n line quot -- n ) : skip ( n line quot -- n )
#! Find the next character that satisfies the quotation, #! Find the next character that satisfies the quotation,
@ -108,7 +108,7 @@ USE: unparser
] ifte ; ] ifte ;
: scan ( -- token ) : scan ( -- token )
"pos" get "line" get dup >r (scan) dup "pos" set "col" get "line" get dup >r (scan) dup "col" set
2dup = [ 2dup = [
r> 3drop f r> 3drop f
] [ ] [
@ -155,10 +155,10 @@ USE: unparser
! Used by parsing words ! Used by parsing words
: ch-search ( ch -- index ) : ch-search ( ch -- index )
"pos" get "line" get rot index-of* ; "col" get "line" get rot index-of* ;
: (until) ( index -- str ) : (until) ( index -- str )
"pos" get swap dup succ "pos" set "line" get substring ; "col" get swap dup succ "col" set "line" get substring ;
: until ( ch -- str ) : until ( ch -- str )
ch-search (until) ; ch-search (until) ;
@ -170,4 +170,4 @@ USE: unparser
end? [ "Unexpected EOF" throw ] [ ch advance ] ifte ; end? [ "Unexpected EOF" throw ] [ ch advance ] ifte ;
: next-word-ch ( -- ch ) : next-word-ch ( -- ch )
"pos" get "line" get skip-blank "pos" set next-ch ; "col" get "line" get skip-blank "col" set next-ch ;

View File

@ -11,6 +11,8 @@ void init_sockaddr(struct sockaddr_in* name,
if(hostinfo == NULL) if(hostinfo == NULL)
io_error(__FUNCTION__); io_error(__FUNCTION__);
name->sin_addr = *((struct in_addr *)hostinfo->h_addr);
} }
int make_client_socket(const char* hostname, uint16_t port) int make_client_socket(const char* hostname, uint16_t port)
@ -23,15 +25,18 @@ int make_client_socket(const char* hostname, uint16_t port)
if(sock < 0) if(sock < 0)
io_error(__FUNCTION__); io_error(__FUNCTION__);
if(fcntl(sock,F_SETFL,O_NONBLOCK,1) == -1) /* if(fcntl(sock,F_SETFL,O_NONBLOCK,1) == -1)
io_error(__FUNCTION__); io_error(__FUNCTION__); */
/* Connect to the server. */ /* Connect to the server. */
init_sockaddr(&servername,hostname,port); init_sockaddr(&servername,hostname,port);
if(connect(sock,(struct sockaddr *)&servername,sizeof(servername)) < 0) if(connect(sock,(struct sockaddr *)&servername,sizeof(servername)) < 0)
{ {
if(errno != EINPROGRESS) if(errno != EINPROGRESS)
{
close(sock);
io_error(__FUNCTION__); io_error(__FUNCTION__);
}
} }
return sock; return sock;