prettyprinter recursion limit; better inspector
parent
253ce9cc1a
commit
d0cab962c0
|
|
@ -80,10 +80,10 @@ USE: url-encoding
|
||||||
] with-stream ;
|
] with-stream ;
|
||||||
|
|
||||||
: quit-flag ( -- ? )
|
: quit-flag ( -- ? )
|
||||||
"httpd-quit" get ;
|
global [ "httpd-quit" get ] bind ;
|
||||||
|
|
||||||
: clear-quit-flag ( -- )
|
: clear-quit-flag ( -- )
|
||||||
"httpd-quit" off ;
|
global [ "httpd-quit" off ] bind ;
|
||||||
|
|
||||||
: httpd-loop ( server -- server )
|
: httpd-loop ( server -- server )
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ IN: init
|
||||||
USE: combinators
|
USE: combinators
|
||||||
USE: compiler
|
USE: compiler
|
||||||
USE: continuations
|
USE: continuations
|
||||||
|
USE: errors
|
||||||
USE: interpreter
|
USE: interpreter
|
||||||
USE: kernel
|
USE: kernel
|
||||||
USE: lists
|
USE: lists
|
||||||
|
|
@ -84,9 +85,13 @@ USE: strings
|
||||||
: init-interpreter ( -- )
|
: init-interpreter ( -- )
|
||||||
#! If we're run stand-alone, start the interpreter on stdio.
|
#! If we're run stand-alone, start the interpreter on stdio.
|
||||||
"interactive" get [
|
"interactive" get [
|
||||||
|
[
|
||||||
[ "top-level-continuation" set ] callcc0
|
[ "top-level-continuation" set ] callcc0
|
||||||
|
|
||||||
interpreter-loop
|
interpreter-loop
|
||||||
|
] [
|
||||||
|
default-error-handler
|
||||||
|
] catch
|
||||||
] [
|
] [
|
||||||
f "top-level-continuation" set
|
f "top-level-continuation" set
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,6 @@ USE: words
|
||||||
#! List all usages of a word in all vocabularies.
|
#! List all usages of a word in all vocabularies.
|
||||||
intern vocabs [ dupd usages-in-vocab. ] each drop ;
|
intern vocabs [ dupd usages-in-vocab. ] each drop ;
|
||||||
|
|
||||||
: vocabs. ( -- )
|
|
||||||
#! List vocabularies.
|
|
||||||
"vocabularies" describe-object-path ;
|
|
||||||
|
|
||||||
: words. ( vocab -- )
|
|
||||||
#! List a vocabulary.
|
|
||||||
"vocabularies'" swap cat2 describe-object-path ;
|
|
||||||
|
|
||||||
: vocab-apropos ( substring vocab -- list )
|
: vocab-apropos ( substring vocab -- list )
|
||||||
#! Push a list of all words in a vocabulary whose names
|
#! Push a list of all words in a vocabulary whose names
|
||||||
#! contain a string.
|
#! contain a string.
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ IN: inspector
|
||||||
USE: combinators
|
USE: combinators
|
||||||
USE: format
|
USE: format
|
||||||
USE: kernel
|
USE: kernel
|
||||||
|
USE: hashtables
|
||||||
USE: lists
|
USE: lists
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: stack
|
USE: stack
|
||||||
|
|
@ -52,19 +53,25 @@ USE: vocabularies
|
||||||
uncons unparse swap relative>absolute-object-path
|
uncons unparse swap relative>absolute-object-path
|
||||||
default-style clone [ "link" set write-attr ] bind ;
|
default-style clone [ "link" set write-attr ] bind ;
|
||||||
|
|
||||||
: value. ( max [ name | value ] -- )
|
: var-name. ( max name -- )
|
||||||
dup [ car tuck pad-string write write ] dip
|
default-style clone [
|
||||||
": " write
|
tuck pad-string write
|
||||||
var. terpri ;
|
dup relative>absolute-object-path "link" set
|
||||||
|
write-attr
|
||||||
|
] bind ;
|
||||||
|
|
||||||
: describe-banner ( obj -- )
|
: value. ( max name value -- )
|
||||||
"OBJECT: " write dup .
|
>r var-name. ": " write r> . ;
|
||||||
"CLASS : " write class-of print
|
|
||||||
"-------" print ;
|
: describe-assoc ( alist -- )
|
||||||
|
dup [ car ] inject max-str-length swap
|
||||||
|
[ dupd uncons value. ] each drop ;
|
||||||
|
|
||||||
: describe-namespace ( namespace -- )
|
: describe-namespace ( namespace -- )
|
||||||
[ vars max-str-length vars-values ] bind
|
[ vars-values ] bind describe-assoc ;
|
||||||
[ dupd value. ] each drop ;
|
|
||||||
|
: describe-hashtable ( hashtables -- )
|
||||||
|
hash>alist describe-assoc ;
|
||||||
|
|
||||||
: describe ( obj -- )
|
: describe ( obj -- )
|
||||||
[
|
[
|
||||||
|
|
@ -74,8 +81,14 @@ USE: vocabularies
|
||||||
[ string? ]
|
[ string? ]
|
||||||
[ print ]
|
[ print ]
|
||||||
|
|
||||||
|
[ assoc? ]
|
||||||
|
[ describe-assoc ]
|
||||||
|
|
||||||
|
[ hashtable? ]
|
||||||
|
[ describe-hashtable ]
|
||||||
|
|
||||||
[ has-namespace? ]
|
[ has-namespace? ]
|
||||||
[ dup describe-banner describe-namespace ]
|
[ describe-namespace ]
|
||||||
|
|
||||||
[ drop t ]
|
[ drop t ]
|
||||||
[ prettyprint ]
|
[ prettyprint ]
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,8 @@ primitives,
|
||||||
max 2list length reverse nth list? 2rlist
|
max 2list length reverse nth list? 2rlist
|
||||||
all? clone-list clone-list-iter subset subset-iter
|
all? clone-list clone-list-iter subset subset-iter
|
||||||
subset-add car= cdr= cons= cons-hashcode
|
subset-add car= cdr= cons= cons-hashcode
|
||||||
tree-contains? =-or-contains? last* last inject
|
tree-contains? =-or-contains?
|
||||||
|
last* last inject
|
||||||
] [ worddef worddef, ] each
|
] [ worddef worddef, ] each
|
||||||
|
|
||||||
version,
|
version,
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ USE: unparser
|
||||||
t "interactive" set
|
t "interactive" set
|
||||||
|
|
||||||
init-stdio
|
init-stdio
|
||||||
|
"stdio" get <ansi-stream> "stdio" set
|
||||||
init-errors
|
init-errors
|
||||||
init-search-path
|
init-search-path
|
||||||
init-scratchpad
|
init-scratchpad
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,10 @@ USE: words
|
||||||
#! Change this to suit your tastes.
|
#! Change this to suit your tastes.
|
||||||
4 ;
|
4 ;
|
||||||
|
|
||||||
|
: prettyprint-limit ( -- limit )
|
||||||
|
#! Avoid infinite loops -- maximum indent, 10 levels.
|
||||||
|
"prettyprint-limit" get [ 40 ] unless* ;
|
||||||
|
|
||||||
: prettyprint-indent ( indent -- )
|
: prettyprint-indent ( indent -- )
|
||||||
#! Print the given number of spaces.
|
#! Print the given number of spaces.
|
||||||
" " fill write ;
|
" " fill write ;
|
||||||
|
|
@ -85,15 +89,32 @@ DEFER: prettyprint*
|
||||||
dup prettyprint-newline
|
dup prettyprint-newline
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
|
: check-recursion ( indent obj quot -- )
|
||||||
|
>r over prettyprint-limit >= [
|
||||||
|
r> drop drop "#< ... >" write
|
||||||
|
] [
|
||||||
|
r> call
|
||||||
|
] ifte ;
|
||||||
|
|
||||||
: prettyprint-[ ( indent -- indent )
|
: prettyprint-[ ( indent -- indent )
|
||||||
"[" write <prettyprint ;
|
"[" write <prettyprint ;
|
||||||
|
|
||||||
: prettyprint-] ( indent -- indent )
|
: prettyprint-] ( indent -- indent )
|
||||||
prettyprint> "]" write ;
|
prettyprint> "]" write ;
|
||||||
|
|
||||||
|
: (prettyprint-list) ( indent list -- indent )
|
||||||
|
uncons >r prettyprint-element r>
|
||||||
|
dup cons? [
|
||||||
|
(prettyprint-list)
|
||||||
|
] [
|
||||||
|
[
|
||||||
|
"|" write prettyprint-space prettyprint-element
|
||||||
|
] when*
|
||||||
|
] ifte ;
|
||||||
|
|
||||||
: prettyprint-list ( indent list -- indent )
|
: prettyprint-list ( indent list -- indent )
|
||||||
#! Pretty-print a list, without [ and ].
|
#! Pretty-print a list, without [ and ].
|
||||||
[ prettyprint-element ] each ;
|
[ (prettyprint-list) ] check-recursion ;
|
||||||
|
|
||||||
: prettyprint-[] ( indent list -- indent )
|
: prettyprint-[] ( indent list -- indent )
|
||||||
swap prettyprint-[ swap prettyprint-list prettyprint-] ;
|
swap prettyprint-[ swap prettyprint-list prettyprint-] ;
|
||||||
|
|
@ -106,7 +127,7 @@ DEFER: prettyprint*
|
||||||
|
|
||||||
: prettyprint-vector ( indent list -- indent )
|
: prettyprint-vector ( indent list -- indent )
|
||||||
#! Pretty-print a vector, without { and }.
|
#! Pretty-print a vector, without { and }.
|
||||||
[ prettyprint-element ] vector-each ;
|
[ [ prettyprint-element ] vector-each ] check-recursion ;
|
||||||
|
|
||||||
: prettyprint-{} ( indent list -- indent )
|
: prettyprint-{} ( indent list -- indent )
|
||||||
swap prettyprint-{ swap prettyprint-vector prettyprint-} ;
|
swap prettyprint-{ swap prettyprint-vector prettyprint-} ;
|
||||||
|
|
@ -142,7 +163,7 @@ DEFER: prettyprint*
|
||||||
: prettyprint* ( indent obj -- indent )
|
: prettyprint* ( indent obj -- indent )
|
||||||
[
|
[
|
||||||
[ f = ] [ prettyprint-object ]
|
[ f = ] [ prettyprint-object ]
|
||||||
[ list? ] [ prettyprint-[] ]
|
[ cons? ] [ prettyprint-[] ]
|
||||||
[ vector? ] [ prettyprint-{} ]
|
[ vector? ] [ prettyprint-{} ]
|
||||||
[ comment? ] [ prettyprint-comment ]
|
[ comment? ] [ prettyprint-comment ]
|
||||||
[ word? ] [ prettyprint-word ]
|
[ word? ] [ prettyprint-word ]
|
||||||
|
|
@ -168,7 +189,9 @@ DEFER: prettyprint*
|
||||||
|
|
||||||
: . ( obj -- )
|
: . ( obj -- )
|
||||||
<namespace> [
|
<namespace> [
|
||||||
"prettyprint-single-line" on prettyprint
|
"prettyprint-single-line" on
|
||||||
|
prettyprint-indent 4 * "prettyprint-limit" set
|
||||||
|
prettyprint
|
||||||
] bind ;
|
] bind ;
|
||||||
|
|
||||||
: [.] ( list -- )
|
: [.] ( list -- )
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
void fatal_error(char* msg, CELL tagged);
|
void fatal_error(char* msg, CELL tagged);
|
||||||
void critical_error(char* msg, CELL tagged);
|
void critical_error(char* msg, CELL tagged);
|
||||||
void fix_stacks(void);
|
void fix_stacks(void);
|
||||||
|
void check_stacks(void);
|
||||||
void throw_error(CELL object);
|
void throw_error(CELL object);
|
||||||
void general_error(CELL error, CELL tagged);
|
void general_error(CELL error, CELL tagged);
|
||||||
void type_error(CELL type, CELL tagged);
|
void type_error(CELL type, CELL tagged);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
/* Memory heap size */
|
/* Memory heap size */
|
||||||
#define DEFAULT_ARENA (4 * 1024 * 1024)
|
#define DEFAULT_ARENA (4 * 1024 * 1024)
|
||||||
#define STACK_SIZE 256
|
#define STACK_SIZE 1024
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
|
||||||
14
native/run.c
14
native/run.c
|
|
@ -7,18 +7,6 @@ void clear_environment(void)
|
||||||
env.user[i] = 0;
|
env.user[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_datastack(void)
|
|
||||||
{
|
|
||||||
env.ds = UNTAG(env.ds_bot) + sizeof(ARRAY);
|
|
||||||
env.dt = empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset_callstack(void)
|
|
||||||
{
|
|
||||||
env.cs = UNTAG(env.cs_bot) + sizeof(ARRAY);
|
|
||||||
cpush(empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_environment(void)
|
void init_environment(void)
|
||||||
{
|
{
|
||||||
/* + CELLS * 2 to skip header and length cell */
|
/* + CELLS * 2 to skip header and length cell */
|
||||||
|
|
@ -40,6 +28,8 @@ void run(void)
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
check_stacks();
|
||||||
|
|
||||||
if(env.cf == F)
|
if(env.cf == F)
|
||||||
{
|
{
|
||||||
if(cpeek() == empty)
|
if(cpeek() == empty)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,17 @@
|
||||||
#include "factor.h"
|
#include "factor.h"
|
||||||
|
|
||||||
|
void reset_datastack(void)
|
||||||
|
{
|
||||||
|
env.ds = UNTAG(env.ds_bot) + sizeof(ARRAY);
|
||||||
|
env.dt = empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_callstack(void)
|
||||||
|
{
|
||||||
|
env.cs = UNTAG(env.cs_bot) + sizeof(ARRAY);
|
||||||
|
cpush(empty);
|
||||||
|
}
|
||||||
|
|
||||||
void primitive_drop(void)
|
void primitive_drop(void)
|
||||||
{
|
{
|
||||||
check_non_empty(env.dt);
|
check_non_empty(env.dt);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,22 @@
|
||||||
|
#define UNDERFLOW_CHECKING
|
||||||
|
|
||||||
|
#define OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + object_size(bot))
|
||||||
|
|
||||||
|
INLINE void check_stacks(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef UNDERFLOW_CHECKING
|
||||||
|
if(OVERFLOW(env.ds,env.ds_bot))
|
||||||
|
fatal_error("datastack overflow",env.ds);
|
||||||
|
if(OVERFLOW(env.cs,env.cs_bot))
|
||||||
|
fatal_error("callstack overflow",env.ds);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_datastack(void);
|
||||||
|
void reset_callstack(void);
|
||||||
|
|
||||||
void primitive_drop(void);
|
void primitive_drop(void);
|
||||||
void primitive_dup(void);
|
void primitive_dup(void);
|
||||||
void primitive_swap(void);
|
void primitive_swap(void);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue