diff --git a/Makefile b/Makefile index 54450585ae..249cb0ef0a 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ -CC = gcc +CC = gcc34 # On FreeBSD, to use SDL and other libc_r libs: -CFLAGS = -g -Wall -export-dynamic -pthread +# CFLAGS = -g -Wall -export-dynamic -pthread # On PowerPC G5: # CFLAGS = -mcpu=970 -mtune=970 -mpowerpc64 -ffast-math -O3 # On Pentium 4: -# CFLAGS = -march=pentium4 -ffast-math -Os -fomit-frame-pointer -export-dynamic -pthread +CFLAGS = -march=pentium4 -ffast-math -Os -fomit-frame-pointer -export-dynamic -pthread # Add -fomit-frame-pointer if you don't care about debugging # CFLAGS = -Os -g -Wall diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 2b8a806a7d..4602784ef3 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -4,12 +4,14 @@ FFI: - BIN: 2: bad - compile word twice; no more 'cannot compile' error! - -- compiled? messy +- doc comments in assoc, image, inferior +- styles - could use some cleanup +- list - trim down +- move quadratic and simpson to contrib +- init-assembler called twice - compiler: drop literal peephole optimization - compiling when* - compiling unless* -- eliminate uses of 2dip - getenv/setenv: if literal arg, compile as a load/store - inline words diff --git a/library/compiler/compile-all.factor b/library/compiler/compile-all.factor index 32214150a9..b5841e5c55 100644 --- a/library/compiler/compile-all.factor +++ b/library/compiler/compile-all.factor @@ -27,9 +27,13 @@ IN: compiler USE: combinators +USE: errors USE: lists USE: logic +USE: namespaces +USE: prettyprint USE: stack +USE: stdio USE: vectors USE: words @@ -99,6 +103,14 @@ DEFER: can-compile-vector? "can-compile" set-word-property ] ifte ; +SYMBOL: compilable-word-list + : compilable-words ( -- list ) #! Make a list of all words that can be compiled. [, [ dup can-compile? [ , ] [ drop ] ifte ] each-word ,] ; + +: init-compiler ( -- ) + #! Compile all words. + compilable-word-list get [ + [ compile ] [ [ "Cannot compile " write . ] when ] catch + ] each ; diff --git a/library/compiler/compiler.factor b/library/compiler/compiler.factor index bc06bb4e8d..c8332533b9 100644 --- a/library/compiler/compiler.factor +++ b/library/compiler/compiler.factor @@ -211,7 +211,6 @@ SYMBOL: compile-callstack : (compile) ( word -- ) #! Should be called inside the with-compiler scope. - dup . flush intern dup save-xt word-parameter compile-quot RET ; : compile-postponed ( -- ) diff --git a/library/compiler/dummy-compiler.factor b/library/compiler/dummy-compiler.factor new file mode 100644 index 0000000000..80a379f28a --- /dev/null +++ b/library/compiler/dummy-compiler.factor @@ -0,0 +1,5 @@ +! Loaded on non-x86 platforms. + +SYMBOL: compilable-word-list +: compilable-words f ; +: init-compiler ; diff --git a/library/platform/native/boot-stage2.factor b/library/platform/native/boot-stage2.factor index 3478fa658f..d61d9a4b7a 100644 --- a/library/platform/native/boot-stage2.factor +++ b/library/platform/native/boot-stage2.factor @@ -27,9 +27,11 @@ IN: init USE: combinators +USE: compiler USE: errors USE: kernel USE: lists +USE: namespaces USE: parser USE: stack USE: strings @@ -135,35 +137,47 @@ USE: stdio "/library/jedit/jedit-remote.factor" "/library/jedit/jedit.factor" - "/library/compiler/assembler.factor" - "/library/compiler/assembly-x86.factor" - "/library/compiler/compiler-macros.factor" - "/library/compiler/compiler.factor" - "/library/compiler/ifte.factor" - "/library/compiler/generic.factor" - "/library/compiler/interpret-only.factor" - "/library/compiler/compile-all.factor" - "/library/compiler/alien-types.factor" - "/library/compiler/alien-macros.factor" - "/library/compiler/alien.factor" - "/library/platform/native/primitives.factor" "/library/init.factor" - "/library/platform/native/init-stage2.factor" ] [ dup print run-resource ] each +cpu "x86" = [ + [ + "/library/compiler/assembler.factor" + "/library/compiler/assembly-x86.factor" + "/library/compiler/compiler-macros.factor" + "/library/compiler/compiler.factor" + "/library/compiler/ifte.factor" + "/library/compiler/generic.factor" + "/library/compiler/interpret-only.factor" + "/library/compiler/compile-all.factor" + "/library/compiler/alien-types.factor" + "/library/compiler/alien-macros.factor" + "/library/compiler/alien.factor" + ] [ + dup print + run-resource + ] each +] [ + "/library/compiler/dummy-compiler.factor" dup print run-resource +] ifte + +"/library/platform/native/init-stage2.factor" dup print run-resource + IN: init DEFER: warm-boot IN: compiler -DEFER: init-assembler +DEFER: compilable-words +DEFER: compilable-word-list -: set-boot ( quot -- ) 8 setenv ; -[ init-assembler warm-boot ] set-boot +[ warm-boot ] set-boot + +compilable-words compilable-word-list set garbage-collection "factor.image" save-image diff --git a/library/platform/native/init-stage2.factor b/library/platform/native/init-stage2.factor index e69d25f0fa..b66579516b 100644 --- a/library/platform/native/init-stage2.factor +++ b/library/platform/native/init-stage2.factor @@ -62,10 +62,13 @@ USE: words t "user-init" set t "interactive" set t "ansi" set + t "compile" set ! The first CLI arg is the image name. cli-args uncons parse-command-line "image" set + "compile" get [ init-compiler ] when + run-user-init "ansi" get [ "stdio" get "stdio" set ] when diff --git a/library/platform/native/kernel.factor b/library/platform/native/kernel.factor index 94b1b40c73..9ccdb9645c 100644 --- a/library/platform/native/kernel.factor +++ b/library/platform/native/kernel.factor @@ -46,6 +46,10 @@ USE: words USE: unparser USE: vectors +: cpu ( -- arch ) + #! Returns one of "x86" or "unknown". + 11 getenv ; + ! The 'fake vtable' used here speeds things up a lot. ! It is quite clumsy, however. A higher-level CLOS-style ! 'generic words' system will be built later. @@ -116,6 +120,10 @@ IN: kernel [ drop t ] [ ( return the object ) ] ] cond ; +: set-boot ( quot -- ) + #! Set the boot quotation. + 8 setenv ; + : java? f ; : native? t ; diff --git a/native/factor.c b/native/factor.c index 58721fcc31..ad200c062b 100644 --- a/native/factor.c +++ b/native/factor.c @@ -27,6 +27,12 @@ int main(int argc, char** argv) userenv[ARGS_ENV] = args; +#if defined(i386) || defined(__i386) || defined(__i386__) + userenv[CPU_ENV] = tag_object(from_c_string("x86")); +#else + userenv[CPU_ENV] = tag_object(from_c_string("unknown")); +#endif + run(); return 0; diff --git a/native/run.h b/native/run.h index 09f08a287f..550fc98206 100644 --- a/native/run.h +++ b/native/run.h @@ -11,6 +11,7 @@ #define BOOT_ENV 8 #define RUNQUEUE_ENV 9 /* used by library only */ #define ARGS_ENV 10 +#define CPU_ENV 11 /* Profiling timer */ struct itimerval prof_timer;