USE: strings
USE: vectors
+: undefined-method ( object generic -- )
+ #! This word is redefined in tools/debugger.factor with a
+ #! more useful definition once unparse is available.
+ "No suitable method" throw ;
+
! This is a very lightweight exception handling system.
: catchstack ( -- cs ) 6 getenv ;
USE: vectors
USE: math
USE: math-internals
+USE: unparser
! A simple single-dispatch generic word system.
! Metaclasses have priority -- this induces an order in which
! methods are added to the vtable.
-: undefined-method
- "No applicable method." throw ;
-
: metaclass ( class -- metaclass )
"metaclass" word-property ;
#! Add the method entry to the vtable. Unlike define-method,
#! this is called at vtable build time, and in the sorted
#! order.
- dup metaclass "add-method" word-property
- [ [ undefined-method ] ] unless* call ;
+ dup metaclass "add-method" word-property [
+ [ "Metaclass is missing add-method" throw ]
+ ] unless* call ;
-: <empty-vtable> ( -- vtable )
- num-types [ drop [ undefined-method ] ] vector-project ;
+: <empty-vtable> ( generic -- vtable )
+ unit num-types
+ [ drop dup [ car undefined-method ] cons ] vector-project
+ nip ;
: <vtable> ( generic -- vtable )
- <empty-vtable> over methods [
+ dup <empty-vtable> over methods [
( generic vtable method )
>r 2dup r> unswons add-method
] each nip ;
\ - [ [ number number ] [ number ] ] "infer-effect" set-word-property
\ undefined-method t "terminator" set-word-property
+\ undefined-method [ [ object word ] [ ] ] "infer-effect" set-word-property
\ not-a-number t "terminator" set-word-property
\ throw t "terminator" set-word-property
[ prettyprint-element ] each ;
M: list prettyprint* ( indent list -- indent )
- swap prettyprint-[ swap prettyprint-list prettyprint-] ;
+ [
+ swap prettyprint-[ swap prettyprint-list prettyprint-]
+ ] [
+ f unparse write
+ ] ifte* ;
M: cons prettyprint* ( indent cons -- indent )
\ [[ prettyprint* " " write
[ dup save-error rethrow ] 5 setenv ( kernel calls on error )
kernel-error 12 setenv ;
+: undefined-method ( object generic -- )
+ #! We 2dup here to leave both values on the stack, for
+ #! post-mortem inspection.
+ 2dup [
+ "The generic word " ,
+ unparse ,
+ " does not have a suitable method for " ,
+ unparse ,
+ ] make-string throw ;
+
! So that stage 2 boot gives a useful error message if something
! fails after this file is loaded.
init-error-handler