diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index df66df31b6..8b7a1945ef 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -28,12 +28,14 @@ recrossref t [ "/library/inference/conditions.factor" "/library/inference/dataflow.factor" + "/library/inference/values.factor" "/library/inference/inference.factor" "/library/inference/ties.factor" "/library/inference/branches.factor" "/library/inference/words.factor" "/library/inference/stack.factor" "/library/inference/types.factor" + "/library/inference/partial-eval.factor" "/library/compiler/assembler.factor" "/library/compiler/relocate.factor" diff --git a/library/bootstrap/boot-stage3.factor b/library/bootstrap/boot-stage3.factor index 5b76939734..89a5939392 100644 --- a/library/bootstrap/boot-stage3.factor +++ b/library/bootstrap/boot-stage3.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2004, 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. -USING: alien assembler command-line compiler io-internals kernel -lists math namespaces parser sequences stdio unparser words ; +USING: alien assembler command-line compiler compiler-backend +io-internals kernel lists math namespaces parser sequences stdio +unparser words ; "Compiling base..." print @@ -36,6 +37,7 @@ compile? [ \ = compile \ unparse compile \ scan compile + \ (generate) compile ] when "Loading more library code..." print diff --git a/library/collections/sequences-epilogue.factor b/library/collections/sequences-epilogue.factor index b8620f8419..3b95f914ad 100644 --- a/library/collections/sequences-epilogue.factor +++ b/library/collections/sequences-epilogue.factor @@ -182,7 +182,7 @@ C: range ( from to -- range ) [ set-range-from ] keep ; M: range length ( range -- n ) - dup range-to swap range-from - abs 1 + ; + dup range-to swap range-from - abs ; M: range nth ( n range -- n ) [ range-step * ] keep range-from + ; @@ -200,6 +200,9 @@ M: slice nth ( n slice -- obj ) M: slice set-nth ( obj n slice -- ) [ delegate nth ] keep slice-seq set-nth ; +: tail-slice ( n seq -- slice ) + [ length [ swap - ] keep ] keep ; + IN: kernel : depth ( -- n ) diff --git a/library/compiler/intrinsics.factor b/library/compiler/intrinsics.factor index 8bb1478e4c..63c8c93a81 100644 --- a/library/compiler/intrinsics.factor +++ b/library/compiler/intrinsics.factor @@ -11,18 +11,20 @@ sequences words ; #! by GC, and is indexed through a table. dup fixnum? swap f eq? or ; +: push-1 ( obj -- ) + 0 swap literal-value dup + immediate? [ %immediate ] [ %indirect ] ifte , ; + #push [ - 1 %inc-d , - [ node-param get ] bind dup immediate? [ - %immediate-d , - ] [ - 0 swap %indirect , out-1 - ] ifte + [ node-produce-d get ] bind + dup length dup %inc-d , + 1 - swap [ + push-1 0 over %replace-d , + ] each drop ] "linearizer" set-word-prop -\ drop [ - drop - 1 %dec-d , +#drop [ + [ node-consume-d get length ] bind %dec-d , ] "linearizer" set-word-prop \ dup [ @@ -171,9 +173,12 @@ sequences words ; 1 0 rot execute , r> 0 %replace-d , ; +: literal-fixnum? ( value -- ? ) + dup literal? [ literal-value fixnum? ] [ drop f ] ifte ; + : binary-op ( node op out -- ) #! out is a vreg where the vop stores the result. - >r >r node-peek dup literal? [ + >r >r node-peek dup literal-fixnum? [ 1 %dec-d , in-1 literal-value 0 r> execute , @@ -206,7 +211,7 @@ sequences words ; \ fixnum* [ ! Turn multiplication by a power of two into a left shift. - node-peek dup literal? [ + node-peek dup literal-fixnum? [ literal-value dup power-of-2? [ 1 %dec-d , in-1 diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index c58a5015c7..97853d2fa9 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -21,16 +21,6 @@ math namespaces words strings errors prettyprint sequences ; #! rest is arguments. [ %prologue , (linearize) ] make-list ; -: 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-prop - : linearize-label ( node -- ) #! Labels are tricky, because they might contain non-tail #! calls. So we push the address of the location right after @@ -39,7 +29,8 @@ math namespaces words strings errors prettyprint sequences ; #! this in the common case where the labelled block does #! not contain non-tail recursive calls to itself.