]> gitweb.factorcode.org Git - factor.git/commitdiff
words: undefined error now contains the word in question
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 1 Feb 2010 05:45:08 +0000 (18:45 +1300)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 3 Feb 2010 10:11:23 +0000 (23:11 +1300)
basis/bootstrap/image/image.factor
basis/debugger/debugger.factor
basis/prettyprint/prettyprint.factor
core/syntax/syntax.factor
core/words/words-tests.factor
core/words/words.factor
vm/callstack.cpp

index c99b047686501a5c3ed13e369a564ca222d3c36a..3552f0bd92ca44c5bff578ca35d01d031a039f38 100644 (file)
@@ -545,7 +545,7 @@ M: quotation '
     \ c-to-factor c-to-factor-word set
     \ lazy-jit-compile lazy-jit-compile-word set
     \ unwind-native-frames unwind-native-frames-word set
-    [ undefined ] undefined-quot set ;
+    undefined-def undefined-quot set ;
 
 : emit-special-objects ( -- )
     special-objects get keys [ emit-special-object ] each ;
index d5284133b25f7cb8088adc97487fea92c0812ad9..ba90d761cce53981be3b92cad610ae9bfc1a0b36 100644 (file)
@@ -236,7 +236,10 @@ M: redefine-error error.
     def>> . ;
 
 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.
     "Attempting to define " write
index 65d25f1812f5d386a121e92b8cb5ab522e1fd2dc..ccc77068e6f45527a504ca41bbf5af6adbcec687 100644 (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.
 USING: arrays accessors assocs colors combinators grouping io
 io.streams.string io.styles kernel make math math.parser namespaces
 parser prettyprint.backend prettyprint.config prettyprint.custom
 prettyprint.sections quotations sequences sorting strings vocabs
-vocabs.prettyprint words sets ;
+vocabs.prettyprint words sets generic ;
 IN: prettyprint
 
 : with-use ( obj quot -- )
@@ -72,24 +72,31 @@ SYMBOL: ->
     ] [ ] make ;
 
 : remove-breakpoints ( quot pos -- quot' )
-    over quotation? [
-        1 + short cut [ (remove-breakpoints) ] bi@
-        [ -> ] glue
-    ] [
-        drop
-    ] if ;
-
-PRIVATE>
+    1 + short cut [ (remove-breakpoints) ] bi@ [ -> ] glue ;
 
-: callstack. ( callstack -- )
-    callstack>array 2 <groups> [
+: callframe. ( triple -- )
+    first3
+    [
+        {
+            { [ dup method-body? ] [ "Method: " write . ] }
+            { [ dup word? ] [ "Word: " write . ] }
+            [ drop ]
+        } cond
+    ] 2dip
+    over quotation? [
+        "Quotation: " write
         remove-breakpoints
         [
             3 nesting-limit set
             100 length-limit set
             .
         ] with-scope
-    ] assoc-each ;
+    ] [ 2drop ] if ;
+
+PRIVATE>
+
+: callstack. ( callstack -- )
+    callstack>array 3 <groups> [ nl ] [ callframe. ] interleave ;
 
 : .c ( -- ) callstack callstack. ;
 
index dfb3e0bc1054b93e981a7770b0bdfb462b56e615..cf2c49fff989c22b20796d3ad5e1a0d76ae70a2f 100644 (file)
@@ -135,7 +135,7 @@ IN: bootstrap.syntax
 
     "DEFER:" [
         scan current-vocab create
-        [ fake-definition ] [ set-word ] [ [ undefined ] define ] tri
+        [ fake-definition ] [ set-word ] [ undefined-def define ] tri
     ] define-core-syntax
     
     "ALIAS:" [
index 46b20bf2e608c89fc11c91130fa3a4caeeefca11..2734defaacee0c1ca4f8af1356439742600e10ae 100644 (file)
@@ -64,9 +64,14 @@ FORGET: forgotten
 FORGET: another-forgotten
 : another-forgotten ( -- ) ;
 
+! Make sure that undefined words throw proper errors
+DEFER: deferred
+[ deferred ] [ T{ undefined f deferred } = ] must-fail-with
 
-DEFER: x
-[ x ] [ undefined? ] must-fail-with
+[ "IN: words.tests DEFER: not-compiled << not-compiled >>" eval( -- ) ]
+[ 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
 [ f ] [ "no-loc" "words.tests" lookup where ] unit-test
index 4fe00d1edf4dcf9796d2d185743f825e9465eb25..6c6e0d188b88c9c1b11da4168a13b2c9633a0385 100644 (file)
@@ -32,9 +32,22 @@ M: word definition def>> ;
 
 : 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 definition drop f ;
 
index 4aa9321353517b92c4260cfe5fd631dab0a6eb7d..195b212d8b3899b1b741a39e19c7a20af58ca9ad 100755 (executable)
@@ -132,10 +132,12 @@ struct stack_frame_accumulator {
 
        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);
 
                frames.add(executing.value());
+               frames.add(executing_quot.value());
                frames.add(scan.value());
        }
 };