-CC = gcc34
+CC = gcc
# 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
\r
- compiled? messy\r
- compiler: drop literal peephole optimization\r
-- compiler: arithmetic-type { ... } execute\r
+- compiling when*\r
+- compiling unless*\r
+- eliminate uses of 2dip\r
- getenv/setenv: if literal arg, compile as a load/store\r
- inline words\r
\r
nextLine();
} //}}}
+ //{{{ isEOL() method
+ private boolean isEOL()
+ {
+ return position >= line.length();
+ } //}}}
+
+ //{{{ skipWhitespace() method
+ /**
+ * The Factor parser is so much nicer in Factor than Java!
+ */
+ public void skipWhitespace() throws FactorParseException
+ {
+ for(;;)
+ {
+ if(isEOL())
+ return;
+
+ char ch = line.charAt(position++);
+
+ int type = readtable.getCharacterType(ch);
+
+ switch(type)
+ {
+ case ReadTable.INVALID:
+ error("Invalid character in input: " + ch);
+ break;
+ case ReadTable.WHITESPACE:
+ break;
+ default:
+ position--;
+ return;
+ }
+ }
+ } //}}}
+
//{{{ next() method
/**
+ * Read a word name. Note that no escaping of characters is done.
+ *
* @param readNumbers If true, will return either a Number or a
* String. Otherwise, only Strings are returned.
* @param start If true, dispatches will be handled by their parsing
for(;;)
{
- if(position == line.length())
+ if(position >= line.length())
{
// EOL
if(buf.length() != 0)
return word(readNumbers,base);
}
case ReadTable.CONSTITUENT:
- buf.append(ch);
- break;
case ReadTable.SINGLE_ESCAPE:
- buf.append(escape());
+ buf.append(ch);
break;
}
}
} //}}}
//{{{ readUntil() method
+ /**
+ * Characters are escaped.
+ */
public String readUntil(char start, char end, boolean escapesAllowed)
throws IOException, FactorParseException
{
for(;;)
{
- if(position == line.length())
+ if(isEOL())
{
error("Expected " + end + " before EOL");
break;
//{{{ readNonEOF() method
public char readNonEOF() throws FactorParseException, IOException
{
- if(position == line.length())
+ if(isEOL())
{
error("Unexpected EOL");
return '\0';
//{{{ atEndOfWord() method
public boolean atEndOfWord() throws IOException
{
- if(position == line.length())
+ if(isEOL())
return true;
if(line == null)
return true;
//{{{ toString() method
public String toString()
{
- return name == null ? "#<unnamed>"
- : FactorReader.charsToEscapes(name);
+ return name == null ? "#<unnamed>" : name;
} //}}}
}
public void eval(FactorInterpreter interp, FactorReader reader)
throws IOException, FactorParseException
{
- String word = (String)reader.nextNonEOL(false,false);
- if(word.length() != 1)
- reader.error("Bad character literal: " + word);
- reader.append(new Character(word.charAt(0)));
+ FactorScanner scanner = reader.getScanner();
+ scanner.skipWhitespace();
+ char ch = scanner.readNonEOFEscaped();
+ reader.append(new Character(ch));
}
}
USE: parser
USE: prettyprint
USE: stack
+USE: stdio
USE: strings
USE: unparser
USE: vectors
compiled-xts off ;
: compiled-xt ( word -- xt )
- dup compiled-xts get assoc dup [
- nip
- ] [
- drop word-xt
- ] ifte ;
+ dup compiled-xts get assoc [ nip ] [ word-xt ] ifte* ;
! "fixup-xts" is a list of [ where word relative ] pairs; the xt
! of word when its done compiling will be written to the offset,
SYMBOL: deferred-xts
+! Words being compiled are consed onto this list. When a word
+! is encountered that has not been previously compiled, it is
+! consed onto this list. Compilation stops when the list is
+! empty.
+
+SYMBOL: compile-words
+
: defer-xt ( word where relative -- )
#! After word is compiled, put its XT at where, relative.
3list deferred-xts cons@ ;
: compiled? ( word -- ? )
#! This is a hack.
- dup "compiled" word-property swap primitive? or ;
+ dup "compiled" word-property [
+ drop t
+ ] [
+ primitive?
+ ] ifte ;
: fixup-deferred-xt ( word where relative -- )
rot dup compiled? [
] each
deferred-xts off ;
-! Words being compiled are consed onto this list. When a word
-! is encountered that has not been previously compiled, it is
-! consed onto this list. Compilation stops when the list is
-! empty.
-
-SYMBOL: compile-words
-
: postpone-word ( word -- )
- dup compiled? [
- drop
- ] [
- t over "compiled" set-word-property compile-words cons@
+ dup compiled? [ drop ] [
+ t over "compiled" set-word-property
+ compile-words unique@
] ifte ;
! During compilation, these two variables store pending
: (compile) ( word -- )
#! Should be called inside the with-compiler scope.
+ dup . flush
intern dup save-xt word-parameter compile-quot RET ;
: compile-postponed ( -- )
tail? [ RET f ] [ JUMP ] ifte swap branch-target ;
: end-if ( fixup -- )
- tail? [ drop RET ] [ branch-target ] ifte ;
+ tail? [ RET ] when [ branch-target ] when* ;
: compile-ifte ( compile-time: true false -- )
pop-literal pop-literal commit-literals
: compile-unless ( compile-time: false -- )
pop-literal commit-literals
compile-t-test >r
- ( t -- ) compile-quot
+ ( f -- ) compile-quot
r> end-if ;
[ compile-ifte ] \ ifte "compiling" set-word-property
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
USE: combinators
+USE: errors
USE: kernel
USE: lists
USE: math
alien-1
set-alien-1
heap-stats
+ throw
] [
swap succ tuck primitive,
] each drop ;
#! Use rethrow when passing an error on from a catch block.
#! For convinience, this word is a no-op if error is f.
[ c> call ] when* ;
-
-: throw ( error -- ) dup save-error rethrow ;
IN: errors
USE: kernel
+USE: stack
USE: strings
+DEFER: save-error
+DEFER: rethrow
+
+: throw ( error -- )
+ #! Throw an error that will be caught by a surrounding
+ #! catch block.
+ dup save-error rethrow ;
+
: catchstack* ( -- cs )
interpreter
"factor.FactorInterpreter" "catchstack" jvar-get ;
IN: init
USE: ansi
USE: combinators
+USE: compiler
USE: errors
USE: httpd-responder
USE: kernel
USE: namespaces
USE: parser
USE: random
+USE: stack
USE: streams
USE: styles
USE: words
: init-error-handler ( -- )
[ 1 exit* ] >c ( last resort )
[ default-error-handler 1 exit* ] >c
- [ throw ] 5 setenv ( kernel calls on error ) ;
+ [ dup save-error rethrow ] 5 setenv ( kernel calls on error ) ;
: warm-boot ( -- )
#! A fully bootstrapped image has this as the boot
init-error-handler
init-random
+ init-assembler
! Some flags are *on* by default, unless user specifies
! -no-<flag> CLI switch
USE: combinators
USE: alien
USE: compiler
+USE: errors
USE: files
USE: io-internals
USE: kernel
[ alien-1 | " alien off -- n " ]
[ set-alien-1 | " n alien off -- " ]
[ heap-stats | " -- instances bytes " ]
+ [ throw | " error -- " ]
] [
unswons "stack-effect" set-word-property
] each
USE: stack
USE: test
-[ ] [ 3 [ ] cond ] unit-test
-[ t ] [ 4 [ [ 1 = ] [ ] [ 4 = ] [ drop t ] [ 2 = ] [ ] ] cond ] unit-test
+[ 5 ] [ [ 2 2 + ] 1 slip + ] unit-test
+[ 6 ] [ [ 2 2 + ] 1 1 2slip + + ] unit-test
+[ 6 ] [ [ 2 1 + ] 1 1 1 3slip + + + ] unit-test
-[ 0 1 2 3 4 ] [ 5 [ ] times* ] unit-test
-[ ] [ 0 [ ] times* ] unit-test
+[ 6 ] [ 2 [ sq ] keep + ] unit-test
-[ #{ 1 1 } ] [ #{ 2 3 } #{ 1 0 } 2times-succ ] unit-test
-[ #{ 1 2 } ] [ #{ 2 3 } #{ 1 1 } 2times-succ ] unit-test
-[ #{ 2 0 } ] [ #{ 3 3 } #{ 1 2 } 2times-succ ] unit-test
-[ #{ 2 1 } ] [ #{ 3 3 } #{ 2 0 } 2times-succ ] unit-test
-[ #{ 2 0 } ] [ #{ 2 2 } #{ 1 1 } 2times-succ ] unit-test
+[ ] [ 3 [ ] cond ] unit-test
+[ t ] [ 4 [ [ 1 = ] [ ] [ 4 = ] [ drop t ] [ 2 = ] [ ] ] cond ] unit-test
-[ #{ 0 0 } #{ 0 1 } #{ 1 0 } #{ 1 1 } ]
-[ #{ 2 2 } [ ] 2times* ] unit-test
+[ 0 ] [ f [ sq ] [ 0 ] ifte* ] unit-test
+[ 4 ] [ 2 [ sq ] [ 0 ] ifte* ] unit-test
-[ #{ 0 0 } #{ 0 1 } #{ 0 2 } #{ 1 0 } #{ 1 1 } #{ 1 2 }
- #{ 2 0 } #{ 2 1 } #{ 2 2 } ]
-[ #{ 3 3 } [ ] 2times* ] unit-test
+[ 0 ] [ f [ 0 ] unless* ] unit-test
+[ t ] [ t [ "Hello" ] unless* ] unit-test
IN: scratchpad
USE: files
+USE: lists
USE: test
[ "txt" ] [ "foo.txt" file-extension ] unit-test
[ "txt" ] [ "foo.bar.txt" file-extension ] unit-test
[ "text/plain" ] [ "foo.bar.txt" mime-type ] unit-test
[ "text/html" ] [ "index.html" mime-type ] unit-test
+
+! Some tests to ensure these words simply work, since we can't
+! really test them
+
+[ t ] [ cwd directory list? ] unit-test
+
+cwd directory.
--- /dev/null
+IN: scratchpad
+USE: namespaces
+USE: streams
+USE: stdio
+USE: test
+
+
+[ "xyzzy" ] [ [ "xyzzy" write ] with-string ] unit-test
+
+[
+ "<xyzzy>"
+] [
+ [
+ [
+ "stdio" get <extend-stream> [
+ [ "<" write write ">" write ] "fwrite" set
+ [ "<" write write ">" print ] "fprint" set
+ ] extend "stdio" set
+
+ "xyzzy" write
+ ] with-scope
+ ] with-string
+] unit-test
"math/bignum"
"math/bitops"
"math/gcd"
+ "math/math-combinators"
"math/rational"
"math/float"
"math/complex"
[ 64 f ] [ f 4 dummy-when-4 ] unit-test
[ f t ] [ t f dummy-when-4 ] unit-test
+: dummy-when-5 f [ dup fixnum* ] when ; compiled
+
+[ f ] [ f dummy-when-5 ] unit-test
+
: dummy-unless-1 t [ ] unless ; compiled
[ ] [ dummy-unless-1 ] unit-test
siglongjmp(toplevel,1);
}
+void primitive_throw(void)
+{
+ throw_error(dpop());
+}
+
void general_error(CELL error, CELL tagged)
{
CELL c = cons(error,cons(tagged,F));
void throw_error(CELL object);
void general_error(CELL error, CELL tagged);
void type_error(CELL type, CELL tagged);
+void primitive_throw(void);
void range_error(CELL tagged, CELL index, CELL max);
primitive_set_alien_2,
primitive_alien_1,
primitive_set_alien_1,
- primitive_heap_stats
+ primitive_heap_stats,
+ primitive_throw
};
CELL primitive_to_xt(CELL primitive)
extern XT primitives[];
-#define PRIMITIVE_COUNT 194
+#define PRIMITIVE_COUNT 195
CELL primitive_to_xt(CELL primitive);