symbols in functors

db4
Joe Groff 2009-04-27 14:02:14 -05:00
parent 0d03dea74b
commit 49771779c1
2 changed files with 30 additions and 2 deletions

View File

@ -63,6 +63,24 @@ WHERE
[ 4 ] [ 1 3 blah ] unit-test [ 4 ] [ 1 3 blah ] unit-test
<<
FUNCTOR: symbol-test ( W -- )
W DEFINES ${W}
WHERE
SYMBOL: W
;FUNCTOR
"blorgh" symbol-test
>>
[ blorgh ] [ blorgh ] unit-test
GENERIC: some-generic ( a -- b ) GENERIC: some-generic ( a -- b )
! Does replacing an ordinary word with a functor-generated one work? ! Does replacing an ordinary word with a functor-generated one work?
@ -72,6 +90,7 @@ GENERIC: some-generic ( a -- b )
TUPLE: some-tuple ; TUPLE: some-tuple ;
: some-word ( -- ) ; : some-word ( -- ) ;
M: some-tuple some-generic ; M: some-tuple some-generic ;
SYMBOL: some-symbol
"> <string-reader> "functors-test" parse-stream "> <string-reader> "functors-test" parse-stream
] unit-test ] unit-test
@ -82,6 +101,7 @@ GENERIC: some-generic ( a -- b )
"some-tuple" "functors.tests" lookup "some-tuple" "functors.tests" lookup
"some-generic" "functors.tests" lookup method >boolean "some-generic" "functors.tests" lookup method >boolean
] unit-test ; ] unit-test ;
[ t ] [ "some-symbol" "functors.tests" lookup >boolean ] unit-test
test-redefinition test-redefinition
@ -90,12 +110,14 @@ FUNCTOR: redefine-test ( W -- )
W-word DEFINES ${W}-word W-word DEFINES ${W}-word
W-tuple DEFINES-CLASS ${W}-tuple W-tuple DEFINES-CLASS ${W}-tuple
W-generic IS ${W}-generic W-generic IS ${W}-generic
W-symbol DEFINES ${W}-symbol
WHERE WHERE
TUPLE: W-tuple ; TUPLE: W-tuple ;
: W-word ( -- ) ; : W-word ( -- ) ;
M: W-tuple W-generic ; M: W-tuple W-generic ;
SYMBOL: W-symbol
;FUNCTOR ;FUNCTOR
@ -106,3 +128,4 @@ M: W-tuple W-generic ;
] unit-test ] unit-test
test-redefinition test-redefinition

View File

@ -5,7 +5,7 @@ words interpolate namespaces sequences io.streams.string fry
classes.mixin effects lexer parser classes.tuple.parser classes.mixin effects lexer parser classes.tuple.parser
effects.parser locals.types locals.parser generic.parser effects.parser locals.types locals.parser generic.parser
locals.rewrite.closures vocabs.parser classes.parser locals.rewrite.closures vocabs.parser classes.parser
arrays accessors ; arrays accessors words.symbol ;
IN: functors IN: functors
! This is a hack ! This is a hack
@ -80,6 +80,10 @@ SYNTAX: `:
parse-declared* parse-declared*
\ define-declared* parsed ; \ define-declared* parsed ;
SYNTAX: `SYMBOL:
scan-param parsed
\ define-symbol parsed ;
SYNTAX: `SYNTAX: SYNTAX: `SYNTAX:
scan-param parsed scan-param parsed
parse-definition* parse-definition*
@ -116,6 +120,7 @@ DEFER: ;FUNCTOR delimiter
{ ":" POSTPONE: `: } { ":" POSTPONE: `: }
{ "INSTANCE:" POSTPONE: `INSTANCE: } { "INSTANCE:" POSTPONE: `INSTANCE: }
{ "SYNTAX:" POSTPONE: `SYNTAX: } { "SYNTAX:" POSTPONE: `SYNTAX: }
{ "SYMBOL:" POSTPONE: `SYMBOL: }
{ "inline" POSTPONE: `inline } { "inline" POSTPONE: `inline }
} ; } ;