From 3174f87b67553fef009fe7f72f11c4f87f4a2e80 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 10 Dec 2005 06:02:13 +0000 Subject: [PATCH] minor cleanups all over the place --- TODO.FACTOR.txt | 11 +++++- contrib/httpd/mime.factor | 3 ++ contrib/math/utils.factor | 4 +++ library/alien/aliens.factor | 3 +- library/alien/c-types.factor | 18 +++++----- library/bootstrap/primitives.factor | 2 +- library/collections/arrays.factor | 2 +- library/collections/sequence-eq.factor | 2 +- library/collections/sequences.factor | 5 +-- library/collections/strings-epilogue.factor | 5 ++- library/compiler/amd64/alien.factor | 15 ++++++++ library/compiler/amd64/architecture.factor | 7 ++++ library/compiler/generator.factor | 10 ++---- library/compiler/linearizer.factor | 3 +- library/compiler/vops.factor | 8 ----- library/compiler/x86/architecture.factor | 6 ++++ library/compiler/x86/fixnum.factor | 40 +++++++-------------- library/compiler/x86/generator.factor | 14 ++++---- library/compiler/x86/slots.factor | 10 +++--- library/generic/slots.factor | 5 +-- library/inference/branches.factor | 3 -- library/inference/call-optimizers.factor | 8 ----- library/inference/split-nodes.factor | 8 +++-- library/io/files.factor | 3 -- library/math/arc-trig-hyp.factor | 8 ++--- library/math/constants.factor | 1 + library/math/float.factor | 2 -- library/math/vectors.factor | 4 --- library/test/files.factor | 8 ----- library/test/test.factor | 6 ++-- library/unix/io.factor | 11 ++---- library/vocabularies.factor | 2 +- 32 files changed, 106 insertions(+), 131 deletions(-) create mode 100644 library/compiler/amd64/alien.factor delete mode 100644 library/test/files.factor diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index a18491a1b9..f4f335b4a6 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,5 +1,15 @@ + 0.80: +- -with combinators are ackward + +- cleanups: + alien/compiler + inference/shuffle + inference-words inline-block + io/buffer - use aliens not integers + alien/malloc - use aliens not integers + ui/line-editor - don't use variables +- fix powerpc backend - ( length initial ) - ( length initial ) - remove repetitions @@ -25,7 +35,6 @@ word help sections: parsing word sections: - syntax -- malloc, free, realloc, memcpy: aliens - check 'see' - intrinsic char-slot set-char-slot for x86 - closing ui does not stop timers diff --git a/contrib/httpd/mime.factor b/contrib/httpd/mime.factor index aed930cb02..99e0df9f56 100644 --- a/contrib/httpd/mime.factor +++ b/contrib/httpd/mime.factor @@ -3,6 +3,9 @@ IN: httpd USING: io hashtables kernel lists namespaces ; +: file-extension ( filename -- extension ) + "." split dup length 1 <= [ drop f ] [ peek ] if ; + : mime-type ( filename -- mime-type ) file-extension "mime-types" get hash [ "text/plain" ] unless* ; diff --git a/contrib/math/utils.factor b/contrib/math/utils.factor index 5e4d6cf1c7..98ac0e6060 100644 --- a/contrib/math/utils.factor +++ b/contrib/math/utils.factor @@ -36,6 +36,10 @@ USING: errors kernel sequences math sequences-internals namespaces arrays ; #! Complex inner product. 0 [ ** + ] 2reduce ; +: proj ( u v -- w ) + #! Orthogonal projection of u onto v. + [ [ v. ] keep norm-sq v/n ] keep n*v ; + : minmax ( seq -- min max ) #! find the min and max of a seq in one pass inf -inf rot [ dup pick max -rot nip pick min -rot nip ] each ; diff --git a/library/alien/aliens.factor b/library/alien/aliens.factor index 518d51b30e..daa2d335bc 100644 --- a/library/alien/aliens.factor +++ b/library/alien/aliens.factor @@ -15,8 +15,7 @@ M: alien = ( obj obj -- ? ) 2drop f ] if ; -: library ( name -- object ) - dup [ "libraries" get hash ] when ; +: library ( name -- object ) "libraries" get hash ; : load-library ( name -- dll ) #! Higher level wrapper around dlopen primitive. diff --git a/library/alien/c-types.factor b/library/alien/c-types.factor index b894c2b298..58ee471264 100644 --- a/library/alien/c-types.factor +++ b/library/alien/c-types.factor @@ -18,24 +18,22 @@ sequences sequences-internals strings words ; SYMBOL: c-types : c-type ( name -- type ) - dup c-types get hash [ ] [ - "No such C type: " swap append throw f - ] ?if ; + dup c-types get hash + [ ] [ "No such C type: " swap append throw ] ?if ; -: c-size ( name -- size ) - "width" swap c-type hash ; +: c-size ( name -- size ) "width" swap c-type hash ; -: c-getter ( name -- quot ) - "getter" swap c-type hash ; +: c-getter ( name -- quot ) "getter" swap c-type hash ; -: c-setter ( name -- quot ) - "setter" swap c-type hash ; +: c-setter ( name -- quot ) "setter" swap c-type hash ; : define-c-type ( quot name -- ) >r [ swap bind ] keep r> c-types get set-hash ; inline -: ( size -- c-ptr ) cell / ceiling ; +: bytes>cells cell / ceiling ; + +: ( size -- c-ptr ) bytes>cells ; : define-pointer ( type -- ) "void*" c-type swap "*" append c-types get set-hash ; diff --git a/library/bootstrap/primitives.factor b/library/bootstrap/primitives.factor index 1a79d82878..22708dfdc9 100644 --- a/library/bootstrap/primitives.factor +++ b/library/bootstrap/primitives.factor @@ -18,7 +18,7 @@ words ; "syntax" vocab H{ } clone vocabularies set -f crossref set +crossref off vocabularies get [ "syntax" set [ reveal ] each ] bind diff --git a/library/collections/arrays.factor b/library/collections/arrays.factor index 14524f3b1c..1d11118765 100644 --- a/library/collections/arrays.factor +++ b/library/collections/arrays.factor @@ -12,7 +12,7 @@ USING: kernel math math-internals sequences sequences-internals ; ] all? 2nip ] [ 2drop f - ] if ; flushable + ] if ; inline IN: arrays diff --git a/library/collections/sequence-eq.factor b/library/collections/sequence-eq.factor index e7984400ef..2e148023f9 100644 --- a/library/collections/sequence-eq.factor +++ b/library/collections/sequence-eq.factor @@ -15,7 +15,7 @@ UNION: sequence array string sbuf vector ; dup length [ >r 2dup r> 2nth-unsafe = ] all? 2nip ] [ 2drop f - ] if ; flushable + ] if ; inline M: sequence = ( obj seq -- ? ) 2dup eq? [ diff --git a/library/collections/sequences.factor b/library/collections/sequences.factor index 1075340e7d..f17f9e2142 100644 --- a/library/collections/sequences.factor +++ b/library/collections/sequences.factor @@ -6,10 +6,7 @@ USING: errors generic kernel math math-internals strings vectors ; ! This file is needed very early in bootstrap. ! Sequences support the following protocol. Concrete examples -! are strings, string buffers, vectors, and arrays. Arrays are -! low level and no | quot: elt -- ? t bounds-checked; they are in the -! kernel-internals vocabulary, so don't use them unless you have -! a good reason. +! are strings, string buffers, vectors, and arrays. GENERIC: empty? ( sequence -- ? ) flushable GENERIC: length ( sequence -- n ) flushable diff --git a/library/collections/strings-epilogue.factor b/library/collections/strings-epilogue.factor index 1bf3707b63..e0c246c4e2 100644 --- a/library/collections/strings-epilogue.factor +++ b/library/collections/strings-epilogue.factor @@ -11,8 +11,7 @@ sequences strings ; >string ; inline : padding ( string count char -- string ) - >r swap length - dup 0 <= [ r> 2drop "" ] [ r> fill ] if ; - flushable + >r swap length - 0 max r> fill ; flushable : pad-left ( string count char -- string ) pick >r padding r> append ; flushable @@ -21,7 +20,7 @@ sequences strings ; pick >r padding r> swap append ; flushable : ch>string ( ch -- str ) - 1 [ push ] keep (sbuf>string) ; flushable + 1 swap fill ; flushable : >sbuf ( seq -- sbuf ) dup length [ swap nappend ] keep ; inline diff --git a/library/compiler/amd64/alien.factor b/library/compiler/amd64/alien.factor new file mode 100644 index 0000000000..72986b9104 --- /dev/null +++ b/library/compiler/amd64/alien.factor @@ -0,0 +1,15 @@ +! Copyright (C) 2005 Slava Pestov. +! See http://factor.sf.net/license.txt for BSD license. +IN: compiler-backend +USING: alien assembler compiler inference kernel +kernel-internals lists math memory namespaces words ; + +M: %alien-invoke generate-node drop ; + +M: %parameter generate-node drop ; + +M: %unbox generate-node drop ; + +M: %box generate-node drop ; + +M: %cleanup generate-node drop ; diff --git a/library/compiler/amd64/architecture.factor b/library/compiler/amd64/architecture.factor index fb5907b97c..21b8966133 100644 --- a/library/compiler/amd64/architecture.factor +++ b/library/compiler/amd64/architecture.factor @@ -17,6 +17,13 @@ USING: assembler compiler-backend kernel sequences ; : vregs { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; inline +: param-regs { R9 R8 RCX RDX RSI RDI } ; + +DEFER: compile-c-call + +: compile-c-call* ( symbol dll -- operands ) + param-regs swap [ MOV ] 2each compile-c-call ; + ! FIXME M: int-regs fastcall-regs drop 0 ; M: int-regs reg-class-size drop 4 ; diff --git a/library/compiler/generator.factor b/library/compiler/generator.factor index 96016ff233..fa8f6bac78 100644 --- a/library/compiler/generator.factor +++ b/library/compiler/generator.factor @@ -55,14 +55,8 @@ SYMBOL: previous-offset M: %label generate-node ( vop -- ) vop-label save-xt ; -M: %end-dispatch generate-node ( vop -- ) drop ; - -: compile-target ( word -- ) 0 assemble-cell absolute-cell ; - -M: %target-label generate-node vop-label compile-target ; - -M: %target generate-node - vop-label dup postpone-word compile-target ; +M: %target-label generate-node ( vop -- ) + drop label 0 assemble-cell absolute-cell ; M: %parameters generate-node ( vop -- ) drop ; diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index 524f0f72b5..856270432f 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -77,8 +77,7 @@ M: #if linearize* ( node -- ) in-1 -1 %inc-d , 0 %dispatch , - [