ARTICLE: "namespaces-internals" "Namespace implementation details"
"The namestack holds namespaces."
-{ $subsection namestack* }
{ $subsection namestack }
{ $subsection set-namestack }
"A pair of words push and pop namespaces on the namestack."
] map-with ;
: iter ( c z nb-iter -- x )
- over absq 4.0 >= over 0 = or
+ over absq 4.0 >= over zero? or
[ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline
SYMBOL: cols
IN: namespaces
-USING: help ;
+USING: help kernel-internals ;
HELP: get "( variable -- value )"
{ $values { "variable" "a variable, by convention a symbol" } { "value" "the value, or " { $link f } } }
! See http://factor.sf.net/license.txt for BSD license.
IN: compiler
USING: assembler errors generic hashtables kernel
-kernel-internals lists math namespaces prettyprint sequences
-strings vectors words ;
+kernel-internals lists math namespaces prettyprint queues
+sequences strings vectors words ;
: <label> ( -- label )
#! Make a label.
: inlining-class ( #call -- class )
#! If the generic dispatch can be eliminated, return the
#! class of the method that will always be invoked here.
- dup node-param swap dispatching-class
- specific-method ;
+ dup node-param swap dispatching-class specific-method ;
: will-inline-method ( node -- quot/t )
#! t indicates failure
#! t indicates failure
{
{ [ 3dup math-both-known? ] [ math-method ] }
- { [ 3dup drop specific-method ] [ left-partial-math ] }
- { [ 3dup nip specific-method ] [ right-partial-math ] }
+ ! { [ 3dup drop specific-method ] [ left-partial-math ] }
+ ! { [ 3dup nip specific-method ] [ right-partial-math ] }
{ [ t ] [ 3drop t ] }
} cond ;
will-inline-math-method (inline-method) ;
: inline-math-method? ( #call -- ? )
- dup node-history empty? swap node-param 2generic? and ;
+ dup node-history [ 2generic? ] contains? not
+ swap node-param 2generic? and ;
: inline-method ( #call -- node )
{
: optimize-predicate? ( #call -- ? )
dup node-param "predicating" word-prop dup [
- >r dup 0 node-class# r> comparable?
+ >r 0 node-class# r> comparable?
] [
2drop f
] if ;
! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: optimizer
-USING: generic hashtables inference io kernel
-lists math namespaces sequences vectors ;
+USING: generic hashtables inference io kernel lists math
+namespaces sequences test vectors ;
SYMBOL: optimizer-changed
-USING: errors help kernel ;
+USING: errors help kernel kernel-internals ;
HELP: catchstack* "( -- catchstack )"
{ $values { "catchstack" "a vector" } }
: first/last ( seq -- pair ) dup first swap peek 2array ;
+: math-class? ( object -- ? )
+ dup word? [ number bootstrap-word class< ] [ drop f ] if ;
+
: math-class-compare ( class class -- n )
[
- dup number class<
+ dup math-class?
[ types first/last ] [ drop { 100 100 } ] if
] 2apply <=> ;
: math-vtable ( picker quot -- quot )
num-tags swap math-vtable* ; inline
-: math-class? ( object -- ? )
- dup word? [ "math-priority" word-prop ] [ drop f ] if ;
-
: math-combination ( word -- quot )
\ over [
dup math-class? [
USING: generic help math ;
-HELP: math-priority "( class -- n )"
-{ $values { "class" "a class word" } { "n" "a non-negative integer" } }
-{ $description "Outputs the priority of a built-in number class. If class A has a lower priority than class B, then applying a binary math operation to an instance of A and B will upgrade the instance of A to B's type." }
-{ $notes "To simplify implementation of the math method combination, this word outputs 100 for non-numeric classes. Priorities of numeric classes must always be less than 100." } ;
-
-HELP: math-class< "( class1 class2 -- ? )"
-{ $values { "class1" "a class word" } { "class2" "a class word" } { "?" "a boolean" } }
-{ $description "Defines a total ordering on built-in number classes." } ;
-
HELP: math-upgrade "( class1 class2 -- quot )"
{ $values { "class1" "a class word" } { "class2" "a class word" } { "quot" "a quotation with stack effect " { $snippet "( n n -- n n )" } } }
{ $description "Outputs a quotation for upgrading numberical types. It takes two numbers on the stack, an instance of " { $snippet "class1" } ", and an instance of " { $snippet "class2" } ", and converts the one with the lower priority to the higher priority type." }
GENERIC: zero? ( x -- ? ) foldable
M: object zero? drop f ;
-: sq dup * ; inline
-: neg 0 swap - ; inline
-: recip 1 swap / ; inline
+: sq dup * ; foldable
+: neg 0 swap - ; foldable
+: recip 1 swap / ; foldable
: max ( x y -- z ) [ > ] 2keep ? ; foldable
: min ( x y -- z ) [ < ] 2keep ? ; foldable
: between? ( x min max -- ? ) pick >= >r >= r> and ; foldable
: truncate ( x -- y ) dup 1 mod - ; foldable
: floor ( x -- y )
- dup 1 mod dup 0 =
+ dup 1 mod dup zero?
[ drop ] [ dup 0 < [ - 1- ] [ - ] if ] if ; foldable
: ceiling ( x -- y ) neg floor neg ; foldable
nip [ swap % dup [ walk ] curry , , \ if , ] [ ] make
] annotate ;
-: with-profile ( quot word -- )
- millis >r >r call r> millis r> - swap global [ +@ ] bind ;
- inline
-
: profile ( word -- )
- [ swap [ with-profile ] curry cons ] annotate ;
+ [ swap [ global [ inc ] bind call ] curry cons ] annotate ;