words: undefined error now contains the word in question

db4
Slava Pestov 2010-02-01 18:45:08 +13:00
parent b7fde7af27
commit fbf078d4b3
7 changed files with 51 additions and 21 deletions

View File

@ -545,7 +545,7 @@ M: quotation '
\ c-to-factor c-to-factor-word set \ c-to-factor c-to-factor-word set
\ lazy-jit-compile lazy-jit-compile-word set \ lazy-jit-compile lazy-jit-compile-word set
\ unwind-native-frames unwind-native-frames-word set \ unwind-native-frames unwind-native-frames-word set
[ undefined ] undefined-quot set ; undefined-def undefined-quot set ;
: emit-special-objects ( -- ) : emit-special-objects ( -- )
special-objects get keys [ emit-special-object ] each ; special-objects get keys [ emit-special-object ] each ;

View File

@ -236,7 +236,10 @@ M: redefine-error error.
def>> . ; def>> . ;
M: undefined summary M: undefined summary
drop "Calling a deferred word before it has been defined" ; word>> undefined?
"Cannot call a deferred word before it has been defined"
"Cannot call a word before it has been compiled"
? ;
M: no-compilation-unit error. M: no-compilation-unit error.
"Attempting to define " write "Attempting to define " write

View File

@ -1,10 +1,10 @@
! Copyright (C) 2003, 2009 Slava Pestov. ! Copyright (C) 2003, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays accessors assocs colors combinators grouping io USING: arrays accessors assocs colors combinators grouping io
io.streams.string io.styles kernel make math math.parser namespaces io.streams.string io.styles kernel make math math.parser namespaces
parser prettyprint.backend prettyprint.config prettyprint.custom parser prettyprint.backend prettyprint.config prettyprint.custom
prettyprint.sections quotations sequences sorting strings vocabs prettyprint.sections quotations sequences sorting strings vocabs
vocabs.prettyprint words sets ; vocabs.prettyprint words sets generic ;
IN: prettyprint IN: prettyprint
: with-use ( obj quot -- ) : with-use ( obj quot -- )
@ -72,24 +72,31 @@ SYMBOL: ->
] [ ] make ; ] [ ] make ;
: remove-breakpoints ( quot pos -- quot' ) : remove-breakpoints ( quot pos -- quot' )
1 + short cut [ (remove-breakpoints) ] bi@ [ -> ] glue ;
: callframe. ( triple -- )
first3
[
{
{ [ dup method-body? ] [ "Method: " write . ] }
{ [ dup word? ] [ "Word: " write . ] }
[ drop ]
} cond
] 2dip
over quotation? [ over quotation? [
1 + short cut [ (remove-breakpoints) ] bi@ "Quotation: " write
[ -> ] glue
] [
drop
] if ;
PRIVATE>
: callstack. ( callstack -- )
callstack>array 2 <groups> [
remove-breakpoints remove-breakpoints
[ [
3 nesting-limit set 3 nesting-limit set
100 length-limit set 100 length-limit set
. .
] with-scope ] with-scope
] assoc-each ; ] [ 2drop ] if ;
PRIVATE>
: callstack. ( callstack -- )
callstack>array 3 <groups> [ nl ] [ callframe. ] interleave ;
: .c ( -- ) callstack callstack. ; : .c ( -- ) callstack callstack. ;

View File

@ -135,7 +135,7 @@ IN: bootstrap.syntax
"DEFER:" [ "DEFER:" [
scan current-vocab create scan current-vocab create
[ fake-definition ] [ set-word ] [ [ undefined ] define ] tri [ fake-definition ] [ set-word ] [ undefined-def define ] tri
] define-core-syntax ] define-core-syntax
"ALIAS:" [ "ALIAS:" [

View File

@ -64,9 +64,14 @@ FORGET: forgotten
FORGET: another-forgotten FORGET: another-forgotten
: another-forgotten ( -- ) ; : another-forgotten ( -- ) ;
! Make sure that undefined words throw proper errors
DEFER: deferred
[ deferred ] [ T{ undefined f deferred } = ] must-fail-with
DEFER: x [ "IN: words.tests DEFER: not-compiled << not-compiled >>" eval( -- ) ]
[ x ] [ undefined? ] must-fail-with [ error>> [ undefined? ] [ word>> name>> "not-compiled" = ] bi and ] must-fail-with
[ ] [ "IN: words.tests FORGET: not-compiled" eval( -- ) ] unit-test
[ ] [ [ "no-loc" "words.tests" create drop ] with-compilation-unit ] unit-test [ ] [ [ "no-loc" "words.tests" create drop ] with-compilation-unit ] unit-test
[ f ] [ "no-loc" "words.tests" lookup where ] unit-test [ f ] [ "no-loc" "words.tests" lookup where ] unit-test

View File

@ -32,9 +32,22 @@ M: word definition def>> ;
: reset-props ( word seq -- ) [ remove-word-prop ] with each ; : reset-props ( word seq -- ) [ remove-word-prop ] with each ;
ERROR: undefined ; <PRIVATE
PREDICATE: deferred < word ( obj -- ? ) def>> [ undefined ] = ; : caller ( callstack -- word ) callstack>array <reversed> third ;
PRIVATE>
TUPLE: undefined word ;
: undefined ( -- * ) callstack caller \ undefined boa throw ;
: undefined-def ( -- quot )
#! 'f' inhibits tail call optimization in non-optimizing
#! compiler, ensuring that we can pull out the caller word
#! above.
[ undefined f ] ;
PREDICATE: deferred < word ( obj -- ? ) def>> undefined-def = ;
M: deferred definer drop \ DEFER: f ; M: deferred definer drop \ DEFER: f ;
M: deferred definition drop f ; M: deferred definition drop f ;

View File

@ -132,10 +132,12 @@ struct stack_frame_accumulator {
void operator()(stack_frame *frame) void operator()(stack_frame *frame)
{ {
data_root<object> executing(parent->frame_executing_quot(frame),parent); data_root<object> executing_quot(parent->frame_executing_quot(frame),parent);
data_root<object> executing(parent->frame_executing(frame),parent);
data_root<object> scan(parent->frame_scan(frame),parent); data_root<object> scan(parent->frame_scan(frame),parent);
frames.add(executing.value()); frames.add(executing.value());
frames.add(executing_quot.value());
frames.add(scan.value()); frames.add(scan.value());
} }
}; };