]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 25 Sep 2009 23:23:36 +0000 (18:23 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 25 Sep 2009 23:23:36 +0000 (18:23 -0500)
basis/bootstrap/image/image.factor
basis/compiler/tests/alien.factor
vm/os-unix.cpp
vm/quotations.cpp
vm/quotations.hpp
vm/run.hpp

index ee081a14ca4b73d5c06e5a6d24724f21963d6dee..eee65c1eba719f5dbd293be9e888e1a417d93376 100644 (file)
@@ -163,6 +163,7 @@ USERENV: jit-3dip 40
 USERENV: jit-execute-word 41
 USERENV: jit-execute-jump 42
 USERENV: jit-execute-call 43
+USERENV: jit-declare-word 44
 
 ! PIC stubs
 USERENV: pic-load 47
@@ -493,6 +494,7 @@ M: quotation '
     \ inline-cache-miss-tail \ pic-miss-tail-word set
     \ mega-cache-lookup \ mega-lookup-word set
     \ mega-cache-miss \ mega-miss-word set
+    \ declare jit-declare-word set
     [ undefined ] undefined-quot set ;
 
 : emit-userenvs ( -- )
index e21e13dc1325569c18d896f85115aedf791cdbe3..9d3a66df5bb0978096d449b7b46aa2e0ae3a1401 100755 (executable)
@@ -588,3 +588,8 @@ FUNCTION: short ffi_test_48 ( bool-field-test x ) ;
         123 >>parents
     ffi_test_48
 ] unit-test
+
+! Regression: calling an undefined function would raise a protection fault
+FUNCTION: void this_does_not_exist ( ) ;
+
+[ this_does_not_exist ] [ { "kernel-error" 10 f f } = ] must-fail-with
index e9e26240cd4e130df53b53b5a128f3444a23a1f7..bd8f33aac2b9cbeb7d972144a318f2ccd31e38df 100644 (file)
@@ -21,9 +21,8 @@ pthread_key_t tlsKey = 0;
 
 void init_platform_globals()
 {
-       if (pthread_key_create(&tlsKey, NULL) != 0){
+       if (pthread_key_create(&tlsKey, NULL) != 0)
                fatal_error("pthread_key_create() failed",0);
-       }
 
 }
 
@@ -75,8 +74,6 @@ void factor_vm::ffi_dlclose(dll *dll)
        dll->dll = NULL;
 }
 
-
-
 inline void factor_vm::primitive_existsp()
 {
        struct stat sb;
index e5a2a53f86ef1a0e33d517ee543d9ae4afe339ee..5580d8a67e9396163fbfe16e37d8ad0116297340 100755 (executable)
@@ -36,51 +36,47 @@ includes stack shufflers, some fixnum arithmetic words, and words such as tag,
 slot and eq?. A primitive call is relatively expensive (two subroutine calls)
 so this results in a big speedup for relatively little effort. */
 
-bool quotation_jit::primitive_call_p(cell i)
+bool quotation_jit::primitive_call_p(cell i, cell length)
 {
-       return (i + 2) == array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(FIXNUM_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_PRIMITIVE_WORD];
+       return (i + 2) == length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_PRIMITIVE_WORD];
 }
 
-bool quotation_jit::fast_if_p(cell i)
+bool quotation_jit::fast_if_p(cell i, cell length)
 {
-       return (i + 3) == array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
+       return (i + 3) == length
                && tagged<object>(array_nth(elements.untagged(),i + 1)).type_p(QUOTATION_TYPE)
                && array_nth(elements.untagged(),i + 2) == parent_vm->userenv[JIT_IF_WORD];
 }
 
-bool quotation_jit::fast_dip_p(cell i)
+bool quotation_jit::fast_dip_p(cell i, cell length)
 {
-       return (i + 2) <= array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DIP_WORD];
+       return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DIP_WORD];
 }
 
-bool quotation_jit::fast_2dip_p(cell i)
+bool quotation_jit::fast_2dip_p(cell i, cell length)
 {
-       return (i + 2) <= array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_2DIP_WORD];
+       return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_2DIP_WORD];
 }
 
-bool quotation_jit::fast_3dip_p(cell i)
+bool quotation_jit::fast_3dip_p(cell i, cell length)
 {
-       return (i + 2) <= array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_3DIP_WORD];
+       return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_3DIP_WORD];
 }
 
-bool quotation_jit::mega_lookup_p(cell i)
+bool quotation_jit::mega_lookup_p(cell i, cell length)
 {
-       return (i + 3) < array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(ARRAY_TYPE)
+       return (i + 4) <= length
                && tagged<object>(array_nth(elements.untagged(),i + 1)).type_p(FIXNUM_TYPE)
                && tagged<object>(array_nth(elements.untagged(),i + 2)).type_p(ARRAY_TYPE)
                && array_nth(elements.untagged(),i + 3) == parent_vm->userenv[MEGA_LOOKUP_WORD];
 }
 
+bool quotation_jit::declare_p(cell i, cell length)
+{
+       return (i + 2) <= length
+               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DECLARE_WORD];
+}
+
 bool quotation_jit::stack_frame_p()
 {
        fixnum length = array_capacity(elements.untagged());
@@ -96,7 +92,7 @@ bool quotation_jit::stack_frame_p()
                                return true;
                        break;
                case QUOTATION_TYPE:
-                       if(fast_dip_p(i) || fast_2dip_p(i) || fast_3dip_p(i))
+                       if(fast_dip_p(i,length) || fast_2dip_p(i,length) || fast_3dip_p(i,length))
                                return true;
                        break;
                default:
@@ -179,19 +175,21 @@ void quotation_jit::iterate_quotation()
                        break;
                case FIXNUM_TYPE:
                        /* Primitive calls */
-                       if(primitive_call_p(i))
+                       if(primitive_call_p(i,length))
                        {
                                emit_with(parent_vm->userenv[JIT_PRIMITIVE],obj.value());
 
                                i++;
 
                                tail_call = true;
-                               break;
                        }
+                       else
+                               push(obj.value());
+                       break;
                case QUOTATION_TYPE:
                        /* 'if' preceeded by two literal quotations (this is why if and ? are
                           mutually recursive in the library, but both still work) */
-                       if(fast_if_p(i))
+                       if(fast_if_p(i,length))
                        {
                                if(stack_frame) emit(parent_vm->userenv[JIT_EPILOG]);
                                tail_call = true;
@@ -207,39 +205,37 @@ void quotation_jit::iterate_quotation()
                                emit(parent_vm->userenv[JIT_IF]);
 
                                i += 2;
-
-                               break;
                        }
                        /* dip */
-                       else if(fast_dip_p(i))
+                       else if(fast_dip_p(i,length))
                        {
                                if(compiling)
                                        parent_vm->jit_compile(obj.value(),relocate);
                                emit_with(parent_vm->userenv[JIT_DIP],obj.value());
                                i++;
-                               break;
                        }
                        /* 2dip */
-                       else if(fast_2dip_p(i))
+                       else if(fast_2dip_p(i,length))
                        {
                                if(compiling)
                                        parent_vm->jit_compile(obj.value(),relocate);
                                emit_with(parent_vm->userenv[JIT_2DIP],obj.value());
                                i++;
-                               break;
                        }
                        /* 3dip */
-                       else if(fast_3dip_p(i))
+                       else if(fast_3dip_p(i,length))
                        {
                                if(compiling)
                                        parent_vm->jit_compile(obj.value(),relocate);
                                emit_with(parent_vm->userenv[JIT_3DIP],obj.value());
                                i++;
-                               break;
                        }
+                       else
+                               push(obj.value());
+                       break;
                case ARRAY_TYPE:
                        /* Method dispatch */
-                       if(mega_lookup_p(i))
+                       if(mega_lookup_p(i,length))
                        {
                                emit_mega_cache_lookup(
                                        array_nth(elements.untagged(),i),
@@ -247,8 +243,13 @@ void quotation_jit::iterate_quotation()
                                        array_nth(elements.untagged(),i + 2));
                                i += 3;
                                tail_call = true;
-                               break;
                        }
+                       /* Non-optimizing compiler ignores declarations */
+                       else if(declare_p(i,length))
+                               i++;
+                       else
+                               push(obj.value());
+                       break;
                default:
                        push(obj.value());
                        break;
index 43beb0511276b025927a664e3862b4efbe47511d..b9b25b8ff34d20cba4b8d6bb5a5e6c5dd879bdc7 100755 (executable)
@@ -12,12 +12,13 @@ struct quotation_jit : public jit {
                  relocate(relocate_){};
 
        void emit_mega_cache_lookup(cell methods, fixnum index, cell cache);
-       bool primitive_call_p(cell i);
-       bool fast_if_p(cell i);
-       bool fast_dip_p(cell i);
-       bool fast_2dip_p(cell i);
-       bool fast_3dip_p(cell i);
-       bool mega_lookup_p(cell i);
+       bool primitive_call_p(cell i, cell length);
+       bool fast_if_p(cell i, cell length);
+       bool fast_dip_p(cell i, cell length);
+       bool fast_2dip_p(cell i, cell length);
+       bool fast_3dip_p(cell i, cell length);
+       bool mega_lookup_p(cell i, cell length);
+       bool declare_p(cell i, cell length);
        bool stack_frame_p();
        void iterate_quotation();
 };
index d10a6678b821cd5e5125a84b06aa9e1ce7434c46..562eef92200cd0b693c2ffbaa68f13f046d24464 100755 (executable)
@@ -57,6 +57,7 @@ enum special_object {
        JIT_EXECUTE_WORD,
        JIT_EXECUTE_JUMP,
        JIT_EXECUTE_CALL,
+       JIT_DECLARE_WORD,
 
        /* Polymorphic inline cache generation in inline_cache.c */
        PIC_LOAD            = 47,