Make M\ throw an error upon lookup failure. Change method -> ?lookup-method, lookup-method is the throwing version of ?lookup-method. Fixes #229.
parent
8ee9fcc11f
commit
181f11faa8
|
@ -540,6 +540,6 @@ STRUCT: going-to-redefine { a uint } ;
|
||||||
[ ] [
|
[ ] [
|
||||||
"IN: classes.struct.tests TUPLE: going-to-redefine b ;" eval( -- )
|
"IN: classes.struct.tests TUPLE: going-to-redefine b ;" eval( -- )
|
||||||
] unit-test
|
] unit-test
|
||||||
[ f ] [ \ going-to-redefine \ clone method ] unit-test
|
[ f ] [ \ going-to-redefine \ clone ?lookup-method ] unit-test
|
||||||
[ f ] [ \ going-to-redefine \ struct-slot-values method ] unit-test
|
[ f ] [ \ going-to-redefine \ struct-slot-values ?lookup-method ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ M: struct-c-type base-type ;
|
||||||
define-inline-method ;
|
define-inline-method ;
|
||||||
|
|
||||||
: forget-struct-slot-values-method ( class -- )
|
: forget-struct-slot-values-method ( class -- )
|
||||||
\ struct-slot-values method forget ;
|
\ struct-slot-values ?lookup-method forget ;
|
||||||
|
|
||||||
: clone-underlying ( struct -- byte-array )
|
: clone-underlying ( struct -- byte-array )
|
||||||
binary-object memory>byte-array ; inline
|
binary-object memory>byte-array ; inline
|
||||||
|
@ -207,7 +207,7 @@ M: struct-c-type base-type ;
|
||||||
define-inline-method ;
|
define-inline-method ;
|
||||||
|
|
||||||
: forget-clone-method ( class -- )
|
: forget-clone-method ( class -- )
|
||||||
\ clone method forget ;
|
\ clone ?lookup-method forget ;
|
||||||
|
|
||||||
:: c-type-for-class ( class slots size align -- c-type )
|
:: c-type-for-class ( class slots size align -- c-type )
|
||||||
struct-c-type new
|
struct-c-type new
|
||||||
|
|
|
@ -15,7 +15,7 @@ M: integer method-redefine-generic-1 3 + ;
|
||||||
|
|
||||||
[ 7 ] [ method-redefine-test-1 ] unit-test
|
[ 7 ] [ method-redefine-test-1 ] unit-test
|
||||||
|
|
||||||
[ ] [ [ fixnum \ method-redefine-generic-1 method forget ] with-compilation-unit ] unit-test
|
[ ] [ [ fixnum \ method-redefine-generic-1 lookup-method forget ] with-compilation-unit ] unit-test
|
||||||
|
|
||||||
[ 6 ] [ method-redefine-test-1 ] unit-test
|
[ 6 ] [ method-redefine-test-1 ] unit-test
|
||||||
|
|
||||||
|
@ -33,6 +33,6 @@ M: integer method-redefine-generic-2 3 + ;
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
[
|
[
|
||||||
fixnum string [ \ method-redefine-generic-2 method forget ] bi@
|
fixnum string [ \ method-redefine-generic-2 lookup-method forget ] bi@
|
||||||
] with-compilation-unit
|
] with-compilation-unit
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -18,18 +18,18 @@ M: empty-mixin sheeple drop "wake up" ; inline
|
||||||
|
|
||||||
[ "sheeple" ] [ sheeple-test ] unit-test
|
[ "sheeple" ] [ sheeple-test ] unit-test
|
||||||
[ t ] [ \ sheeple-test optimized? ] unit-test
|
[ t ] [ \ sheeple-test optimized? ] unit-test
|
||||||
[ t ] [ object \ sheeple method \ sheeple-test compiled-use? ] unit-test
|
[ t ] [ object \ sheeple lookup-method \ sheeple-test compiled-use? ] unit-test
|
||||||
[ f ] [ empty-mixin \ sheeple method \ sheeple-test compiled-use? ] unit-test
|
[ f ] [ empty-mixin \ sheeple lookup-method \ sheeple-test compiled-use? ] unit-test
|
||||||
|
|
||||||
[ ] [ "IN: compiler.tests.redefine3 USE: arrays INSTANCE: array empty-mixin" eval( -- ) ] unit-test
|
[ ] [ "IN: compiler.tests.redefine3 USE: arrays INSTANCE: array empty-mixin" eval( -- ) ] unit-test
|
||||||
|
|
||||||
[ "wake up" ] [ sheeple-test ] unit-test
|
[ "wake up" ] [ sheeple-test ] unit-test
|
||||||
[ f ] [ object \ sheeple method \ sheeple-test compiled-use? ] unit-test
|
[ f ] [ object \ sheeple lookup-method \ sheeple-test compiled-use? ] unit-test
|
||||||
[ t ] [ empty-mixin \ sheeple method \ sheeple-test compiled-use? ] unit-test
|
[ t ] [ empty-mixin \ sheeple lookup-method \ sheeple-test compiled-use? ] unit-test
|
||||||
|
|
||||||
[ ] [ [ array empty-mixin remove-mixin-instance ] with-compilation-unit ] unit-test
|
[ ] [ [ array empty-mixin remove-mixin-instance ] with-compilation-unit ] unit-test
|
||||||
|
|
||||||
[ "sheeple" ] [ sheeple-test ] unit-test
|
[ "sheeple" ] [ sheeple-test ] unit-test
|
||||||
[ t ] [ \ sheeple-test optimized? ] unit-test
|
[ t ] [ \ sheeple-test optimized? ] unit-test
|
||||||
[ t ] [ object \ sheeple method \ sheeple-test compiled-use? ] unit-test
|
[ t ] [ object \ sheeple lookup-method \ sheeple-test compiled-use? ] unit-test
|
||||||
[ f ] [ empty-mixin \ sheeple method \ sheeple-test compiled-use? ] unit-test
|
[ f ] [ empty-mixin \ sheeple lookup-method \ sheeple-test compiled-use? ] unit-test
|
||||||
|
|
|
@ -91,7 +91,7 @@ M: broadcast (consult-method-quot)
|
||||||
\ protocol-consult word-prop delete-at ;
|
\ protocol-consult word-prop delete-at ;
|
||||||
|
|
||||||
: unconsult-method ( word consultation -- )
|
: unconsult-method ( word consultation -- )
|
||||||
[ class>> swap first method ] keep
|
[ class>> swap first lookup-method ] keep
|
||||||
over [
|
over [
|
||||||
over "consultation" word-prop eq?
|
over "consultation" word-prop eq?
|
||||||
[ forget ] [ drop ] if
|
[ forget ] [ drop ] if
|
||||||
|
@ -124,7 +124,7 @@ M: consultation forget*
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: forget-all-methods ( classes words -- )
|
: forget-all-methods ( classes words -- )
|
||||||
[ first method forget ] cartesian-each ;
|
[ first lookup-method forget ] cartesian-each ;
|
||||||
|
|
||||||
: protocol-users ( protocol -- users )
|
: protocol-users ( protocol -- users )
|
||||||
protocol-consult keys ;
|
protocol-consult keys ;
|
||||||
|
|
|
@ -275,7 +275,7 @@ MEMO: array-capacity-interval ( -- interval )
|
||||||
: interval/-safe ( i1 i2 -- i3 )
|
: interval/-safe ( i1 i2 -- i3 )
|
||||||
#! Just a hack to make the compiler work if bootstrap.math
|
#! Just a hack to make the compiler work if bootstrap.math
|
||||||
#! is not loaded.
|
#! is not loaded.
|
||||||
\ integer \ / method [ interval/ ] [ 2drop f ] if ;
|
\ integer \ / ?lookup-method [ interval/ ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: interval/i ( i1 i2 -- i3 )
|
: interval/i ( i1 i2 -- i3 )
|
||||||
[
|
[
|
||||||
|
|
|
@ -127,7 +127,7 @@ M: word integer-op-input-classes
|
||||||
|
|
||||||
: define-math-ops ( op -- )
|
: define-math-ops ( op -- )
|
||||||
{ fixnum bignum float }
|
{ fixnum bignum float }
|
||||||
[ [ dup 3array ] [ swap method ] 2bi ] with { } map>assoc
|
[ [ dup 3array ] [ swap ?lookup-method ] 2bi ] with { } map>assoc
|
||||||
[ nip ] assoc-filter
|
[ nip ] assoc-filter
|
||||||
[ def>> ] assoc-map
|
[ def>> ] assoc-map
|
||||||
[ nip length 1 = ] assoc-filter
|
[ nip length 1 = ] assoc-filter
|
||||||
|
|
|
@ -224,7 +224,7 @@ M: word see*
|
||||||
: seeing-implementors ( class -- seq )
|
: seeing-implementors ( class -- seq )
|
||||||
dup implementors
|
dup implementors
|
||||||
[ [ reader? ] [ writer? ] bi or not ] filter
|
[ [ reader? ] [ writer? ] bi or not ] filter
|
||||||
[ method ] with map
|
[ ?lookup-method ] with map
|
||||||
natural-sort ;
|
natural-sort ;
|
||||||
|
|
||||||
: seeing-methods ( generic -- seq )
|
: seeing-methods ( generic -- seq )
|
||||||
|
|
|
@ -25,6 +25,7 @@ stack-checker.transforms
|
||||||
stack-checker.dependencies
|
stack-checker.dependencies
|
||||||
stack-checker.recursive-state
|
stack-checker.recursive-state
|
||||||
stack-checker.row-polymorphism ;
|
stack-checker.row-polymorphism ;
|
||||||
|
QUALIFIED-WITH: generic.single.private gsp
|
||||||
IN: stack-checker.known-words
|
IN: stack-checker.known-words
|
||||||
|
|
||||||
: infer-special ( word -- )
|
: infer-special ( word -- )
|
||||||
|
@ -417,7 +418,7 @@ M: object infer-call* \ call bad-macro-input ;
|
||||||
\ innermost-frame-executing { callstack } { object } define-primitive
|
\ innermost-frame-executing { callstack } { object } define-primitive
|
||||||
\ innermost-frame-scan { callstack } { fixnum } define-primitive
|
\ innermost-frame-scan { callstack } { fixnum } define-primitive
|
||||||
\ jit-compile { quotation } { } define-primitive
|
\ jit-compile { quotation } { } define-primitive
|
||||||
\ lookup-method { object array } { word } define-primitive
|
\ gsp:lookup-method { object array } { word } define-primitive
|
||||||
\ minor-gc { } { } define-primitive
|
\ minor-gc { } { } define-primitive
|
||||||
\ modify-code-heap { array object object } { } define-primitive
|
\ modify-code-heap { array object object } { } define-primitive
|
||||||
\ nano-count { } { integer } define-primitive \ nano-count make-flushable
|
\ nano-count { } { integer } define-primitive \ nano-count make-flushable
|
||||||
|
|
|
@ -30,7 +30,7 @@ IN: tools.profiler
|
||||||
all-words [ subwords ] cumulative-counters ;
|
all-words [ subwords ] cumulative-counters ;
|
||||||
|
|
||||||
: methods-on ( class -- methods )
|
: methods-on ( class -- methods )
|
||||||
dup implementors [ method ] with map ;
|
dup implementors [ lookup-method ] with map ;
|
||||||
|
|
||||||
: class-counters ( -- alist )
|
: class-counters ( -- alist )
|
||||||
classes [ methods-on ] cumulative-counters ;
|
classes [ methods-on ] cumulative-counters ;
|
||||||
|
|
|
@ -476,7 +476,7 @@ must-fail-with
|
||||||
|
|
||||||
: accessor-exists? ( name -- ? )
|
: accessor-exists? ( name -- ? )
|
||||||
[ "forget-accessors-test" "classes.tuple.tests" lookup ] dip
|
[ "forget-accessors-test" "classes.tuple.tests" lookup ] dip
|
||||||
">>" append "accessors" lookup method >boolean ;
|
">>" append "accessors" lookup ?lookup-method >boolean ;
|
||||||
|
|
||||||
[ t ] [ "x" accessor-exists? ] unit-test
|
[ t ] [ "x" accessor-exists? ] unit-test
|
||||||
[ t ] [ "y" accessor-exists? ] unit-test
|
[ t ] [ "y" accessor-exists? ] unit-test
|
||||||
|
@ -594,7 +594,7 @@ T{ reshape-test f "hi" } "tuple" set
|
||||||
|
|
||||||
[ ] [ "IN: classes.tuple.tests TUPLE: reshape-test { x read-only } ;" eval( -- ) ] unit-test
|
[ ] [ "IN: classes.tuple.tests TUPLE: reshape-test { x read-only } ;" eval( -- ) ] unit-test
|
||||||
|
|
||||||
[ f ] [ \ reshape-test \ x<< method ] unit-test
|
[ f ] [ \ reshape-test \ x<< ?lookup-method ] unit-test
|
||||||
|
|
||||||
[ "tuple" get 5 >>x ] must-fail
|
[ "tuple" get 5 >>x ] must-fail
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ SLOT: kex
|
||||||
drop
|
drop
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ \ change-slot-test \ kex>> method >boolean ] unit-test
|
[ t ] [ \ change-slot-test \ kex>> ?lookup-method >boolean ] unit-test
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
"IN: classes.tuple.tests USING: kernel accessors ; TUPLE: change-slot-test kex ;"
|
"IN: classes.tuple.tests USING: kernel accessors ; TUPLE: change-slot-test kex ;"
|
||||||
|
@ -686,7 +686,7 @@ SLOT: kex
|
||||||
drop
|
drop
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ \ change-slot-test \ kex>> method >boolean ] unit-test
|
[ t ] [ \ change-slot-test \ kex>> ?lookup-method >boolean ] unit-test
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
"IN: classes.tuple.tests USING: kernel accessors ; TUPLE: change-slot-test ; SLOT: kex M: change-slot-test kex>> drop 3 ;"
|
"IN: classes.tuple.tests USING: kernel accessors ; TUPLE: change-slot-test ; SLOT: kex M: change-slot-test kex>> drop 3 ;"
|
||||||
|
@ -694,8 +694,8 @@ SLOT: kex
|
||||||
drop
|
drop
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ \ change-slot-test \ kex>> method >boolean ] unit-test
|
[ t ] [ \ change-slot-test \ kex>> ?lookup-method >boolean ] unit-test
|
||||||
[ f ] [ \ change-slot-test \ kex>> method "reading" word-prop ] unit-test
|
[ f ] [ \ change-slot-test \ kex>> ?lookup-method "reading" word-prop ] unit-test
|
||||||
|
|
||||||
DEFER: redefine-tuple-twice
|
DEFER: redefine-tuple-twice
|
||||||
|
|
||||||
|
|
|
@ -319,8 +319,8 @@ M: tuple-class reset-class
|
||||||
[
|
[
|
||||||
dup "slots" word-prop [
|
dup "slots" word-prop [
|
||||||
name>>
|
name>>
|
||||||
[ reader-word method forget ]
|
[ reader-word ?lookup-method forget ]
|
||||||
[ writer-word method forget ] 2bi
|
[ writer-word ?lookup-method forget ] 2bi
|
||||||
] with each
|
] with each
|
||||||
] [
|
] [
|
||||||
[ call-next-method ]
|
[ call-next-method ]
|
||||||
|
|
|
@ -25,9 +25,14 @@ M: generic definition drop f ;
|
||||||
PREDICATE: method < word
|
PREDICATE: method < word
|
||||||
"method-generic" word-prop >boolean ;
|
"method-generic" word-prop >boolean ;
|
||||||
|
|
||||||
: method ( class generic -- method/f )
|
ERROR: method-lookup-failed class generic ;
|
||||||
|
|
||||||
|
: ?lookup-method ( class generic -- method/f )
|
||||||
"methods" word-prop at ;
|
"methods" word-prop at ;
|
||||||
|
|
||||||
|
: lookup-method ( class generic -- method/* )
|
||||||
|
2dup ?lookup-method [ 2nip ] [ method-lookup-failed ] if* ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: interesting-class? ( class1 class2 -- ? )
|
: interesting-class? ( class1 class2 -- ? )
|
||||||
|
@ -56,7 +61,7 @@ PRIVATE>
|
||||||
method-classes interesting-classes smallest-class ;
|
method-classes interesting-classes smallest-class ;
|
||||||
|
|
||||||
: method-for-class ( class generic -- method/f )
|
: method-for-class ( class generic -- method/f )
|
||||||
[ nip ] [ nearest-class ] 2bi dup [ swap method ] [ 2drop f ] if ;
|
[ nip ] [ nearest-class ] 2bi dup [ swap ?lookup-method ] [ 2drop f ] if ;
|
||||||
|
|
||||||
GENERIC: effective-method ( generic -- method )
|
GENERIC: effective-method ( generic -- method )
|
||||||
|
|
||||||
|
@ -66,7 +71,7 @@ GENERIC: effective-method ( generic -- method )
|
||||||
method-classes [ class< ] with filter smallest-class ;
|
method-classes [ class< ] with filter smallest-class ;
|
||||||
|
|
||||||
: next-method ( class generic -- method/f )
|
: next-method ( class generic -- method/f )
|
||||||
[ next-method-class ] keep method ;
|
[ next-method-class ] keep ?lookup-method ;
|
||||||
|
|
||||||
GENERIC: next-method-quot* ( class generic combination -- quot )
|
GENERIC: next-method-quot* ( class generic combination -- quot )
|
||||||
|
|
||||||
|
@ -131,7 +136,7 @@ M: method crossref?
|
||||||
2bi ;
|
2bi ;
|
||||||
|
|
||||||
: create-method ( class generic -- method )
|
: create-method ( class generic -- method )
|
||||||
2dup method dup [ 2nip dup reset-generic ] [
|
2dup ?lookup-method dup [ 2nip dup reset-generic ] [
|
||||||
drop
|
drop
|
||||||
[ <method> dup ] 2keep
|
[ <method> dup ] 2keep
|
||||||
reveal-method
|
reveal-method
|
||||||
|
@ -158,7 +163,7 @@ M: method forget*
|
||||||
[
|
[
|
||||||
[ "method-class" word-prop ]
|
[ "method-class" word-prop ]
|
||||||
[ "method-generic" word-prop ] bi
|
[ "method-generic" word-prop ] bi
|
||||||
2dup method
|
2dup ?lookup-method
|
||||||
] keep eq?
|
] keep eq?
|
||||||
[
|
[
|
||||||
[ [ delete-at ] with-methods ]
|
[ [ delete-at ] with-methods ]
|
||||||
|
@ -195,4 +200,4 @@ M: generic subwords
|
||||||
] { } make ;
|
] { } make ;
|
||||||
|
|
||||||
M: class forget-methods
|
M: class forget-methods
|
||||||
[ implementors ] [ [ swap method ] curry ] bi map forget-all ;
|
[ implementors ] [ [ swap ?lookup-method ] curry ] bi map forget-all ;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
USING: accessors definitions generic generic.single
|
USING: accessors definitions generic generic.single
|
||||||
generic.single.private kernel namespaces words kernel.private
|
generic.single.private kernel namespaces words kernel.private
|
||||||
quotations sequences ;
|
quotations sequences ;
|
||||||
|
QUALIFIED-WITH: generic.single.private gsp
|
||||||
IN: generic.hook
|
IN: generic.hook
|
||||||
|
|
||||||
TUPLE: hook-combination < single-combination var ;
|
TUPLE: hook-combination < single-combination var ;
|
||||||
|
@ -18,7 +19,7 @@ M: hook-combination picker
|
||||||
M: hook-combination dispatch# drop 0 ;
|
M: hook-combination dispatch# drop 0 ;
|
||||||
|
|
||||||
M: hook-combination mega-cache-quot
|
M: hook-combination mega-cache-quot
|
||||||
1quotation picker [ lookup-method (execute) ] surround ;
|
1quotation picker [ gsp:lookup-method (execute) ] surround ;
|
||||||
|
|
||||||
M: hook-generic definer drop \ HOOK: f ;
|
M: hook-generic definer drop \ HOOK: f ;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ ERROR: no-math-method left right generic ;
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (math-method) ( generic class -- quot )
|
: (math-method) ( generic class -- quot )
|
||||||
over method
|
over ?lookup-method
|
||||||
[ 1quotation ]
|
[ 1quotation ]
|
||||||
[ default-math-method ] ?if ;
|
[ default-math-method ] ?if ;
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,10 @@ M: single-combination next-method-quot* ( class generic combination -- quot )
|
||||||
] with-combination ;
|
] with-combination ;
|
||||||
|
|
||||||
: method-for-object ( obj word -- method )
|
: method-for-object ( obj word -- method )
|
||||||
[ [ method-classes [ instance? ] with filter smallest-class ] keep method ]
|
[
|
||||||
[ "default-method" word-prop ]
|
[ method-classes [ instance? ] with filter smallest-class ] keep
|
||||||
|
?lookup-method
|
||||||
|
] [ "default-method" word-prop ]
|
||||||
bi or ;
|
bi or ;
|
||||||
|
|
||||||
M: single-combination make-default-method
|
M: single-combination make-default-method
|
||||||
|
|
|
@ -236,7 +236,7 @@ GENERIC: generic-forget-test ( a -- b )
|
||||||
|
|
||||||
M: f generic-forget-test ;
|
M: f generic-forget-test ;
|
||||||
|
|
||||||
[ ] [ \ f \ generic-forget-test method "m" set ] unit-test
|
[ ] [ \ f \ generic-forget-test lookup-method "m" set ] unit-test
|
||||||
|
|
||||||
[ ] [ [ "m" get forget ] with-compilation-unit ] unit-test
|
[ ] [ [ "m" get forget ] with-compilation-unit ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ IN: bootstrap.syntax
|
||||||
|
|
||||||
"POSTPONE:" [ scan-word suffix! ] define-core-syntax
|
"POSTPONE:" [ scan-word suffix! ] define-core-syntax
|
||||||
"\\" [ scan-word <wrapper> suffix! ] define-core-syntax
|
"\\" [ scan-word <wrapper> suffix! ] define-core-syntax
|
||||||
"M\\" [ scan-word scan-word method <wrapper> suffix! ] define-core-syntax
|
"M\\" [ scan-word scan-word lookup-method <wrapper> suffix! ] define-core-syntax
|
||||||
"inline" [ word make-inline ] define-core-syntax
|
"inline" [ word make-inline ] define-core-syntax
|
||||||
"recursive" [ word make-recursive ] define-core-syntax
|
"recursive" [ word make-recursive ] define-core-syntax
|
||||||
"foldable" [ word make-foldable ] define-core-syntax
|
"foldable" [ word make-foldable ] define-core-syntax
|
||||||
|
|
Loading…
Reference in New Issue