diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index c6b9e1e188..4ce20f9048 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,6 +1,7 @@ + native: -- parsing: #\, | +- top level catch should be a continuation +- parsing: #\ - {...} vectors - parsing should be parsing - telnetd: listening on a socket diff --git a/native/build.sh b/build.sh similarity index 61% rename from native/build.sh rename to build.sh index 642d50437f..17fd95fb12 100644 --- a/native/build.sh +++ b/build.sh @@ -3,11 +3,6 @@ rm *.o export CC=gcc34 export CFLAGS="-pedantic -Wall -Winline -O4 -Os -march=pentium4 -fomit-frame-pointer -falign-functions=8" -$CC $CFLAGS -o f *.c +$CC $CFLAGS -o f native/*.c strip f - -#export CC=gcc -#export CFLAGS="-g" - -#$CC $CFLAGS -o f-debug *.c diff --git a/factor/.FactorInterpreter.java.marks b/factor/.FactorInterpreter.java.marks index d7496649ac..c699161e89 100644 Binary files a/factor/.FactorInterpreter.java.marks and b/factor/.FactorInterpreter.java.marks differ diff --git a/factor/FactorInterpreter.java b/factor/FactorInterpreter.java index 2941bccc4c..66afc6ff22 100644 --- a/factor/FactorInterpreter.java +++ b/factor/FactorInterpreter.java @@ -153,23 +153,39 @@ public class FactorInterpreter implements FactorObject, Runnable in = "builtins"; use = new Cons(in,null); - // parsing words + /* comments */ FactorWord lineComment = define("builtins","!"); lineComment.parsing = new LineComment(lineComment,false); FactorWord stackComment = define("builtins","("); stackComment.parsing = new StackComment(stackComment); + FactorWord docComment = define("builtins","#!"); + docComment.parsing = new LineComment(docComment,true); + + /* strings */ FactorWord str = define("builtins","\""); str.parsing = new StringLiteral(str,true); + FactorWord ch = define("builtins","CHAR:"); + ch.parsing = new CharLiteral(ch); + FactorWord raw = define("builtins","#\""); + raw.parsing = new StringLiteral(raw,false); + + /* constants */ FactorWord t = define("builtins","t"); t.parsing = new T(t); FactorWord f = define("builtins","f"); f.parsing = new F(f); + FactorWord complex = define("builtins","#{"); + complex.parsing = new ComplexLiteral(complex,"}"); + + /* lists */ FactorWord bra = define("builtins","["); bra.parsing = new Bra(bra); FactorWord ket = define("builtins","]"); ket.parsing = new Ket(bra,ket); FactorWord bar = define("builtins","|"); bar.parsing = new Bar(bar); + + /* word defs */ FactorWord def = define("builtins",":"); def.parsing = new Def(def); def.getNamespace().setVariable("doc-comments",Boolean.TRUE); @@ -178,20 +194,17 @@ public class FactorInterpreter implements FactorObject, Runnable FactorWord shuffle = define("builtins","~<<"); shuffle.parsing = new Shuffle(shuffle,">>~"); - FactorWord noParsing = define("builtins","POSTPONE:"); - noParsing.parsing = new NoParsing(noParsing); + /* reading numbers with another base */ + FactorWord bin = define("builtins","BIN:"); + bin.parsing = new Base(bin,2); + FactorWord oct = define("builtins","OCT:"); + oct.parsing = new Base(oct,8); + FactorWord hex = define("builtins","HEX:"); + hex.parsing = new Base(hex,16); - // #X + /* specials */ FactorWord dispatch = define("builtins","#"); dispatch.parsing = new Dispatch(dispatch); - FactorWord ch = define("builtins","#\\"); - ch.parsing = new CharLiteral(ch); - FactorWord raw = define("builtins","#\""); - raw.parsing = new StringLiteral(raw,false); - FactorWord complex = define("builtins","#{"); - complex.parsing = new ComplexLiteral(complex,"}"); - FactorWord docComment = define("builtins","#!"); - docComment.parsing = new LineComment(docComment,true); FactorWord unreadable = define("builtins","#<"); unreadable.parsing = new Unreadable(unreadable); @@ -201,7 +214,9 @@ public class FactorInterpreter implements FactorObject, Runnable FactorWord passthru = define("builtins","#:"); passthru.parsing = new PassThrough(passthru); - // vocabulary parsing words + /* vocabulary parsing words */ + FactorWord noParsing = define("builtins","POSTPONE:"); + noParsing.parsing = new NoParsing(noParsing); FactorWord defer = define("builtins","DEFER:"); defer.parsing = new Defer(defer); FactorWord in = define("builtins","IN:"); @@ -213,14 +228,6 @@ public class FactorInterpreter implements FactorObject, Runnable interpreterGet.def = new InterpreterGet(interpreterGet); interpreterGet.inline = true; - // reading numbers with another base - FactorWord bin = define("builtins","BIN:"); - bin.parsing = new Base(bin,2); - FactorWord oct = define("builtins","OCT:"); - oct.parsing = new Base(oct,8); - FactorWord hex = define("builtins","HEX:"); - hex.parsing = new Base(hex,16); - // primitives used by 'expand' and 'map' FactorWord restack = define("builtins","restack"); restack.def = new Restack(restack); diff --git a/factor/parser/CharLiteral.java b/factor/parser/CharLiteral.java index 53aa0ff35f..42b987b74b 100644 --- a/factor/parser/CharLiteral.java +++ b/factor/parser/CharLiteral.java @@ -47,8 +47,9 @@ public class CharLiteral extends FactorParsingDefinition public void eval(FactorInterpreter interp, FactorReader reader) throws IOException, FactorParseException { - reader.append(new Character( - reader.getScanner() - .readNonEOFEscaped())); + String word = (String)reader.nextNonEOF(false,false); + if(word.length() != 1) + reader.error("Bad character literal: " + word); + reader.append(new Character(word.charAt(0))); } } diff --git a/library/ansi.factor b/library/ansi.factor index fac785efc6..e0408c2645 100644 --- a/library/ansi.factor +++ b/library/ansi.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -35,7 +35,8 @@ USE: stack USE: streams USE: strings -!!! Some words for outputting ANSI colors. +! Some words for outputting ANSI colors. + : black 0 ; inline : red 1 ; inline : green 2 ; inline diff --git a/library/assoc.factor b/library/assoc.factor index b61e5a6911..0b5e5ab0e1 100644 --- a/library/assoc.factor +++ b/library/assoc.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/combinators.factor b/library/combinators.factor index 5fad275265..6219463ccc 100644 --- a/library/combinators.factor +++ b/library/combinators.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/cons.factor b/library/cons.factor index c6fef017fc..2d06641276 100644 --- a/library/cons.factor +++ b/library/cons.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/continuations.factor b/library/continuations.factor index 8fac305ffc..40a68b9a9f 100644 --- a/library/continuations.factor +++ b/library/continuations.factor @@ -1,8 +1,8 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! -! Copyright (C) 2003 Slava Pestov. +! Copyright (C) 2003, 2004 Slava Pestov. ! ! Redistribution and use in source and binary forms, with or without ! modification, are permitted provided that the following conditions are met: diff --git a/library/debugger.factor b/library/debugger.factor index 7691e4b5d2..ef8f788a65 100644 --- a/library/debugger.factor +++ b/library/debugger.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/errors.factor b/library/errors.factor index 0fb9b813b7..bb4f09b242 100644 --- a/library/errors.factor +++ b/library/errors.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/format.factor b/library/format.factor index 100441996a..41b2c66997 100644 --- a/library/format.factor +++ b/library/format.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/hashtables.factor b/library/hashtables.factor index e2d964c4bb..e28c6b2c7b 100644 --- a/library/hashtables.factor +++ b/library/hashtables.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -33,9 +33,9 @@ USE: lists USE: stack USE: vectors -!!! Note that the length of a hashtable vector must not change -!!! for the lifetime of the hashtable, otherwise problems will -!!! occur. Do not use vector words with hashtables. +! Note that the length of a hashtable vector must not change +! for the lifetime of the hashtable, otherwise problems will +! occur. Do not use vector words with hashtables. : hashtable? ( obj -- ? ) dup vector? [ [ assoc? ] vector-all? ] [ drop f ] ifte ; diff --git a/library/httpd/default-responders.factor b/library/httpd/default-responders.factor index e5f47398ea..0e42a876b5 100644 --- a/library/httpd/default-responders.factor +++ b/library/httpd/default-responders.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/httpd/file-responder.factor b/library/httpd/file-responder.factor index 7bfbda4da7..f0cbc39ba4 100644 --- a/library/httpd/file-responder.factor +++ b/library/httpd/file-responder.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/httpd/html.factor b/library/httpd/html.factor index 622b7abed8..36518d680d 100644 --- a/library/httpd/html.factor +++ b/library/httpd/html.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -40,11 +40,11 @@ USE: url-encoding : html-entities ( -- alist ) [ - [ #\< | "<" ] - [ #\> | ">" ] - [ #\& | "&" ] - [ #\' | "'" ] - [ #\" | """ ] + [ CHAR: < | "<" ] + [ CHAR: > | ">" ] + [ CHAR: & | "&" ] + [ CHAR: ' | "'" ] + [ CHAR: " | """ ] ] ; : chars>entities ( str -- str ) diff --git a/library/httpd/http-common.factor b/library/httpd/http-common.factor index 33dd523ea7..b9b2000f77 100644 --- a/library/httpd/http-common.factor +++ b/library/httpd/http-common.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/httpd/httpd.factor b/library/httpd/httpd.factor index 4c06743cb1..6d451f4a11 100644 --- a/library/httpd/httpd.factor +++ b/library/httpd/httpd.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/httpd/inspect-responder.factor b/library/httpd/inspect-responder.factor index 73fafcb059..47dd4e4dfb 100644 --- a/library/httpd/inspect-responder.factor +++ b/library/httpd/inspect-responder.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/httpd/quit-responder.factor b/library/httpd/quit-responder.factor index afa885f95d..cb77914d98 100644 --- a/library/httpd/quit-responder.factor +++ b/library/httpd/quit-responder.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/httpd/responder.factor b/library/httpd/responder.factor index 7a5050dcdc..4346f7c203 100644 --- a/library/httpd/responder.factor +++ b/library/httpd/responder.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/httpd/test-responder.factor b/library/httpd/test-responder.factor index 38920023a9..879e251701 100644 --- a/library/httpd/test-responder.factor +++ b/library/httpd/test-responder.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/httpd/url-encoding.factor b/library/httpd/url-encoding.factor index 8b65bb45da..1a4528331a 100644 --- a/library/httpd/url-encoding.factor +++ b/library/httpd/url-encoding.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/httpd/wiki-responder.factor b/library/httpd/wiki-responder.factor index 9f758eb555..4aa31379c4 100644 --- a/library/httpd/wiki-responder.factor +++ b/library/httpd/wiki-responder.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/init.factor b/library/init.factor index 34f020b83e..643e49bde5 100644 --- a/library/init.factor +++ b/library/init.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -39,8 +39,8 @@ USE: stdio USE: streams USE: strings -!!! This file is run as the last stage of boot.factor; it relies -!!! on all other words already being defined. +! This file is run as the last stage of boot.factor; it relies +! on all other words already being defined. : init-search-path ( -- ) #! Sets up the default vocabularies. diff --git a/library/inspect-vocabularies.factor b/library/inspect-vocabularies.factor index 7c33d922dd..2046f1410d 100644 --- a/library/inspect-vocabularies.factor +++ b/library/inspect-vocabularies.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/inspector.factor b/library/inspector.factor index a11eaeb0af..ba6f1bdb29 100644 --- a/library/inspector.factor +++ b/library/inspector.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/interpreter.factor b/library/interpreter.factor index ca6dd33977..030ea3ba43 100644 --- a/library/interpreter.factor +++ b/library/interpreter.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/list-namespaces.factor b/library/list-namespaces.factor index 63b30ed73b..febd2c120d 100644 --- a/library/list-namespaces.factor +++ b/library/list-namespaces.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/lists.factor b/library/lists.factor index 7bb819efc8..fa37fd315f 100644 --- a/library/lists.factor +++ b/library/lists.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/logging.factor b/library/logging.factor index 3785505086..08707e91f9 100644 --- a/library/logging.factor +++ b/library/logging.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/logic.factor b/library/logic.factor index 0ff690ec85..fc6da86f11 100644 --- a/library/logic.factor +++ b/library/logic.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/arc-trig-hyp.factor b/library/math/arc-trig-hyp.factor index f7b06377aa..8a57f71fe7 100644 --- a/library/math/arc-trig-hyp.factor +++ b/library/math/arc-trig-hyp.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/arithmetic.factor b/library/math/arithmetic.factor index b7bfe6c97c..66c1b35767 100644 --- a/library/math/arithmetic.factor +++ b/library/math/arithmetic.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/list-math.factor b/library/math/list-math.factor index ba32fd7503..beee2697c7 100644 --- a/library/math/list-math.factor +++ b/library/math/list-math.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/math-combinators.factor b/library/math/math-combinators.factor index 6aba07bc20..2a3fa66abf 100644 --- a/library/math/math-combinators.factor +++ b/library/math/math-combinators.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/math/math.factor b/library/math/math.factor index 40fb475872..38f3aaeac4 100644 --- a/library/math/math.factor +++ b/library/math/math.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/namespace-math.factor b/library/math/namespace-math.factor index f23e7cc291..ceaaecdda4 100644 --- a/library/math/namespace-math.factor +++ b/library/math/namespace-math.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/pow.factor b/library/math/pow.factor index 0f73783d9d..267387791c 100644 --- a/library/math/pow.factor +++ b/library/math/pow.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/quadratic.factor b/library/math/quadratic.factor index 8e0f392bd9..f7587bb7ff 100644 --- a/library/math/quadratic.factor +++ b/library/math/quadratic.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/math/trig-hyp.factor b/library/math/trig-hyp.factor index 5af291641c..b8f6ff089e 100644 --- a/library/math/trig-hyp.factor +++ b/library/math/trig-hyp.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/namespaces.factor b/library/namespaces.factor index 11b92fa847..7b3add7e3a 100644 --- a/library/namespaces.factor +++ b/library/namespaces.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -34,24 +34,24 @@ USE: stack USE: strings USE: vectors -!!! Other languages have classes, objects, variables, etc. -!!! Factor has similar concepts. -!!! -!!! 5 "x" set -!!! "x" get 2 + . -!!! 7 -!!! 7 "x" set -!!! "x" get 2 + . -!!! 9 -!!! -!!! get ( name -- value ) and set ( value name -- ) search in -!!! the namespaces on the namespace stack, in top-down order. -!!! -!!! At the bottom of the namespace stack, is the global -!!! namespace; it is always present. -!!! -!!! bind ( namespace quot -- ) executes a quotation with a -!!! namespace pushed on the namespace stack. +! Other languages have classes, objects, variables, etc. +! Factor has similar concepts. +! +! 5 "x" set +! "x" get 2 + . +! 7 +! 7 "x" set +! "x" get 2 + . +! 9 +! +! get ( name -- value ) and set ( value name -- ) search in +! the namespaces on the namespace stack, in top-down order. +! +! At the bottom of the namespace stack, is the global +! namespace; it is always present. +! +! bind ( namespace quot -- ) executes a quotation with a +! namespace pushed on the namespace stack. : namestack ( -- stack ) #! Push a copy of the namespace stack; same naming diff --git a/library/platform/jvm/arithmetic.factor b/library/platform/jvm/arithmetic.factor index fd1befa874..01247fede4 100644 --- a/library/platform/jvm/arithmetic.factor +++ b/library/platform/jvm/arithmetic.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/platform/jvm/boot-mini.factor b/library/platform/jvm/boot-mini.factor index c8736fe99e..20c5126d32 100644 --- a/library/platform/jvm/boot-mini.factor +++ b/library/platform/jvm/boot-mini.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/boot-sumo.factor b/library/platform/jvm/boot-sumo.factor index 5368ff5d50..bd2554e42c 100644 --- a/library/platform/jvm/boot-sumo.factor +++ b/library/platform/jvm/boot-sumo.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/boot.factor b/library/platform/jvm/boot.factor index 3d82ede77d..6986480274 100644 --- a/library/platform/jvm/boot.factor +++ b/library/platform/jvm/boot.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/combinators.factor b/library/platform/jvm/combinators.factor index 156420166e..a54c9bf3e9 100644 --- a/library/platform/jvm/combinators.factor +++ b/library/platform/jvm/combinators.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/compiler.factor b/library/platform/jvm/compiler.factor index 5f07d71383..e0e3bbf7d0 100644 --- a/library/platform/jvm/compiler.factor +++ b/library/platform/jvm/compiler.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/cons.factor b/library/platform/jvm/cons.factor index 5ffd5a1644..20f9d18e92 100644 --- a/library/platform/jvm/cons.factor +++ b/library/platform/jvm/cons.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/debugger.factor b/library/platform/jvm/debugger.factor index 2ef8ec5fff..9b5f8091fe 100644 --- a/library/platform/jvm/debugger.factor +++ b/library/platform/jvm/debugger.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/errors.factor b/library/platform/jvm/errors.factor index afb702cc5c..9d9adc689c 100644 --- a/library/platform/jvm/errors.factor +++ b/library/platform/jvm/errors.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/init.factor b/library/platform/jvm/init.factor index bc762ddcf3..bf12631b4b 100644 --- a/library/platform/jvm/init.factor +++ b/library/platform/jvm/init.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/kernel.factor b/library/platform/jvm/kernel.factor index 6573e2778f..74054ccdd7 100644 --- a/library/platform/jvm/kernel.factor +++ b/library/platform/jvm/kernel.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/listener.factor b/library/platform/jvm/listener.factor index e771e11d70..cbd9d3c014 100644 --- a/library/platform/jvm/listener.factor +++ b/library/platform/jvm/listener.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/math-types.factor b/library/platform/jvm/math-types.factor index 68a2905355..c70a41eed5 100644 --- a/library/platform/jvm/math-types.factor +++ b/library/platform/jvm/math-types.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/platform/jvm/namespaces.factor b/library/platform/jvm/namespaces.factor index 267a7c90fe..f393931264 100644 --- a/library/platform/jvm/namespaces.factor +++ b/library/platform/jvm/namespaces.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/parser.factor b/library/platform/jvm/parser.factor index 13460f9b7d..a87cc71d27 100644 --- a/library/platform/jvm/parser.factor +++ b/library/platform/jvm/parser.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/prettyprint.factor b/library/platform/jvm/prettyprint.factor index 313b8a8ed0..d97d469794 100644 --- a/library/platform/jvm/prettyprint.factor +++ b/library/platform/jvm/prettyprint.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/random.factor b/library/platform/jvm/random.factor index 8a13de40ee..c5feab711e 100644 --- a/library/platform/jvm/random.factor +++ b/library/platform/jvm/random.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/platform/jvm/real-math.factor b/library/platform/jvm/real-math.factor index bf07fbd86c..88c23c124d 100644 --- a/library/platform/jvm/real-math.factor +++ b/library/platform/jvm/real-math.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/platform/jvm/regexp.factor b/library/platform/jvm/regexp.factor index 5d56cb5c29..85297ffd38 100644 --- a/library/platform/jvm/regexp.factor +++ b/library/platform/jvm/regexp.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/sbuf.factor b/library/platform/jvm/sbuf.factor index 7a98915828..a511ac9274 100644 --- a/library/platform/jvm/sbuf.factor +++ b/library/platform/jvm/sbuf.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/platform/jvm/stack.factor b/library/platform/jvm/stack.factor index b20a5e7671..114d1544de 100644 --- a/library/platform/jvm/stack.factor +++ b/library/platform/jvm/stack.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/stack2.factor b/library/platform/jvm/stack2.factor index cbbcdda2f2..9c8b81b427 100644 --- a/library/platform/jvm/stack2.factor +++ b/library/platform/jvm/stack2.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/stream.factor b/library/platform/jvm/stream.factor index b89d429726..a076c601c9 100644 --- a/library/platform/jvm/stream.factor +++ b/library/platform/jvm/stream.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/strings.factor b/library/platform/jvm/strings.factor index 6d8dfb41ec..b93d9a7270 100644 --- a/library/platform/jvm/strings.factor +++ b/library/platform/jvm/strings.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/platform/jvm/threads.factor b/library/platform/jvm/threads.factor index d08f2ca459..dc4001c3ad 100644 --- a/library/platform/jvm/threads.factor +++ b/library/platform/jvm/threads.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/unparser.factor b/library/platform/jvm/unparser.factor index 9df7be59f4..ef20353593 100644 --- a/library/platform/jvm/unparser.factor +++ b/library/platform/jvm/unparser.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/vectors.factor b/library/platform/jvm/vectors.factor index ad62ebce32..b154c85bd6 100644 --- a/library/platform/jvm/vectors.factor +++ b/library/platform/jvm/vectors.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/vocabularies.factor b/library/platform/jvm/vocabularies.factor index f6a5252ea9..f226d9eaa1 100644 --- a/library/platform/jvm/vocabularies.factor +++ b/library/platform/jvm/vocabularies.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/jvm/words.factor b/library/platform/jvm/words.factor index f672734d3d..cb884bd04f 100644 --- a/library/platform/jvm/words.factor +++ b/library/platform/jvm/words.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/.image.factor.marks b/library/platform/native/.image.factor.marks index fac84b4fde..3338d6b262 100644 Binary files a/library/platform/native/.image.factor.marks and b/library/platform/native/.image.factor.marks differ diff --git a/library/platform/native/.kernel.factor.marks b/library/platform/native/.kernel.factor.marks index 55b01478ee..d622ba2c62 100644 --- a/library/platform/native/.kernel.factor.marks +++ b/library/platform/native/.kernel.factor.marks @@ -1 +1 @@ -!a;2200;2200 +!a;2201;2201 diff --git a/library/platform/native/boot.factor b/library/platform/native/boot.factor index 75619d5ebd..93dd4f80a3 100644 --- a/library/platform/native/boot.factor +++ b/library/platform/native/boot.factor @@ -1,4 +1,4 @@ -!:folding=none:collapseFolds=1: +! :folding=none:collapseFolds=1: ! $Id$ ! @@ -79,8 +79,11 @@ primitives, "/library/platform/native/io-internals.factor" "/library/platform/native/stream.factor" "/library/platform/native/kernel.factor" + "/library/platform/native/image.factor" "/library/platform/native/namespaces.factor" + "/library/platform/native/parse-numbers.factor" "/library/platform/native/parser.factor" + "/library/platform/native/parse-syntax.factor" "/library/platform/native/parse-stream.factor" "/library/platform/native/prettyprint.factor" "/library/platform/native/stack.factor" @@ -100,7 +103,7 @@ primitives, max 2list length reverse nth list? 2rlist all? clone-list clone-list-iter subset subset-iter subset-add car= cdr= cons= cons-hashcode - tree-contains? =-or-contains? last* last + tree-contains? =-or-contains? last* last inject ] [ worddef worddef, ] each version, diff --git a/library/platform/native/cross-compiler.factor b/library/platform/native/cross-compiler.factor index f9d1e8295b..c43193aa1b 100644 --- a/library/platform/native/cross-compiler.factor +++ b/library/platform/native/cross-compiler.factor @@ -1,4 +1,4 @@ -!:folding=none:collapseFolds=1: +! :folding=none:collapseFolds=1: ! $Id$ ! @@ -107,7 +107,11 @@ IN: cross-compiler mod /mod bitand + bitor bitxor + bitnot + shift> + shift< < <= > @@ -176,4 +180,4 @@ IN: cross-compiler ! Uncomment this on sparc and powerpc. ! "big-endian" on - "native/factor.image" write-image ; + "factor.image" write-image ; diff --git a/library/platform/native/errors.factor b/library/platform/native/errors.factor index c2486caa94..541155bf22 100644 --- a/library/platform/native/errors.factor +++ b/library/platform/native/errors.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/image.factor b/library/platform/native/image.factor index 99a6640ce2..e78cd706d4 100644 --- a/library/platform/native/image.factor +++ b/library/platform/native/image.factor @@ -1,4 +1,4 @@ -!:folding=none:collapseFolds=1: +! :folding=none:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/init.factor b/library/platform/native/init.factor index 6e15553fe4..8f21e7a21b 100644 --- a/library/platform/native/init.factor +++ b/library/platform/native/init.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/io-internals.factor b/library/platform/native/io-internals.factor index a2629fa08f..f9c779c7a9 100644 --- a/library/platform/native/io-internals.factor +++ b/library/platform/native/io-internals.factor @@ -1,4 +1,4 @@ -!:folding=none:collapseFolds=1: +! :folding=none:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/kernel.factor b/library/platform/native/kernel.factor index 50dc6b4a7f..1d8973add6 100644 --- a/library/platform/native/kernel.factor +++ b/library/platform/native/kernel.factor @@ -1,4 +1,4 @@ -!:folding=none:collapseFolds=1: +! :folding=none:collapseFolds=1: ! $Id$ ! @@ -95,9 +95,11 @@ USE: words : inline ; : interpret-only ; -!!! HACK +! HACKS IN: strings +: char? drop f ; +: >char ; : >upper ; : >lower ; IN: lists diff --git a/library/platform/native/namespaces.factor b/library/platform/native/namespaces.factor index 2e28e1a964..b66bf9eb38 100644 --- a/library/platform/native/namespaces.factor +++ b/library/platform/native/namespaces.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/parse-numbers.factor b/library/platform/native/parse-numbers.factor new file mode 100644 index 0000000000..906559c588 --- /dev/null +++ b/library/platform/native/parse-numbers.factor @@ -0,0 +1,81 @@ +! :folding=indent:collapseFolds=1: + +! $Id$ +! +! Copyright (C) 2004 Slava Pestov. +! +! Redistribution and use in source and binary forms, with or without +! modification, are permitted provided that the following conditions are met: +! +! 1. Redistributions of source code must retain the above copyright notice, +! this list of conditions and the following disclaimer. +! +! 2. Redistributions in binary form must reproduce the above copyright notice, +! this list of conditions and the following disclaimer in the documentation +! and/or other materials provided with the distribution. +! +! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +IN: parser +USE: arithmetic +USE: combinators +USE: errors +USE: kernel +USE: lists +USE: logic +USE: namespaces +USE: stack +USE: strings +USE: words +USE: vocabularies +USE: unparser + +! Number parsing + +: letter? CHAR: a CHAR: z between? ; +: LETTER? CHAR: A CHAR: Z between? ; +: digit? CHAR: 0 CHAR: 9 between? ; + +: not-a-number "Not a number" throw ; + +: digit> ( ch -- n ) + [ + [ digit? ] [ CHAR: 0 - ] + [ letter? ] [ CHAR: a - 10 + ] + [ LETTER? ] [ CHAR: A - 10 + ] + [ drop t ] [ not-a-number ] + ] cond ; + +: >digit ( n -- ch ) + dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] ifte ; + +: digit ( num digit -- num ) + "base" get swap 2dup > [ + >r * r> + + ] [ + not-a-number + ] ifte ; + +: (str>fixnum) ( str -- num ) + 0 swap [ digit> digit ] str-each ; + +: str>fixnum ( str -- num ) + #! Parse a string representation of an integer. + dup str-length 0 = [ + drop not-a-number + ] [ + dup "-" str-head? dup [ + nip str>fixnum neg + ] [ + drop (str>fixnum) + ] ifte + ] ifte ; diff --git a/library/platform/native/parse-stream.factor b/library/platform/native/parse-stream.factor index c8d19a3247..ff85b981fe 100644 --- a/library/platform/native/parse-stream.factor +++ b/library/platform/native/parse-stream.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/parse-syntax.factor b/library/platform/native/parse-syntax.factor new file mode 100644 index 0000000000..b30ea49cb7 --- /dev/null +++ b/library/platform/native/parse-syntax.factor @@ -0,0 +1,125 @@ +! :folding=indent:collapseFolds=1: + +! $Id$ +! +! Copyright (C) 2004 Slava Pestov. +! +! Redistribution and use in source and binary forms, with or without +! modification, are permitted provided that the following conditions are met: +! +! 1. Redistributions of source code must retain the above copyright notice, +! this list of conditions and the following disclaimer. +! +! 2. Redistributions in binary form must reproduce the above copyright notice, +! this list of conditions and the following disclaimer in the documentation +! and/or other materials provided with the distribution. +! +! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +IN: parser +USE: arithmetic +USE: combinators +USE: errors +USE: kernel +USE: lists +USE: logic +USE: namespaces +USE: stack +USE: strings +USE: words +USE: vocabularies +USE: unparser + +! Parsing words. 'builtins' is a stupid vocabulary name now +! that it does not contain Java words anymore! + +IN: builtins + +! Constants +: t t parsed ; parsing +: f f parsed ; parsing + +! Lists +: [ f ; parsing +: ] nreverse parsed ; parsing + +: | ( syntax: | cdr ] ) + #! See the word 'parsed'. We push a special sentinel, and + #! 'parsed' acts accordingly. + "|" ; parsing + +! Colon defs +: : + #! Begin a word definition. Word name follows. + scan "in" get create f ; parsing + +: ; + #! End a word definition. + nreverse define ; parsing + +! Vocabularies +: DEFER: scan "in" get create drop ; parsing +: USE: scan "use" cons@ ; parsing +: IN: scan dup "use" cons@ "in" set ; parsing + +! \x +: escape ( ch -- esc ) + [ + [ CHAR: e | CHAR: \e ] + [ CHAR: n | CHAR: \n ] + [ CHAR: r | CHAR: \r ] + [ CHAR: t | CHAR: \t ] + [ CHAR: s | CHAR: \s ] + [ CHAR: \s | CHAR: \s ] + [ CHAR: 0 | CHAR: \0 ] + [ CHAR: \\ | CHAR: \\ ] + [ CHAR: \" | CHAR: \" ] + ] assoc ; + +! String literal + +: parse-escape ( -- ) + next-ch escape dup [ drop "Bad escape" throw ] unless ; + +: parse-ch ( ch -- ch ) + dup CHAR: \\ = [ drop parse-escape ] when ; + +: parse-string ( -- ) + next-ch dup CHAR: " = [ + drop + ] [ + parse-ch % parse-string + ] ifte ; + +: " + #! Note the ugly hack to carry the new value of 'pos' from + #! the <% %> scope up to the original scope. + <% parse-string "pos" get %> swap "pos" set parsed ; parsing + +! Char literal +: CHAR: ( -- ) skip-blank next-ch parse-ch parsed ; parsing + +! Comments +: ( ")" until drop ; parsing +: ! until-eol drop ; parsing +: #! until-eol drop ; parsing + +! Reading numbers in other bases + +: BASE: ( base -- ) + #! Read a number in a specific base. + "base" get >r "base" set scan number, r> "base" set ; + +: HEX: 16 BASE: ; parsing +: DEC: 10 BASE: ; parsing +: OCT: 8 BASE: ; parsing +: BIN: 2 BASE: ; parsing diff --git a/library/platform/native/parser.factor b/library/platform/native/parser.factor index fde4ce1526..f60617d38d 100644 --- a/library/platform/native/parser.factor +++ b/library/platform/native/parser.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -39,47 +39,6 @@ USE: words USE: vocabularies USE: unparser -! Number parsing - -: letter? #\a #\z between? ; -: LETTER? #\A #\Z between? ; -: digit? #\0 #\9 between? ; - -: not-a-number "Not a number" throw ; - -: digit> ( ch -- n ) - [ - [ digit? ] [ #\0 - ] - [ letter? ] [ #\a - 10 + ] - [ LETTER? ] [ #\A - 10 + ] - [ drop t ] [ not-a-number ] - ] cond ; - -: >digit ( n -- ch ) - dup 10 < [ #\0 + ] [ 10 - #\a + ] ifte ; - -: digit ( num digit -- num ) - "base" get swap 2dup >= [ - >r * r> + - ] [ - not-a-number - ] ifte ; - -: (str>fixnum) ( str -- num ) - 0 swap [ digit> digit ] str-each ; - -: str>fixnum ( str -- num ) - #! Parse a string representation of an integer. - dup str-length 0 = [ - drop not-a-number - ] [ - dup "-" str-head? dup [ - nip str>fixnum neg - ] [ - drop (str>fixnum) - ] ifte - ] ifte ; - ! The parser uses a number of variables: ! line - the line being parsed ! pos - position in the line @@ -118,7 +77,7 @@ USE: unparser #! "hello world" #! #! Will call the parsing word ". - ch "\"!" str-contains? ; + ch "\"" str-contains? ; : (scan) ( -- start end ) skip-blank "pos" get @@ -165,7 +124,7 @@ USE: unparser : eval ( "X" -- X ) parse call ; -!!! Used by parsing words +! Used by parsing words : ch-search ( ch -- index ) "pos" get "line" get rot index-of* ; @@ -175,87 +134,8 @@ USE: unparser : until ( ch -- str ) ch-search (until) ; -: until-eol ( ch -- str ) +: until-eol ( -- str ) "line" get str-length (until) ; : next-ch ( -- ch ) end? [ "Unexpected EOF" throw ] [ ch advance ] ifte ; - -!!! Parsing words. 'builtins' is a stupid vocabulary name now -!!! that it does not contain Java words anymore! - -IN: builtins - -! Constants -: t t parsed ; parsing -: f f parsed ; parsing - -! Lists -: [ f ; parsing -: ] nreverse parsed ; parsing - -: | ( syntax: | cdr ] ) - #! See the word 'parsed'. We push a special sentinel, and - #! 'parsed' acts accordingly. - "|" ; parsing - -! Colon defs -: : - #! Begin a word definition. Word name follows. - scan "in" get create f ; parsing - -: ; - #! End a word definition. - nreverse define ; parsing - -! Vocabularies -: DEFER: scan "in" get create drop ; parsing -: USE: scan "use" cons@ ; parsing -: IN: scan dup "use" cons@ "in" set ; parsing - -! \x -: escape ( ch -- esc ) - [ - [ #\e | #\\e ] - [ #\n | #\\n ] - [ #\r | #\\r ] - [ #\t | #\\t ] - [ #\s | #\\s ] - [ #\\s | #\\s ] - [ #\0 | #\\0 ] - [ #\\\ | #\\\ ] - [ #\\" | #\\" ] - ] assoc ; - -! String literal - -: parse-escape ( -- ) - next-ch escape dup [ % ] [ drop "Bad escape" throw ] ifte ; - -: parse-string ( -- ) - next-ch dup #\" = [ - drop - ] [ - dup #\\\ = [ drop parse-escape ] [ % ] ifte parse-string - ] ifte ; - -: " - #! Note the ugly hack to carry the new value of 'pos' from - #! the <% %> scope up to the original scope. - <% parse-string "pos" get %> swap "pos" set parsed ; parsing - -! Comments -: ( ")" until drop ; parsing -: ! until-eol drop ; parsing -: #! until-eol drop ; parsing - -! Reading numbers in other bases - -: BASE: ( base -- ) - #! Read a number in a specific base. - "base" get >r "base" set scan number, r> "base" set ; - -: HEX: 16 BASE: ; parsing -: DEC: 10 BASE: ; parsing -: OCT: 8 BASE: ; parsing -: BIN: 2 BASE: ; parsing diff --git a/library/platform/native/prettyprint.factor b/library/platform/native/prettyprint.factor index 55032fd286..4f4789139e 100644 --- a/library/platform/native/prettyprint.factor +++ b/library/platform/native/prettyprint.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/stack.factor b/library/platform/native/stack.factor index 3970c135c2..b936bae628 100644 --- a/library/platform/native/stack.factor +++ b/library/platform/native/stack.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/stream.factor b/library/platform/native/stream.factor index c94bd2c8d1..364ccc1744 100644 --- a/library/platform/native/stream.factor +++ b/library/platform/native/stream.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -53,5 +53,11 @@ USE: namespaces : ( path mode -- stream ) open-file dup ; +: ( path -- stream ) + "r" ; + +: ( path -- stream ) + "w" ; + : init-stdio ( -- ) stdin stdout "stdio" set ; diff --git a/library/platform/native/unparser.factor b/library/platform/native/unparser.factor index d3ea7ca55d..09338e6444 100644 --- a/library/platform/native/unparser.factor +++ b/library/platform/native/unparser.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -54,7 +54,7 @@ USE: vocabularies : unparse-str ( str -- str ) #! Not done - <% #\" % % #\" % %> ; + <% CHAR: " % % CHAR: " % %> ; : unparse-word ( word -- str ) word-name dup "#" ? ; diff --git a/library/platform/native/vectors.factor b/library/platform/native/vectors.factor index f786f62eb2..06ce9c7f3d 100644 --- a/library/platform/native/vectors.factor +++ b/library/platform/native/vectors.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/vocabularies.factor b/library/platform/native/vocabularies.factor index d81c2f8e06..6299670228 100644 --- a/library/platform/native/vocabularies.factor +++ b/library/platform/native/vocabularies.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/platform/native/words.factor b/library/platform/native/words.factor index 0b03e176f5..74f374eb3c 100644 --- a/library/platform/native/words.factor +++ b/library/platform/native/words.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/prettyprint.factor b/library/prettyprint.factor index 749a4bda1b..dc8c89d32c 100644 --- a/library/prettyprint.factor +++ b/library/prettyprint.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/random.factor b/library/random.factor index 25f6009bd6..f75de33a1a 100644 --- a/library/random.factor +++ b/library/random.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/sbuf.factor b/library/sbuf.factor index 1afebc7078..6f3ca6e417 100644 --- a/library/sbuf.factor +++ b/library/sbuf.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=0: +! :folding=indent:collapseFolds=0: ! $Id$ ! diff --git a/library/stdio.factor b/library/stdio.factor index 2c489c822b..cb565cd21e 100644 --- a/library/stdio.factor +++ b/library/stdio.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/stream.factor b/library/stream.factor index 55456934bc..10e8817682 100644 --- a/library/stream.factor +++ b/library/stream.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/strings.factor b/library/strings.factor index abc3091da6..8a7b8ccfcf 100644 --- a/library/strings.factor +++ b/library/strings.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/styles.factor b/library/styles.factor index d016a3eb2e..13e147575d 100644 --- a/library/styles.factor +++ b/library/styles.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -31,12 +31,12 @@ USE: kernel USE: namespaces USE: stack -!!! A style is a namespace whose variable names and values hold -!!! significance to the 'fwrite-attr' word when applied to a -!!! stream that supports attributed string output. -!!! -!!! The default style enumerates the canonical names and values -!!! to determine a style. +! A style is a namespace whose variable names and values hold +! significance to the 'fwrite-attr' word when applied to a +! stream that supports attributed string output. +! +! The default style enumerates the canonical names and values +! to determine a style. : default-style ( -- style ) #! Push the default style object. diff --git a/library/telnetd.factor b/library/telnetd.factor index 13c8f8b0c5..e0ba8a78c2 100644 --- a/library/telnetd.factor +++ b/library/telnetd.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/vector-combinators.factor b/library/vector-combinators.factor index 582fcb0d57..68e79c2446 100644 --- a/library/vector-combinators.factor +++ b/library/vector-combinators.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/vectors.factor b/library/vectors.factor index f63eb8907b..ba4d48db99 100644 --- a/library/vectors.factor +++ b/library/vectors.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/vocabularies.factor b/library/vocabularies.factor index 8808699811..28d07718c0 100644 --- a/library/vocabularies.factor +++ b/library/vocabularies.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/vocabulary-style.factor b/library/vocabulary-style.factor index 8113f52967..fe4bb40547 100644 --- a/library/vocabulary-style.factor +++ b/library/vocabulary-style.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/library/words.factor b/library/words.factor index 8a563f762a..cd7226b272 100644 --- a/library/words.factor +++ b/library/words.factor @@ -1,4 +1,4 @@ -!:folding=indent:collapseFolds=1: +! :folding=indent:collapseFolds=1: ! $Id$ ! diff --git a/native/error.c b/native/error.c index 4776d27812..c3ac2999bf 100644 --- a/native/error.c +++ b/native/error.c @@ -42,7 +42,6 @@ void general_error(CELL error, CELL tagged) void type_error(CELL type, CELL tagged) { - printf("throwing %d %d\n",type,tagged); CONS* c = cons(tag_fixnum(type),tag_cons(cons(tagged,F))); general_error(ERROR_TYPE,tag_cons(c)); } diff --git a/native/fixnum.c b/native/fixnum.c index 137f887560..c11a64cf66 100644 --- a/native/fixnum.c +++ b/native/fixnum.c @@ -58,12 +58,36 @@ void primitive_and(void) env.dt = x & y; } +void primitive_or(void) +{ + BINARY_OP(x,y); + env.dt = x | y; +} + void primitive_xor(void) { BINARY_OP(x,y); env.dt = x ^ y; } +void primitive_not(void) +{ + type_check(FIXNUM_TYPE,env.dt); + env.dt = RETAG(~env.dt,FIXNUM_TYPE); +} + +void primitive_shiftleft(void) +{ + BINARY_OP(x,y); + env.dt = UNTAG(x >> (y >> TAG_BITS)); +} + +void primitive_shiftright(void) +{ + BINARY_OP(x,y); + env.dt = x << (y >> TAG_BITS); +} + void primitive_less(void) { BINARY_OP(x,y); diff --git a/native/fixnum.h b/native/fixnum.h index f68556cd81..be26f5dd84 100644 --- a/native/fixnum.h +++ b/native/fixnum.h @@ -19,7 +19,11 @@ void primitive_divide(void); void primitive_mod(void); void primitive_divmod(void); void primitive_and(void); +void primitive_or(void); void primitive_xor(void); +void primitive_not(void); +void primitive_shiftleft(void); +void primitive_shiftright(void); void primitive_less(void); void primitive_lesseq(void); void primitive_greater(void); diff --git a/native/primitives.c b/native/primitives.c index 401480f9d5..fc5aa4ea8e 100644 --- a/native/primitives.c +++ b/native/primitives.c @@ -42,44 +42,48 @@ XT primitives[] = { primitive_mod, /* 38 */ primitive_divmod, /* 39 */ primitive_and, /* 40 */ - primitive_xor, /* 41 */ - primitive_less, /* 42 */ - primitive_lesseq, /* 43 */ - primitive_greater, /* 44 */ - primitive_greatereq, /* 45 */ - primitive_wordp, /* 46 */ - primitive_word, /* 47 */ - primitive_word_primitive, /* 48 */ - primitive_set_word_primitive, /* 49 */ - primitive_word_parameter, /* 50 */ - primitive_set_word_parameter, /* 51 */ - primitive_word_plist, /* 52 */ - primitive_set_word_plist, /* 53 */ - primitive_drop, /* 54 */ - primitive_dup, /* 55 */ - primitive_swap, /* 56 */ - primitive_over, /* 57 */ - primitive_pick, /* 58 */ - primitive_nip, /* 59 */ - primitive_tuck, /* 60 */ - primitive_rot, /* 61 */ - primitive_to_r, /* 62 */ - primitive_from_r, /* 63 */ - primitive_eq, /* 64 */ - primitive_getenv, /* 65 */ - primitive_setenv, /* 66 */ - primitive_open_file, /* 67 */ - primitive_read_line_8, /* 68 */ - primitive_write_8, /* 69 */ - primitive_close, /* 70 */ - primitive_gc, /* 71 */ - primitive_save_image, /* 72 */ - primitive_datastack, /* 73 */ - primitive_callstack, /* 74 */ - primitive_set_datastack, /* 75 */ - primitive_set_callstack, /* 76 */ - primitive_handlep, /* 77 */ - primitive_exit /* 78 */ + primitive_or, /* 41 */ + primitive_xor, /* 42 */ + primitive_not, /* 43 */ + primitive_shiftleft, /* 44 */ + primitive_shiftright, /* 45 */ + primitive_less, /* 46 */ + primitive_lesseq, /* 47 */ + primitive_greater, /* 48 */ + primitive_greatereq, /* 49 */ + primitive_wordp, /* 50 */ + primitive_word, /* 51 */ + primitive_word_primitive, /* 52 */ + primitive_set_word_primitive, /* 53 */ + primitive_word_parameter, /* 54 */ + primitive_set_word_parameter, /* 55 */ + primitive_word_plist, /* 56 */ + primitive_set_word_plist, /* 57 */ + primitive_drop, /* 58 */ + primitive_dup, /* 59 */ + primitive_swap, /* 60 */ + primitive_over, /* 61 */ + primitive_pick, /* 62 */ + primitive_nip, /* 63 */ + primitive_tuck, /* 64 */ + primitive_rot, /* 65 */ + primitive_to_r, /* 66 */ + primitive_from_r, /* 67 */ + primitive_eq, /* 68 */ + primitive_getenv, /* 69 */ + primitive_setenv, /* 70 */ + primitive_open_file, /* 71 */ + primitive_read_line_8, /* 72 */ + primitive_write_8, /* 73 */ + primitive_close, /* 74 */ + primitive_gc, /* 75 */ + primitive_save_image, /* 76 */ + primitive_datastack, /* 77 */ + primitive_callstack, /* 78 */ + primitive_set_datastack, /* 79 */ + primitive_set_callstack, /* 80 */ + primitive_handlep, /* 81 */ + primitive_exit /* 82 */ }; CELL primitive_to_xt(CELL primitive) diff --git a/native/primitives.h b/native/primitives.h index e7a48cf6b5..070f5faea3 100644 --- a/native/primitives.h +++ b/native/primitives.h @@ -1,5 +1,5 @@ extern XT primitives[]; -#define PRIMITIVE_COUNT 79 +#define PRIMITIVE_COUNT 83 CELL primitive_to_xt(CELL primitive);