- type inference\r
- some way to step over a word in the stepper\r
- step: print NEXT word to execute, not word that JUST executed\r
-- step: start a nested listener\r
\r
+ compiler/ffi:\r
\r
\r
+ kernel:\r
\r
-- dissolve library/platform/native/\r
- profiler is inaccurate: wrong word on cs\r
- better i/o scheduler\r
-- >lower, >upper for strings\r
- don't rehash strings on every startup\r
- remove sbufs\r
- cat, reverse-cat primitives\r
\r
+ misc:\r
\r
-- alist -vs- assoc terminology\r
- jedit ==> jedit-word, jedit takes a file name\r
- command line parsing cleanup\r
- nicer way to combine two paths\r
-- catchstack lists\r
- OOP\r
- ditch object paths\r
- browser responder for word links in HTTPd; inspect responder for\r
import console.*;
import factor.Cons;
import javax.swing.text.*;
-import javax.swing.Action;
+import javax.swing.*;
import java.awt.Color;
import org.gjt.sp.jedit.GUIUtilities;
else if("actions".equals(key))
addAttribute(ConsolePane.Actions,createActionsMenu((Cons)value));
else if("icon".equals(key))
- addAttribute(StyleConstants.IconAttribute,
- GUIUtilities.loadIcon((String)value));
+ {
+ StyleConstants.setIcon(this,GUIUtilities.loadIcon(
+ "jeditresource:/Factor.jar!" + value));
+ }
} //}}}
//{{{ toColor() method
[
warm-boot
- "interactive" get [ init-listener ] when
+ garbage-collection
+ "interactive" get [ print-banner listener ] when
0 exit*
] set-boot
0 [ drop succ ] each-word unparse write " words" print
"Inferring stack effects..." print
-[ 2 car ] [ ] catch
0 [ unit try-infer [ succ ] when ] each-word
unparse write " words have a stack effect" print
: boot ( -- )
#! Initialize an interpreter with the basic services.
- init-errors
init-namespaces
init-threads
init-stdio
! This is a very lightweight exception handling system.
-: catchstack* ( -- cs ) 6 getenv ;
-: catchstack ( -- cs ) catchstack* vector-clone ;
-: set-catchstack* ( cs -- ) 6 setenv ;
-: set-catchstack ( cs -- ) vector-clone set-catchstack* ;
+: catchstack ( -- cs ) 6 getenv ;
+: set-catchstack ( cs -- ) 6 setenv ;
-: init-errors ( -- )
- 64 <vector> set-catchstack* ;
-
-: >c ( catch -- ) catchstack* vector-push ;
-: c> ( catch -- ) catchstack* vector-pop ;
+: >c ( catch -- ) catchstack cons set-catchstack ;
+: c> ( catch -- ) catchstack uncons set-catchstack ;
: save-error ( error -- )
#! Save the stacks and parser state for post-mortem
USE: stdio
: eval-catch ( str -- )
- [ eval ] print-error ;
+ [ eval ] [ [ default-error-handler drop ] when* ] catch ;
: eval>string ( in -- out )
[ eval-catch ] with-string ;
[
schedule-thread
! Clear stacks since we never go up from this point
- { } set-catchstack
+ [ ] set-catchstack
{ } set-callstack
print-error
(yield)
write-attr ;
: prettyprint-[ ( indent -- indent )
- \ [ prettyprint-word <prettyprint ;
+ \ [ prettyprint-word <prettyprint ;
: prettyprint-] ( indent -- indent )
- prettyprint> \ ] prettyprint-word ;
+ prettyprint> \ ] prettyprint-word ;
: prettyprint-list ( indent list -- indent )
#! Pretty-print a list, without [ and ].
] ifte ;
: prettyprint-{{ ( indent -- indent )
- \ {{ prettyprint-word <prettyprint ;
+ \ {{ prettyprint-word <prettyprint ;
: prettyprint-}} ( indent -- indent )
- prettyprint> \ }} prettyprint-word ;
+ prettyprint> \ }} prettyprint-word ;
: prettyprint-{{}} ( indent hashtable -- indent )
hash>alist dup length 0 = [
#! Unparse each element on its own line.
stack>list [ . ] each ;
-: .n namestack [.] ;
: .s datastack {.} ;
: .r callstack {.} ;
-: .c catchstack {.} ;
+: .n namestack [.] ;
+: .c catchstack [.] ;
! For integers only
: .b >bin print ;
] [
dupd pred ack >r pred r> ack
] ifte
- ] ifte ; compiled
+ ] ifte ;
[ 4093 ] [ 3 9 ack ] unit-test
USE: stack
USE: test
USE: lists
+USE: parser
+USE: stdio
[ f ] [ [ ] [ ] catch ] unit-test
"Hello" =
] unit-test
-[ ] [ [ ] print-error ] unit-test
-[ ] [ [ 2 car ] print-error ] unit-test
+"!!! The following error is part of the test" print
+
+[ ] [ [ 6 [ 12 [ "2 car" ] ] ] default-error-handler ] unit-test
+
+"!!! The following error is part of the test" print
+
+[ [ "2 car" ] parse ] [ default-error-handler ] catch
[ 2 ] [ yield "x" get ] unit-test
[ ] [ [ flush ] in-thread flush ] unit-test
[ ] [ [ "Errors, errors" throw ] in-thread ] unit-test
+yield
: :s ( -- ) "error-datastack" get {.} ;
: :r ( -- ) "error-callstack" get {.} ;
: :n ( -- ) "error-namestack" get [.] ;
-: :c ( -- ) "error-catchstack" get {.} ;
+: :c ( -- ) "error-catchstack" get [.] ;
: :get ( var -- value ) "error-namestack" get (get) ;
+: flush-error-handler ( error -- )
+ #! Last resort.
+ [ "Error in default error handler!" print drop ] when ;
+
: default-error-handler ( error -- )
- #! Print the error and return to the top level.
+ #! Print the error.
[
in-parser? [ parse-dump ] [ standard-dump ] ifte
"show stacks at time of error." print
\ :get prettyprint-word
" ( var -- value ) inspects the error namestack." print
- ] when* ;
+ ] [
+ flush-error-handler
+ ] catch ;
: print-error ( quot -- )
#! Execute a quotation, and if it throws an error, print it
: apply-compound ( word -- )
#! Infer a compound word's stack effect.
- dup "inline" word-property [
+ dup "inline-infer" word-property [
inline-compound
] [
[
infer-compound consume/produce
] [
[
- dup t "inline" set-word-property
+ dup t "inline-infer" set-word-property
inline-compound
] when
] catch
! partial evaluation, also for trace and step.
! Meta-stacks
+USE: listener
SYMBOL: meta-r
: push-r meta-r get vector-push ;
: pop-r meta-r get vector-pop ;
: &c
#! Print stepper catch stack.
- meta-c get {.} ;
+ meta-c get [.] ;
: &get ( var -- value )
#! Print stepper variable value.
" ( var -- value ) inspects the stepper namestack." print
\ step prettyprint-word " -- single step" print
\ (trace) prettyprint-word " -- trace until end" print
- \ (run) prettyprint-word " -- run until end" print ;
+ \ (run) prettyprint-word " -- run until end" print
+ \ exit prettyprint-word " -- exit single-stepper" print ;
: walk ( quot -- )
#! Single-step through execution of a quotation.
- init-interpreter
- meta-cf set
- walk-banner ;
+ [
+ "walk" listener-prompt set
+ init-interpreter
+ meta-cf set
+ walk-banner
+ listener
+ ] with-scope ;
!
! jEdit sends a packet with code to eval, it receives the output
! captured with with-string.
+USE: listener
: write-packet ( string -- )
dup str-length write-big-endian-32 write flush ;
: stream-server ( -- )
#! Execute this in the inferior Factor.
- "stdio" get <jedit-stream> "stdio" set ;
+ "stdio" get <jedit-stream> "stdio" set
+ print-banner ;
: jedit-lookup ( word vocabs -- )
#! A utility word called by the Factor plugin to get some
SYMBOL: cont-prompt
SYMBOL: listener-prompt
+SYMBOL: quit-flag
global [
"..." cont-prompt set
"ok" listener-prompt set
] bind
-: print-banner ( -- )
- "Factor " write version print
- "Copyright (C) 2003, 2004 Slava Pestov" print
- "Copyright (C) 2004 Chris Double" print
- "Type ``exit'' to exit, ``help'' for help." print ;
-
: prompt. ( text -- )
"prompt" style write-attr
! Print the space without a style, to workaround a bug in
" " write flush ;
: exit ( -- )
- "quit-flag" on ;
+ #! Exit the current listener.
+ quit-flag on ;
: (read-multiline) ( quot depth -- quot ? )
#! Flag indicates EOF.
#! EOF.
f depth (read-multiline) >r reverse r> ;
-: listener-step ( -- )
+: listen ( -- )
+ #! Wait for user input, and execute.
listener-prompt get prompt.
[ read-multiline [ call ] [ exit ] ifte ] print-error ;
-: listener-loop ( -- )
- "quit-flag" get [
- "quit-flag" off
- ] [
- listener-step listener-loop
- ] ifte ;
+: listener ( -- )
+ #! Run a listener loop that executes user input.
+ quit-flag get [ quit-flag off ] [ listen listener ] ifte ;
: kb. 1024 /i unparse write " KB" write ;
"Data space: " write (room.)
"Code space: " write (room.) ;
-: init-listener ( -- )
- print-banner
+: print-banner ( -- )
+ "Factor " write version print
+ "Copyright (C) 2003, 2004 Slava Pestov" print
+ "Copyright (C) 2004 Chris Double" print
+ "Type ``exit'' to exit, ``help'' for help." print
terpri
room.
- terpri
-
- listener-loop ;
+ terpri ;
: help ( -- )
"SESSION:" print
dup [
"client" set
log-client
- listener-loop
+ listener
] with-stream ;
: telnet-connection ( socket -- )
[ telnet-client ] in-thread drop ;
-: quit-flag ( -- ? )
- global [ "telnetd-quit-flag" get ] bind ;
-
-: clear-quit-flag ( -- )
- global [ f "telnetd-quit-flag" set ] bind ;
-
: telnetd-loop ( server -- server )
- quit-flag [
- dup >r accept telnet-connection r>
- telnetd-loop
- ] unless ;
+ [ [ accept telnet-connection ] keep ] forever ;
: telnetd ( port -- )
[
- <server> [
- telnetd-loop
- ] [
- clear-quit-flag swap fclose rethrow
- ] catch
+ <server> [ telnetd-loop ] [ swap fclose rethrow ] catch
] with-logging ;