2010-01-19 02:00:33 -05:00
|
|
|
! Copyright (C) 2004, 2010 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2016-11-12 18:22:21 -05:00
|
|
|
USING: arrays assocs bootstrap.image.primitives
|
|
|
|
bootstrap.image.private classes classes.builtin classes.intersection
|
|
|
|
classes.predicate classes.private classes.singleton classes.tuple
|
|
|
|
classes.tuple.private classes.union combinators compiler.units io
|
|
|
|
kernel kernel.private layouts make math math.private namespaces parser
|
|
|
|
quotations sequences slots source-files splitting vocabs vocabs.loader
|
|
|
|
words ;
|
2008-03-20 16:30:59 -04:00
|
|
|
IN: bootstrap.primitives
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2016-03-29 09:41:58 -04:00
|
|
|
"* Creating primitives and basic runtime structures..." print flush
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-07-11 18:25:46 -04:00
|
|
|
H{ } clone sub-primitives set
|
|
|
|
|
2009-02-15 20:53:21 -05:00
|
|
|
"vocab:bootstrap/syntax.factor" parse-file
|
2007-12-24 17:18:26 -05:00
|
|
|
|
2015-05-22 14:29:20 -04:00
|
|
|
: asm-file ( arch -- file )
|
|
|
|
"-" split reverse "." join
|
|
|
|
"vocab:bootstrap/assembler/" ".factor" surround ;
|
|
|
|
|
|
|
|
architecture get asm-file parse-file
|
2008-01-26 22:38:30 -05:00
|
|
|
|
2009-02-15 20:53:21 -05:00
|
|
|
"vocab:bootstrap/layouts/layouts.factor" parse-file
|
2008-01-30 00:13:47 -05:00
|
|
|
|
|
|
|
! Now we have ( syntax-quot arch-quot layouts-quot ) on the stack
|
2008-01-26 22:38:30 -05:00
|
|
|
|
|
|
|
! Bring up a bare cross-compiling vocabulary.
|
2015-06-08 15:02:25 -04:00
|
|
|
"syntax" lookup-vocab vocab-words-assoc bootstrap-syntax set
|
2009-01-23 01:37:02 -05:00
|
|
|
|
2010-01-27 23:30:35 -05:00
|
|
|
H{ } clone dictionary set
|
|
|
|
H{ } clone root-cache set
|
|
|
|
H{ } clone source-files set
|
|
|
|
H{ } clone update-map set
|
|
|
|
H{ } clone implementors-map set
|
2008-02-26 04:30:11 -05:00
|
|
|
|
2010-01-27 23:30:35 -05:00
|
|
|
init-caches
|
2008-03-20 16:30:59 -04:00
|
|
|
|
2010-01-27 09:02:54 -05:00
|
|
|
bootstrapping? on
|
2009-03-13 20:42:35 -04:00
|
|
|
|
2013-11-23 23:12:35 -05:00
|
|
|
call( -- ) ! layouts quot
|
|
|
|
call( -- ) ! arch quot
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2010-01-27 23:30:35 -05:00
|
|
|
! Vocabulary for slot accessors
|
|
|
|
"accessors" create-vocab drop
|
|
|
|
|
2008-03-26 04:57:48 -04:00
|
|
|
! After we execute bootstrap/layouts
|
|
|
|
num-types get f <array> builtins set
|
|
|
|
|
2009-11-13 09:05:02 -05:00
|
|
|
[
|
|
|
|
|
2013-11-23 23:12:35 -05:00
|
|
|
call( -- ) ! syntax-quot
|
2010-01-27 23:30:35 -05:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
! create-word some empty vocabs where the below primitives and
|
2007-09-20 18:09:08 -04:00
|
|
|
! classes will go
|
|
|
|
{
|
|
|
|
"alien"
|
2008-01-31 21:11:46 -05:00
|
|
|
"alien.accessors"
|
2009-03-26 00:00:19 -04:00
|
|
|
"alien.libraries"
|
2010-03-26 22:44:43 -04:00
|
|
|
"alien.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"arrays"
|
|
|
|
"byte-arrays"
|
|
|
|
"classes.private"
|
2008-03-29 04:34:48 -04:00
|
|
|
"classes.tuple"
|
|
|
|
"classes.tuple.private"
|
2008-06-29 22:37:57 -04:00
|
|
|
"classes.predicate"
|
2008-01-09 04:52:08 -05:00
|
|
|
"compiler.units"
|
2007-09-20 18:09:08 -04:00
|
|
|
"continuations.private"
|
2009-04-28 17:58:05 -04:00
|
|
|
"generic.single"
|
2009-04-24 21:43:01 -04:00
|
|
|
"generic.single.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"growable"
|
|
|
|
"hashtables"
|
|
|
|
"hashtables.private"
|
|
|
|
"io"
|
|
|
|
"io.files"
|
|
|
|
"io.files.private"
|
|
|
|
"io.streams.c"
|
2008-10-23 06:49:32 -04:00
|
|
|
"locals.backend"
|
2007-09-20 18:09:08 -04:00
|
|
|
"kernel"
|
|
|
|
"kernel.private"
|
|
|
|
"math"
|
2009-05-02 14:45:38 -04:00
|
|
|
"math.parser.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"math.private"
|
|
|
|
"memory"
|
2009-05-02 14:45:38 -04:00
|
|
|
"memory.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"quotations"
|
|
|
|
"quotations.private"
|
|
|
|
"sbufs"
|
|
|
|
"sbufs.private"
|
|
|
|
"scratchpad"
|
|
|
|
"sequences"
|
|
|
|
"sequences.private"
|
|
|
|
"slots.private"
|
|
|
|
"strings"
|
|
|
|
"strings.private"
|
|
|
|
"system"
|
2008-03-06 21:44:52 -05:00
|
|
|
"system.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"threads.private"
|
2009-11-05 02:07:59 -05:00
|
|
|
"tools.dispatch.private"
|
2011-09-05 19:27:37 -04:00
|
|
|
"tools.memory.private"
|
2011-10-31 02:05:54 -04:00
|
|
|
"tools.profiler.sampling.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"words"
|
2009-09-27 22:09:11 -04:00
|
|
|
"words.private"
|
2007-09-20 18:09:08 -04:00
|
|
|
"vectors"
|
|
|
|
"vectors.private"
|
2009-09-02 05:43:21 -04:00
|
|
|
"vm"
|
2008-03-18 22:45:04 -04:00
|
|
|
} [ create-vocab drop ] each
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2007-12-25 18:10:05 -05:00
|
|
|
! Builtin classes
|
2007-09-20 18:09:08 -04:00
|
|
|
: lookup-type-number ( word -- n )
|
2011-10-19 13:40:12 -04:00
|
|
|
[ target-word ] with-global type-number ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-03-13 19:56:24 -04:00
|
|
|
: register-builtin ( class -- )
|
2008-03-31 02:19:21 -04:00
|
|
|
[ dup lookup-type-number "type" set-word-prop ]
|
|
|
|
[ dup "type" word-prop builtins get set-nth ]
|
2008-05-11 00:59:02 -04:00
|
|
|
[ f f f builtin-class define-class ]
|
2008-04-02 19:50:21 -04:00
|
|
|
tri ;
|
2008-03-13 19:56:24 -04:00
|
|
|
|
2008-06-28 03:36:20 -04:00
|
|
|
: prepare-slots ( slots -- slots' )
|
2015-06-08 15:38:38 -04:00
|
|
|
[ [ dup pair? [ first2 create-word ] when ] map ] map ;
|
2008-06-28 03:36:20 -04:00
|
|
|
|
|
|
|
: define-builtin-slots ( class slots -- )
|
2008-07-14 00:26:43 -04:00
|
|
|
prepare-slots make-slots 1 finalize-slots
|
2008-06-28 03:36:20 -04:00
|
|
|
[ "slots" set-word-prop ] [ define-accessors ] 2bi ;
|
2008-03-13 19:56:24 -04:00
|
|
|
|
2010-01-20 06:44:34 -05:00
|
|
|
: define-builtin-predicate ( class -- )
|
|
|
|
dup class>type [ eq? ] curry [ tag ] prepend define-predicate ;
|
|
|
|
|
2008-03-13 19:56:24 -04:00
|
|
|
: define-builtin ( symbol slotspec -- )
|
2008-11-23 03:44:56 -05:00
|
|
|
[ [ define-builtin-predicate ] keep ] dip define-builtin-slots ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2016-04-09 18:53:32 -04:00
|
|
|
{
|
|
|
|
{ "alien" "alien" }
|
|
|
|
{ "array" "arrays" }
|
|
|
|
{ "bignum" "math" }
|
|
|
|
{ "byte-array" "byte-arrays" }
|
|
|
|
{ "callstack" "kernel" }
|
|
|
|
{ "dll" "alien" }
|
|
|
|
{ "fixnum" "math" }
|
|
|
|
{ "float" "math" }
|
|
|
|
{ "quotation" "quotations" }
|
|
|
|
{ "string" "strings" }
|
|
|
|
{ "tuple" "kernel" }
|
|
|
|
{ "word" "words" }
|
|
|
|
{ "wrapper" "kernel" }
|
|
|
|
} [ create-word register-builtin ] assoc-each
|
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
"f" "syntax" lookup-word register-builtin
|
2008-02-04 17:20:07 -05:00
|
|
|
|
2008-06-29 03:12:44 -04:00
|
|
|
! We need this before defining c-ptr below
|
2011-11-06 18:57:24 -05:00
|
|
|
"f" "syntax" lookup-word { } define-builtin
|
2008-06-29 03:12:44 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"f" "syntax" create-word [ not ] "predicate" set-word-prop
|
2015-06-08 15:02:25 -04:00
|
|
|
"f?" "syntax" vocab-words-assoc delete-at
|
2008-06-29 03:12:44 -04:00
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
"t" "syntax" lookup-word define-singleton-class
|
2011-10-31 03:24:04 -04:00
|
|
|
|
2008-06-29 03:12:44 -04:00
|
|
|
! Some unions
|
2015-06-08 15:38:38 -04:00
|
|
|
"c-ptr" "alien" create-word [
|
2011-11-06 18:57:24 -05:00
|
|
|
"alien" "alien" lookup-word ,
|
|
|
|
"f" "syntax" lookup-word ,
|
|
|
|
"byte-array" "byte-arrays" lookup-word ,
|
2008-06-29 03:12:44 -04:00
|
|
|
] { } make define-union-class
|
|
|
|
|
2016-03-18 15:21:51 -04:00
|
|
|
"integer" "math" create-word
|
|
|
|
"fixnum" "math" lookup-word "bignum" "math" lookup-word 2array
|
|
|
|
define-union-class
|
|
|
|
|
|
|
|
! Two predicate classes used for declarations.
|
2015-06-08 15:38:38 -04:00
|
|
|
"array-capacity" "sequences.private" create-word
|
2011-11-06 18:57:24 -05:00
|
|
|
"fixnum" "math" lookup-word
|
2008-11-23 05:22:38 -05:00
|
|
|
[
|
|
|
|
[ dup 0 fixnum>= ] %
|
|
|
|
bootstrap-max-array-capacity <fake-bignum> [ fixnum<= ] curry ,
|
|
|
|
[ [ drop f ] if ] %
|
|
|
|
] [ ] make
|
2008-06-29 03:12:44 -04:00
|
|
|
define-predicate-class
|
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
"array-capacity" "sequences.private" lookup-word
|
2008-12-09 00:37:18 -05:00
|
|
|
[ >fixnum ] bootstrap-max-array-capacity <fake-bignum> [ fixnum-bitand ] curry append
|
2008-12-06 10:16:29 -05:00
|
|
|
"coercer" set-word-prop
|
|
|
|
|
2016-03-18 15:21:51 -04:00
|
|
|
"integer-array-capacity" "sequences.private" create-word
|
|
|
|
"integer" "math" lookup-word
|
|
|
|
[
|
|
|
|
[ dup 0 >= ] %
|
|
|
|
bootstrap-max-array-capacity <fake-bignum> [ <= ] curry ,
|
|
|
|
[ [ drop f ] if ] %
|
|
|
|
] [ ] make
|
|
|
|
define-predicate-class
|
|
|
|
|
2008-04-02 19:50:21 -04:00
|
|
|
! Catch-all class for providing a default method.
|
2015-06-08 15:38:38 -04:00
|
|
|
"object" "kernel" create-word
|
2008-05-11 02:37:37 -04:00
|
|
|
[ f f { } intersection-class define-class ]
|
|
|
|
[ [ drop t ] "predicate" set-word-prop ]
|
|
|
|
bi
|
|
|
|
|
2015-06-08 15:02:25 -04:00
|
|
|
"object?" "kernel" vocab-words-assoc delete-at
|
2008-04-02 19:50:21 -04:00
|
|
|
|
|
|
|
! Empty class with no instances
|
2015-06-08 15:38:38 -04:00
|
|
|
"null" "kernel" create-word
|
2008-05-11 00:59:02 -04:00
|
|
|
[ f { } f union-class define-class ]
|
2008-04-02 22:27:49 -04:00
|
|
|
[ [ drop f ] "predicate" set-word-prop ]
|
|
|
|
bi
|
|
|
|
|
2015-06-08 15:02:25 -04:00
|
|
|
"null?" "kernel" vocab-words-assoc delete-at
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"fixnum" "math" create-word { } define-builtin
|
|
|
|
"fixnum" "math" create-word "integer>fixnum-strict" "math" create-word 1quotation "coercer" set-word-prop
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"bignum" "math" create-word { } define-builtin
|
|
|
|
"bignum" "math" create-word ">bignum" "math" create-word 1quotation "coercer" set-word-prop
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"float" "math" create-word { } define-builtin
|
|
|
|
"float" "math" create-word ">float" "math" create-word 1quotation "coercer" set-word-prop
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"array" "arrays" create-word {
|
2008-07-16 17:48:09 -04:00
|
|
|
{ "length" { "array-capacity" "sequences.private" } read-only }
|
|
|
|
} define-builtin
|
2008-03-13 19:56:24 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"wrapper" "kernel" create-word {
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "wrapped" read-only }
|
2007-09-20 18:09:08 -04:00
|
|
|
} define-builtin
|
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"string" "strings" create-word {
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "length" { "array-capacity" "sequences.private" } read-only }
|
2008-06-29 03:12:44 -04:00
|
|
|
"aux"
|
2007-09-20 18:09:08 -04:00
|
|
|
} define-builtin
|
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"quotation" "quotations" create-word {
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "array" { "array" "arrays" } read-only }
|
2009-03-16 21:11:36 -04:00
|
|
|
"cached-effect"
|
|
|
|
"cache-counter"
|
2007-09-20 18:09:08 -04:00
|
|
|
} define-builtin
|
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"dll" "alien" create-word {
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "path" { "byte-array" "byte-arrays" } read-only }
|
2008-07-01 17:33:45 -04:00
|
|
|
} define-builtin
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"alien" "alien" create-word {
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "underlying" { "c-ptr" "alien" } read-only }
|
2008-07-01 17:33:45 -04:00
|
|
|
"expired"
|
|
|
|
} define-builtin
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"word" "words" create-word {
|
2008-06-29 03:12:44 -04:00
|
|
|
{ "hashcode" { "fixnum" "math" } }
|
2012-07-27 22:35:48 -04:00
|
|
|
"name"
|
2008-06-29 03:12:44 -04:00
|
|
|
"vocabulary"
|
2008-06-29 22:37:57 -04:00
|
|
|
{ "def" { "quotation" "quotations" } initial: [ ] }
|
2008-06-29 03:12:44 -04:00
|
|
|
"props"
|
2009-05-06 20:22:22 -04:00
|
|
|
"pic-def"
|
|
|
|
"pic-tail-def"
|
2008-07-11 18:25:46 -04:00
|
|
|
{ "sub-primitive" read-only }
|
2007-09-20 18:09:08 -04:00
|
|
|
} define-builtin
|
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"byte-array" "byte-arrays" create-word {
|
2008-07-16 17:48:09 -04:00
|
|
|
{ "length" { "array-capacity" "sequences.private" } read-only }
|
|
|
|
} define-builtin
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"callstack" "kernel" create-word { } define-builtin
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"tuple" "kernel" create-word
|
2008-07-14 00:26:43 -04:00
|
|
|
[ { } define-builtin ]
|
|
|
|
[ define-tuple-layout ]
|
2008-09-03 04:46:56 -04:00
|
|
|
bi
|
2008-03-26 04:57:48 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
! create-word special tombstone values
|
|
|
|
"tombstone" "hashtables.private" create-word
|
2008-04-14 06:27:04 -04:00
|
|
|
tuple
|
2008-09-03 04:46:56 -04:00
|
|
|
{ "state" } define-tuple-class
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2016-03-25 04:52:07 -04:00
|
|
|
"+empty+" "hashtables.private" create-word
|
2014-11-29 19:54:50 -05:00
|
|
|
{ f } "tombstone" "hashtables.private" lookup-word
|
|
|
|
slots>tuple 1quotation ( -- value ) define-inline
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2016-03-25 04:52:07 -04:00
|
|
|
"+tombstone+" "hashtables.private" create-word
|
2014-11-29 19:54:50 -05:00
|
|
|
{ t } "tombstone" "hashtables.private" lookup-word
|
|
|
|
slots>tuple 1quotation ( -- value ) define-inline
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-01-28 19:15:21 -05:00
|
|
|
! Some tuple classes
|
2015-06-08 15:38:38 -04:00
|
|
|
"curry" "kernel" create-word
|
2008-04-14 06:27:04 -04:00
|
|
|
tuple
|
2008-02-11 14:50:29 -05:00
|
|
|
{
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "obj" read-only }
|
|
|
|
{ "quot" read-only }
|
2008-06-28 03:36:20 -04:00
|
|
|
} prepare-slots define-tuple-class
|
2008-02-11 14:50:29 -05:00
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
"curry" "kernel" lookup-word
|
2008-07-20 02:15:58 -04:00
|
|
|
{
|
|
|
|
[ f "inline" set-word-prop ]
|
|
|
|
[ make-flushable ]
|
|
|
|
[ ]
|
2008-11-21 05:37:17 -05:00
|
|
|
[
|
|
|
|
[
|
|
|
|
callable instance-check-quot %
|
|
|
|
tuple-layout ,
|
|
|
|
\ <tuple-boa> ,
|
|
|
|
] [ ] make
|
|
|
|
]
|
2008-07-20 02:15:58 -04:00
|
|
|
} cleave
|
2011-10-18 16:18:42 -04:00
|
|
|
( obj quot -- curry ) define-declared
|
2008-03-26 04:57:48 -04:00
|
|
|
|
2015-06-08 15:38:38 -04:00
|
|
|
"compose" "kernel" create-word
|
2008-04-14 06:27:04 -04:00
|
|
|
tuple
|
2008-02-11 14:50:29 -05:00
|
|
|
{
|
2008-06-30 02:44:58 -04:00
|
|
|
{ "first" read-only }
|
|
|
|
{ "second" read-only }
|
2008-06-28 03:36:20 -04:00
|
|
|
} prepare-slots define-tuple-class
|
2008-02-11 14:50:29 -05:00
|
|
|
|
2011-11-06 18:57:24 -05:00
|
|
|
"compose" "kernel" lookup-word
|
2008-07-20 02:15:58 -04:00
|
|
|
{
|
|
|
|
[ f "inline" set-word-prop ]
|
|
|
|
[ make-flushable ]
|
|
|
|
[ ]
|
2008-11-21 05:37:17 -05:00
|
|
|
[
|
|
|
|
[
|
2008-11-23 03:44:56 -05:00
|
|
|
callable instance-check-quot [ dip ] curry %
|
2008-11-21 05:37:17 -05:00
|
|
|
callable instance-check-quot %
|
|
|
|
tuple-layout ,
|
|
|
|
\ <tuple-boa> ,
|
|
|
|
] [ ] make
|
|
|
|
]
|
2008-07-20 02:15:58 -04:00
|
|
|
} cleave
|
2011-10-18 16:18:42 -04:00
|
|
|
( quot1 quot2 -- compose ) define-declared
|
2008-03-26 04:57:48 -04:00
|
|
|
|
2016-03-29 09:41:58 -04:00
|
|
|
"* Declaring primitives..." print flush
|
2016-11-12 18:22:21 -05:00
|
|
|
all-primitives create-primitives
|
2007-12-25 18:10:05 -05:00
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
! Bump build number
|
2015-06-08 15:38:38 -04:00
|
|
|
"build" "kernel" create-word build 1 + [ ] curry ( -- n ) define-declared
|
2009-11-13 09:05:02 -05:00
|
|
|
|
|
|
|
] with-compilation-unit
|