better error reporting in native factor
parent
3712ae68e5
commit
b23622f947
|
@ -1,10 +1,8 @@
|
||||||
- plugin should not exit jEdit on fatal errors
|
- plugin should not exit jEdit on fatal errors
|
||||||
- auto insert USE:
|
- auto insert USE:
|
||||||
- add a socket timeout
|
- add a socket timeout
|
||||||
- read# and eof
|
|
||||||
- don't allow multiple reads on the same port
|
- don't allow multiple reads on the same port
|
||||||
- multiple tasks should be able to write to the same port
|
- multiple tasks should be able to write to the same port
|
||||||
- prettyprinting an empty vector
|
|
||||||
- jvm factor -- still supporting httpd?
|
- jvm factor -- still supporting httpd?
|
||||||
- make inferior.factor nicer to use
|
- make inferior.factor nicer to use
|
||||||
|
|
||||||
|
@ -47,7 +45,6 @@
|
||||||
- accept multi-line input in listener
|
- accept multi-line input in listener
|
||||||
- gc call in the middle of some ops might affect callstack
|
- gc call in the middle of some ops might affect callstack
|
||||||
- better i/o scheduler
|
- better i/o scheduler
|
||||||
- better error reporting
|
|
||||||
|
|
||||||
+ JVM compiler:
|
+ JVM compiler:
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
<include name="factor/**/*.class"/>
|
<include name="factor/**/*.class"/>
|
||||||
<include name="factor/**/*.props"/>
|
<include name="factor/**/*.props"/>
|
||||||
<include name="factor/**/*.bsh"/>
|
<include name="factor/**/*.bsh"/>
|
||||||
|
<include name="factor/**/*.txt"/>
|
||||||
<include name="*.xml"/>
|
<include name="*.xml"/>
|
||||||
<include name="library/**/*.factor"/>
|
<include name="library/**/*.factor"/>
|
||||||
<include name="org/**/*.class"/>
|
<include name="org/**/*.class"/>
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class FactorLib
|
||||||
int read = 0;
|
int read = 0;
|
||||||
while((read = in.read(bytes,offset,count - offset)) > 0)
|
while((read = in.read(bytes,offset,count - offset)) > 0)
|
||||||
offset += read;
|
offset += read;
|
||||||
return new String(bytes,"ASCII");
|
return new String(bytes,0,offset,"ASCII");
|
||||||
} //}}}
|
} //}}}
|
||||||
|
|
||||||
//{{{ readCount() method
|
//{{{ readCount() method
|
||||||
|
@ -234,6 +234,6 @@ public class FactorLib
|
||||||
int read = 0;
|
int read = 0;
|
||||||
while((read = in.read(chars,offset,count - offset)) > 0)
|
while((read = in.read(chars,offset,count - offset)) > 0)
|
||||||
offset += read;
|
offset += read;
|
||||||
return new String(chars);
|
return new String(chars,0,offset);
|
||||||
} //}}}
|
} //}}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ USE: strings
|
||||||
: run-file ( path -- )
|
: run-file ( path -- )
|
||||||
parse-file call ;
|
parse-file call ;
|
||||||
|
|
||||||
|
: <resource-stream> ( path -- stream )
|
||||||
|
<rreader> f <char-stream> ;
|
||||||
|
|
||||||
: parse-resource* ( resource -- list )
|
: parse-resource* ( resource -- list )
|
||||||
dup <rreader> swap "resource:" swap cat2 swap parse-stream ;
|
dup <rreader> swap "resource:" swap cat2 swap parse-stream ;
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,13 @@ USE: stdio
|
||||||
"/library/platform/native/parser.factor"
|
"/library/platform/native/parser.factor"
|
||||||
"/library/platform/native/parse-syntax.factor"
|
"/library/platform/native/parse-syntax.factor"
|
||||||
"/library/platform/native/parse-stream.factor"
|
"/library/platform/native/parse-stream.factor"
|
||||||
|
"/library/platform/native/unparser.factor"
|
||||||
|
"/library/format.factor"
|
||||||
|
"/library/styles.factor"
|
||||||
|
"/library/vocabulary-style.factor"
|
||||||
|
"/library/prettyprint.factor"
|
||||||
|
"/library/debugger.factor"
|
||||||
|
"/library/platform/native/debugger.factor"
|
||||||
"/library/platform/native/init.factor"
|
"/library/platform/native/init.factor"
|
||||||
|
|
||||||
"/library/math/math.factor"
|
"/library/math/math.factor"
|
||||||
|
|
|
@ -40,38 +40,65 @@ USE: strings
|
||||||
USE: unparser
|
USE: unparser
|
||||||
USE: vectors
|
USE: vectors
|
||||||
|
|
||||||
: kernel-error? ( obj -- ? )
|
: expired-port-error ( obj -- )
|
||||||
dup cons? [ car fixnum? ] [ drop f ] ifte ;
|
"Expired port: " write . ;
|
||||||
|
|
||||||
: ?vector-nth ( n vec -- obj )
|
: undefined-word-error ( obj -- )
|
||||||
over [
|
"Undefined word: " write . ;
|
||||||
dup >r vector-length min 0 max r> vector-nth
|
|
||||||
] [
|
|
||||||
2drop f
|
|
||||||
] ifte ;
|
|
||||||
|
|
||||||
: error# ( n -- str )
|
: type-check-error ( list -- )
|
||||||
|
"Type check error" print
|
||||||
|
uncons car dup "Object: " write .
|
||||||
|
"Object type: " write type-of type-name print
|
||||||
|
"Expected type: " write type-name print ;
|
||||||
|
|
||||||
|
: array-range-error ( list -- )
|
||||||
|
"Array range check error" print
|
||||||
|
unswons "Object: " write .
|
||||||
|
uncons car "Maximum index: " write .
|
||||||
|
"Requested index: " write . ;
|
||||||
|
|
||||||
|
: io-error ( list -- )
|
||||||
|
"I/O error in kernel function " write
|
||||||
|
unswons write ": " write car print ;
|
||||||
|
|
||||||
|
: numerical-comparison-error ( list -- )
|
||||||
|
"Cannot compare " write unswons unparse write
|
||||||
|
" with " write unparse print ;
|
||||||
|
|
||||||
|
: float-format-error ( list -- )
|
||||||
|
"Invalid floating point literal format: " write car . ;
|
||||||
|
|
||||||
|
: signal-error ( obj -- )
|
||||||
|
"Operating system signal " write . ;
|
||||||
|
|
||||||
|
: io-task-twice-error ( obj -- )
|
||||||
|
"Attempting to perform two simulatenous I/O operations on "
|
||||||
|
write . ;
|
||||||
|
|
||||||
|
: no-io-tasks-error ( obj -- )
|
||||||
|
"No I/O tasks" print ;
|
||||||
|
|
||||||
|
: kernel-error. ( obj n -- str )
|
||||||
{
|
{
|
||||||
"Expired port: "
|
expired-port-error
|
||||||
"Undefined word: "
|
undefined-word-error
|
||||||
"Type check: "
|
type-check-error
|
||||||
"Array range check: "
|
array-range-error
|
||||||
"Underflow"
|
io-error
|
||||||
"I/O error: "
|
numerical-comparison-error
|
||||||
"Overflow"
|
float-format-error
|
||||||
"Incomparable types: "
|
signal-error
|
||||||
"Float format: "
|
io-task-twice-error
|
||||||
"Signal "
|
no-io-tasks-error
|
||||||
"Adding I/O task twice on port: "
|
} vector-nth execute ;
|
||||||
"No I/O tasks"
|
|
||||||
} ?vector-nth ;
|
|
||||||
|
|
||||||
: ?kernel-error ( cons -- error# param )
|
: kernel-error? ( obj -- ? )
|
||||||
dup cons? [ uncons dup cons? [ car ] when ] [ f ] ifte ;
|
dup cons? [ uncons cons? swap fixnum? and ] [ drop f ] ifte ;
|
||||||
|
|
||||||
: kernel-error. ( error -- )
|
|
||||||
?kernel-error swap error# dup "" ? write
|
|
||||||
dup [ . ] [ drop terpri ] ifte ;
|
|
||||||
|
|
||||||
: error. ( error -- str )
|
: error. ( error -- str )
|
||||||
dup kernel-error? [ kernel-error. ] [ . ] ifte ;
|
dup kernel-error? [
|
||||||
|
uncons car swap kernel-error.
|
||||||
|
] [
|
||||||
|
dup string? [ print ] [ . ] ifte
|
||||||
|
] ifte ;
|
||||||
|
|
|
@ -82,23 +82,26 @@ USE: vectors
|
||||||
[ drop t ] [ ( return the object ) ]
|
[ drop t ] [ ( return the object ) ]
|
||||||
] cond ;
|
] cond ;
|
||||||
|
|
||||||
: class-of ( obj -- name )
|
: type-name ( n -- str )
|
||||||
[
|
[
|
||||||
[ fixnum? ] [ drop "fixnum" ]
|
[ 0 | "fixnum" ]
|
||||||
[ bignum? ] [ drop "bignum" ]
|
[ 1 | "word" ]
|
||||||
[ ratio? ] [ drop "ratio" ]
|
[ 2 | "cons" ]
|
||||||
[ float? ] [ drop "float" ]
|
[ 4 | "ratio" ]
|
||||||
[ complex? ] [ drop "complex" ]
|
[ 5 | "complex" ]
|
||||||
[ cons? ] [ drop "cons" ]
|
[ 6 | "f" ]
|
||||||
[ word? ] [ drop "word" ]
|
[ 7 | "t" ]
|
||||||
[ f = ] [ drop "f" ]
|
[ 9 | "vector" ]
|
||||||
[ t = ] [ drop "t" ]
|
[ 10 | "string" ]
|
||||||
[ vector? ] [ drop "vector" ]
|
[ 11 | "sbuf" ]
|
||||||
[ string? ] [ drop "string" ]
|
[ 12 | "port" ]
|
||||||
[ sbuf? ] [ drop "sbuf" ]
|
[ 13 | "bignum" ]
|
||||||
[ port? ] [ drop "port" ]
|
[ 14 | "float" ]
|
||||||
[ drop t ] [ drop "unknown" ]
|
[ 100 | "fixnum/bignum" ]
|
||||||
] cond ;
|
[ 101 | "fixnum/bignum/ratio" ]
|
||||||
|
[ 102 | "fixnum/bignum/ratio/float" ]
|
||||||
|
[ 103 | "fixnum/bignum/ratio/float/complex" ]
|
||||||
|
] assoc ;
|
||||||
|
|
||||||
: toplevel ( -- )
|
: toplevel ( -- )
|
||||||
init-namespaces
|
init-namespaces
|
||||||
|
|
|
@ -122,5 +122,5 @@ USE: words
|
||||||
[ float? ] [ unparse-float fix-float ]
|
[ float? ] [ unparse-float fix-float ]
|
||||||
[ complex? ] [ unparse-complex ]
|
[ complex? ] [ unparse-complex ]
|
||||||
[ string? ] [ unparse-str ]
|
[ string? ] [ unparse-str ]
|
||||||
[ drop t ] [ <% "#<" % class-of % ">" % %> ]
|
[ drop t ] [ <% "#<" % type-of type-name % ">" % %> ]
|
||||||
] cond ;
|
] cond ;
|
||||||
|
|
|
@ -130,8 +130,12 @@ DEFER: prettyprint*
|
||||||
#! Pretty-print a vector, without { and }.
|
#! Pretty-print a vector, without { and }.
|
||||||
[ [ prettyprint-element ] vector-each ] check-recursion ;
|
[ [ prettyprint-element ] vector-each ] check-recursion ;
|
||||||
|
|
||||||
: prettyprint-{} ( indent list -- indent )
|
: prettyprint-{} ( indent vector -- indent )
|
||||||
swap prettyprint-{ swap prettyprint-vector prettyprint-} ;
|
dup vector-length 0 = [
|
||||||
|
drop "{ }" write
|
||||||
|
] [
|
||||||
|
swap prettyprint-{ swap prettyprint-vector prettyprint-}
|
||||||
|
] ifte ;
|
||||||
|
|
||||||
: trim-newline ( str -- str )
|
: trim-newline ( str -- str )
|
||||||
dup ends-with-newline? dup [ nip ] [ drop ] ifte ;
|
dup ends-with-newline? dup [ nip ] [ drop ] ifte ;
|
||||||
|
|
|
@ -23,3 +23,9 @@ USE: test
|
||||||
] [
|
] [
|
||||||
"/library/test/io/mac-os-eol.txt" <resource-stream> lines-test
|
"/library/test/io/mac-os-eol.txt" <resource-stream> lines-test
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
"This is a line.\rThis is another line.\r"
|
||||||
|
] [
|
||||||
|
500 "/library/test/io/mac-os-eol.txt" <resource-stream> fread#
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
IN: scratchpad
|
IN: scratchpad
|
||||||
|
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
|
USE: stdio
|
||||||
USE: test
|
USE: test
|
||||||
USE: threads
|
USE: threads
|
||||||
|
|
||||||
! This only tests co-operative threads in CFactor.
|
! This only tests co-operative threads in CFactor.
|
||||||
|
! It won't give intended results in Java (or in CFactor if
|
||||||
|
! we ever get preemptive threads).
|
||||||
|
|
||||||
3 "x" set
|
3 "x" set
|
||||||
[ yield 2 "x" set ] in-thread
|
[ yield 2 "x" set ] in-thread
|
||||||
[ 2 ] [ yield "x" get ] unit-test
|
[ 2 ] [ yield "x" get ] unit-test
|
||||||
|
|
||||||
|
[ flush ] in-thread flush
|
||||||
|
|
|
@ -162,26 +162,29 @@ CELL divfloat_complex(CELL x, CELL y)
|
||||||
return possibly_complex(divfloat(r,mag),divfloat(i,mag));
|
return possibly_complex(divfloat(r,mag),divfloat(i,mag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define INCOMPARABLE(x,y) general_error(ERROR_INCOMPARABLE, \
|
||||||
|
tag_cons(cons(tag_complex(x),tag_complex(y))));
|
||||||
|
|
||||||
CELL less_complex(CELL x, CELL y)
|
CELL less_complex(CELL x, CELL y)
|
||||||
{
|
{
|
||||||
general_error(ERROR_INCOMPARABLE,tag_cons(cons(x,y)));
|
INCOMPARABLE(x,y);
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELL lesseq_complex(CELL x, CELL y)
|
CELL lesseq_complex(CELL x, CELL y)
|
||||||
{
|
{
|
||||||
general_error(ERROR_INCOMPARABLE,tag_cons(cons(x,y)));
|
INCOMPARABLE(x,y);
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELL greater_complex(CELL x, CELL y)
|
CELL greater_complex(CELL x, CELL y)
|
||||||
{
|
{
|
||||||
general_error(ERROR_INCOMPARABLE,tag_cons(cons(x,y)));
|
INCOMPARABLE(x,y);
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELL greatereq_complex(CELL x, CELL y)
|
CELL greatereq_complex(CELL x, CELL y)
|
||||||
{
|
{
|
||||||
general_error(ERROR_INCOMPARABLE,tag_cons(cons(x,y)));
|
INCOMPARABLE(x,y);
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,12 @@
|
||||||
#define ERROR_UNDEFINED_WORD (1<<3)
|
#define ERROR_UNDEFINED_WORD (1<<3)
|
||||||
#define ERROR_TYPE (2<<3)
|
#define ERROR_TYPE (2<<3)
|
||||||
#define ERROR_RANGE (3<<3)
|
#define ERROR_RANGE (3<<3)
|
||||||
#define ERROR_UNDERFLOW (4<<3)
|
#define ERROR_IO (4<<3)
|
||||||
#define ERROR_IO (5<<3)
|
#define ERROR_INCOMPARABLE (5<<3)
|
||||||
#define ERROR_OVERFLOW (6<<3)
|
#define ERROR_FLOAT_FORMAT (6<<3)
|
||||||
#define ERROR_INCOMPARABLE (7<<3)
|
#define ERROR_SIGNAL (7<<3)
|
||||||
#define ERROR_FLOAT_FORMAT (8<<3)
|
#define ERROR_IO_TASK_TWICE (8<<3)
|
||||||
#define ERROR_SIGNAL (9<<3)
|
#define ERROR_IO_TASK_NONE (9<<3)
|
||||||
#define ERROR_IO_TASK_TWICE (10<<3)
|
|
||||||
#define ERROR_IO_TASK_NONE (11<<3)
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue