]> gitweb.factorcode.org Git - factor.git/commitdiff
huge cleanup
authorSlava Pestov <slava@factorcode.org>
Fri, 24 Dec 2004 07:52:02 +0000 (07:52 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 24 Dec 2004 07:52:02 +0000 (07:52 +0000)
62 files changed:
TODO.FACTOR.txt
library/bootstrap/boot-stage2.factor
library/bootstrap/init-stage2.factor
library/bootstrap/primitives.factor
library/cli.factor
library/combinators.factor
library/compiler/assembler.factor
library/cons.factor
library/errors.factor
library/generic/generic.factor
library/httpd/default-responders.factor
library/httpd/html.factor
library/httpd/inspect-responder.factor [deleted file]
library/inference/branches.factor
library/inference/words.factor
library/io/io-internals.factor
library/kernel.factor
library/math/complex.factor
library/math/integer.factor
library/math/ratio.factor
library/namespaces.factor
library/primitives.factor
library/stack.factor
library/strings.factor
library/test/dataflow.factor
library/test/init.factor
library/test/lists/cons.factor
library/test/math/float.factor
library/test/namespaces.factor
library/test/vectors.factor
library/threads.factor
library/tools/debugger.factor
library/tools/inspector.factor [deleted file]
library/vectors.factor
library/vocabularies.factor
library/words.factor
native/arithmetic.c
native/arithmetic.h
native/array.c
native/array.h
native/compiler.c
native/compiler.h
native/complex.c
native/complex.h
native/cons.c
native/cons.h
native/factor.h
native/float.c
native/primitives.c
native/primitives.h
native/ratio.c
native/ratio.h
native/sbuf.c
native/string.c
native/string.h
native/types.c
native/types.h
native/unix/io.c
native/vector.c
native/vector.h
native/word.c
native/word.h

index 1b3f3ad8c465d5207626c83bb7b8c396c89df23d..502bec0e0027e298619bd966b60f8d8367e62e89 100644 (file)
@@ -13,6 +13,8 @@
 \r
 + compiler:\r
 \r
+- slot compilation\r
+- optimize away dispatch\r
 - getenv/setenv: if literal arg, compile as a load/store\r
 - assembler opcodes dispatch on operand types\r
 - save code in image\r
@@ -21,6 +23,7 @@
 \r
 - make see work with generics\r
 - doc comments of generics\r
+- redo traits with generic method map\r
 \r
 + ffi:\r
 \r
 - remove sbufs\r
 - cat, reverse-cat primitives\r
 - first-class hashtables\r
-- rewrite accessors and mutators in Factor, with slot/set-slot primitive\r
 - add a socket timeout\r
 - do transfer-word in fixup\r
-- move dispatch getenv setenv to kernel-internals\r
 \r
 + misc:\r
 \r
@@ -62,8 +63,7 @@
 - jedit ==> jedit-word, jedit takes a file name\r
 - nicer way to combine two paths\r
 - ditch object paths\r
-- browser responder for word links in HTTPd; inspect responder for\r
-  objects\r
+- browser responder for word links in HTTPd\r
 - worddef props\r
 - prettyprint: when unparse called due to recursion, write a link\r
 \r
index a39fbe2e61c8c6b39befe4f2697ae83bad22945d..daef16f2b79b43cbb9981a9d2bb43dd2610006f8 100644 (file)
@@ -99,7 +99,6 @@ USE: namespaces
     "/library/io/files.factor"\r
     "/library/eval-catch.factor"\r
     "/library/tools/listener.factor"\r
-    "/library/tools/inspector.factor"\r
     "/library/tools/word-tools.factor"\r
     "/library/test/test.factor"\r
     "/library/io/ansi.factor"\r
@@ -146,7 +145,6 @@ USE: namespaces
     "/library/httpd/responder.factor"\r
     "/library/httpd/httpd.factor"\r
     "/library/httpd/file-responder.factor"\r
-    "/library/httpd/inspect-responder.factor"\r
     "/library/httpd/test-responder.factor"\r
     "/library/httpd/quit-responder.factor"\r
     "/library/httpd/resource-responder.factor"\r
index 7a9cf4b3c1ee3ca0c96209918bd0fc8952f93267..da2f26fe87e04eaf972b06cd24910958e8c15114 100644 (file)
@@ -42,6 +42,7 @@ USE: stdio
 USE: presentation
 USE: words
 USE: unparser
+USE: kernel-internals
 
 : cli-args ( -- args ) 10 getenv ;
 
index 2587b3d03cd42149d59f7e7080185d9a02eb67b9..9aed3d7c354ec0844919669a67c2a2de574971b7 100644 (file)
@@ -55,14 +55,9 @@ vocabularies get [
     [ "kernel" | "call" ]
     [ "kernel" | "ifte" ]
     [ "lists" | "cons" ]
-    [ "lists" | "car" ]
-    [ "lists" | "cdr" ]
     [ "vectors" | "<vector>" ]
-    [ "vectors" | "vector-length" ]
-    [ "vectors" | "set-vector-length" ]
     [ "vectors" | "vector-nth" ]
     [ "vectors" | "set-vector-nth" ]
-    [ "strings" | "str-length" ]
     [ "strings" | "str-nth" ]
     [ "strings" | "str-compare" ]
     [ "strings" | "str=" ]
@@ -85,15 +80,10 @@ vocabularies get [
     [ "math" | ">fixnum" ]
     [ "math" | ">bignum" ]
     [ "math" | ">float" ]
-    [ "math" | "numerator" ]
-    [ "math" | "denominator" ]
-    [ "math" | "fraction>" ]
+    [ "math-internals" | "(fraction>)" ]
     [ "parser" | "str>float" ]
     [ "unparser" | "(unparse-float)" ]
-    [ "math" | "float>bits" ]
-    [ "math" | "real" ]
-    [ "math" | "imaginary" ]
-    [ "math" | "rect>" ]
+    [ "math-internals" | "(rect>)" ]
     [ "math-internals" | "fixnum=" ]
     [ "math-internals" | "fixnum+" ]
     [ "math-internals" | "fixnum-" ]
@@ -150,21 +140,9 @@ vocabularies get [
     [ "math-internals" | "fsinh" ]
     [ "math-internals" | "fsqrt" ]
     [ "words" | "<word>" ]
-    [ "words" | "word-hashcode" ]
-    [ "words" | "word-xt" ]
-    [ "words" | "set-word-xt" ]
-    [ "words" | "word-primitive" ]
-    [ "words" | "set-word-primitive" ]
-    [ "words" | "word-parameter" ]
-    [ "words" | "set-word-parameter" ]
-    [ "words" | "word-plist" ]
-    [ "words" | "set-word-plist" ]
+    [ "words" | "update-xt" ]
     [ "profiler" | "call-profiling" ]
-    [ "profiler" | "call-count" ]
-    [ "profiler" | "set-call-count" ]
     [ "profiler" | "allot-profiling" ]
-    [ "profiler" | "allot-count" ]
-    [ "profiler" | "set-allot-count" ]
     [ "words" | "compiled?" ]
     [ "kernel" | "drop" ]
     [ "kernel" | "dup" ]
@@ -174,8 +152,8 @@ vocabularies get [
     [ "kernel" | ">r" ]
     [ "kernel" | "r>" ]
     [ "kernel" | "eq?" ]
-    [ "kernel" | "getenv" ]
-    [ "kernel" | "setenv" ]
+    [ "kernel-internals" | "getenv" ]
+    [ "kernel-internals" | "setenv" ]
     [ "io-internals" | "open-file" ]
     [ "files" | "stat" ]
     [ "files" | "(directory)" ]
@@ -214,8 +192,6 @@ vocabularies get [
     [ "files" | "cd" ]
     [ "compiler" | "compiled-offset" ]
     [ "compiler" | "set-compiled-offset" ]
-    [ "compiler" | "set-compiled-cell" ]
-    [ "compiler" | "set-compiled-byte" ]
     [ "compiler" | "literal-top" ]
     [ "compiler" | "set-literal-top" ]
     [ "kernel" | "address" ]
@@ -239,6 +215,15 @@ vocabularies get [
     [ "kernel-internals" | "memory>string" ]
     [ "alien" | "local-alien?" ]
     [ "alien" | "alien-address" ]
+    [ "lists" | ">cons" ]
+    [ "vectors" | ">vector" ]
+    [ "strings" | ">string" ]
+    [ "words" | ">word" ]
+    [ "kernel-internals" | "slot" ]
+    [ "kernel-internals" | "set-slot" ]
+    [ "kernel-internals" | "integer-slot" ]
+    [ "kernel-internals" | "set-integer-slot" ]
+    [ "kernel-internals" | "grow-array" ]
 ] [
     unswons create swap succ [ f define ] keep
 ] each drop
index 8a61dc9c355a584cb0911fb42d68726329347610..5585e233a34b863555e6d7afd8abc8e764db5170 100644 (file)
@@ -54,8 +54,12 @@ USE: words
         ?run-file
     ] when ;
 
-: cli-var-param ( name value -- )
-    swap ":" split set-object-path ;
+: set-path ( value list -- )
+    unswons over [ nest [ set-path ] bind ] [ nip set ] ifte ;
+
+: cli-var-param ( name value -- ) swap ":" split set-path ;
+
+: cli-bool-param ( name -- ) "no-" ?str-head not put ;
 
 : cli-param ( param -- )
     #! Handle a command-line argument starting with '-' by
@@ -64,11 +68,7 @@ USE: words
     #!
     #! Arguments containing = are handled differently; they
     #! set the object path.
-    "=" split1 [
-        cli-var-param
-    ] [
-        "no-" ?str-head not put
-    ] ifte* ;
+    "=" split1 [ cli-var-param ] [ cli-bool-param ] ifte* ;
 
 : cli-arg ( argument -- argument )
     #! Handle a command-line argument. If the argument was
index 197fc7c0ebbc951ecc3dcb1c9e401ec6642d5287..394b8c981ccca321b00371af276239d5c821c05d 100644 (file)
@@ -26,7 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: kernel
-USE: lists
 
 : slip ( quot x -- x )
     >r call r> ; inline
@@ -51,36 +50,6 @@ USE: lists
     #! Apply code to input.
     swap dup >r call r> swap ; inline
 
-IN: lists DEFER: uncons IN: kernel
-: cond ( x list -- )
-    #! The list is of this form:
-    #!
-    #! [ [ condition 1 ] [ code 1 ]
-    #!   [ condition 2 ] [ code 2 ]
-    #!   ... ]
-    #!
-    #! Each condition is evaluated in turn. If it returns true,
-    #! the code is evaluated. If it returns false, the next
-    #! condition is checked.
-    #!
-    #! Before evaluating each condition, the top of the stack is
-    #! duplicated. After the last condition is evaluated, the
-    #! top of the stack is popped.
-    #!
-    #! So each condition and code block must have stack effect:
-    #! ( X -- )
-    #!
-    #! This combinator will not compile.
-    dup [
-        uncons >r over >r call r> r> rot [
-            car call
-        ] [
-            cdr cond
-        ] ifte
-    ] [
-        2drop
-    ] ifte ;
-
 : ifte* ( cond true false -- )
     #! If the condition is not f, execute the 'true' quotation,
     #! with the condition on the stack. Otherwise, pop the
index c4384fd11ec792db88e8a54c95d310eecadcdf30..4cc3347c1f5dcdae8fe8f3cf7ca28176ad5a2983 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: compiler
+USE: alien
 USE: math
 USE: kernel
 
-: cell 4 ;
-: literal-table 1024 cell * ;
+: cell 4 ; inline
+: literal-table 1024 cell * ; inline
 
 : init-assembler ( -- )
     compiled-offset literal-table + set-compiled-offset ;
 
+: set-compiled-byte ( n addr -- )
+    <alien> 0 set-alien-1 ; inline
+
+: set-compiled-cell ( n addr -- )
+    <alien> 0 set-alien-cell ; inline
+
 : compile-aligned ( n -- )
-    compiled-offset swap align set-compiled-offset ;
+    compiled-offset swap align set-compiled-offset ; inline
 
 : intern-literal ( obj -- lit# )
     address
@@ -45,8 +52,8 @@ USE: kernel
 
 : compile-byte ( n -- )
     compiled-offset set-compiled-byte
-    compiled-offset 1 + set-compiled-offset ;
+    compiled-offset 1 + set-compiled-offset ; inline
 
 : compile-cell ( n -- )
     compiled-offset set-compiled-cell
-    compiled-offset cell + set-compiled-offset ;
+    compiled-offset cell + set-compiled-offset ; inline
index 165a8c0316e632b2f15d7796626e681859cf74a3..689791bc66c0cf87635ffe31ca88f865bcf9a902 100644 (file)
@@ -28,6 +28,7 @@
 IN: lists
 USE: generic
 USE: kernel
+USE: kernel-internals
 
 ! This file contains vital list-related words that everything
 ! else depends on, and is loaded early in bootstrap.
@@ -35,6 +36,9 @@ USE: kernel
 
 BUILTIN: cons 2
 
+: car ( [ car | cdr ] -- car ) >cons 0 slot ; inline
+: cdr ( [ car | cdr ] -- cdr ) >cons 1 slot ; inline
+
 : swons ( cdr car -- [ car | cdr ] )
     #! Push a new cons cell. If the cdr is f or a proper list,
     #! has the effect of prepending the car to the cdr.
index 53eded4680e43256519e08950762871c2d56dfa1..ad0109c116fd6bb02614dd6d67635376275368a5 100644 (file)
@@ -30,6 +30,7 @@ DEFER: callcc1
 
 IN: errors
 USE: kernel
+USE: kernel-internals
 USE: lists
 USE: math
 USE: namespaces
index 6db948354324ef4048aecb512c4597ebaf62218d..affa2bb049e701dc6bb0fe02c8d29f2854f295bd 100644 (file)
@@ -29,6 +29,7 @@ IN: generic
 USE: errors
 USE: hashtables
 USE: kernel
+USE: kernel-internals
 USE: lists
 USE: namespaces
 USE: parser
index 5ccf6217ebc8b6945a0dcae3e8999ac8fa350fa3..39cc7c89d4d9749dc545bd712695689c62dacb12 100644 (file)
@@ -51,12 +51,6 @@ global [ <namespace> "httpd-responders" set ] bind
     [ test-responder ] "get" set
 ] extend add-responder
 
-<responder> [
-    "inspect" "responder" set
-    [ inspect-responder ] "get" set
-    "global" "default-argument" set
-] extend add-responder
-
 <responder> [
     "quit" "responder" set
     [ quit-responder ] "get" set
index d73e3d60c45e1add6c5f7d125ad4305b82e3cd21..00f3f3fdad27b8e1ad6d0b1f907ce22995cb550b 100644 (file)
@@ -110,17 +110,6 @@ USE: generic
         call
     ] ifte* ;
 
-: object-link-href ( path -- href )
-    #! Perhaps this should not be hard-coded.
-    "/responder/inspect/" swap cat2 ;
-
-: object-link-tag ( style quot -- )
-    over "object-link" swap assoc [
-        <a href= object-link-href url-encode a> call </a>
-    ] [
-        call
-    ] ifte* ;
-
 : icon-tag ( string style quot -- )
     over "icon" swap assoc dup [
         <img src= "/responder/resource/" swap cat2 img/>
@@ -137,10 +126,8 @@ M: html-stream fwrite-attr ( str style stream -- )
     [
         [
             [
-                [
-                    [ drop chars>entities write ] span-tag
-                ] file-link-tag
-            ] object-link-tag
+                [ drop chars>entities write ] span-tag
+            ] file-link-tag
         ] icon-tag
     ] bind ;
 
diff --git a/library/httpd/inspect-responder.factor b/library/httpd/inspect-responder.factor
deleted file mode 100644 (file)
index 3b626cb..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-! :folding=indent:collapseFolds=0:
-
-! $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.
-
-IN: inspect-responder
-USE: html
-USE: inspector
-USE: namespaces
-USE: kernel
-
-USE: httpd
-USE: httpd-responder
-
-: inspect-responder ( argument -- )
-    serving-html dup [
-        describe-path
-    ] simple-html-document ;
index 56b16f00025766d0b375054b3dff3ad88a5ba7e9..c47b5405b618ef5f7b13725288084d72b385a983 100644 (file)
@@ -194,5 +194,6 @@ USE: hashtables
     pop-d drop ( n )
     infer-branches ;
 
+USE: kernel-internals
 \ dispatch [ infer-dispatch ] "infer" set-word-property
 \ dispatch [ 2 | 0 ] "infer-effect" set-word-property
index b35838b65a055ee018f4a45dab4927001ff4bc26..970efd7f9eb6f63416bbd1d6344548a49ba196d9 100644 (file)
@@ -136,7 +136,9 @@ USE: parser
         ] when*
     ] catch ;
 
-: apply-compound ( word -- )
+GENERIC: (apply-word)
+
+M: compound (apply-word) ( word -- )
     #! Infer a compound word's stack effect.
     dup "inline" word-property [
         inline-compound drop
@@ -144,6 +146,9 @@ USE: parser
         infer-compound
     ] ifte ;
 
+M: symbol (apply-word) ( word -- )
+    apply-literal ;
+
 : current-word ( -- word )
     #! Push word we're currently inferring effect of.
     recursive-state get car car ;
@@ -175,9 +180,6 @@ USE: parser
         2drop no-base-case
     ] ifte ;
 
-: no-effect? ( word -- ? )
-    "no-effect" word-property ;
-
 : apply-word ( word -- )
     #! Apply the word's stack effect to the inferencer state.
     dup recursive-state get assoc dup [
@@ -186,13 +188,11 @@ USE: parser
         drop dup "infer-effect" word-property dup [
             apply-effect
         ] [
-            drop
-            [
-                [ no-effect? ] [ no-effect      ]
-                [ compound?  ] [ apply-compound ]
-                [ symbol?    ] [ apply-literal  ]
-                [ drop t     ] [ no-effect      ]
-            ] cond
+            drop dup "no-effect" word-property [
+                no-effect
+            ] [
+                (apply-word)
+            ] ifte
         ] ifte
     ] ifte ;
 
index 0496ac27936a18610a2377c29566a76b44b507a5..b0e55c2f8341812b6048c1e63cdf1e0a30ca14c3 100644 (file)
@@ -28,6 +28,7 @@
 IN: io-internals
 USE: generic
 USE: kernel
+USE: kernel-internals
 USE: namespaces
 USE: strings
 USE: threads
index 00620bcf3cd75bbbc96e2c683e5dbfd7a382c7c0..8785ff03aab192ad20bfa6baa205f4536aba59a3 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: kernel
+IN: kernel-internals
 USE: generic
+USE: kernel
 USE: vectors
 
+: dispatch ( n vtable -- )
+    vector-nth call ;
+
+IN: kernel
+
 GENERIC: hashcode ( obj -- n )
 M: object hashcode drop 0 ;
 
@@ -43,9 +49,6 @@ M: object = eq? ;
     #! Returns one of "unix" or "win32".
     11 getenv ;
 
-: dispatch ( n vtable -- )
-    vector-nth call ;
-
 : set-boot ( quot -- )
     #! Set the boot quotation.
     8 setenv ;
index fe5ab31fad26cfa03d0f1c487480f687087a26f7..2e606f88252a1096e4d8db166c9fe10650141d86 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+IN: errors
+DEFER: throw
+
 IN: math
 USE: generic
 USE: kernel
+USE: kernel-internals
 USE: math
 USE: math-internals
 
+GENERIC: real ( #{ re im } -- re )
+M: real real ;
+M: complex real 0 slot ;
+
+GENERIC: imaginary ( #{ re im } -- im )
+M: real imaginary drop 0 ;
+M: complex imaginary 1 slot ;
+
+: rect> ( xr xi -- x )
+    over real? over real? and [
+        dup 0 = [ drop ] [ (rect>) ] ifte
+    ] [
+        "Complex number must have real components" throw drop
+    ] ifte ; inline
+
 : >rect ( x -- xr xi ) dup real swap imaginary ; inline
 
 : conjugate ( z -- z* )
index 312a12ed5b0e7c65dbf906dba364bf4c2f4bd8cc..182388351ef0e4d7e686228bbba2f7a18f4fb56d 100644 (file)
@@ -25,6 +25,9 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+IN: errors
+DEFER: throw
+
 IN: math-internals
 USE: generic
 USE: kernel
@@ -34,6 +37,17 @@ USE: math
     dup 0 < [ swap neg swap neg ] when
     2dup gcd tuck /i >r /i r> ; inline
 
+: fraction> ( a b -- a/b )
+    dup 0 = [
+        "Division by zero" throw drop
+    ] [
+        dup 1 = [
+            drop
+        ] [
+            (fraction>)
+        ] ifte
+    ] ifte ; inline
+
 : integer/ ( x y -- x/y )
     reduce fraction> ; inline
 
index 7ac630d47ff83d3c0bc600c763cc1046cd1f538c..2ab1ebd2248ced05ea16fc0d496941693ab7990d 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: math-internals
+IN: math
 USE: generic
 USE: kernel
+USE: kernel-internals
 USE: math
+USE: math-internals
+
+GENERIC: numerator ( a/b -- a )
+M: integer numerator ;
+M: ratio numerator 0 slot ;
+
+GENERIC: denominator ( a/b -- b )
+M: integer denominator drop 1 ;
+M: ratio denominator 1 slot ;
+
+IN: math-internals
 
 : 2>fraction ( a/b c/d -- a c b d )
     [ swap numerator swap numerator ] 2keep
index 79160b77b5185228d645a335ffce960667709383..2d669d5d955a4822c829c0f74f2b6246196b1e80 100644 (file)
@@ -28,9 +28,8 @@
 IN: namespaces
 USE: hashtables
 USE: kernel
+USE: kernel-internals
 USE: lists
-USE: strings
-USE: vectors
 
 ! Other languages have classes, objects, variables, etc.
 ! Factor has similar concepts.
@@ -72,11 +71,9 @@ USE: vectors
 : init-namespaces ( -- )
     global >n ;
 
-: namespace-buckets 23 ;
-
 : <namespace> ( -- n )
     #! Create a new namespace.
-    namespace-buckets <hashtable> ;
+    23 <hashtable> ;
 
 : (get) ( var ns -- value )
     #! Internal word for searching the namestack.
@@ -98,6 +95,15 @@ USE: vectors
 : set ( value variable -- ) namespace set-hash ;
 : put ( variable value -- ) swap set ;
 
+: nest ( variable -- hash )
+    #! If the variable is set in the current namespace, return
+    #! its value, otherwise set its value to a new namespace.
+    dup namespace hash dup [
+        nip
+    ] [
+        drop >r <namespace> dup r> set
+    ] ifte ;
+
 : change ( var quot -- )
     #! Execute the quotation with the variable value on the
     #! stack. The set the variable to the return value of the
@@ -121,31 +127,5 @@ USE: vectors
     #!      ] extend ;
     over >r bind r> ; inline
 
-: traverse-path ( name object -- object )
-    dup hashtable? [ hash ] [ 2drop f ] ifte ;
-
-: (object-path) ( object list -- object )
-    [ uncons >r swap traverse-path r> (object-path) ] when* ;
-
-: object-path ( list -- object )
-    #! An object path is a list of strings. Each string is a
-    #! variable name in the object namespace at that level.
-    #! Returns f if any of the objects are not set.
-    namespace swap (object-path) ;
-
-: (set-object-path) ( name -- namespace )
-    dup namespace hash dup [
-        nip
-    ] [
-        drop <namespace> tuck put
-    ] ifte ;
-
-: set-object-path ( value list -- )
-    unswons over [
-        (set-object-path) [ set-object-path ] bind
-    ] [
-        nip set
-    ] ifte ;
-
 : on ( var -- ) t put ;
 : off ( var -- ) f put ;
index bb0d2fb105f8ea027c442a057b4878d37ca7786a..867fdcaf8f27fb874ee81d39a1026559a93950ec 100644 (file)
@@ -27,6 +27,7 @@
 
 IN: alien
 DEFER: alien
+DEFER: dll
 
 USE: alien
 USE: compiler
@@ -52,14 +53,9 @@ USE: words
     [ call                   " quot -- "                          [ [ general-list ] [ ] ] ]
     [ ifte                   " cond true false -- "               [ [ object general-list general-list ] [ ] ] ]
     [ cons                   " car cdr -- [ car | cdr ] "         [ [ object object ] [ cons ] ] ]
-    [ car                    " [ car | cdr ] -- car "             [ [ cons ] [ object ] ] ]
-    [ cdr                    " [ car | cdr ] -- cdr "             [ [ cons ] [ object ] ] ]
     [ <vector>               " capacity -- vector"                [ [ integer ] [ vector ] ] ]
-    [ vector-length          " vector -- n "                      [ [ vector ] [ integer ] ] ]
-    [ set-vector-length      " n vector -- "                      [ [ integer vector ] [ ] ] ]
     [ vector-nth             " n vector -- obj "                  [ [ integer vector ] [ object ] ] ]
     [ set-vector-nth         " obj n vector -- "                  [ [ object integer vector ] [ ] ] ]
-    [ str-length             " str -- n "                         [ [ string ] [ integer ] ] ]
     [ str-nth                " n str -- ch "                      [ [ integer string ] [ integer ] ] ]
     [ str-compare            " str str -- -1/0/1 "                [ [ string string ] [ integer ] ] ]
     [ str=                   " str str -- ? "                     [ [ string string ] [ boolean ] ] ]
@@ -82,15 +78,10 @@ USE: words
     [ >fixnum                " n -- fixnum "                      [ [ number ] [ fixnum ] ] ]
     [ >bignum                " n -- bignum "                      [ [ number ] [ bignum ] ] ]
     [ >float                 " n -- float "                       [ [ number ] [ float ] ] ]
-    [ numerator              " a/b -- a "                         [ [ rational ] [ integer ] ] ]
-    [ denominator            " a/b -- b "                         [ [ rational ] [ integer ] ] ]
-    [ fraction>              " a b -- a/b "                       [ [ integer integer ] [ rational ] ] ]
+    [ (fraction>)            " a b -- a/b "                       [ [ integer integer ] [ rational ] ] ]
     [ str>float              " str -- float "                     [ [ string ] [ float ] ] ]
     [ (unparse-float)        " float -- str "                     [ [ float ] [ string ] ] ]
-    [ float>bits             " float -- n "                       [ [ float ] [ integer ] ] ]
-    [ real                   " #{ re im } -- re "                 [ [ number ] [ real ] ] ]
-    [ imaginary              " #{ re im } -- im "                 [ [ number ] [ real ] ] ]
-    [ rect>                  " re im -- #{ re im } "              [ [ real real ] [ number ] ] ]
+    [ (rect>)                " re im -- #{ re im } "              [ [ real real ] [ number ] ] ]
     [ fixnum=                " x y -- ? "                         [ [ fixnum fixnum ] [ boolean ] ] ]
     [ fixnum+                " x y -- x+y "                       [ [ fixnum fixnum ] [ integer ] ] ]
     [ fixnum-                " x y -- x-y "                       [ [ fixnum fixnum ] [ integer ] ] ]
@@ -146,16 +137,8 @@ USE: words
     [ fsin                   " x -- y "                           [ [ real ] [ float ] ] ]
     [ fsinh                  " x -- y "                           [ [ real ] [ float ] ] ]
     [ fsqrt                  " x -- y "                           [ [ real ] [ float ] ] ]
-    [ <word>                 " prim param plist -- word "         [ [ integer object general-list ] [ word ] ] ]
-    [ word-hashcode          " word -- n "                        [ [ word ] [ integer ] ] ]
-    [ word-xt                " word -- xt "                       [ [ word ] [ integer ] ] ]
-    [ set-word-xt            " xt word -- "                       [ [ integer word ] [ ] ] ]
-    [ word-primitive         " word -- n "                        [ [ word ] [ integer ] ] ]
-    [ set-word-primitive     " n word -- "                        [ [ integer word ] [ ] ] ]
-    [ word-parameter         " word -- obj "                      [ [ word ] [ object ] ] ]
-    [ set-word-parameter     " obj word -- "                      [ [ object word ] [ ] ] ]
-    [ word-plist             " word -- alist"                     [ [ word ] [ general-list ] ] ]
-    [ set-word-plist         " alist word -- "                    [ [ general-list word ] [ ] ] ]
+    [ <word>                 " -- word "                          [ [ ] [ word ] ] ]
+    [ update-xt              " word -- "                          [ [ word ] [ ] ] ]
     [ drop                   " x -- "                             [ [ object ] [ ] ] ]
     [ dup                    " x -- x x "                         [ [ object ] [ object object ] ] ]
     [ swap                   " x y -- y x "                       [ [ object object ] [ object object ] ] ]
@@ -166,19 +149,19 @@ USE: words
     [ eq?                    " x y -- ? "                         [ [ object object ] [ boolean ] ] ]
     [ getenv                 " n -- obj "                         [ [ fixnum ] [ object ] ] ]
     [ setenv                 " obj n -- "                         [ [ object fixnum ] [ ] ] ]
-    [ open-file              " path r w -- port "                 [ 3 | 1 ] ]
-    [ stat                   " path -- [ dir? perm size mtime ] " [ 1 | 1 ] ]
-    [ (directory)            " path -- list "                     [ 1 | 1 ] ]
-    [ garbage-collection     " -- "                               [ 0 | 0 ] ]
-    [ save-image             " path -- "                          [ 1 | 0 ] ]
+    [ open-file              " path r w -- port "                 [ [ string object object ] [ port ] ] ]
+    [ stat                   " path -- [ dir? perm size mtime ] " [ [ string ] [ cons ] ] ]
+    [ (directory)            " path -- list "                     [ [ string ] [ general-list ] ] ]
+    [ garbage-collection     " -- "                               [ [ ] [ ] ] ]
+    [ save-image             " path -- "                          [ [ string ] [ ] ] ]
     [ datastack              " -- ds "                            f ]
     [ callstack              " -- cs "                            f ]
     [ set-datastack          " ds -- "                            f ]
     [ set-callstack          " cs -- "                            f ]
-    [ exit*                  " n -- "                             [ 1 | 0 ] ]
-    [ client-socket          " host port -- in out "              [ 2 | 2 ] ]
-    [ server-socket          " port -- server "                   [ 1 | 1 ] ]
-    [ close-port             " port -- "                          [ 1 | 0 ] ]
+    [ exit*                  " n -- "                             [ [ integer ] [ ] ] ]
+    [ client-socket          " host port -- in out "              [ [ string integer ] [ port port ] ] ]
+    [ server-socket          " port -- server "                   [ [ integer ] [ port ] ] ]
+    [ close-port             " port -- "                          [ [ port ] ] ]
     [ add-accept-io-task     " server callback -- "               [ 2 | 0 ] ]
     [ accept-fd              " server -- host port in out "       [ 1 | 4 ] ]
     [ can-read-line?         " port -- ? "                        [ 1 | 1 ] ]
@@ -195,45 +178,48 @@ USE: words
     [ next-io-task           " -- callback "                      [ 0 | 1 ] ]
     [ room                   " -- free total free total "         [ 0 | 4 ] ]
     [ os-env                 " str -- str "                       [ 1 | 1 ] ]
-    [ millis                 " -- n "                             [ 0 | 1 ] ]
-    [ init-random            " -- "                               [ 0 | 0 ] ]
-    [ (random-int)           " -- n "                             [ 0 | 1 ] ]
-    [ type                   " obj -- n "                         [ 1 | 1 ] ]
-    [ call-profiling         " depth -- "                         [ 1 | 0 ] ]
-    [ call-count             " word -- n "                        [ 1 | 1 ] ]
-    [ set-call-count         " n word -- "                        [ 2 | 0 ] ]
-    [ allot-profiling        " depth -- "                         [ 1 | 0 ] ]
-    [ allot-count            " word -- n "                        [ 1 | 1 ] ]
-    [ set-allot-count        " n word -- n "                      [ 2 | 1 ] ]
-    [ cwd                    " -- dir "                           [ 0 | 1 ] ]
-    [ cd                     " dir -- "                           [ 1 | 0 ] ]
-    [ compiled-offset        " -- ptr "                           [ 0 | 1 ] ]
-    [ set-compiled-offset    " ptr -- "                           [ 1 | 0 ] ]
-    [ set-compiled-cell      " n ptr -- "                         [ 2 | 0 ] ]
-    [ set-compiled-byte      " n ptr -- "                         [ 2 | 0 ] ]
-    [ literal-top            " -- ptr "                           [ 0 | 1 ] ]
-    [ set-literal-top        " ptr -- "                           [ 1 | 0 ] ]
-    [ address                " obj -- ptr "                       [ 1 | 1 ] ]
-    [ dlopen                 " path -- dll "                      [ 1 | 1 ] ]
-    [ dlsym                  " name dll -- ptr "                  [ 2 | 1 ] ]
-    [ dlsym-self             " name -- ptr "                      [ 1 | 1 ] ]
-    [ dlclose                " dll -- "                           [ 1 | 0 ] ]
-    [ <alien>                " ptr -- alien "                     [ 1 | 1 ] ]
-    [ <local-alien>          " len -- alien "                     [ 1 | 1 ] ]
-    [ alien-cell             " alien off -- n "                   [ 2 | 1 ] ]
-    [ set-alien-cell         " n alien off -- "                   [ 3 | 0 ] ]
-    [ alien-4                " alien off -- n "                   [ 2 | 1 ] ]
-    [ set-alien-4            " n alien off -- "                   [ 3 | 0 ] ]
-    [ alien-2                " alien off -- n "                   [ 2 | 1 ] ]
-    [ set-alien-2            " n alien off -- "                   [ 3 | 0 ] ]
-    [ alien-1                " alien off -- n "                   [ 2 | 1 ] ]
-    [ set-alien-1            " n alien off -- "                   [ 3 | 0 ] ]
+    [ millis                 " -- n "                             [ [ ] [ integer ] ] ]
+    [ init-random            " -- "                               [ [ ] [ ] ] ]
+    [ (random-int)           " -- n "                             [ [ ] [ integer ] ] ]
+    [ type                   " obj -- n "                         [ [ object ] [ fixnum ] ] ]
+    [ call-profiling         " depth -- "                         [ [ integer ] [ ] ] ]
+    [ allot-profiling        " depth -- "                         [ [ integer ] [ ] ] ]
+    [ cwd                    " -- dir "                           [ [ ] [ string ] ] ]
+    [ cd                     " dir -- "                           [ [ string ] [ ] ] ]
+    [ compiled-offset        " -- ptr "                           [ [ ] [ integer ] ] ]
+    [ set-compiled-offset    " ptr -- "                           [ [ integer ] [ ] ] ]
+    [ literal-top            " -- ptr "                           [ [ ] [ integer ] ] ]
+    [ set-literal-top        " ptr -- "                           [ [ integer ] [ ] ] ]
+    [ address                " obj -- ptr "                       [ [ object ] [ integer ] ] ]
+    [ dlopen                 " path -- dll "                      [ [ string ] [ dll ] ] ]
+    [ dlsym                  " name dll -- ptr "                  [ [ string dll ] [ integer ] ] ]
+    [ dlsym-self             " name -- ptr "                      [ [ string ] [ integer ] ] ]
+    [ dlclose                " dll -- "                           [ [ dll ] [ ] ] ]
+    [ <alien>                " ptr -- alien "                     [ [ integer ] [ alien ] ] ]
+    [ <local-alien>          " len -- alien "                     [ [ integer ] [ alien ] ] ]
+    [ alien-cell             " alien off -- n "                   [ [ alien integer ] [ integer ] ] ]
+    [ set-alien-cell         " n alien off -- "                   [ [ integer alien integer ] [ ] ] ]
+    [ alien-4                " alien off -- n "                   [ [ alien integer ] [ integer ] ] ]
+    [ set-alien-4            " n alien off -- "                   [ [ integer alien integer ] [ ] ] ]
+    [ alien-2                " alien off -- n "                   [ [ alien integer ] [ fixnum ] ] ]
+    [ set-alien-2            " n alien off -- "                   [ [ integer alien integer ] [ ] ] ]
+    [ alien-1                " alien off -- n "                   [ [ alien integer ] [ fixnum ] ] ]
+    [ set-alien-1            " n alien off -- "                   [ [ integer alien integer ] [ ] ] ]
     [ heap-stats             " -- instances bytes "               [ [ ] [ general-list ] ] ]
     [ throw                  " error -- "                         [ [ object ] [ ] ] ]
     [ string>memory          " str address -- "                   [ [ string integer ] [ ] ] ]
     [ memory>string          " address length -- str "            [ [ integer integer ] [ string ] ] ]
     [ local-alien?           " alien -- ? "                       [ [ alien ] [ object ] ] ]
     [ alien-address          " alien -- address "                 [ [ alien ] [ integer ] ] ]
+    [ >cons                  " cons -- cons "                     [ [ cons ] [ cons ] ] ]
+    [ >vector                " vector -- vector "                 [ [ vector ] [ vector ] ] ]
+    [ >string                " string -- string "                 [ [ string ] [ string ] ] ]
+    [ >word                  " word -- word "                     [ [ word ] [ word ] ] ]
+    [ slot                   " obj n -- obj "                     [ [ object fixnum ] [ object ] ] ]
+    [ set-slot               " obj obj n -- "                     [ [ object object fixnum ] [ ] ] ]
+    [ integer-slot           " obj n -- n "                       [ [ object fixnum ] [ integer ] ] ]
+    [ set-integer-slot       " n obj n -- "                       [ [ integer object fixnum ] [ ] ] ]
+    [ grow-array             " n array -- array "                 [ [ integer array ] [ integer ] ] ]
 ] [
     uncons dupd uncons car ( word word stack-effect infer-effect )
     >r "stack-effect" set-word-property r>
index 1ab96642ab65c5519192786c5a3fa670084e5027..19dfc2d7d4dabe44cc623b18347d9ac0ebc9f71e 100644 (file)
@@ -26,7 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: kernel
-USE: vectors
 
 : 2drop ( x x -- ) drop drop ; inline
 : 3drop ( x x x -- ) drop drop drop ; inline
@@ -44,7 +43,3 @@ USE: vectors
     #! this from a word definition will clobber any values left
     #! on the data stack by the caller.
     { } set-datastack ;
-
-: depth ( -- n )
-    #! Push the number of elements on the datastack.
-    datastack vector-length ;
index b93b9c65ed128f9bd200d05289b554874565bc9b..d8d9efbc8df1cc084811b1a3784ceab2c3675845 100644 (file)
@@ -28,6 +28,7 @@
 IN: strings
 USE: generic
 USE: kernel
+USE: kernel-internals
 USE: lists
 USE: math
 
@@ -36,6 +37,8 @@ BUILTIN: string 12
 M: string hashcode str-hashcode ;
 M: string = str= ;
 
+: str-length ( str -- len ) >string 1 integer-slot ; inline
+
 BUILTIN: sbuf   13
 M: sbuf hashcode sbuf-hashcode ;
 M: sbuf = sbuf= ;
index 2c31aae44157c401669f1358f08e8f662f145051..ec395c7616b52d5ed1e92d5869b5c31f92dabc32 100644 (file)
@@ -10,6 +10,7 @@ USE: namespaces
 USE: prettyprint
 USE: words
 USE: kernel
+USE: kernel-internals
 USE: generic
 
 : dataflow-contains-op? ( object list -- ? )
@@ -36,7 +37,7 @@ USE: generic
     car car ; inline
 
 [ t ] [
-    \ car [ inline-test ] dataflow dataflow-contains-param? >boolean
+    \ slot [ inline-test ] dataflow dataflow-contains-param? >boolean
 ] unit-test
 
 [ t ] [
index 9df05858d67fa9e2b9e6f76c4f964e795fe49e9b..9886cc084ad5ccdf370fad2c4ac024dd1cd45cb6 100644 (file)
@@ -2,6 +2,9 @@ IN: scratchpad
 USE: command-line
 USE: namespaces
 USE: test
+USE: kernel
+USE: hashtables
+USE: lists
 
 [
     [ f ] [ "-no-user-init" cli-arg ] unit-test
@@ -12,3 +15,26 @@ USE: test
     
     [ "sdl.factor" ] [ "sdl.factor" cli-arg ] unit-test
 ] with-scope
+
+: traverse-path ( name object -- object )
+    dup hashtable? [ hash ] [ 2drop f ] ifte ;
+
+: (object-path) ( object list -- object )
+    [ uncons >r swap traverse-path r> (object-path) ] when* ;
+
+: object-path ( list -- object )
+    #! An object path is a list of strings. Each string is a
+    #! variable name in the object namespace at that level.
+    #! Returns f if any of the objects are not set.
+    namespace swap (object-path) ;
+
+[
+    5 [ "test" "object" "path" ] set-path
+    [ 5 ] [ [ "test" "object" "path" ] object-path ] unit-test
+
+    7 [ "test" "object" "pathe" ] set-path
+    [ 7 ] [ [ "test" "object" "pathe" ] object-path ] unit-test
+
+    9 [ "teste" "object" "pathe" ] set-path
+    [ 9 ] [ [ "teste" "object" "pathe" ] object-path ] unit-test
+] with-scope
index 9d82af3315d883c4234e2224ee5dad886a330b5a..34c04040e4ad6ebe1d452223ef65f06f326ecf20 100644 (file)
@@ -2,6 +2,9 @@ IN: scratchpad
 USE: lists
 USE: test
 
+[ 5 car ] unit-test-fails
+[ "Hello world" cdr ] unit-test-fails
+
 [ f ] [ f         cons? ] unit-test
 [ f ] [ t         cons? ] unit-test
 [ t ] [ [ t | f ] cons? ] unit-test
index 756451be33bfacd41b5a822ed887c7956dbfa75c..7aa69d0107178b58c22e18851aabdb656b82db11 100644 (file)
@@ -29,7 +29,3 @@ USE: test
 
 [ t ] [ pi 3 > ] unit-test
 [ f ] [ e 2 <= ] unit-test
-
-[ 4607182418800017408 ] [ 1.0 float>bits ] unit-test
-[ 4614256656552045848 ] [ pi float>bits ] unit-test
-[ 4613303445314885481 ] [ e float>bits ] unit-test
index 08926e7be7fb7ab0616259dd82e8d270f0bd78d4..0cb8d54e3f838855dd8ecdc307685ef3f5a648e1 100644 (file)
@@ -11,40 +11,15 @@ USE: words
 
 [ t ] [ test-namespace ] unit-test
 
-! Object paths should not resolve further up in the namestack.
-
-<namespace> "test-namespace" set
-[ f ]
-[ [ "test-namespace" "test-namespace" ] object-path ]
-unit-test
-
-[ f ]
-[ [ "alalal" "boobobo" "bah" ] object-path ]
-unit-test
+[
+    "nested" off
 
-[ t ]
-[ namespace [ ] object-path = ]
-unit-test
+    "nested" nest [ 5 "x" set ] bind
+    [ 5 ] [ "nested" nest [ "x" get ] bind ] unit-test
 
-[ t ]
-[
-    \ test-word
-    global [ [ vocabularies "test" "test-word" ] object-path ] bind
-    =
-] unit-test
+] with-scope
 
 10 "some-global" set
 [ f ]
 [ <namespace> [ f "some-global" set "some-global" get ] bind ]
 unit-test
-
-[
-    5 [ "test" "object" "path" ] set-object-path
-    [ 5 ] [ [ "test" "object" "path" ] object-path ] unit-test
-
-    7 [ "test" "object" "pathe" ] set-object-path
-    [ 7 ] [ [ "test" "object" "pathe" ] object-path ] unit-test
-
-    9 [ "teste" "object" "pathe" ] set-object-path
-    [ 9 ] [ [ "teste" "object" "pathe" ] object-path ] unit-test
-] with-scope
index 618c40366d5d5346bf195582bdbef1a4e4367c19..5c4c2be505ff6c665bc4a861d641ce42adb57a94 100644 (file)
@@ -6,9 +6,20 @@ USE: test
 USE: vectors
 USE: strings
 
+[ [ t f t ] vector-length ] unit-test-fails
+[ 3 ] [ { t f t } vector-length ] unit-test
+
 [ 3 { } vector-nth ] unit-test-fails
 [ 3 #{ 1 2 } vector-nth ] unit-test-fails
 
+[ "hey" [ 1 2 ] set-vector-length ] unit-test-fails
+[ "hey" { 1 2 } set-vector-length ] unit-test-fails
+
+[ 3 ] [ 3 0 <vector> [ set-vector-length ] keep vector-length ] unit-test
+[ "yo" ] [
+    "yo" 4 1 <vector> [ set-vector-nth ] keep 4 swap vector-nth
+] unit-test
+
 [ 5 list>vector ] unit-test-fails
 [ { } ] [ [ ] list>vector ] unit-test
 [ { 1 2 } ] [ [ 1 2 ] list>vector ] unit-test
index cdf9239fd9803d736a4999ad507bfd889e37115b..90f4a0e99fc0fbc8eba77c2287505901965eb323 100644 (file)
@@ -28,6 +28,7 @@
 IN: threads
 USE: io-internals
 USE: kernel
+USE: kernel-internals
 USE: lists
 
 ! Core of the multitasker. Used by io-internals.factor and
index 441e753efeae2f242c5e4edb49d269c381a78bbf..c7678d6f27c4272dbe55e02bd132a24f162e2699 100644 (file)
@@ -27,6 +27,7 @@
 
 IN: errors
 USE: kernel
+USE: kernel-internals
 USE: lists
 USE: namespaces
 USE: prettyprint
@@ -63,10 +64,7 @@ USE: generic
     #! reporting.
     dup [
         [ 100 | "fixnum/bignum" ]
-        [ 101 | "fixnum/bignum/ratio" ]
-        [ 102 | "fixnum/bignum/ratio/float" ]
-        [ 103 | "fixnum/bignum/ratio/float/complex" ]
-        [ 104 | "fixnum/string" ]
+        [ 104 | "fixnum/bignum/string" ]
     ] assoc dup [
         nip
     ] [
diff --git a/library/tools/inspector.factor b/library/tools/inspector.factor
deleted file mode 100644 (file)
index 6cfbf98..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
-! Copyright (C) 2003, 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.
-
-IN: inspector
-USE: kernel
-USE: hashtables
-USE: lists
-USE: namespaces
-USE: stdio
-USE: strings
-USE: presentation
-USE: words
-USE: prettyprint
-USE: unparser
-USE: vectors
-USE: math
-
-: relative>absolute-object-path ( string -- string )
-    "object-path" get [ "'" rot cat3 ] when* ;
-
-: vars. ( -- )
-    #! Print a list of defined variables.
-    namespace hash-keys [.] ;
-
-: object-actions ( -- alist )
-    [
-        [ "Describe" | "describe-path"  ]
-        [ "Push"     | "lookup"         ]
-    ] ;
-
-: link-style ( path -- style )
-    relative>absolute-object-path
-    dup "object-link" swons swap
-    object-actions <actions> "actions" swons
-    t "underline" swons
-    3list
-    default-style append ;
-
-: pad-string ( len str -- str )
-    str-length - " " fill ;
-
-: var-name. ( max name -- )
-    tuck unparse pad-string write dup link-style
-    swap unparse swap write-attr ;
-
-: value. ( max name value -- )
-    >r var-name. ": " write r> . ;
-
-: max-str-length ( list -- len )
-    #! Returns the length of the longest string in the given
-    #! list.
-    0 swap [ str-length max ] each ;
-
-: name-padding ( alist -- col )
-    [ car unparse ] map max-str-length ;
-
-: describe-assoc ( alist -- )
-    dup name-padding swap
-    [ dupd uncons value. ] each drop ;
-
-: alist-sort ( list -- list )
-    [ swap car unparse swap car unparse str-lexi> ] sort ;
-
-: describe-hashtable ( hashtables -- )
-    hash>alist alist-sort describe-assoc ;
-
-: describe ( obj -- )
-    [
-        [ word? ]
-        [ see ]
-        
-        [ string? ]
-        [ print ]
-        
-        [ assoc? ]
-        [ describe-assoc ]
-        
-        [ hashtable? ]
-        [ describe-hashtable ]
-        
-        [ drop t ]
-        [ prettyprint ]
-    ] cond ;
-
-: lookup ( str -- object )
-    global [ "'" split object-path ] bind ;
-
-: describe-path ( string -- )
-    [ dup "object-path" set lookup describe ] with-scope ;
index ef43e04af3eaac0066eff424225f3f240bcb0b1a..7919f0dfa998f6dd707f729a8a0d063cc2e5e916 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: kernel-internals
 USE: generic
+USE: kernel
+USE: lists
+USE: math
+
+IN: errors
+DEFER: throw
+
+IN: kernel-internals
 
 BUILTIN: array 8
 
+! UNSAFE!
+: array-capacity   ( array -- n )   1 integer-slot ; inline
+: vector-array     ( vec -- array ) 2 slot ; inline
+: set-vector-array ( array vec -- ) 2 set-slot ; inline
+
+: grow-vector-array ( len vec -- )
+    [ vector-array grow-array ] keep set-vector-array ; inline
+
+: (set-vector-length) ( len vec -- ) 1 set-integer-slot ; inline
+
 IN: vectors
-USE: kernel
-USE: lists
-USE: math
 
 BUILTIN: vector 11
 
+: vector-length ( vec -- len ) >vector 1 integer-slot ; inline
+
+: set-vector-length ( len vec -- )
+    >vector over 0 < [
+        "Vector length must be positive" throw 2drop
+    ] [
+        2dup (set-vector-length) grow-vector-array
+    ] ifte ;
+
 : empty-vector ( len -- vec )
     #! Creates a vector with 'len' elements set to f. Unlike
     #! <vector>, which gives an empty vector with a certain
@@ -162,3 +185,10 @@ M: vector hashcode ( vec -- n )
     #! vector. For example, if n=1, this returns a vector of
     #! one element.
     [ vector-length swap - ] keep vector-tail ;
+
+! Find a better place for this
+IN: kernel
+
+: depth ( -- n )
+    #! Push the number of elements on the datastack.
+    datastack vector-length ;
index e4d9301beef4942764f9291fc771c11da03c9a3d..85f78d699e64f290f701ffcf8e186331e2aed56a 100644 (file)
@@ -77,14 +77,14 @@ USE: strings
 
 : (create) ( name vocab -- word )
     #! Create an undefined word without adding to a vocabulary.
-    <plist> 0 f rot <word> ;
+    <plist> <word> [ set-word-plist ] keep ;
 
 : reveal ( word -- )
     #! Add a new word to its vocabulary.
     vocabularies get [
-        dup word-vocabulary
-        over word-name
-        2list set-object-path
+        dup word-vocabulary nest [
+            dup word-name set
+        ] bind
     ] bind ;
 
 : create ( name vocab -- word )
@@ -115,7 +115,6 @@ USE: strings
         "inference"
         "inferior"
         "interpreter"
-        "inspector"
         "jedit"
         "kernel"
         "listener"
index 90434601053790e23b01bcd20c9c78426ae3bcf8..3ff1628f16b9f3e32142115a6cfbdb5109975fa2 100644 (file)
@@ -29,6 +29,7 @@ IN: words
 USE: generic
 USE: hashtables
 USE: kernel
+USE: kernel-internals
 USE: lists
 USE: math
 USE: namespaces
@@ -36,17 +37,36 @@ USE: strings
 
 BUILTIN: word 1
 
-M: word hashcode word-hashcode ;
+M: word hashcode 1 integer-slot ;
+
+: word-xt     ( w -- xt ) >word 2 integer-slot ; inline
+: set-word-xt ( xt w -- ) >word 2 set-integer-slot ; inline
+
+: word-primitive ( w -- n ) >word 3 integer-slot ; inline
+: set-word-primitive ( n w -- )
+    >word [ 3 set-integer-slot ] keep update-xt ; inline
+
+: word-parameter     ( w -- obj ) >word 4 slot ; inline
+: set-word-parameter ( obj w -- ) >word 4 set-slot ; inline
+
+: word-plist     ( w -- obj ) >word 5 slot ; inline
+: set-word-plist ( obj w -- ) >word 5 set-slot ; inline
+
+: call-count     ( w -- n ) >word 6 integer-slot ; inline
+: set-call-count ( n w -- ) >word 6 set-integer-slot ; inline
+
+: allot-count     ( w -- n ) >word 7 integer-slot ; inline
+: set-allot-count ( n w -- ) >word 7 set-integer-slot ; inline
 
 SYMBOL: vocabularies
 
 : word-property ( word pname -- pvalue )
-    swap word-plist assoc ;
+    swap word-plist assoc ; inline
 
 : set-word-property ( word pvalue pname -- )
     pick word-plist
     pick [ set-assoc ] [ remove-assoc nip ] ifte
-    swap set-word-plist ;
+    swap set-word-plist ; inline
 
 PREDICATE: word compound  ( obj -- ? ) word-primitive 1 = ;
 PREDICATE: word primitive ( obj -- ? ) word-primitive 2 > ;
index 0bb13ed4bce0c73875bdfdbce791c1d0533039c5..24caa1e9fcab4f78de8425a4c436247c3406f46d 100644 (file)
@@ -91,57 +91,3 @@ void primitive_arithmetic_type(void)
 
        dpush(tag_fixnum(type));
 }
-
-bool realp(CELL tagged)
-{
-       switch(type_of(tagged))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-       case RATIO_TYPE:
-       case FLOAT_TYPE:
-               return true;
-               break;
-       default:
-               return false;
-               break;
-       }
-}
-
-bool zerop(CELL tagged)
-{
-       switch(type_of(tagged))
-       {
-       case FIXNUM_TYPE:
-               return tagged == 0;
-       case BIGNUM_TYPE:
-               return BIGNUM_ZERO_P((F_ARRAY*)UNTAG(tagged));
-       case FLOAT_TYPE:
-               return ((F_FLOAT*)UNTAG(tagged))->n == 0.0;
-       case RATIO_TYPE:
-       case COMPLEX_TYPE:
-               return false;
-       default:
-               type_error(NUMBER_TYPE,tagged);
-               return false; /* Can't happen */
-       }
-}
-
-bool onep(CELL tagged)
-{
-       switch(type_of(tagged))
-       {
-       case FIXNUM_TYPE:
-               return tagged == tag_fixnum(1);
-       case BIGNUM_TYPE:
-               return BIGNUM_ONE_P((F_ARRAY*)UNTAG(tagged),0);
-       case FLOAT_TYPE:
-               return ((F_FLOAT*)UNTAG(tagged))->n == 1.0;
-       case RATIO_TYPE:
-       case COMPLEX_TYPE:
-               return false;
-       default:
-               type_error(NUMBER_TYPE,tagged);
-               return false; /* Can't happen */
-       }
-}
index 2c01f86f350e93275f244bd38d90b72c8861d8aa..bd98828725f864a63a499260ab45bc701263dedb 100644 (file)
@@ -1,8 +1,3 @@
 #include "factor.h"
 
 void primitive_arithmetic_type(void);
-
-bool realp(CELL tagged);
-
-bool zerop(CELL tagged);
-bool onep(CELL tagged);
index 35faf04bc82e8c97aaa0b872eee4042fc59872e1..b72571438255ea885d8c58132a844dcb3a75e3ec 100644 (file)
@@ -1,7 +1,7 @@
 #include "factor.h"
 
 /* untagged */
-F_ARRAY* allot_array(CELL type, F_FIXNUM capacity)
+F_ARRAY* allot_array(CELL type, CELL capacity)
 {
        F_ARRAY* array;
        if(capacity < 0)
@@ -12,7 +12,7 @@ F_ARRAY* allot_array(CELL type, F_FIXNUM capacity)
 }
 
 /* untagged */
-F_ARRAY* array(F_FIXNUM capacity, CELL fill)
+F_ARRAY* array(CELL capacity, CELL fill)
 {
        int i;
 
@@ -24,12 +24,16 @@ F_ARRAY* array(F_FIXNUM capacity, CELL fill)
        return array;
 }
 
-F_ARRAY* grow_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill)
+F_ARRAY* grow_array(F_ARRAY* array, CELL capacity, CELL fill)
 {
        /* later on, do an optimization: if end of array is here, just grow */
        int i;
+       F_ARRAY* new_array;
 
-       F_ARRAY* new_array = allot_array(untag_header(array->header),capacity);
+       if(array->capacity >= capacity)
+               return array;
+
+       new_array = allot_array(untag_header(array->header),capacity);
 
        memcpy(new_array + 1,array + 1,array->capacity * CELLS);
 
@@ -39,7 +43,14 @@ F_ARRAY* grow_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill)
        return new_array;
 }
 
-F_ARRAY* shrink_array(F_ARRAY* array, F_FIXNUM capacity)
+void primitive_grow_array(void)
+{
+       F_ARRAY* array = untag_array(dpop());
+       CELL capacity = to_fixnum(dpop());
+       dpush(tag_object(grow_array(array,capacity,F)));
+}
+
+F_ARRAY* shrink_array(F_ARRAY* array, CELL capacity)
 {
        F_ARRAY* new_array = allot_array(untag_header(array->header),capacity);
        memcpy(new_array + 1,array + 1,capacity * CELLS);
index 32618f8bd44db4283f12120db568017f4a6d9daf..74d56506e7c4001728a21a4f935415b4b6331068 100644 (file)
@@ -10,10 +10,11 @@ INLINE F_ARRAY* untag_array(CELL tagged)
        return (F_ARRAY*)UNTAG(tagged); /* FIXME */
 }
 
-F_ARRAY* allot_array(CELL type, F_FIXNUM capacity);
-F_ARRAY* array(F_FIXNUM capacity, CELL fill);
-F_ARRAY* grow_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill);
-F_ARRAY* shrink_array(F_ARRAY* array, F_FIXNUM capacity);
+F_ARRAY* allot_array(CELL type, CELL capacity);
+F_ARRAY* array(CELL capacity, CELL fill);
+F_ARRAY* grow_array(F_ARRAY* array, CELL capacity, CELL fill);
+void primitive_grow_array(void);
+F_ARRAY* shrink_array(F_ARRAY* array, CELL capacity);
 
 #define AREF(array,index) ((CELL)(array) + sizeof(F_ARRAY) + (index) * CELLS)
 
index 36193c1842bdd206f2c1a52817d6dfc907e98239..98b15a03d2c04617326e5e5ad117de325c00d123 100644 (file)
@@ -6,28 +6,6 @@ void init_compiler(void)
        literal_top = compiling.base;
 }
 
-void check_compiled_offset(CELL offset)
-{
-       if(offset < compiling.base || offset >= compiling.limit)
-               range_error(F,0,to_integer(offset),compiling.limit);
-}
-
-void primitive_set_compiled_byte(void)
-{
-       CELL offset = unbox_integer();
-       BYTE b = to_fixnum(dpop());
-       check_compiled_offset(offset);
-       bput(offset,b);
-}
-
-void primitive_set_compiled_cell(void)
-{
-       CELL offset = unbox_integer();
-       CELL c = to_fixnum(dpop());
-       check_compiled_offset(offset);
-       put(offset,c);
-}
-
 void primitive_compiled_offset(void)
 {
        box_integer(compiling.here);
@@ -36,7 +14,6 @@ void primitive_compiled_offset(void)
 void primitive_set_compiled_offset(void)
 {
        CELL offset = unbox_integer();
-       check_compiled_offset(offset);
        compiling.here = offset;
 }
 
@@ -48,16 +25,12 @@ void primitive_literal_top(void)
 void primitive_set_literal_top(void)
 {
        CELL offset = unbox_integer();
-       check_compiled_offset(offset);
        literal_top = offset;
 }
 
 void collect_literals(void)
 {
-       CELL i = compiling.base;
-       while(i < literal_top)
-       {
+       CELL i;
+       for(i = compiling.base; i < literal_top; i += CELLS)
                copy_object((CELL*)i);
-               i += CELLS;
-       }
 }
index 539b53aa9688169c6f834060ad079b19c946a750..cc187d19bbbb22bfb0477231ab17b1da49b8dea7 100644 (file)
@@ -2,8 +2,6 @@ ZONE compiling;
 CELL literal_top;
 
 void init_compiler(void);
-void primitive_set_compiled_byte(void);
-void primitive_set_compiled_cell(void);
 void primitive_compiled_offset(void);
 void primitive_set_compiled_offset(void);
 void primitive_literal_top(void);
index 00007759704aef73e95fa463ceef6d1ba8e6ad64..a5fdced5596fb919093abfbd71e6dfc5a32fbed5 100644 (file)
@@ -1,65 +1,15 @@
 #include "factor.h"
 
-void primitive_real(void)
-{
-       switch(type_of(dpeek()))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-       case FLOAT_TYPE:
-       case RATIO_TYPE:
-               /* No op */
-               break;
-       case COMPLEX_TYPE:
-               drepl(untag_complex(dpeek())->real);
-               break;
-       default:
-               type_error(NUMBER_TYPE,dpeek());
-               break;
-       }
-}
-
-void primitive_imaginary(void)
-{
-       switch(type_of(dpeek()))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-       case FLOAT_TYPE:
-       case RATIO_TYPE:
-               drepl(tag_fixnum(0));
-               break;
-       case COMPLEX_TYPE:
-               drepl(untag_complex(dpeek())->imaginary);
-               break;
-       default:
-               type_error(NUMBER_TYPE,dpeek());
-               break;
-       }
-}
-
 void primitive_from_rect(void)
 {
-       CELL imaginary, real;
+       CELL imaginary = dpop();
+       CELL real = dpop();
+       F_COMPLEX* complex;
 
        maybe_garbage_collection();
 
-       imaginary = dpop();
-       real = dpop();
-
-       if(!realp(imaginary))
-               type_error(REAL_TYPE,imaginary);
-
-       if(!realp(real))
-               type_error(REAL_TYPE,real);
-
-       if(zerop(imaginary))
-               dpush(real);
-       else
-       {
-               F_COMPLEX* complex = allot(sizeof(F_COMPLEX));
-               complex->real = real;
-               complex->imaginary = imaginary;
-               dpush(tag_complex(complex));
-       }
+       complex = allot(sizeof(F_COMPLEX));
+       complex->real = real;
+       complex->imaginary = imaginary;
+       dpush(tag_complex(complex));
 }
index 4fc174e78d1b6176b1b6c92fefe58c70a299189b..247b9696597e67d61c499a2903f739d5c6adce5f 100644 (file)
@@ -3,17 +3,9 @@ typedef struct {
        CELL imaginary;
 } F_COMPLEX;
 
-INLINE F_COMPLEX* untag_complex(CELL tagged)
-{
-       type_check(COMPLEX_TYPE,tagged);
-       return (F_COMPLEX*)UNTAG(tagged);
-}
-
 INLINE CELL tag_complex(F_COMPLEX* complex)
 {
        return RETAG(complex,COMPLEX_TYPE);
 }
 
-void primitive_real(void);
-void primitive_imaginary(void);
 void primitive_from_rect(void);
index 690cd810d41cba6fa878661870c9cddae34ef85c..b139f3fc3bd2dcdbe720fbbe13a20a80161f7913 100644 (file)
@@ -17,12 +17,7 @@ void primitive_cons(void)
        dpush(cons(car,cdr));
 }
 
-void primitive_car(void)
+void primitive_to_cons(void)
 {
-       drepl(car(dpeek()));
-}
-
-void primitive_cdr(void)
-{
-       drepl(cdr(dpeek()));
+       type_check(CONS_TYPE,dpeek());
 }
index 6b7730bdbca3140e10bb0066bbb05cdaa9b850ca..6af6f51b82d0204676186a17c195fe4a3c1d594a 100644 (file)
@@ -27,5 +27,4 @@ INLINE CELL cdr(CELL cons)
 }
 
 void primitive_cons(void);
-void primitive_car(void);
-void primitive_cdr(void);
+void primitive_to_cons(void);
index ffe2776044e130151ed946d48be4fdc885e5c225..8b3970ae91aed48d29cd22762964fb640e650ba2 100644 (file)
@@ -113,6 +113,7 @@ typedef unsigned char BYTE;
 #include "word.h"
 #include "run.h"
 #include "signal.h"
+#include "cons.h"
 #include "fixnum.h"
 #include "array.h"
 #include "s48_bignumint.h"
@@ -132,7 +133,6 @@ typedef unsigned char BYTE;
 #include "write.h"
 #include "file.h"
 #include "socket.h"
-#include "cons.h"
 #include "image.h"
 #include "primitives.h"
 #include "vector.h"
index 4d90e8268189e3744e1f5897c6e89560f9d1afc9..b6b8b00e166715f244391bdccf5c7282c84e6f6d 100644 (file)
@@ -59,18 +59,6 @@ void primitive_float_to_str(void)
        box_c_string(tmp);
 }
 
-void primitive_float_to_bits(void)
-{
-       double f;
-       int64_t f_raw;
-
-       maybe_garbage_collection();
-
-       f = untag_float(dpeek());
-       f_raw = *(int64_t*)&f;
-       drepl(tag_object(s48_long_long_to_bignum(f_raw)));
-}
-
 #define GC_AND_POP_FLOATS(x,y) \
        double x, y; \
        maybe_garbage_collection(); \
index 406da752ae8396ed848fd653355a33edeb3e89eb..111b83144fca23a4adc225b4936f84fa6ce862a9 100644 (file)
@@ -8,14 +8,9 @@ XT primitives[] = {
        primitive_call,
        primitive_ifte,
        primitive_cons,
-       primitive_car,
-       primitive_cdr,
        primitive_vector,
-       primitive_vector_length,
-       primitive_set_vector_length,
        primitive_vector_nth,
        primitive_set_vector_nth,
-       primitive_string_length,
        primitive_string_nth,
        primitive_string_compare,
        primitive_string_eq,
@@ -38,14 +33,9 @@ XT primitives[] = {
        primitive_to_fixnum,
        primitive_to_bignum,
        primitive_to_float,
-       primitive_numerator,
-       primitive_denominator,
        primitive_from_fraction,
        primitive_str_to_float,
        primitive_float_to_str,
-       primitive_float_to_bits,
-       primitive_real,
-       primitive_imaginary,
        primitive_from_rect,
        primitive_fixnum_eq,
        primitive_fixnum_add,
@@ -103,21 +93,9 @@ XT primitives[] = {
         primitive_fsinh,
         primitive_fsqrt,
        primitive_word,
-       primitive_word_hashcode,
-       primitive_word_xt,
-       primitive_set_word_xt,
-       primitive_word_primitive,
-       primitive_set_word_primitive,
-       primitive_word_parameter,
-       primitive_set_word_parameter,
-       primitive_word_plist,
-       primitive_set_word_plist,
+       primitive_update_xt,
        primitive_call_profiling,
-       primitive_word_call_count,
-       primitive_set_word_call_count,
        primitive_allot_profiling,
-       primitive_word_allot_count,
-       primitive_set_word_allot_count,
        primitive_word_compiledp,
        primitive_drop,
        primitive_dup,
@@ -167,8 +145,6 @@ XT primitives[] = {
        primitive_cd,
        primitive_compiled_offset,
        primitive_set_compiled_offset,
-       primitive_set_compiled_cell,
-       primitive_set_compiled_byte,
        primitive_literal_top,
        primitive_set_literal_top,
        primitive_address,
@@ -192,6 +168,15 @@ XT primitives[] = {
        primitive_memory_to_string,
        primitive_local_alienp,
        primitive_alien_address,
+       primitive_to_cons,
+       primitive_to_vector,
+       primitive_to_string,
+       primitive_to_word,
+       primitive_slot,
+       primitive_set_slot,
+       primitive_integer_slot,
+       primitive_set_integer_slot,
+       primitive_grow_array
 };
 
 CELL primitive_to_xt(CELL primitive)
index 1aa49ac28140a009df69e8ae1f2e8e2ec6c3c589..ea9414b4d834b39076a8fcf72cca1bf3d0672f31 100644 (file)
@@ -1,4 +1,4 @@
 extern XT primitives[];
-#define PRIMITIVE_COUNT 192
+#define PRIMITIVE_COUNT 195
 
 CELL primitive_to_xt(CELL primitive);
index e3e0a5caa67c02fd9eb5b9c501a4e3e37342fe46..36fb921da11747f67348230449796c064aa41a44 100644 (file)
@@ -4,55 +4,14 @@
 library implementation, to avoid breaking invariants. */
 void primitive_from_fraction(void)
 {
-       CELL numerator, denominator;
+       CELL denominator = dpop();
+       CELL numerator = dpop();
+       F_RATIO* ratio;
 
        maybe_garbage_collection();
 
-       denominator = dpop();
-       numerator = dpop();
-       if(zerop(denominator))
-               raise(SIGFPE);
-       if(onep(denominator))
-               dpush(numerator);
-       else
-       {
-               F_RATIO* ratio = allot(sizeof(F_RATIO));
-               ratio->numerator = numerator;
-               ratio->denominator = denominator;
-               dpush(tag_ratio(ratio));
-       }
-}
-
-void primitive_numerator(void)
-{
-       switch(type_of(dpeek()))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-               /* No op */
-               break;
-       case RATIO_TYPE:
-               drepl(untag_ratio(dpeek())->numerator);
-               break;
-       default:
-               type_error(RATIONAL_TYPE,dpeek());
-               break;
-       }
-}
-
-void primitive_denominator(void)
-{
-       switch(type_of(dpeek()))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-               drepl(tag_fixnum(1));
-               break;
-       case RATIO_TYPE:
-               drepl(untag_ratio(dpeek())->denominator);
-               break;
-       default:
-               type_error(RATIONAL_TYPE,dpeek());
-               break;
-       }
+       ratio = allot(sizeof(F_RATIO));
+       ratio->numerator = numerator;
+       ratio->denominator = denominator;
+       dpush(tag_ratio(ratio));
 }
index 3cf91f9eac85c2af792b7ddc806f53ef029d28eb..464a675d8d914d952bfd65b01b63e717d554d92d 100644 (file)
@@ -3,17 +3,9 @@ typedef struct {
        CELL denominator;
 } F_RATIO;
 
-INLINE F_RATIO* untag_ratio(CELL tagged)
-{
-       type_check(RATIO_TYPE,tagged);
-       return (F_RATIO*)UNTAG(tagged);
-}
-
 INLINE CELL tag_ratio(F_RATIO* ratio)
 {
        return RETAG(ratio,RATIO_TYPE);
 }
 
-void primitive_numerator(void);
-void primitive_denominator(void);
 void primitive_from_fraction(void);
index 7881829f3aca51b9e0193a5ff5f254961773bf8e..63f288f282eeadbcd6de271e122562b0e31329f8 100644 (file)
@@ -168,7 +168,7 @@ void primitive_sbuf_eq(void)
 {
        F_SBUF* s1 = untag_sbuf(dpop());
        CELL with = dpop();
-       if(typep(SBUF_TYPE,with))
+       if(type_of(with) == SBUF_TYPE)
                dpush(tag_boolean(sbuf_eq(s1,(F_SBUF*)UNTAG(with))));
        else
                dpush(F);
index b8884068145e2eb6fa87894ef169fffb83650adb..19a7c4a7768f7c3addb1e5e4b8f2e31707b08a98 100644 (file)
@@ -139,11 +139,6 @@ BYTE* unbox_c_string(void)
        return to_c_string(untag_string(dpop()));
 }
 
-void primitive_string_length(void)
-{
-       drepl(tag_fixnum(untag_string(dpeek())->capacity));
-}
-
 void primitive_string_nth(void)
 {
        F_STRING* string = untag_string(dpop());
@@ -205,7 +200,7 @@ void primitive_string_eq(void)
 {
        F_STRING* s1 = untag_string(dpop());
        CELL with = dpop();
-       if(typep(STRING_TYPE,with))
+       if(type_of(with) == STRING_TYPE)
                dpush(tag_boolean(string_eq(s1,(F_STRING*)UNTAG(with))));
        else
                dpush(F);
@@ -349,3 +344,8 @@ void primitive_string_reverse(void)
        rehash_string(s);
        drepl(tag_object(s));
 }
+
+void primitive_to_string(void)
+{
+       type_check(STRING_TYPE,dpeek());
+}
index 4e48f20c65566de4cbc1987ccf016b7d05cf7971..1e84a62de679d6663084feb8bb6d99de21c3e1fc 100644 (file)
@@ -42,7 +42,6 @@ INLINE void set_string_nth(F_STRING* string, CELL index, uint16_t value)
        cput(SREF(string,index),value);
 }
 
-void primitive_string_length(void);
 void primitive_string_nth(void);
 F_FIXNUM string_compare_head(F_STRING* s1, F_STRING* s2, CELL len);
 F_FIXNUM string_compare(F_STRING* s1, F_STRING* s2);
@@ -54,3 +53,4 @@ void primitive_substring(void);
 void string_reverse(F_STRING* s, int len);
 F_STRING* string_clone(F_STRING* s, int len);
 void primitive_string_reverse(void);
+void primitive_to_string(void);
index 2ed580cffd3d805b9bae111bac74899ecbbabc4f..13b9c90d9e880a411edf3fafe0bf2f1fd581189d 100644 (file)
@@ -1,10 +1,5 @@
 #include "factor.h"
 
-bool typep(CELL type, CELL tagged)
-{
-       return type_of(tagged) == type;
-}
-
 /*
  * It is up to the caller to fill in the object's fields in a meaningful
  * fashion!
@@ -102,3 +97,35 @@ void primitive_type(void)
 {
        drepl(tag_fixnum(type_of(dpeek())));
 }
+
+#define SLOT(obj,slot) UNTAG(obj) + slot * CELLS
+
+void primitive_slot(void)
+{
+       F_FIXNUM slot = untag_fixnum_fast(dpop());
+       CELL obj = dpop();
+       dpush(get(SLOT(obj,slot)));
+}
+
+void primitive_set_slot(void)
+{
+       F_FIXNUM slot = untag_fixnum_fast(dpop());
+       CELL obj = dpop();
+       CELL value = dpop();
+       put(SLOT(obj,slot),value);
+}
+
+void primitive_integer_slot(void)
+{
+       F_FIXNUM slot = untag_fixnum_fast(dpop());
+       CELL obj = dpop();
+       dpush(tag_integer(get(SLOT(obj,slot))));
+}
+
+void primitive_set_integer_slot(void)
+{
+       F_FIXNUM slot = untag_fixnum_fast(dpop());
+       CELL obj = dpop();
+       F_FIXNUM value = to_integer(dpop());
+       put(SLOT(obj,slot),value);
+}
index c2f6c9e88a691c6d42fcf3b2e366b0c70a000e71..8ff015d2f7cffe213a4c0b0953e6a426f987c4f6 100644 (file)
@@ -38,13 +38,8 @@ CELL T;
 
 /* Pseudo-types. For error reporting only. */
 #define INTEGER_TYPE 100 /* F_FIXNUM or BIGNUM */
-#define RATIONAL_TYPE 101 /* INTEGER or F_RATIO */
-#define REAL_TYPE 102 /* RATIONAL or F_FLOAT */
-#define NUMBER_TYPE 103 /* F_COMPLEX or REAL */
 #define TEXT_TYPE 104 /* F_FIXNUM or F_STRING */
 
-bool typep(CELL type, CELL tagged);
-
 INLINE CELL tag_header(CELL cell)
 {
        return RETAG(cell << TAG_BITS,HEADER_TYPE);
@@ -117,3 +112,8 @@ INLINE CELL type_of(CELL tagged)
        else
                return tag;
 }
+
+void primitive_slot(void);
+void primitive_set_slot(void);
+void primitive_integer_slot(void);
+void primitive_set_integer_slot(void);
index 894f52afff7f956d6beb9bc1368c038a4be7ede7..37db181e59904051b6b8f9926656771a8309d774 100644 (file)
@@ -126,7 +126,7 @@ bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks,
 
        for(i = 0; i < fd_count; i++)
        {
-               if(typep(PORT_TYPE,io_tasks[i].port))
+               if(type_of(io_tasks[i].port) == PORT_TYPE)
                {
                        if(untag_port(io_tasks[i].port)->closed)
                                *closed = true;
@@ -205,7 +205,7 @@ CELL perform_io_tasks(fd_set* fdset, IO_TASK* io_tasks, int* fd_count)
        {
                IO_TASK io_task = io_tasks[i];
 
-               if(typep(PORT_TYPE,io_task.port))
+               if(type_of(io_task.port) == PORT_TYPE)
                {
                        F_PORT* port = untag_port(io_task.port);
                        if(port->closed)
index a805036146fd559a595a56c97f3dd6dc1a08a6c0..2c8a19624b6cd1dfa32a0efba36f7a5b03f6c401 100644 (file)
@@ -14,28 +14,9 @@ void primitive_vector(void)
        drepl(tag_object(vector(to_fixnum(dpeek()))));
 }
 
-void primitive_vector_length(void)
+void primitive_to_vector(void)
 {
-       drepl(tag_fixnum(untag_vector(dpeek())->top));
-}
-
-void primitive_set_vector_length(void)
-{
-       F_VECTOR* vector;
-       F_FIXNUM length;
-       F_ARRAY* array;
-
-       maybe_garbage_collection();
-
-       vector = untag_vector(dpop());
-       length = to_fixnum(dpop());
-       array = untag_array(vector->array);
-
-       if(length < 0)
-               range_error(tag_object(vector),0,tag_fixnum(length),vector->top);
-       vector->top = length;
-       if(length > array->capacity)
-               vector->array = tag_object(grow_array(array,length,F));
+       type_check(VECTOR_TYPE,dpeek());
 }
 
 void primitive_vector_nth(void)
index 1bbd5916afb471f6e12d93b33aa523d0ccc4e1fe..a851779c16d213851c3e05cca5409eec3562bdc8 100644 (file)
@@ -16,8 +16,7 @@ INLINE F_VECTOR* untag_vector(CELL tagged)
 F_VECTOR* vector(F_FIXNUM capacity);
 
 void primitive_vector(void);
-void primitive_vector_length(void);
-void primitive_set_vector_length(void);
+void primitive_to_vector(void);
 void primitive_vector_nth(void);
 void vector_ensure_capacity(F_VECTOR* vector, CELL index);
 void primitive_set_vector_nth(void);
index 41952ef772c4a5f54aa78ed4a0a66a983222e457..d02f0600ee56d8856577e1e124248c264660507f 100644 (file)
@@ -1,19 +1,5 @@
 #include "factor.h"
 
-F_WORD* word(CELL primitive, CELL parameter, CELL plist)
-{
-       F_WORD* word = allot_object(WORD_TYPE,sizeof(F_WORD));
-       word->hashcode = (CELL)word; /* initial address */
-       word->xt = primitive_to_xt(primitive);
-       word->primitive = primitive;
-       word->parameter = parameter;
-       word->plist = plist;
-       word->call_count = 0;
-       word->allot_count = 0;
-
-       return word;
-}
-
 /* When a word is executed we jump to the value of the xt field. However this
    value is an unportable function pointer, so in the image we store a primitive
    number that indexes a list of xts. */
@@ -25,93 +11,35 @@ void update_xt(F_WORD* word)
 /* <word> ( primitive parameter plist -- word ) */
 void primitive_word(void)
 {
-       CELL plist, parameter;
-       F_FIXNUM primitive;
+       F_WORD* word;
 
        maybe_garbage_collection();
 
-       plist = dpop();
-       parameter = dpop();
-       primitive = to_fixnum(dpop());
-       dpush(tag_word(word(primitive,parameter,plist)));
-}
-
-void primitive_word_hashcode(void)
-{
-       drepl(tag_fixnum(untag_word(dpeek())->hashcode));
-}
-
-void primitive_word_xt(void)
-{
-       drepl(tag_cell(untag_word(dpeek())->xt));
-}
-
-void primitive_set_word_xt(void)
-{
-       F_WORD* word = untag_word(dpop());
-       word->xt = unbox_integer();
-}
-
-void primitive_word_primitive(void)
-{
-       drepl(tag_fixnum(untag_word(dpeek())->primitive));
-}
-
-void primitive_set_word_primitive(void)
-{
-       F_WORD* word = untag_word(dpop());
-       word->primitive = to_fixnum(dpop());
-       update_xt(word);
-}
-
-void primitive_word_parameter(void)
-{
-       drepl(untag_word(dpeek())->parameter);
-}
-
-void primitive_set_word_parameter(void)
-{
-       F_WORD* word = untag_word(dpop());
-       word->parameter = dpop();
-}
-
-void primitive_word_plist(void)
-{
-       drepl(untag_word(dpeek())->plist);
-}
-
-void primitive_set_word_plist(void)
-{
-       F_WORD* word = untag_word(dpop());
-       word->plist = dpop();
-}
-
-void primitive_word_call_count(void)
-{
-       drepl(tag_cell(untag_word(dpeek())->call_count));
-}
-
-void primitive_set_word_call_count(void)
-{
-       F_WORD* word = untag_word(dpop());
-       word->call_count = to_fixnum(dpop());
+       word = allot_object(WORD_TYPE,sizeof(F_WORD));
+       word->hashcode = (CELL)word; /* initial address */
+       word->xt = (CELL)undefined;
+       word->primitive = 0;
+       word->parameter = F;
+       word->plist = F;
+       word->call_count = 0;
+       word->allot_count = 0;
+       dpush(tag_word(word));
 }
 
-void primitive_word_allot_count(void)
+void primitive_update_xt(void)
 {
-       drepl(tag_cell(untag_word(dpeek())->allot_count));
+       update_xt(untag_word(dpop()));
 }
 
-void primitive_set_word_allot_count(void)
+void primitive_word_compiledp(void)
 {
        F_WORD* word = untag_word(dpop());
-       word->allot_count = to_fixnum(dpop());
+       box_boolean(word->xt != (CELL)docol && word->xt != (CELL)dosym);
 }
 
-void primitive_word_compiledp(void)
+void primitive_to_word(void)
 {
-       F_WORD* word = untag_word(dpop());
-       box_boolean(word->xt != (CELL)docol && word->xt != (CELL)dosym);
+       type_check(WORD_TYPE,dpeek());
 }
 
 void fixup_word(F_WORD* word)
index 89cdcb92c84d7da40c349b5cbacd4639c775b1d6..afbbf0d651d64845d94ef86132fc8096bd684164 100644 (file)
@@ -30,22 +30,10 @@ INLINE CELL tag_word(F_WORD* word)
        return RETAG(word,WORD_TYPE);
 }
 
-F_WORD* word(CELL primitive, CELL parameter, CELL plist);
 void update_xt(F_WORD* word);
 void primitive_word(void);
-void primitive_word_hashcode(void);
-void primitive_word_primitive(void);
-void primitive_set_word_primitive(void);
-void primitive_word_xt(void);
-void primitive_set_word_xt(void);
-void primitive_word_parameter(void);
-void primitive_set_word_parameter(void);
-void primitive_word_plist(void);
-void primitive_set_word_plist(void);
-void primitive_word_call_count(void);
-void primitive_set_word_call_count(void);
-void primitive_word_allot_count(void);
-void primitive_set_word_allot_count(void);
+void primitive_update_xt(void);
 void primitive_word_compiledp(void);
+void primitive_to_word(void);
 void fixup_word(F_WORD* word);
 void collect_word(F_WORD* word);