]> gitweb.factorcode.org Git - factor.git/commitdiff
slot compiled efficiently
authorSlava Pestov <slava@factorcode.org>
Thu, 17 Feb 2005 21:10:35 +0000 (21:10 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 17 Feb 2005 21:10:35 +0000 (21:10 +0000)
TODO.FACTOR.txt
factor/jedit/FactorPlugin.java
library/arrays.factor
library/generic/tuple.factor
library/hashtables.factor
library/inference/types.factor
library/test/crashes.factor
library/test/errors.factor
library/tools/debugger.factor
library/tools/interpreter.factor
native/factor.h

index 686e102feed84e8a832a3ccd0e61f39c25c40ccd..f3072197a9f7e146e0181f26c7f7880b06517641 100644 (file)
 - don't hardcode so many colors\r
 - ffi unicode strings: null char security hole\r
 - utf16 string boxing\r
-- slot compile problem\r
 - sdl console crash\r
 - UI: don't roll over if mouse button is down\r
+- more accurate types for various words\r
+- optimize out >array, >tuple, >hashtable etc\r
 \r
 + compiler/ffi:\r
 \r
index 9d4756ef1ff0f54ecd1ffb24e0e5ae9d9fb7e5fd..7337f04cb53d7d60ed0256c8fbfd1af38188dc17 100644 (file)
@@ -507,7 +507,7 @@ public class FactorPlugin extends EditPlugin
                        String text = buffer.getLineText(i);
                        int index = text.indexOf("USING:");
                        if(index != -1)
-                               return index + "USING:".length();
+                               return buffer.getLineStartOffset(i) + index;
                }
                
                return -1;
@@ -565,7 +565,7 @@ public class FactorPlugin extends EditPlugin
                if(end == -1)
                        end = buffer.getLength();
 
-               String decl = text.substring(offset,end);
+               String decl = text.substring(offset + "USING:".length(),end);
                
                List declList = new ArrayList();
                StringTokenizer st = new StringTokenizer(decl);
@@ -574,7 +574,7 @@ public class FactorPlugin extends EditPlugin
                declList.add(vocab);
                Collections.sort(declList);
                
-               StringBuffer buf = new StringBuffer(" ");
+               StringBuffer buf = new StringBuffer("USING: ");
                Iterator iter = declList.iterator();
                while(iter.hasNext())
                {
index 588210289402d8d5f429afbdaeb97c621d13718c..c467186cd34337403b1786b2891c5826709eb6b1 100644 (file)
@@ -15,8 +15,10 @@ USING: generic math-internals kernel lists vectors ;
 
 BUILTIN: array 8
 
-: array-capacity   ( array -- n )   1 slot ; inline
-: vector-array     ( vec -- array ) >vector 2 slot ; inline
+DEFER: %fixnum
+
+: array-capacity   ( array -- n ) 1 slot %fixnum ; inline
+: vector-array     ( vec -- array ) >vector 2 slot %array ; inline
 : set-vector-array ( array vec -- ) >vector 2 set-slot ; inline
 
 : array-nth ( n array -- obj )
index 1cb0cb225947f37c3a094b4e173ab587bc35b4be..2df79f17bc4681f5e8af06b5c32994d287a7c9cc 100644 (file)
@@ -204,7 +204,7 @@ M: tuple clone ( tuple -- tuple )
     clone-tuple dup clone-delegate ;
 
 : tuple>list ( tuple -- list )
-    dup array-capacity swap array>list ;
+    >tuple dup array-capacity swap array>list ;
 
 M: tuple = ( obj tuple -- ? )
     over tuple? [
index b1480dc79e969215fc129f15939a80e650770b71..5980f5c72bf93e2e32b1c09de5f22d6e806d59df 100644 (file)
@@ -15,8 +15,8 @@ BUILTIN: hashtable 10
 
 IN: kernel-internals
 
-: hash-array 2 slot ; inline
-: set-hash-array 2 set-slot ; inline
+: hash-array >hashtable 2 slot ( promise ) %array ; inline
+: set-hash-array swap >array swap >hashtable 2 set-slot ; inline
 
 : hash-bucket ( n hash -- alist )
     swap >fixnum swap >hashtable hash-array array-nth ; inline
index ff91178f5749842dc6e4e93ceb941d809729d0d0..709944114c542bfc386c4729f5908b68e50f17be 100644 (file)
@@ -27,21 +27,25 @@ lists math namespaces strings vectors words stdio prettyprint ;
     \ >string \ string infer-check
 ] "infer" set-word-property
 
-! : literal-slot ( -- )
-!     dataflow-drop, pop-d literal-value
-!     peek-d value-class builtin-supertypes dup length 1 = [
-!         cons \ slot [ [ object ] [ object ] ] (consume/produce)
-!     ] [
-!         "slot called without static type knowledge" throw
-!     ] ifte ;
-! 
-! : computed-slot ( -- )
-!     \ slot dup "infer-effect" word-property consume/produce ;
-! 
-! \ slot [
-!     [ object fixnum ] ensure-d
-!     peek-d literal? [ literal-slot ] [ computed-slot ] ifte
-! ] "infer" set-word-property
+: fast-slot? ( -- ? )
+    #! If the slot number is literal and the object's type is
+    #! known, we can compile a slot access into a single
+    #! instruction (x86).
+    peek-d literal?
+    peek-next-d value-class builtin-supertypes length 1 = and ;
+
+: fast-slot ( -- )
+    dataflow-drop, pop-d literal-value
+    peek-d value-class builtin-supertypes cons
+    \ slot [ [ object ] [ object ] ] (consume/produce) ;
+
+: computed-slot ( -- )
+    \ slot dup "infer-effect" word-property consume/produce ;
+
+\ slot [
+    [ object fixnum ] ensure-d
+    fast-slot? [ fast-slot ] [ computed-slot ] ifte
+] "infer" set-word-property
 
 : type-value-map ( value -- )
     num-types [ dup builtin-type pick swons cons ] project
index eadb5b4f3d1cbc47b8b4b9938dee62d764bfe527..b7a70471df3990199e5185e439a552da4a984179 100644 (file)
@@ -1,19 +1,10 @@
 IN: scratchpad
-USE: errors
-USE: kernel
-USE: math
-USE: namespaces
-USE: parser
-USE: strings
-USE: test
-USE: vectors
-USE: lists
-USE: words
-USE: prettyprint
 
 ! Various things that broke CFactor at various times.
 ! This should run without issue (and tests nothing useful)
 ! in Java Factor
+USING: errors kernel lists math memory namespaces parser
+prettyprint strings test vectors words ;
 
 "20 <sbuf> \"foo\" set" eval
 "garbage-collection" eval
index 5e7a3fb4acd90b14df25c0122aeb97836a771725..b6193a06f44a6c0b0f8ebfb18022e720c49b0d4d 100644 (file)
@@ -25,4 +25,4 @@ USE: stdio
 
 [ [ "2 car" ] parse ] [ print-error ] catch
 
-[ [ "\"\" { } vector-nth" ] parse ] [ type-check-error ] catch
+[ [ "\"\" { } vector-nth" ] parse ] [ type-check-error ] catch
index a80d0e2f7c68063d97460cd1f01cb91bcac77d09..745bbc0bb5b8013ec0b175b120bac002b2aab044 100644 (file)
@@ -97,7 +97,7 @@ M: object error. ( error -- )
         "error-line-number" get [ 1 ] unless* unparse ,
     ] make-string print
     
-    "error-line" get print
+    "error-line" get dup string? [ print ] [ drop ] ifte
     
     [ "error-col" get " " fill , "^" , ] make-string print ;
 
index a523e06ede76f7e8b46281b53c7a8b25ecb5ae6c..7aa137407b984f62fa72b91ff97aadfa38f2d836 100644 (file)
@@ -1,40 +1,8 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
-! Copyright (C) 2004 Slava Pestov.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: interpreter
-USE: vectors
-USE: namespaces
-USE: kernel
-USE: lists
-USE: words
-USE: errors
-USE: strings
-USE: prettyprint
-USE: stdio
+USING: errors kernel lists math namespaces prettyprint stdio
+strings vectors words ;
 
 ! A Factor interpreter written in Factor. Used by compiler for
 ! partial evaluation, also for trace and step.
@@ -48,6 +16,7 @@ SYMBOL: meta-d
 : push-d meta-d get vector-push ;
 : pop-d meta-d get vector-pop ;
 : peek-d meta-d get vector-peek ;
+: peek-next-d meta-d get [ vector-length 2 - ] keep vector-nth ;
 SYMBOL: meta-n
 SYMBOL: meta-c
 
index 1dc542d37b9c517a1a4df29597e44006f16c301d..adb5cad2da119364353a67bfa7f6ab85fb750266 100644 (file)
@@ -19,7 +19,11 @@ typedef unsigned long int CELL;
 CELL ds_bot;
 
 /* raw pointer to datastack top */
-register DLLEXPORT CELL ds asm("esi");
+#ifdef FACTOR_X86
+       register DLLEXPORT CELL ds asm("esi");
+#else
+       CELL ds;
+#endif
 
 /* raw pointer to callstack bottom */
 CELL cs_bot;