- save code in image\r
- compile word twice; no more 'cannot compile' error!\r
\r
++ oop:
+
+- union metaclass
+- make M: order-independent
+- bootstrapping generic words
+- 2generic
+- move generic, 2generic from kernel vocabulary
+- generic = hashcode and math ops
+
+ ffi:\r
\r
- is signed -vs- unsigned pointers an issue?\r
- jedit ==> jedit-word, jedit takes a file name\r
- command line parsing cleanup\r
- nicer way to combine two paths\r
-- finish OOP\r
- ditch object paths\r
- browser responder for word links in HTTPd; inspect responder for\r
objects\r
! -no-<flag> CLI switch
t "user-init" set
t "interactive" set
- t "ansi" set
+ ! We don't want ANSI escape codes on Windows
+ os "unix" = "ansi" set
t "compile" set
! The first CLI arg is the image name.
USE: words
USE: vectors
+: DS ( -- address ) "ds" dlsym-self ;
+
: PUSH-DS ( -- )
#! Push contents of EAX onto datastack.
- 4 ESI R+I
- EAX ESI R>[R] ;
+ DS ECX [I]>R
+ 4 ECX R+I
+ EAX ECX R>[R]
+ ECX DS R>[I] ;
: POP-DS ( -- )
- #! Pop datastack, store pointer to datastack top in EAX.
- ESI EAX [R]>R
- 4 ESI R-I ;
+ #! Pop datastack to EAX.
+ DS ECX [I]>R
+ ECX EAX [R]>R
+ 4 ECX R-I
+ ECX DS R>[I] ;
+
+: PEEK-DS ( -- )
+ #! Peek datastack to EAX.
+ DS ECX [I]>R
+ ECX EAX [R]>R ;
+
+: PEEK-2-DS ( -- )
+ #! Peek second value on datastack to EAX.
+ DS ECX [I]>R
+ 4 ECX R-I
+ ECX EAX [R]>R ;
: SELF-CALL ( name -- )
#! Call named C function in Factor interpreter executable.
dlsym-self CALL JUMP-FIXUP ;
#push-immediate [
- address 4 ESI R+I ESI I>[R]
+ DS ECX [I]>R
+ 4 ECX R+I
+ address ECX I>[R]
+ ECX DS R>[I]
] "generator" set-word-property
#push-indirect [
- intern-literal 4 ESI R+I EAX [I]>R EAX ESI R>[R]
+ DS ECX [I]>R
+ 4 ECX R+I
+ intern-literal EAX [I]>R
+ EAX ECX R>[R]
+ ECX DS R>[I]
] "generator" set-word-property
#call [
#return [ drop RET ] "generator" set-word-property
-#drop [ drop 4 ESI R-I ] "generator" set-word-property
-#dup [
- drop
- ESI EAX [R]>R
- 4 ESI R+I
- EAX ESI R>[R]
-] "generator" set-word-property
-
-! This is crap
-#swap [ drop \ swap CALL compiled-offset defer-xt ] "generator" set-word-property
-#over [ drop \ over CALL compiled-offset defer-xt ] "generator" set-word-property
-#pick [ drop \ pick CALL compiled-offset defer-xt ] "generator" set-word-property
-#>r [ drop \ >r CALL compiled-offset defer-xt ] "generator" set-word-property
-#r> [ drop \ r> CALL compiled-offset defer-xt ] "generator" set-word-property
+[
+ [ #drop drop ]
+ [ #dup dup ]
+ [ #swap swap ]
+ [ #over over ]
+ [ #pick pick ]
+ [ #>r >r ]
+ [ #r> r> ]
+] [
+ uncons [
+ car CALL compiled-offset defer-xt drop
+ ] cons "generator" set-word-property
+] each
: begin-jump-table ( -- )
#! Compile a piece of code that jumps to an offset in a
: TYPE ( -- )
#! Peek datastack, store type # in EAX.
- ESI PUSH-[R]
+ PEEK-DS
+ EAX PUSH-R
"type_of" SELF-CALL
4 ESP R+I ;
: ARITHMETIC-TYPE ( -- )
#! Peek top two on datastack, store arithmetic type # in EAX.
- ESI EAX R>R
- EAX PUSH-[R]
- 4 EAX R-I
- EAX PUSH-[R]
+ PEEK-DS
+ EAX PUSH-R
+ PEEK-2-DS
+ EAX PUSH-R
"arithmetic_type" SELF-CALL
8 ESP R+I ;
#! Returns one of "x86" or "unknown".
7 getenv ;
+: os ( -- arch )
+ #! Returns one of "unix" or "win32".
+ 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.
\ plist-test "sample-property" word-property
] unit-test
-: test-last ( -- ) ;
-word word-name "last-word-test" set
-
-[ "test-last" ] [ ] [ "last-word-test" get ] test-word
[ f ] [ 5 ] [ compound? ] test-word
"create-test" "scratchpad" create { 1 2 } "testing" set-word-property
SYMBOL: a-symbol
[ f ] [ \ a-symbol compound? ] unit-test
[ t ] [ \ a-symbol symbol? ] unit-test
+
+: test-last ( -- ) ;
+word word-name "last-word-test" set
+
+[ "test-last" ] [ ] [ "last-word-test" get ] test-word
"Code space: " write (room.) ;
: print-banner ( -- )
- "Factor " write version print
+ "Factor " write version write
+ " (OS: " write os write
+ " CPU: " write cpu write
+ ")" print
"Copyright (C) 2003, 2004 Slava Pestov" print
"Copyright (C) 2004 Chris Double" print
"Copyright (C) 2004 Mackenzie Straight" print
#else
userenv[CPU_ENV] = tag_object(from_c_string("unknown"));
#endif
+
+#ifdef WIN32
+ userenv[OS_ENV] = tag_object(from_c_string("win32"));
+#else
+ userenv[OS_ENV] = tag_object(from_c_string("unix"));
+#endif
}
int main(int argc, char** argv)
CELL ds_bot;
/* raw pointer to datastack top */
-#ifdef FACTOR_X86
-register CELL ds asm("%esi");
-#else
CELL ds;
-#endif
/* raw pointer to callstack bottom */
CELL cs_bot;
#define BOOT_ENV 8
#define RUNQUEUE_ENV 9 /* used by library only */
#define ARGS_ENV 10
+#define OS_ENV 11
/* Profiling timer */
#ifndef WIN32