Merge branch 'master' of git://factorcode.org/git/factor

Slava Pestov 2008-03-20 17:26:50 -05:00
commit a2a81b3eaa
22 changed files with 57 additions and 112 deletions

View File

@ -65,21 +65,21 @@ TUPLE: library path abi dll ;
TUPLE: alien-callback return parameters abi quot xt ; TUPLE: alien-callback return parameters abi quot xt ;
TUPLE: alien-callback-error ; ERROR: alien-callback-error ;
: alien-callback ( return parameters abi quot -- alien ) : alien-callback ( return parameters abi quot -- alien )
\ alien-callback-error construct-empty throw ; alien-callback-error ;
TUPLE: alien-indirect return parameters abi ; TUPLE: alien-indirect return parameters abi ;
TUPLE: alien-indirect-error ; ERROR: alien-indirect-error ;
: alien-indirect ( ... funcptr return parameters abi -- ) : alien-indirect ( ... funcptr return parameters abi -- )
\ alien-indirect-error construct-empty throw ; alien-indirect-error ;
TUPLE: alien-invoke library function return parameters ; TUPLE: alien-invoke library function return parameters ;
TUPLE: alien-invoke-error library symbol ; ERROR: alien-invoke-error library symbol ;
: alien-invoke ( ... return library function parameters -- ... ) : alien-invoke ( ... return library function parameters -- ... )
2over \ alien-invoke-error construct-boa throw ; 2over alien-invoke-error ;

View File

@ -26,9 +26,7 @@ global [
c-types [ H{ } assoc-like ] change c-types [ H{ } assoc-like ] change
] bind ] bind
TUPLE: no-c-type name ; ERROR: no-c-type name ;
: no-c-type ( type -- * ) \ no-c-type construct-boa throw ;
: (c-type) ( name -- type/f ) : (c-type) ( name -- type/f )
c-types get-global at dup [ c-types get-global at dup [

View File

@ -79,7 +79,7 @@ nl
"." write flush "." write flush
{ {
malloc free memcpy malloc calloc free memcpy
} compile } compile
" done" print flush " done" print flush

View File

@ -5,16 +5,12 @@ USING: arrays sequences sequences.private math.private
kernel kernel.private math assocs quotations vectors kernel kernel.private math assocs quotations vectors
hashtables sorting ; hashtables sorting ;
TUPLE: no-cond ; ERROR: no-cond ;
: no-cond ( -- * ) \ no-cond construct-empty throw ;
: cond ( assoc -- ) : cond ( assoc -- )
[ first call ] find nip dup [ second call ] [ no-cond ] if ; [ first call ] find nip dup [ second call ] [ no-cond ] if ;
TUPLE: no-case ; ERROR: no-case ;
: no-case ( -- * ) \ no-case construct-empty throw ;
: case ( obj assoc -- ) : case ( obj assoc -- )
[ dup array? [ dupd first = ] [ quotation? ] if ] find nip [ dup array? [ dupd first = ] [ quotation? ] if ] find nip

View File

@ -75,9 +75,7 @@ SYMBOL: error-hook
: try ( quot -- ) : try ( quot -- )
[ error-hook get call ] recover ; [ error-hook get call ] recover ;
TUPLE: assert got expect ; ERROR: assert got expect ;
: assert ( got expect -- * ) \ assert construct-boa throw ;
: assert= ( a b -- ) 2dup = [ 2drop ] [ assert ] if ; : assert= ( a b -- ) 2dup = [ 2drop ] [ assert ] if ;
@ -86,28 +84,22 @@ TUPLE: assert got expect ;
: trim-datastacks ( seq1 seq2 -- seq1' seq2' ) : trim-datastacks ( seq1 seq2 -- seq1' seq2' )
2dup [ length ] 2apply min tuck tail >r tail r> ; 2dup [ length ] 2apply min tuck tail >r tail r> ;
TUPLE: relative-underflow stack ; ERROR: relative-underflow stack ;
: relative-underflow ( before after -- * )
trim-datastacks nip \ relative-underflow construct-boa throw ;
M: relative-underflow summary M: relative-underflow summary
drop "Too many items removed from data stack" ; drop "Too many items removed from data stack" ;
TUPLE: relative-overflow stack ; ERROR: relative-overflow stack ;
M: relative-overflow summary M: relative-overflow summary
drop "Superfluous items pushed to data stack" ; drop "Superfluous items pushed to data stack" ;
: relative-overflow ( before after -- * )
trim-datastacks drop \ relative-overflow construct-boa throw ;
: assert-depth ( quot -- ) : assert-depth ( quot -- )
>r datastack r> swap slip >r datastack r> >r datastack r> swap slip >r datastack r>
2dup [ length ] compare sgn { 2dup [ length ] compare sgn {
{ -1 [ relative-underflow ] } { -1 [ trim-datastacks nip relative-underflow ] }
{ 0 [ 2drop ] } { 0 [ 2drop ] }
{ 1 [ relative-overflow ] } { 1 [ trim-datastacks drop relative-overflow ] }
} case ; inline } case ; inline
: expired-error. ( obj -- ) : expired-error. ( obj -- )
@ -210,13 +202,13 @@ M: no-method error.
M: no-math-method summary M: no-math-method summary
drop "No suitable arithmetic method" ; drop "No suitable arithmetic method" ;
M: check-closed summary M: stream-closed-twice summary
drop "Attempt to perform I/O on closed stream" ; drop "Attempt to perform I/O on closed stream" ;
M: check-method summary M: check-method summary
drop "Invalid parameters for create-method" ; drop "Invalid parameters for create-method" ;
M: check-tuple summary M: no-tuple-class summary
drop "Invalid class for define-constructor" ; drop "Invalid class for define-constructor" ;
M: no-cond summary M: no-cond summary
@ -254,7 +246,7 @@ M: no-compilation-unit error.
M: no-vocab summary M: no-vocab summary
drop "Vocabulary does not exist" ; drop "Vocabulary does not exist" ;
M: check-ptr summary M: bad-ptr summary
drop "Memory allocation failed" ; drop "Memory allocation failed" ;
M: double-free summary M: double-free summary

View File

@ -3,10 +3,7 @@
IN: definitions IN: definitions
USING: kernel sequences namespaces assocs graphs ; USING: kernel sequences namespaces assocs graphs ;
TUPLE: no-compilation-unit definition ; ERROR: no-compilation-unit definition ;
: no-compilation-unit ( definition -- * )
\ no-compilation-unit construct-boa throw ;
GENERIC: where ( defspec -- loc ) GENERIC: where ( defspec -- loc )

View File

@ -33,10 +33,7 @@ PREDICATE: class math-class ( object -- ? )
dup empty? [ [ dip ] curry [ ] like ] unless dup empty? [ [ dip ] curry [ ] like ] unless
r> append ; r> append ;
TUPLE: no-math-method left right generic ; ERROR: no-math-method left right generic ;
: no-math-method ( left right generic -- * )
\ no-math-method construct-boa throw ;
: default-math-method ( generic -- quot ) : default-math-method ( generic -- quot )
[ no-math-method ] curry [ ] like ; [ no-math-method ] curry [ ] like ;

View File

@ -26,10 +26,7 @@ SYMBOL: (dispatch#)
: unpicker ( -- quot ) \ (dispatch#) get unpickers nth ; : unpicker ( -- quot ) \ (dispatch#) get unpickers nth ;
TUPLE: no-method object generic ; ERROR: no-method object generic ;
: no-method ( object generic -- * )
\ no-method construct-boa throw ;
: error-method ( word -- quot ) : error-method ( word -- quot )
picker swap [ no-method ] curry append ; picker swap [ no-method ] curry append ;

View File

@ -514,10 +514,10 @@ DEFER: an-inline-word
{ 0 1 } [ [ 2 ] [ 2 ] [ + ] compose compose call ] must-infer-as { 0 1 } [ [ 2 ] [ 2 ] [ + ] compose compose call ] must-infer-as
TUPLE: custom-error ; ERROR: custom-error ;
[ T{ effect f 0 0 t } ] [ [ T{ effect f 0 0 t } ] [
[ custom-error construct-boa throw ] infer [ custom-error ] infer
] unit-test ] unit-test
: funny-throw throw ; inline : funny-throw throw ; inline

View File

@ -64,14 +64,11 @@ M: pair (bitfield-quot) ( spec -- quot )
\ get-slots [ [get-slots] ] 1 define-transform \ get-slots [ [get-slots] ] 1 define-transform
TUPLE: duplicated-slots-error names ; ERROR: duplicated-slots-error names ;
M: duplicated-slots-error summary M: duplicated-slots-error summary
drop "Calling set-slots with duplicate slot setters" ; drop "Calling set-slots with duplicate slot setters" ;
: duplicated-slots-error ( names -- * )
\ duplicated-slots-error construct-boa throw ;
\ set-slots [ \ set-slots [
dup all-unique? dup all-unique?
[ <reversed> [get-slots] ] [ duplicated-slots-error ] if [ <reversed> [get-slots] ] [ duplicated-slots-error ] if

View File

@ -18,17 +18,13 @@ GENERIC: <decoder> ( stream decoding -- newstream )
TUPLE: decoder stream code cr ; TUPLE: decoder stream code cr ;
TUPLE: decode-error ; ERROR: decode-error ;
: decode-error ( -- * ) \ decode-error construct-empty throw ;
GENERIC: <encoder> ( stream encoding -- newstream ) GENERIC: <encoder> ( stream encoding -- newstream )
TUPLE: encoder stream code ; TUPLE: encoder stream code ;
TUPLE: encode-error ; ERROR: encode-error ;
: encode-error ( -- * ) \ encode-error construct-empty throw ;
! Decoding ! Decoding

View File

@ -48,10 +48,7 @@ M: object root-directory? ( path -- ? ) path-separator? ;
: special-directory? ( name -- ? ) { "." ".." } member? ; : special-directory? ( name -- ? ) { "." ".." } member? ;
TUPLE: no-parent-directory path ; ERROR: no-parent-directory path ;
: no-parent-directory ( path -- * )
\ no-parent-directory construct-boa throw ;
: parent-directory ( path -- parent ) : parent-directory ( path -- parent )
right-trim-separators { right-trim-separators {

View File

@ -11,11 +11,10 @@ TUPLE: duplex-stream in out closed? ;
: <duplex-stream> ( in out -- stream ) : <duplex-stream> ( in out -- stream )
f duplex-stream construct-boa ; f duplex-stream construct-boa ;
TUPLE: check-closed ; ERROR: stream-closed-twice ;
: check-closed ( stream -- ) : check-closed ( stream -- )
duplex-stream-closed? duplex-stream-closed? [ stream-closed-twice ] when ;
[ \ check-closed construct-boa throw ] when ;
: duplex-stream-in+ ( duplex -- stream ) : duplex-stream-in+ ( duplex -- stream )
dup check-closed duplex-stream-in ; dup check-closed duplex-stream-in ;

View File

@ -23,20 +23,14 @@ SYMBOL: mallocs
PRIVATE> PRIVATE>
TUPLE: check-ptr ; ERROR: bad-ptr ;
: check-ptr ( c-ptr -- c-ptr ) : check-ptr ( c-ptr -- c-ptr )
[ \ check-ptr construct-boa throw ] unless* ; [ bad-ptr ] unless* ;
TUPLE: double-free ; ERROR: double-free ;
: double-free ( -- * ) ERROR: realloc-error ptr size ;
\ double-free construct-empty throw ;
TUPLE: realloc-error ptr size ;
: realloc-error ( alien size -- * )
\ realloc-error construct-boa throw ;
<PRIVATE <PRIVATE

View File

@ -98,10 +98,7 @@ M: lexer skip-word ( lexer -- )
: scan ( -- str/f ) lexer get parse-token ; : scan ( -- str/f ) lexer get parse-token ;
TUPLE: bad-escape ; ERROR: bad-escape ;
: bad-escape ( -- * )
\ bad-escape construct-empty throw ;
M: bad-escape summary drop "Bad escape code" ; M: bad-escape summary drop "Bad escape code" ;
@ -215,10 +212,7 @@ SYMBOL: in
: set-in ( name -- ) : set-in ( name -- )
check-vocab-string dup in set create-vocab (use+) ; check-vocab-string dup in set create-vocab (use+) ;
TUPLE: unexpected want got ; ERROR: unexpected want got ;
: unexpected ( want got -- * )
\ unexpected construct-boa throw ;
PREDICATE: unexpected unexpected-eof PREDICATE: unexpected unexpected-eof
unexpected-got not ; unexpected-got not ;
@ -294,10 +288,7 @@ M: no-word summary
: CREATE-METHOD ( -- method ) : CREATE-METHOD ( -- method )
scan-word bootstrap-word scan-word create-method-in ; scan-word bootstrap-word scan-word create-method-in ;
TUPLE: staging-violation word ; ERROR: staging-violation word ;
: staging-violation ( word -- * )
\ staging-violation construct-boa throw ;
M: staging-violation summary M: staging-violation summary
drop drop
@ -352,9 +343,7 @@ SYMBOL: lexer-factory
] if ] if
] if ; ] if ;
TUPLE: bad-number ; ERROR: bad-number ;
: bad-number ( -- * ) \ bad-number construct-boa throw ;
: parse-base ( parsed base -- parsed ) : parse-base ( parsed base -- parsed )
scan swap base> [ bad-number ] unless* parsed ; scan swap base> [ bad-number ] unless* parsed ;

View File

@ -41,19 +41,14 @@ M: sequence lengthen 2dup length > [ set-length ] [ 2drop ] if ;
: bounds-check? ( n seq -- ? ) : bounds-check? ( n seq -- ? )
length 1- 0 swap between? ; inline length 1- 0 swap between? ; inline
TUPLE: bounds-error index seq ; ERROR: bounds-error index seq ;
: bounds-error ( n seq -- * )
\ bounds-error construct-boa throw ;
: bounds-check ( n seq -- n seq ) : bounds-check ( n seq -- n seq )
2dup bounds-check? [ bounds-error ] unless ; inline 2dup bounds-check? [ bounds-error ] unless ; inline
MIXIN: immutable-sequence MIXIN: immutable-sequence
TUPLE: immutable seq ; ERROR: immutable seq ;
: immutable ( seq -- * ) \ immutable construct-boa throw ;
M: immutable-sequence set-nth immutable ; M: immutable-sequence set-nth immutable ;
@ -190,8 +185,7 @@ TUPLE: slice from to seq ;
: collapse-slice ( m n slice -- m' n' seq ) : collapse-slice ( m n slice -- m' n' seq )
dup slice-from swap slice-seq >r tuck + >r + r> r> ; inline dup slice-from swap slice-seq >r tuck + >r + r> r> ; inline
TUPLE: slice-error reason ; ERROR: slice-error reason ;
: slice-error ( str -- * ) \ slice-error construct-boa throw ;
: check-slice ( from to seq -- from to seq ) : check-slice ( from to seq -- from to seq )
pick 0 < [ "start < 0" slice-error ] when pick 0 < [ "start < 0" slice-error ] when

View File

@ -560,6 +560,13 @@ HELP: TUPLE:
$nl $nl
"Tuples are user-defined classes with instances composed of named slots. All tuple classes are subtypes of the built-in " { $link tuple } " type." } ; "Tuples are user-defined classes with instances composed of named slots. All tuple classes are subtypes of the built-in " { $link tuple } " type." } ;
HELP: ERROR:
{ $syntax "ERROR: class slots... ;" }
{ $values { "class" "a new tuple class to define" } { "slots" "a list of slot names" } }
{ $description "Defines a new tuple class. Defines a new word " { $snippet "class?" } " that boa-constructs this tuple and throws it." } ;
{ POSTPONE: ERROR: POSTPONE: TUPLE: } related-words
HELP: C: HELP: C:
{ $syntax "C: constructor class" } { $syntax "C: constructor class" }
{ $values { "constructor" "a new word to define" } { "class" tuple-class } } { $values { "constructor" "a new word to define" } { "class" tuple-class } }

View File

@ -165,6 +165,7 @@ IN: bootstrap.syntax
"ERROR:" [ "ERROR:" [
CREATE-CLASS dup ";" parse-tokens define-tuple-class CREATE-CLASS dup ";" parse-tokens define-tuple-class
dup save-location
dup [ construct-boa throw ] curry define dup [ construct-boa throw ] curry define
] define-syntax ] define-syntax

View File

@ -236,7 +236,7 @@ C: <erg's-reshape-problem> erg's-reshape-problem
[ [
"IN: tuples.tests SYMBOL: not-a-class C: <not-a-class> not-a-class" eval "IN: tuples.tests SYMBOL: not-a-class C: <not-a-class> not-a-class" eval
] [ [ check-tuple? ] is? ] must-fail-with ] [ [ no-tuple-class? ] is? ] must-fail-with
! Hardcore unit tests ! Hardcore unit tests
USE: threads USE: threads

View File

@ -89,11 +89,11 @@ PRIVATE>
2dup define-slots 2dup define-slots
define-accessors ; define-accessors ;
TUPLE: check-tuple class ; ERROR: no-tuple-class class ;
: check-tuple ( class -- ) : check-tuple ( class -- )
dup tuple-class? dup tuple-class?
[ drop ] [ \ check-tuple construct-boa throw ] if ; [ drop ] [ no-tuple-class ] if ;
: define-tuple-class ( class slots -- ) : define-tuple-class ( class slots -- )
2dup check-shape 2dup check-shape

View File

@ -59,16 +59,13 @@ M: f vocab-help ;
: create-vocab ( name -- vocab ) : create-vocab ( name -- vocab )
dictionary get [ <vocab> ] cache ; dictionary get [ <vocab> ] cache ;
TUPLE: no-vocab name ; ERROR: no-vocab name ;
: no-vocab ( name -- * )
vocab-name \ no-vocab construct-boa throw ;
SYMBOL: load-vocab-hook ! ( name -- ) SYMBOL: load-vocab-hook ! ( name -- )
: load-vocab ( name -- vocab ) : load-vocab ( name -- vocab )
dup load-vocab-hook get call dup load-vocab-hook get call
dup vocab [ ] [ no-vocab ] ?if ; dup vocab [ ] [ vocab-name no-vocab ] ?if ;
: vocabs ( -- seq ) : vocabs ( -- seq )
dictionary get keys natural-sort ; dictionary get keys natural-sort ;

View File

@ -21,9 +21,7 @@ M: word definer drop \ : \ ; ;
M: word definition word-def ; M: word definition word-def ;
TUPLE: undefined ; ERROR: undefined ;
: undefined ( -- * ) \ undefined construct-empty throw ;
PREDICATE: word deferred ( obj -- ? ) PREDICATE: word deferred ( obj -- ? )
word-def [ undefined ] = ; word-def [ undefined ] = ;
@ -189,12 +187,11 @@ M: word subwords drop f ;
[ ] [ no-vocab ] ?if [ ] [ no-vocab ] ?if
set-at ; set-at ;
TUPLE: check-create name vocab ; ERROR: bad-create name vocab ;
: check-create ( name vocab -- name vocab ) : check-create ( name vocab -- name vocab )
2dup [ string? ] both? [ 2dup [ string? ] both?
\ check-create construct-boa throw [ bad-create ] unless ;
] unless ;
: create ( name vocab -- word ) : create ( name vocab -- word )
check-create 2dup lookup check-create 2dup lookup