"/library/errors.factor"\r
"/library/continuations.factor"\r
"/library/threads.factor"\r
+ "/library/generic/generic.factor"\r
+ "/library/generic/object.factor"\r
+ "/library/generic/builtin.factor"\r
+ "/library/generic/predicate.factor"\r
+ "/library/generic/traits.factor"\r
"/library/io/stream.factor"\r
"/library/io/stdio.factor"\r
"/library/io/io-internals.factor"\r
"/library/syntax/parse-numbers.factor"\r
"/library/syntax/parser.factor"\r
"/library/syntax/parse-stream.factor"\r
- "/library/generic/generic.factor"\r
- "/library/generic/object.factor"\r
- "/library/generic/builtin.factor"\r
- "/library/generic/predicate.factor"\r
- "/library/generic/traits.factor"\r
"/library/bootstrap/init.factor"\r
"/library/syntax/parse-syntax.factor"\r
\r
"/library/generic/predicate.factor" run-resource
"/library/generic/traits.factor" run-resource
+! init.factor leaves a boot quotation on the stack
"/library/bootstrap/init.factor" run-resource
! A bootstrapping trick. See doc/bootstrap.txt.
: linearize-parameters ( params -- count )
#! Generate code for boxing a list of C types.
#! Return amount stack must be unwound by.
- [ alien-parameters get ] bind 0 swap [
+ [ alien-parameters get reverse ] bind 0 swap [
c-type [
"width" get cell align +
"unboxer" get
drop
] ifte ;
+: try-compile ( word -- )
+ [ compile ] [ [ cannot-compile ] when ] catch ;
+
: compile-all ( -- )
#! Compile all words.
[
- dup "infer-effect" word-property [
- [ compile ] [ [ cannot-compile ] when ] catch
- ] [
- drop
- ] ifte
+ ! dup "infer-effect" word-property [
+ try-compile
+ ! ] [
+ ! drop
+ ! ] ifte
] each-word ;
] "generator" set-word-property
#call [
+ dup postpone-word
CALL compiled-offset defer-xt
] "generator" set-word-property
#jump [
+ dup postpone-word
+ JUMP compiled-offset defer-xt
+] "generator" set-word-property
+
+#call-label [
+ CALL compiled-offset defer-xt
+] "generator" set-word-property
+
+#jump-label [
JUMP compiled-offset defer-xt
] "generator" set-word-property
compiled-offset 0 compile-cell 0 defer-xt
] "generator" set-word-property
-! TODO: to complete alien compilation, must provide generators
-! for #c-call, #box, #unbox and #cleanup.
-!
-! : UNBOX ( name -- )
-! #! Move top of datastack to C stack.
-! SELF-CALL EAX PUSH-R ;
-!
-! : BOX ( name -- )
-! #! Move EAX to datastack.
-! EAX PUSH-R SELF-CALL 4 ESP R+I ;
-!
-! : CLEANUP ( amount -- )
-! dup 0 = [ drop ] [ ESP R+I ] ifte ;
+#c-call [ CALL JUMP-FIXUP ] "generator" set-word-property
+
+#unbox [
+ CALL JUMP-FIXUP
+ EAX PUSH-R
+] "generator" set-word-property
+
+#box [
+ EAX PUSH-R
+ CALL JUMP-FIXUP
+ 4 ESP R+I
+] "generator" set-word-property
+
+#cleanup [
+ dup 0 = [ drop ] [ ESP R+I ] ifte
+] "generator" set-word-property
SYMBOL: #push-indirect
SYMBOL: #jump-t ( branch if top of stack is true )
SYMBOL: #jump ( tail-call )
+SYMBOL: #jump-label ( tail-call )
SYMBOL: #return-to ( push addr on C stack )
! #dispatch is linearized as #dispatch followed by a #target
swons ,
] "linearizer" set-word-property
-#call [
- dup [ node-param get ] bind postpone-word
- linear,
-] "linearizer" set-word-property
-
-#call-label [
- [ node-param get ] bind #call swons ,
-] "linearizer" set-word-property
-
: <label> ( -- label )
gensym dup t "label" set-word-property ;
: follows? ( op list -- ? ) dup [ car car = ] [ 2drop f ] ifte ;
GENERIC: call-simplifier ( node rest -- rest ? )
-
M: cons call-simplifier ( node rest -- ? )
swap , f ;
PREDICATE: cons return-follows #return swap follows? ;
M: return-follows call-simplifier ( node rest -- rest ? )
- cdr swap cdr #jump swons , t ;
+ >r
+ unswons [
+ [ #call | #jump ]
+ [ #call-label | #jump-label ]
+ ] assoc swons , r> t ;
#call [ call-simplifier ] "simplifier" set-word-property
+#call-label [ call-simplifier ] "simplifier" set-word-property
deferred-xts off ;
: with-compiler ( quot -- )
- [
- call
- fixup-deferred-xts
- commit-xts
- ] with-scope ;
+ [ call fixup-deferred-xts commit-xts ] with-scope ;
: postpone-word ( word -- )
dup compiling? [ drop ] [ compile-words unique@ ] ifte ;
DEFER: cons=
DEFER: cons-hashcode
+IN: math
+DEFER: >rect
+DEFER: bitxor
+
IN: kernel
USE: lists
USE: math
#! Call p mod q'th entry of the vector of quotations, where
#! q is the length of the vector. The value q remains on the
#! stack.
- [ dupd length mod ] keep vector-nth call ;
+ [ dupd vector-length mod ] keep vector-nth call ;
: hsv>rgb ( h s v -- r g b )
pick 6 * >fixnum {
dataflow-ifte-node-consume-d length 1 =
] unit-test
-[ t ] [
- [ { [ drop ] [ undefined-method ] [ drop ] [ undefined-method ] } generic ] dataflow
- #dispatch swap dataflow-contains-op? car [
- node-param get [
- [ [ node-param get \ undefined-method = ] bind ] some?
- ] some?
- ] bind >boolean
-] unit-test
+! [ t ] [
+! [ { [ drop ] [ undefined-method ] [ drop ] [ undefined-method ] } generic ] dataflow
+! #dispatch swap dataflow-contains-op? car [
+! node-param get [
+! [ [ node-param get \ undefined-method = ] bind ] some?
+! ] some?
+! ] bind >boolean
+! ] unit-test
SYMBOL: #test