Throw a nice error at parse time if an attempt is made to declare a GENERIC: or MACRO: word inline. Such words cannot be inlined, and doing this before previously result in confusing error messages

db4
Slava Pestov 2010-01-27 21:00:10 +13:00
parent 3237e48b2d
commit ca19d44350
6 changed files with 19 additions and 4 deletions

View File

@ -1,4 +1,4 @@
! Copyright (C) 2004, 2009 Slava Pestov.
! Copyright (C) 2004, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: slots arrays definitions generic hashtables summary io kernel
math namespaces make prettyprint prettyprint.config sequences assocs
@ -252,6 +252,8 @@ M: decode-error summary drop "Character decoding error" ;
M: bad-create summary drop "Bad parameters to create" ;
M: cannot-be-inline summary drop "This type of word cannot be inlined" ;
M: attempt-all-error summary drop "Nothing to attempt" ;
M: already-disposed summary drop "Attempting to operate on disposed object" ;

View File

@ -21,3 +21,5 @@ unit-test
[ ] [ "USING: macros stack-checker kernel ; IN: hanging-macro MACRO: c ( quot -- ) infer drop [ ] ; : a ( -- ) [ a ] c ;" eval( -- ) ] unit-test
[ ] [ "IN: macros.tests USE: macros MACRO: foo ( -- x ) [ ] ;" eval( -- ) ] unit-test
[ "IN: macros.tests USE: macros MACRO: foo ( -- x ) [ ] ; inline" eval( -- ) ] must-fail

View File

@ -1,4 +1,4 @@
! Copyright (C) 2007, 2009 Slava Pestov.
! Copyright (C) 2007, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: parser kernel sequences words effects combinators assocs
definitions quotations namespaces memoize accessors
@ -23,6 +23,8 @@ SYNTAX: MACRO: (:) define-macro ;
PREDICATE: macro < word "macro" word-prop >boolean ;
M: macro make-inline cannot-be-inline ;
M: macro definer drop \ MACRO: \ ; ;
M: macro definition "macro" word-prop ;

View File

@ -282,3 +282,6 @@ M: growable call-next-hooker call-next-method "growable " prepend ;
[ "IN: generic.single.tests GENERIC# broken-generic# -1 ( a -- b )" eval( -- ) ]
[ error>> bad-dispatch-position? ]
must-fail-with
[ ] [ "IN: generic.single.tests GENERIC: foo ( -- x )" eval( -- ) ] unit-test
[ "IN: generic.single.tests GENERIC: foo ( -- x ) inline" eval( -- ) ] must-fail

View File

@ -1,4 +1,4 @@
! Copyright (C) 2009 Slava Pestov.
! Copyright (C) 2009, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs classes classes.algebra
combinators definitions generic hashtables kernel
@ -16,6 +16,8 @@ TUPLE: single-combination ;
PREDICATE: single-generic < generic
"combination" word-prop single-combination? ;
M: single-generic make-inline cannot-be-inline ;
GENERIC: dispatch# ( word -- n )
M: generic dispatch# "combination" word-prop dispatch# ;

View File

@ -87,7 +87,11 @@ M: word subwords drop f ;
: make-deprecated ( word -- )
t "deprecated" set-word-prop ;
: make-inline ( word -- )
ERROR: cannot-be-inline word ;
GENERIC: make-inline ( word -- )
M: word make-inline
dup inline? [ drop ] [
[ t "inline" set-word-prop ]
[ changed-effect ]