From: John Benediktsson Date: Fri, 21 Jan 2022 19:26:03 +0000 (-0800) Subject: bootstrap: some cleanup, move stage1 to basis/bootstrap/ X-Git-Tag: 0.99~1724 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=fc6f53cd37e4704eba784e865974b176c7df35a9 bootstrap: some cleanup, move stage1 to basis/bootstrap/ this keeps it all together and imho makes it easier to understand --- diff --git a/basis/bootstrap/assembler/arm.32.unix.factor b/basis/bootstrap/assembler/arm.32.unix.factor index e8db0416ee..d8945220c6 100644 --- a/basis/bootstrap/assembler/arm.32.unix.factor +++ b/basis/bootstrap/assembler/arm.32.unix.factor @@ -3,6 +3,6 @@ USING: kernel parser sequences ; IN: bootstrap.assembler.arm -<< "vocab:bootstrap/assembler/arm.unix.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.32.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.unix.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.32.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/arm.32.windows.factor b/basis/bootstrap/assembler/arm.32.windows.factor index 70f20056ca..ae11ab5f8d 100644 --- a/basis/bootstrap/assembler/arm.32.windows.factor +++ b/basis/bootstrap/assembler/arm.32.windows.factor @@ -3,6 +3,6 @@ USING: kernel parser sequences ; IN: bootstrap.assembler.arm -<< "vocab:bootstrap/assembler/arm.windows.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.32.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.windows.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.32.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/arm.64.unix.factor b/basis/bootstrap/assembler/arm.64.unix.factor index 4f4fe7d1b9..69a1c87a77 100644 --- a/basis/bootstrap/assembler/arm.64.unix.factor +++ b/basis/bootstrap/assembler/arm.64.unix.factor @@ -56,6 +56,6 @@ IN: bootstrap.assembler.arm : arg4 ( -- reg ) X3 ; : red-zone-size ( -- n ) 16 ; -<< "vocab:bootstrap/assembler/arm.unix.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.64.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.unix.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.64.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/arm.64.windows.factor b/basis/bootstrap/assembler/arm.64.windows.factor index 5f2938a369..16480903e5 100644 --- a/basis/bootstrap/assembler/arm.64.windows.factor +++ b/basis/bootstrap/assembler/arm.64.windows.factor @@ -4,6 +4,6 @@ USING: kernel parser sequences ; IN: bootstrap.assembler.arm -<< "vocab:bootstrap/assembler/arm.windows.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.64.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/arm.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.windows.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.64.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/arm.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/ppc.32.linux.factor b/basis/bootstrap/assembler/ppc.32.linux.factor index 1f019587a2..328b14e61d 100644 --- a/basis/bootstrap/assembler/ppc.32.linux.factor +++ b/basis/bootstrap/assembler/ppc.32.linux.factor @@ -69,5 +69,5 @@ CONSTANT: frame-reg 31 : param-size ( -- n ) 32 ; : saved-int-regs-size ( -- n ) 96 ; -<< "vocab:bootstrap/assembler/ppc.factor" parse-file suffix! >> +<< "resource:basis/bootstrap/assembler/ppc.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/ppc.64.linux.factor b/basis/bootstrap/assembler/ppc.64.linux.factor index bb1d661ca1..1915688f67 100644 --- a/basis/bootstrap/assembler/ppc.64.linux.factor +++ b/basis/bootstrap/assembler/ppc.64.linux.factor @@ -76,5 +76,5 @@ CONSTANT: frame-reg 31 : param-size ( -- n ) 64 ; : saved-int-regs-size ( -- n ) 192 ; -<< "vocab:bootstrap/assembler/ppc.factor" parse-file suffix! >> +<< "resource:basis/bootstrap/assembler/ppc.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/x86.32.unix.factor b/basis/bootstrap/assembler/x86.32.unix.factor index aff19eb7d1..ce7e1b6779 100644 --- a/basis/bootstrap/assembler/x86.32.unix.factor +++ b/basis/bootstrap/assembler/x86.32.unix.factor @@ -3,6 +3,6 @@ USING: kernel parser sequences ; IN: bootstrap.assembler.x86 -<< "vocab:bootstrap/assembler/x86.unix.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.32.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.unix.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.32.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/x86.32.windows.factor b/basis/bootstrap/assembler/x86.32.windows.factor index d7e6e58a93..c190b5611a 100644 --- a/basis/bootstrap/assembler/x86.32.windows.factor +++ b/basis/bootstrap/assembler/x86.32.windows.factor @@ -8,7 +8,7 @@ IN: bootstrap.assembler.x86 : tib-segment ( -- ) FS ; : tib-temp ( -- reg ) EAX ; -<< "vocab:bootstrap/assembler/x86.windows.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.windows.factor" parse-file suffix! >> call : jit-install-seh ( -- ) ! VM pointer must be in vm-reg already @@ -34,5 +34,5 @@ IN: bootstrap.assembler.x86 ! Store exception record in TIB. tib-exception-list-offset [] tib-temp tib-segment MOV ; -<< "vocab:bootstrap/assembler/x86.32.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.32.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/x86.64.unix.factor b/basis/bootstrap/assembler/x86.64.unix.factor index e21962ed2a..55e66759dc 100644 --- a/basis/bootstrap/assembler/x86.64.unix.factor +++ b/basis/bootstrap/assembler/x86.64.unix.factor @@ -16,6 +16,6 @@ IN: bootstrap.assembler.x86 : arg4 ( -- reg ) RCX ; : red-zone-size ( -- n ) 128 ; -<< "vocab:bootstrap/assembler/x86.unix.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.64.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.unix.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.64.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/assembler/x86.64.windows.factor b/basis/bootstrap/assembler/x86.64.windows.factor index ec2fbf4dcd..8e981557e7 100644 --- a/basis/bootstrap/assembler/x86.64.windows.factor +++ b/basis/bootstrap/assembler/x86.64.windows.factor @@ -22,6 +22,6 @@ DEFER: stack-reg : red-zone-size ( -- n ) 0 ; -<< "vocab:bootstrap/assembler/x86.windows.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.64.factor" parse-file suffix! >> call -<< "vocab:bootstrap/assembler/x86.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.windows.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.64.factor" parse-file suffix! >> call +<< "resource:basis/bootstrap/assembler/x86.factor" parse-file suffix! >> call diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index 6bf93c7636..8a9ec7348e 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -531,7 +531,7 @@ PRIVATE> { auto-use? f } } assoc-union! [ H{ } clone special-objects set - "resource:/core/bootstrap/stage1.factor" run-file + "resource:basis/bootstrap/stage1.factor" run-file build-image write-image ] with-variables ; diff --git a/basis/bootstrap/image/primitives/primitives-docs.factor b/basis/bootstrap/image/primitives/primitives-docs.factor index ce435ac5a7..3c6d97ec29 100644 --- a/basis/bootstrap/image/primitives/primitives-docs.factor +++ b/basis/bootstrap/image/primitives/primitives-docs.factor @@ -19,7 +19,7 @@ HELP: primitive-quot { $description "Creates the defining quotation for the primitive. If 'vm-func' is a string, then it is prefixed with 'primitive_' and a quotation calling that C++ function is generated." } ; ARTICLE: "bootstrap.image.primitives" "Bootstrap primitives" -"This vocab contains utilities for declaring primitives to be added to the bootstrap image. It is used by the file " { $snippet "resource:core/bootstrap/primitives.factor" } +"This vocab contains utilities for declaring primitives to be added to the bootstrap image. It is used by the file " { $snippet "resource:basis/bootstrap/primitives.factor" } $nl { $link all-primitives } " is an assoc where all primitives are declared. See that constant for a description of the format." ; diff --git a/basis/bootstrap/layouts.factor b/basis/bootstrap/layouts.factor new file mode 100644 index 0000000000..6ff54d4979 --- /dev/null +++ b/basis/bootstrap/layouts.factor @@ -0,0 +1,34 @@ +! Copyright (C) 2007, 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien arrays byte-arrays kernel layouts math namespaces +quotations strings words ; + +16 data-alignment set + +0b1111 tag-mask set +4 tag-bits set + +32 mega-cache-size set + +! Type tags, should be kept in sync with: +! vm/layouts.hpp +H{ + { fixnum 0 } + { POSTPONE: f 1 } + { array 2 } + { float 3 } + { quotation 4 } + { bignum 5 } + { alien 6 } + { tuple 7 } + { wrapper 8 } + { byte-array 9 } + { callstack 10 } + { string 11 } + { word 12 } + { dll 13 } +} type-numbers set + +14 num-types set + +2 header-bits set diff --git a/basis/bootstrap/primitives.factor b/basis/bootstrap/primitives.factor new file mode 100644 index 0000000000..85092c8605 --- /dev/null +++ b/basis/bootstrap/primitives.factor @@ -0,0 +1,331 @@ +! Copyright (C) 2004, 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +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 ; +IN: bootstrap.primitives + +"* Creating primitives and basic runtime structures..." print flush + +H{ } clone sub-primitives set + +"resource:basis/bootstrap/syntax.factor" parse-file + +: asm-file ( arch -- file ) + "-" split reverse "." join + "resource:basis/bootstrap/assembler/" ".factor" surround ; + +architecture get asm-file parse-file + +"resource:basis/bootstrap/layouts.factor" parse-file + +! Now we have ( syntax-quot arch-quot layouts-quot ) on the stack + +! Bring up a bare cross-compiling vocabulary. +"syntax" lookup-vocab vocab-words-assoc bootstrap-syntax set + +H{ } clone dictionary set +H{ } clone root-cache set +H{ } clone source-files set +H{ } clone update-map set +H{ } clone implementors-map set + +init-caches + +bootstrapping? on + +call( -- ) ! layouts quot +call( -- ) ! arch quot + +! Vocabulary for slot accessors +"accessors" create-vocab drop + +! After we execute bootstrap/layouts +num-types get f builtins set + +[ + +call( -- ) ! syntax-quot + +! create-word some empty vocabs where the below primitives and +! classes will go +{ + "alien" + "alien.accessors" + "alien.libraries" + "alien.private" + "arrays" + "byte-arrays" + "classes.private" + "classes.tuple" + "classes.tuple.private" + "classes.predicate" + "compiler.units" + "continuations.private" + "generic.single" + "generic.single.private" + "growable" + "hashtables" + "hashtables.private" + "io" + "io.files" + "io.files.private" + "io.streams.c" + "locals.backend" + "kernel" + "kernel.private" + "math" + "math.parser.private" + "math.private" + "memory" + "memory.private" + "quotations" + "quotations.private" + "sbufs" + "sbufs.private" + "scratchpad" + "sequences" + "sequences.private" + "slots.private" + "strings" + "strings.private" + "system" + "system.private" + "threads.private" + "tools.dispatch.private" + "tools.memory.private" + "tools.profiler.sampling.private" + "words" + "words.private" + "vectors" + "vectors.private" + "vm" +} [ create-vocab drop ] each + +! Builtin classes +: lookup-type-number ( word -- n ) + [ target-word ] with-global type-number ; + +: register-builtin ( class -- ) + [ dup lookup-type-number "type" set-word-prop ] + [ dup "type" word-prop builtins get set-nth ] + [ f f f builtin-class define-class ] + tri ; + +: prepare-slots ( slots -- slots' ) + [ [ dup pair? [ first2 create-word ] when ] map ] map ; + +: define-builtin-slots ( class slots -- ) + prepare-slots make-slots 1 finalize-slots + [ "slots" set-word-prop ] [ define-accessors ] 2bi ; + +: define-builtin-predicate ( class -- ) + dup class>type [ eq? ] curry [ tag ] prepend define-predicate ; + +: define-builtin ( symbol slotspec -- ) + [ [ define-builtin-predicate ] keep ] dip define-builtin-slots ; + +{ + { "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 + +"f" "syntax" lookup-word register-builtin + +! We need this before defining c-ptr below +"f" "syntax" lookup-word { } define-builtin + +"f" "syntax" create-word [ not ] "predicate" set-word-prop +"f?" "syntax" vocab-words-assoc delete-at + +"t" "syntax" lookup-word define-singleton-class + +! Some unions +"c-ptr" "alien" create-word [ + "alien" "alien" lookup-word , + "f" "syntax" lookup-word , + "byte-array" "byte-arrays" lookup-word , +] { } make define-union-class + +"integer" "math" create-word +"fixnum" "math" lookup-word "bignum" "math" lookup-word 2array +define-union-class + +! Two predicate classes used for declarations. +"array-capacity" "sequences.private" create-word +"fixnum" "math" lookup-word +[ + [ dup 0 fixnum>= ] % + bootstrap-max-array-capacity [ fixnum<= ] curry , + [ [ drop f ] if ] % +] [ ] make +define-predicate-class + +"array-capacity" "sequences.private" lookup-word +[ >fixnum ] bootstrap-max-array-capacity [ fixnum-bitand ] curry append +"coercer" set-word-prop + +"integer-array-capacity" "sequences.private" create-word +"integer" "math" lookup-word +[ + [ dup 0 >= ] % + bootstrap-max-array-capacity [ <= ] curry , + [ [ drop f ] if ] % +] [ ] make +define-predicate-class + +! Catch-all class for providing a default method. +"object" "kernel" create-word +[ f f { } intersection-class define-class ] +[ [ drop t ] "predicate" set-word-prop ] +bi + +"object?" "kernel" vocab-words-assoc delete-at + +! Empty class with no instances +"null" "kernel" create-word +[ f { } f union-class define-class ] +[ [ drop f ] "predicate" set-word-prop ] +bi + +"null?" "kernel" vocab-words-assoc delete-at + +"fixnum" "math" create-word { } define-builtin +"fixnum" "math" create-word "integer>fixnum-strict" "math" create-word 1quotation "coercer" set-word-prop + +"bignum" "math" create-word { } define-builtin +"bignum" "math" create-word ">bignum" "math" create-word 1quotation "coercer" set-word-prop + +"float" "math" create-word { } define-builtin +"float" "math" create-word ">float" "math" create-word 1quotation "coercer" set-word-prop + +"array" "arrays" create-word { + { "length" { "array-capacity" "sequences.private" } read-only } +} define-builtin + +"wrapper" "kernel" create-word { + { "wrapped" read-only } +} define-builtin + +"string" "strings" create-word { + { "length" { "array-capacity" "sequences.private" } read-only } + "aux" +} define-builtin + +"quotation" "quotations" create-word { + { "array" { "array" "arrays" } read-only } + "cached-effect" + "cache-counter" +} define-builtin + +"dll" "alien" create-word { + { "path" { "byte-array" "byte-arrays" } read-only } +} define-builtin + +"alien" "alien" create-word { + { "underlying" { "c-ptr" "alien" } read-only } + "expired" +} define-builtin + +"word" "words" create-word { + { "hashcode" { "fixnum" "math" } } + "name" + "vocabulary" + { "def" { "quotation" "quotations" } initial: [ ] } + "props" + "pic-def" + "pic-tail-def" + { "sub-primitive" read-only } +} define-builtin + +"byte-array" "byte-arrays" create-word { + { "length" { "array-capacity" "sequences.private" } read-only } +} define-builtin + +"callstack" "kernel" create-word { } define-builtin + +"tuple" "kernel" create-word +[ { } define-builtin ] +[ define-tuple-layout ] +bi + +! create-word special tombstone values +"tombstone" "hashtables.private" create-word +tuple +{ "state" } define-tuple-class + +"+empty+" "hashtables.private" create-word +{ f } "tombstone" "hashtables.private" lookup-word +slots>tuple 1quotation ( -- value ) define-inline + +"+tombstone+" "hashtables.private" create-word +{ t } "tombstone" "hashtables.private" lookup-word +slots>tuple 1quotation ( -- value ) define-inline + +! Some tuple classes + +"curried" "kernel" create-word +tuple +{ + { "obj" read-only } + { "quot" read-only } +} prepare-slots define-tuple-class + +"curry" "kernel" create-word +{ + [ f "inline" set-word-prop ] + [ make-flushable ] +} cleave + +"curry" "kernel" lookup-word +[ + callable instance-check-quot % + "curried" "kernel" lookup-word tuple-layout , + \ , +] [ ] make +( obj quot -- curry ) define-declared + +"composed" "kernel" create-word +tuple +{ + { "first" read-only } + { "second" read-only } +} prepare-slots define-tuple-class + +"compose" "kernel" create-word +{ + [ f "inline" set-word-prop ] + [ make-flushable ] +} cleave + +"compose" "kernel" lookup-word +[ + callable instance-check-quot [ dip ] curry % + callable instance-check-quot % + "composed" "kernel" lookup-word tuple-layout , + \ , +] [ ] make +( quot1 quot2 -- compose ) define-declared + +"* Declaring primitives..." print flush +all-primitives create-primitives + +! Bump build number +"build" "kernel" create-word build 1 + [ ] curry ( -- n ) define-declared + +] with-compilation-unit diff --git a/basis/bootstrap/stage1.factor b/basis/bootstrap/stage1.factor new file mode 100644 index 0000000000..0e9c8053f4 --- /dev/null +++ b/basis/bootstrap/stage1.factor @@ -0,0 +1,59 @@ +! Copyright (C) 2004, 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: assocs bootstrap.image.private hash-sets hashtables init +io io.files kernel kernel.private make memory namespaces parser +parser.notes sequences system vocabs vocabs.loader ; + +"Bootstrap stage 1..." print flush + +"resource:basis/bootstrap/primitives.factor" run-file + +load-help? off +{ "resource:core" } vocab-roots set + +! Create a boot quotation for the target by collecting all top-level +! forms into a quotation, surrounded by some boilerplate. +[ + [ + ! Rehash hashtables first, since bootstrap.image creates + ! them using the host image's hashing algorithms. + [ hashtable? ] instances [ hashtables:rehash ] each + [ hash-set? ] instances [ hash-sets:rehash ] each + boot + ] % + + "math.integers" require + "math.ratios" require + "math.floats" require + "memory" require + + "io.streams.c" require + "io.streams.byte-array" require ! for utf16 on Windows + "vocabs.loader" require + + "syntax" require + + "locals" require + "locals.fry" require + "locals.macros" require + + "resource:basis/bootstrap/layouts.factor" parse-file % + + [ + f parser-quiet? set-global + + init-resource-path + + "resource:basis/bootstrap/stage2.factor" + dup file-exists? [ + run-file + ] [ + "Cannot find " write write "." print + "Please move " write image-path write " into the same directory as the Factor sources," print + "and try again." print + 1 (exit) + ] if + ] % +] [ ] make +OBJ-STARTUP-QUOT +bootstrap.image.private:special-objects get set-at diff --git a/basis/bootstrap/stage2.factor b/basis/bootstrap/stage2.factor index db8f335eea..3e6e58a8bb 100644 --- a/basis/bootstrap/stage2.factor +++ b/basis/bootstrap/stage2.factor @@ -95,9 +95,9 @@ CONSTANT: default-components print-report "staging" get [ - "vocab:bootstrap/finish-staging.factor" run-file + "resource:basis/bootstrap/finish-staging.factor" run-file ] [ - "vocab:bootstrap/finish-bootstrap.factor" run-file + "resource:basis/bootstrap/finish-bootstrap.factor" run-file ] if f error set-global @@ -108,7 +108,7 @@ CONSTANT: default-components drop [ load-help? off - [ "vocab:bootstrap/bootstrap-error.factor" parse-file ] save/restore-error + [ "resource:basis/bootstrap/bootstrap-error.factor" parse-file ] save/restore-error call ] with-scope ] recover diff --git a/basis/bootstrap/summary.txt b/basis/bootstrap/summary.txt new file mode 100644 index 0000000000..208332eb9c --- /dev/null +++ b/basis/bootstrap/summary.txt @@ -0,0 +1 @@ +Bootstrap image generation diff --git a/basis/bootstrap/syntax.factor b/basis/bootstrap/syntax.factor new file mode 100644 index 0000000000..302bf7a0ca --- /dev/null +++ b/basis/bootstrap/syntax.factor @@ -0,0 +1,120 @@ +! Copyright (C) 2007, 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: words words.symbol sequences vocabs kernel +compiler.units ; +IN: bootstrap.syntax + +[ + "syntax" create-vocab drop + + { + "\"" + "(" + ":" + ";" + "" + "SBUF\"" + "SINGLETON:" + "SINGLETONS:" + "BUILTIN:" + "SYMBOL:" + "SYMBOLS:" + "CONSTANT:" + "TUPLE:" + "final" + "SLOT:" + "T{" + "UNION:" + "INTERSECTION:" + "REUSE:" + "USE:" + "UNUSE:" + "USING:" + "QUALIFIED:" + "QUALIFIED-WITH:" + "FROM:" + "EXCLUDE:" + "RENAME:" + "ALIAS:" + "SYNTAX:" + "V{" + "W{" + "[" + "\\" + "M\\" + "]" + "auto-use" + "delimiter" + "deprecated" + "f" + "flushable" + "foldable" + "inline" + "recursive" + "t" + "{" + "}" + "CS{" + "<<" + ">>" + "call-next-method" + "not{" + "maybe{" + "union{" + "intersection{" + "initial:" + "read-only" + "call(" + "execute(" + "<<<<<<" + "======" + ">>>>>>" + "<<<<<<<" + "=======" + ">>>>>>>" + "'[" + "'{" + "'H{" + "'HS{" + "_" + "@" + "MACRO:" + "MEMO:" + "IDENTITY-MEMO:" + ":>" + "[|" + "[let" + "::" + "M::" + "MACRO::" + "MEMO::" + "IDENTITY-MEMO::" + } [ "syntax" create-word drop ] each + + "t" "syntax" lookup-word define-symbol +] with-compilation-unit diff --git a/core/bootstrap/layouts.factor b/core/bootstrap/layouts.factor deleted file mode 100644 index 6ff54d4979..0000000000 --- a/core/bootstrap/layouts.factor +++ /dev/null @@ -1,34 +0,0 @@ -! Copyright (C) 2007, 2009 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: alien arrays byte-arrays kernel layouts math namespaces -quotations strings words ; - -16 data-alignment set - -0b1111 tag-mask set -4 tag-bits set - -32 mega-cache-size set - -! Type tags, should be kept in sync with: -! vm/layouts.hpp -H{ - { fixnum 0 } - { POSTPONE: f 1 } - { array 2 } - { float 3 } - { quotation 4 } - { bignum 5 } - { alien 6 } - { tuple 7 } - { wrapper 8 } - { byte-array 9 } - { callstack 10 } - { string 11 } - { word 12 } - { dll 13 } -} type-numbers set - -14 num-types set - -2 header-bits set diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor deleted file mode 100644 index 3707a112dc..0000000000 --- a/core/bootstrap/primitives.factor +++ /dev/null @@ -1,331 +0,0 @@ -! Copyright (C) 2004, 2010 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -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 ; -IN: bootstrap.primitives - -"* Creating primitives and basic runtime structures..." print flush - -H{ } clone sub-primitives set - -"vocab:bootstrap/syntax.factor" parse-file - -: asm-file ( arch -- file ) - "-" split reverse "." join - "vocab:bootstrap/assembler/" ".factor" surround ; - -architecture get asm-file parse-file - -"vocab:bootstrap/layouts.factor" parse-file - -! Now we have ( syntax-quot arch-quot layouts-quot ) on the stack - -! Bring up a bare cross-compiling vocabulary. -"syntax" lookup-vocab vocab-words-assoc bootstrap-syntax set - -H{ } clone dictionary set -H{ } clone root-cache set -H{ } clone source-files set -H{ } clone update-map set -H{ } clone implementors-map set - -init-caches - -bootstrapping? on - -call( -- ) ! layouts quot -call( -- ) ! arch quot - -! Vocabulary for slot accessors -"accessors" create-vocab drop - -! After we execute bootstrap/layouts -num-types get f builtins set - -[ - -call( -- ) ! syntax-quot - -! create-word some empty vocabs where the below primitives and -! classes will go -{ - "alien" - "alien.accessors" - "alien.libraries" - "alien.private" - "arrays" - "byte-arrays" - "classes.private" - "classes.tuple" - "classes.tuple.private" - "classes.predicate" - "compiler.units" - "continuations.private" - "generic.single" - "generic.single.private" - "growable" - "hashtables" - "hashtables.private" - "io" - "io.files" - "io.files.private" - "io.streams.c" - "locals.backend" - "kernel" - "kernel.private" - "math" - "math.parser.private" - "math.private" - "memory" - "memory.private" - "quotations" - "quotations.private" - "sbufs" - "sbufs.private" - "scratchpad" - "sequences" - "sequences.private" - "slots.private" - "strings" - "strings.private" - "system" - "system.private" - "threads.private" - "tools.dispatch.private" - "tools.memory.private" - "tools.profiler.sampling.private" - "words" - "words.private" - "vectors" - "vectors.private" - "vm" -} [ create-vocab drop ] each - -! Builtin classes -: lookup-type-number ( word -- n ) - [ target-word ] with-global type-number ; - -: register-builtin ( class -- ) - [ dup lookup-type-number "type" set-word-prop ] - [ dup "type" word-prop builtins get set-nth ] - [ f f f builtin-class define-class ] - tri ; - -: prepare-slots ( slots -- slots' ) - [ [ dup pair? [ first2 create-word ] when ] map ] map ; - -: define-builtin-slots ( class slots -- ) - prepare-slots make-slots 1 finalize-slots - [ "slots" set-word-prop ] [ define-accessors ] 2bi ; - -: define-builtin-predicate ( class -- ) - dup class>type [ eq? ] curry [ tag ] prepend define-predicate ; - -: define-builtin ( symbol slotspec -- ) - [ [ define-builtin-predicate ] keep ] dip define-builtin-slots ; - -{ - { "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 - -"f" "syntax" lookup-word register-builtin - -! We need this before defining c-ptr below -"f" "syntax" lookup-word { } define-builtin - -"f" "syntax" create-word [ not ] "predicate" set-word-prop -"f?" "syntax" vocab-words-assoc delete-at - -"t" "syntax" lookup-word define-singleton-class - -! Some unions -"c-ptr" "alien" create-word [ - "alien" "alien" lookup-word , - "f" "syntax" lookup-word , - "byte-array" "byte-arrays" lookup-word , -] { } make define-union-class - -"integer" "math" create-word -"fixnum" "math" lookup-word "bignum" "math" lookup-word 2array -define-union-class - -! Two predicate classes used for declarations. -"array-capacity" "sequences.private" create-word -"fixnum" "math" lookup-word -[ - [ dup 0 fixnum>= ] % - bootstrap-max-array-capacity [ fixnum<= ] curry , - [ [ drop f ] if ] % -] [ ] make -define-predicate-class - -"array-capacity" "sequences.private" lookup-word -[ >fixnum ] bootstrap-max-array-capacity [ fixnum-bitand ] curry append -"coercer" set-word-prop - -"integer-array-capacity" "sequences.private" create-word -"integer" "math" lookup-word -[ - [ dup 0 >= ] % - bootstrap-max-array-capacity [ <= ] curry , - [ [ drop f ] if ] % -] [ ] make -define-predicate-class - -! Catch-all class for providing a default method. -"object" "kernel" create-word -[ f f { } intersection-class define-class ] -[ [ drop t ] "predicate" set-word-prop ] -bi - -"object?" "kernel" vocab-words-assoc delete-at - -! Empty class with no instances -"null" "kernel" create-word -[ f { } f union-class define-class ] -[ [ drop f ] "predicate" set-word-prop ] -bi - -"null?" "kernel" vocab-words-assoc delete-at - -"fixnum" "math" create-word { } define-builtin -"fixnum" "math" create-word "integer>fixnum-strict" "math" create-word 1quotation "coercer" set-word-prop - -"bignum" "math" create-word { } define-builtin -"bignum" "math" create-word ">bignum" "math" create-word 1quotation "coercer" set-word-prop - -"float" "math" create-word { } define-builtin -"float" "math" create-word ">float" "math" create-word 1quotation "coercer" set-word-prop - -"array" "arrays" create-word { - { "length" { "array-capacity" "sequences.private" } read-only } -} define-builtin - -"wrapper" "kernel" create-word { - { "wrapped" read-only } -} define-builtin - -"string" "strings" create-word { - { "length" { "array-capacity" "sequences.private" } read-only } - "aux" -} define-builtin - -"quotation" "quotations" create-word { - { "array" { "array" "arrays" } read-only } - "cached-effect" - "cache-counter" -} define-builtin - -"dll" "alien" create-word { - { "path" { "byte-array" "byte-arrays" } read-only } -} define-builtin - -"alien" "alien" create-word { - { "underlying" { "c-ptr" "alien" } read-only } - "expired" -} define-builtin - -"word" "words" create-word { - { "hashcode" { "fixnum" "math" } } - "name" - "vocabulary" - { "def" { "quotation" "quotations" } initial: [ ] } - "props" - "pic-def" - "pic-tail-def" - { "sub-primitive" read-only } -} define-builtin - -"byte-array" "byte-arrays" create-word { - { "length" { "array-capacity" "sequences.private" } read-only } -} define-builtin - -"callstack" "kernel" create-word { } define-builtin - -"tuple" "kernel" create-word -[ { } define-builtin ] -[ define-tuple-layout ] -bi - -! create-word special tombstone values -"tombstone" "hashtables.private" create-word -tuple -{ "state" } define-tuple-class - -"+empty+" "hashtables.private" create-word -{ f } "tombstone" "hashtables.private" lookup-word -slots>tuple 1quotation ( -- value ) define-inline - -"+tombstone+" "hashtables.private" create-word -{ t } "tombstone" "hashtables.private" lookup-word -slots>tuple 1quotation ( -- value ) define-inline - -! Some tuple classes - -"curried" "kernel" create-word -tuple -{ - { "obj" read-only } - { "quot" read-only } -} prepare-slots define-tuple-class - -"curry" "kernel" create-word -{ - [ f "inline" set-word-prop ] - [ make-flushable ] -} cleave - -"curry" "kernel" lookup-word -[ - callable instance-check-quot % - "curried" "kernel" lookup-word tuple-layout , - \ , -] [ ] make -( obj quot -- curry ) define-declared - -"composed" "kernel" create-word -tuple -{ - { "first" read-only } - { "second" read-only } -} prepare-slots define-tuple-class - -"compose" "kernel" create-word -{ - [ f "inline" set-word-prop ] - [ make-flushable ] -} cleave - -"compose" "kernel" lookup-word -[ - callable instance-check-quot [ dip ] curry % - callable instance-check-quot % - "composed" "kernel" lookup-word tuple-layout , - \ , -] [ ] make -( quot1 quot2 -- compose ) define-declared - -"* Declaring primitives..." print flush -all-primitives create-primitives - -! Bump build number -"build" "kernel" create-word build 1 + [ ] curry ( -- n ) define-declared - -] with-compilation-unit diff --git a/core/bootstrap/stage1.factor b/core/bootstrap/stage1.factor deleted file mode 100644 index 54fef16d62..0000000000 --- a/core/bootstrap/stage1.factor +++ /dev/null @@ -1,59 +0,0 @@ -! Copyright (C) 2004, 2009 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: assocs bootstrap.image.private hash-sets hashtables init -io io.files kernel kernel.private make memory namespaces parser -parser.notes sequences system vocabs vocabs.loader ; - -"Bootstrap stage 1..." print flush - -"vocab:bootstrap/primitives.factor" run-file - -load-help? off -{ "resource:core" } vocab-roots set - -! Create a boot quotation for the target by collecting all top-level -! forms into a quotation, surrounded by some boilerplate. -[ - [ - ! Rehash hashtables first, since bootstrap.image creates - ! them using the host image's hashing algorithms. - [ hashtable? ] instances [ hashtables:rehash ] each - [ hash-set? ] instances [ hash-sets:rehash ] each - boot - ] % - - "math.integers" require - "math.ratios" require - "math.floats" require - "memory" require - - "io.streams.c" require - "io.streams.byte-array" require ! for utf16 on Windows - "vocabs.loader" require - - "syntax" require - - "locals" require - "locals.fry" require - "locals.macros" require - - "vocab:bootstrap/layouts.factor" parse-file % - - [ - f parser-quiet? set-global - - init-resource-path - - "resource:basis/bootstrap/stage2.factor" - dup file-exists? [ - run-file - ] [ - "Cannot find " write write "." print - "Please move " write image-path write " into the same directory as the Factor sources," print - "and try again." print - 1 (exit) - ] if - ] % -] [ ] make -OBJ-STARTUP-QUOT -bootstrap.image.private:special-objects get set-at diff --git a/core/bootstrap/summary.txt b/core/bootstrap/summary.txt deleted file mode 100644 index 208332eb9c..0000000000 --- a/core/bootstrap/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Bootstrap image generation diff --git a/core/bootstrap/syntax.factor b/core/bootstrap/syntax.factor deleted file mode 100644 index 302bf7a0ca..0000000000 --- a/core/bootstrap/syntax.factor +++ /dev/null @@ -1,120 +0,0 @@ -! Copyright (C) 2007, 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: words words.symbol sequences vocabs kernel -compiler.units ; -IN: bootstrap.syntax - -[ - "syntax" create-vocab drop - - { - "\"" - "(" - ":" - ";" - "" - "SBUF\"" - "SINGLETON:" - "SINGLETONS:" - "BUILTIN:" - "SYMBOL:" - "SYMBOLS:" - "CONSTANT:" - "TUPLE:" - "final" - "SLOT:" - "T{" - "UNION:" - "INTERSECTION:" - "REUSE:" - "USE:" - "UNUSE:" - "USING:" - "QUALIFIED:" - "QUALIFIED-WITH:" - "FROM:" - "EXCLUDE:" - "RENAME:" - "ALIAS:" - "SYNTAX:" - "V{" - "W{" - "[" - "\\" - "M\\" - "]" - "auto-use" - "delimiter" - "deprecated" - "f" - "flushable" - "foldable" - "inline" - "recursive" - "t" - "{" - "}" - "CS{" - "<<" - ">>" - "call-next-method" - "not{" - "maybe{" - "union{" - "intersection{" - "initial:" - "read-only" - "call(" - "execute(" - "<<<<<<" - "======" - ">>>>>>" - "<<<<<<<" - "=======" - ">>>>>>>" - "'[" - "'{" - "'H{" - "'HS{" - "_" - "@" - "MACRO:" - "MEMO:" - "IDENTITY-MEMO:" - ":>" - "[|" - "[let" - "::" - "M::" - "MACRO::" - "MEMO::" - "IDENTITY-MEMO::" - } [ "syntax" create-word drop ] each - - "t" "syntax" lookup-word define-symbol -] with-compilation-unit