From ee5fc9575db8b25ec1aabbd4d82786e61eb6c4bb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 11 Dec 2004 23:18:43 +0000 Subject: [PATCH] generic.factor cleanups; started generalized dispatching --- factor/jedit/FactorPlugin.java | 2 + library/bootstrap/boot-stage2.factor | 2 +- library/bootstrap/boot.factor | 2 +- library/bootstrap/image.factor | 31 +++++++++--- library/compiler/linearizer.factor | 14 ++++-- library/compiler/optimizer.factor | 26 +++++----- library/generic.factor | 73 ++++++++++++++++++---------- library/httpd/html.factor | 4 +- library/inference/dataflow.factor | 5 ++ library/io/ansi.factor | 2 +- library/io/network.factor | 4 +- library/io/stdio.factor | 6 +-- library/io/stream-impl.factor | 14 +++--- library/io/stream.factor | 10 ++-- library/strings.factor | 11 ++--- library/syntax/parse-syntax.factor | 4 +- library/test/generic.factor | 20 ++++---- library/test/lists/assoc.factor | 3 -- library/test/lists/cons.factor | 8 --- library/test/stream.factor | 10 ++-- library/tools/jedit-wire.factor | 8 +-- library/types.factor | 50 ++++++------------- library/words.factor | 3 +- 23 files changed, 167 insertions(+), 145 deletions(-) diff --git a/factor/jedit/FactorPlugin.java b/factor/jedit/FactorPlugin.java index 6c4be2b07a..23cbadc477 100644 --- a/factor/jedit/FactorPlugin.java +++ b/factor/jedit/FactorPlugin.java @@ -447,6 +447,8 @@ public class FactorPlugin extends EditPlugin String decl = "USE: " + vocab; if(leadingNewline) decl = "\n" + decl; + if(lastUseOffset == 0) + decl = decl + "\n"; buffer.insert(lastUseOffset,decl); showStatus(view,"inserted-use",decl); } //}}} diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index 74dbd719dc..5eff3381a0 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -36,6 +36,7 @@ USE: stdio "/version.factor" "/library/kernel.factor" "/library/stack.factor" + "/library/generic.factor" "/library/types.factor" "/library/math/math.factor" "/library/cons.factor" @@ -50,7 +51,6 @@ USE: stdio "/library/strings.factor" "/library/hashtables.factor" "/library/namespaces.factor" - "/library/generic.factor" "/library/list-namespaces.factor" "/library/sbuf.factor" "/library/continuations.factor" diff --git a/library/bootstrap/boot.factor b/library/bootstrap/boot.factor index 4553f809c7..ae03fdf034 100644 --- a/library/bootstrap/boot.factor +++ b/library/bootstrap/boot.factor @@ -38,6 +38,7 @@ primitives, "/version.factor" "/library/stack.factor" "/library/kernel.factor" + "/library/generic.factor" "/library/types.factor" "/library/combinators.factor" "/library/math/math.factor" @@ -52,7 +53,6 @@ primitives, "/library/strings.factor" "/library/hashtables.factor" "/library/namespaces.factor" - "/library/generic.factor" "/library/list-namespaces.factor" "/library/sbuf.factor" "/library/continuations.factor" diff --git a/library/bootstrap/image.factor b/library/bootstrap/image.factor index c569d6d385..dd3a5730fd 100644 --- a/library/bootstrap/image.factor +++ b/library/bootstrap/image.factor @@ -42,7 +42,6 @@ IN: image USE: errors USE: hashtables USE: kernel -USE: kernel-internals USE: lists USE: math USE: namespaces @@ -84,6 +83,26 @@ SYMBOL: boot-quot : untag ( cell tag -- ) tag-mask bitnot bitand ; : tag ( cell -- tag ) tag-mask bitand ; +: fixnum-tag BIN: 000 ; inline +: word-tag BIN: 001 ; inline +: cons-tag BIN: 010 ; inline +: object-tag BIN: 011 ; inline +: ratio-tag BIN: 100 ; inline +: complex-tag BIN: 101 ; inline +: header-tag BIN: 110 ; inline + +: f-type 6 ; inline +: t-type 7 ; inline +: array-type 8 ; inline +: bignum-type 9 ; inline +: float-type 10 ; inline +: vector-type 11 ; inline +: string-type 12 ; inline +: sbuf-type 13 ; inline +: port-type 14 ; inline +: dll-type 15 ; inline +: alien-type 16 ; inline + : immediate ( x tag -- tagged ) swap tag-bits shift bitor ; : >header ( id -- tagged ) header-tag immediate ; @@ -135,14 +154,14 @@ SYMBOL: boot-quot ( Bignums ) : emit-bignum ( bignum -- tagged ) + #! This can only emit 0, -1 and 1. object-tag here-as >r bignum-type >header emit - dup 0 = 1 2 ? emit ( capacity ) [ - [ 0 = ] [ emit pad ] - [ 0 < ] [ 1 emit neg emit ] - [ 0 > ] [ 0 emit emit ] - ] cond r> ; + [ 0 | [ 1 0 ] ] + [ -1 | [ 2 1 1 ] ] + [ 1 | [ 2 0 1 ] ] + ] assoc [ emit ] each pad r> ; ( Special objects ) diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index e51bd5388b..02d54c658b 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -86,10 +86,16 @@ SYMBOL: #return-to ( push addr on C stack ) : label, ( label -- ) #label swons , ; -: (linearize-label) ( node -- ) +: linearize-simple-label ( node -- ) + #! Some labels become simple labels after the optimization + #! stage. dup [ node-label get ] bind label, [ node-param get ] bind (linearize) ; +#simple-label [ + linearize-simple-label +] "linearizer" set-word-property + : linearize-label ( node -- ) #! Labels are tricky, because they might contain non-tail #! calls. So we push the address of the location right after @@ -98,11 +104,13 @@ SYMBOL: #return-to ( push addr on C stack ) #! this in the common case where the labelled block does #! not contain non-tail recursive calls to itself.