nomennescio 2019-10-18 15:04:42 +02:00
commit 54b1fc086b
315 changed files with 9240 additions and 8972 deletions

View File

@ -1,185 +1,119 @@
./library/compiler/simplifier.factor:! $Id: simplifier.factor,v 1.4 2004/12/19 01:24:45 spestov Exp $
./library/compiler/xt.factor:! $Id: xt.factor,v 1.6 2004/12/17 00:57:03 spestov Exp $
./library/compiler/assembler.factor:! $Id: assembler.factor,v 1.8 2004/12/25 07:55:03 spestov Exp $
./library/compiler/assembly-x86.factor:! $Id: assembly-x86.factor,v 1.15 2004/12/31 07:17:43 spestov Exp $
./library/compiler/generator-x86.factor:! $Id: generator-x86.factor,v 1.19 2004/12/31 07:17:43 spestov Exp $
./library/compiler/alien-types.factor:! $Id: alien-types.factor,v 1.17 2004/12/29 08:35:44 spestov Exp $
./library/compiler/generator.factor:! $Id: generator.factor,v 1.9 2004/12/31 07:17:43 spestov Exp $
./library/compiler/alien.factor:! $Id: alien.factor,v 1.22 2004/12/31 07:17:43 spestov Exp $
./library/compiler/optimizer.factor:! $Id: optimizer.factor,v 1.14 2005/01/01 22:20:47 spestov Exp $
./library/compiler/compiler.factor:! $Id: compiler.factor,v 1.32 2004/12/27 20:27:17 spestov Exp $
./library/compiler/linearizer.factor:! $Id: linearizer.factor,v 1.19 2005/01/01 22:20:47 spestov Exp $
./library/vectors.factor:! $Id: vectors.factor,v 1.25 2004/12/30 07:40:13 spestov Exp $
./library/kernel.factor:! $Id: kernel.factor,v 1.16 2004/12/31 07:17:43 spestov Exp $
./library/compiler/simplifier.factor:! $Id: simplifier.factor,v 1.9 2005/01/19 02:42:21 spestov Exp $
./library/compiler/xt.factor:! $Id: xt.factor,v 1.8 2005/01/07 02:42:07 spestov Exp $
./library/compiler/assembler.factor:! $Id: assembler.factor,v 1.12 2005/02/15 02:58:05 spestov Exp $
./library/compiler/generator.factor:! $Id: generator.factor,v 1.13 2005/01/17 20:32:56 spestov Exp $
./library/compiler/x86/assembler.factor:! $Id: assembler.factor,v 1.3 2005/01/16 22:57:59 spestov Exp $
./library/compiler/x86/fixnum.factor:! $Id: fixnum.factor,v 1.6 2005/02/17 04:24:35 spestov Exp $
./library/compiler/optimizer.factor:! $Id: optimizer.factor,v 1.19 2005/01/20 02:01:46 spestov Exp $
./library/compiler/compiler.factor:! $Id: compiler.factor,v 1.33 2005/01/07 00:10:00 spestov Exp $
./library/compiler/linearizer.factor:! $Id: linearizer.factor,v 1.22 2005/02/18 00:01:10 spestov Exp $
./library/ui/line-editor.factor:! $Id: line-editor.factor,v 1.3 2005/01/04 05:41:14 spestov Exp $
./library/ui/console.factor:! $Id: console.factor,v 1.17 2005/02/15 03:15:02 spestov Exp $
./library/win32/win32-io.factor:! $Id: win32-io.factor,v 1.3 2004/12/29 07:16:03 eiz Exp $
./library/win32/win32-errors.factor:! $Id: win32-errors.factor,v 1.3 2004/12/29 07:16:03 eiz Exp $
./library/win32/winsock.factor:! $Id: winsock.factor,v 1.2 2004/12/29 07:16:03 eiz Exp $
./library/httpd/file-responder.factor:! $Id: file-responder.factor,v 1.16 2004/12/19 08:04:02 spestov Exp $
./library/httpd/http-common.factor:! $Id: http-common.factor,v 1.17 2004/12/19 08:04:02 spestov Exp $
./library/httpd/quit-responder.factor:! $Id: quit-responder.factor,v 1.6 2004/12/11 00:29:03 spestov Exp $
./library/httpd/responder.factor:! $Id: responder.factor,v 1.18 2004/12/11 00:29:03 spestov Exp $
./library/win32/win32-errors.factor:! $Id: win32-errors.factor,v 1.5 2005/02/07 23:04:49 eiz Exp $
./library/win32/winsock.factor:! $Id: winsock.factor,v 1.3 2005/02/18 04:01:29 eiz Exp $
./library/httpd/file-responder.factor:! $Id: file-responder.factor,v 1.17 2005/01/29 05:07:55 spestov Exp $
./library/httpd/http-common.factor:! $Id: http-common.factor,v 1.19 2005/02/15 03:15:00 spestov Exp $
./library/httpd/quit-responder.factor:! $Id: quit-responder.factor,v 1.7 2005/02/15 03:15:00 spestov Exp $
./library/httpd/responder.factor:! $Id: responder.factor,v 1.19 2005/01/14 00:49:44 spestov Exp $
./library/httpd/resource-responder.factor:! $Id: resource-responder.factor,v 1.4 2004/12/11 00:29:03 spestov Exp $
./library/httpd/default-responders.factor:! $Id: default-responders.factor,v 1.12 2004/12/24 07:52:00 spestov Exp $
./library/httpd/html.factor:! $Id: html.factor,v 1.22 2004/12/24 07:52:00 spestov Exp $
./library/httpd/default-responders.factor:! $Id: default-responders.factor,v 1.13 2005/02/14 21:44:15 doublec Exp $
./library/httpd/test-responder.factor:! $Id: test-responder.factor,v 1.5 2004/12/11 00:29:03 spestov Exp $
./library/httpd/httpd.factor:! $Id: httpd.factor,v 1.23 2004/12/26 02:28:46 spestov Exp $
./library/httpd/url-encoding.factor:! $Id: url-encoding.factor,v 1.13 2004/12/29 08:35:44 spestov Exp $
./library/math/arc-trig-hyp.factor:! $Id: arc-trig-hyp.factor,v 1.7 2004/12/29 08:35:45 spestov Exp $
./library/math/float.factor:! $Id: float.factor,v 1.1 2004/12/19 04:18:31 spestov Exp $
./library/math/complex.factor:! $Id: complex.factor,v 1.6 2004/12/31 07:17:45 spestov Exp $
./library/math/constants.factor:! $Id: constants.factor,v 1.2 2004/09/19 02:29:28 spestov Exp $
./library/math/integer.factor:! $Id: integer.factor,v 1.4 2004/12/31 01:46:20 spestov Exp $
./library/math/math-combinators.factor:! $Id: math-combinators.factor,v 1.11 2004/12/29 08:35:45 spestov Exp $
./library/math/pow.factor:! $Id: pow.factor,v 1.9 2004/12/11 00:29:04 spestov Exp $
./library/math/math.factor:! $Id: math.factor,v 1.14 2004/12/30 07:40:14 spestov Exp $
./library/math/ratio.factor:! $Id: ratio.factor,v 1.3 2004/12/31 07:17:45 spestov Exp $
./library/math/trig-hyp.factor:! $Id: trig-hyp.factor,v 1.9 2004/12/11 00:29:04 spestov Exp $
./library/errors.factor:! $Id: errors.factor,v 1.18 2004/12/24 07:51:58 spestov Exp $
./library/random.factor:! $Id: random.factor,v 1.9 2004/12/29 08:35:43 spestov Exp $
./library/combinators.factor:! $Id: combinators.factor,v 1.18 2004/12/24 07:51:58 spestov Exp $
./library/words.factor:! $Id: words.factor,v 1.21 2004/12/31 07:17:43 spestov Exp $
./library/continuations.factor:! $Id: continuations.factor,v 1.6 2004/12/11 00:29:00 spestov Exp $
./library/assoc.factor:! $Id: assoc.factor,v 1.13 2005/01/01 22:20:46 spestov Exp $
./library/list-namespaces.factor:! $Id: list-namespaces.factor,v 1.13 2004/12/23 06:14:04 spestov Exp $
./library/inference/words.factor:! $Id: words.factor,v 1.34 2004/12/31 07:17:44 spestov Exp $
./library/inference/dataflow.factor:! $Id: dataflow.factor,v 1.21 2004/12/26 06:42:08 spestov Exp $
./library/inference/stack.factor:! $Id: stack.factor,v 1.10 2004/12/11 00:29:03 spestov Exp $
./library/inference/branches.factor:! $Id: branches.factor,v 1.39 2005/01/01 22:20:47 spestov Exp $
./library/inference/inference.factor:! $Id: inference.factor,v 1.27 2004/12/31 07:17:44 spestov Exp $
./library/inference/types.factor:! $Id: types.factor,v 1.2 2004/12/31 07:17:44 spestov Exp $
./library/vocabularies.factor:! $Id: vocabularies.factor,v 1.22 2004/12/25 23:08:18 spestov Exp $
./library/generic/object.factor:! $Id: object.factor,v 1.6 2004/12/29 23:01:22 spestov Exp $
./library/generic/builtin.factor:! $Id: builtin.factor,v 1.10 2004/12/29 23:01:22 spestov Exp $
./library/generic/generic.factor:! $Id: generic.factor,v 1.16 2005/01/01 22:20:47 spestov Exp $
./library/generic/predicate.factor:! $Id: predicate.factor,v 1.9 2004/12/31 07:17:43 spestov Exp $
./library/generic/traits.factor:! $Id: traits.factor,v 1.6 2005/01/01 23:02:22 spestov Exp $
./library/generic/union.factor:! $Id: union.factor,v 1.6 2004/12/29 23:01:22 spestov Exp $
./library/lists.factor:! $Id: lists.factor,v 1.44 2005/01/01 22:20:46 spestov Exp $
./library/stack.factor:! $Id: stack.factor,v 1.8 2004/12/24 07:51:59 spestov Exp $
./library/primitives.factor:! $Id: primitives.factor,v 1.20 2004/12/31 07:17:43 spestov Exp $
./library/cons.factor:! $Id: cons.factor,v 1.12 2005/01/01 22:20:46 spestov Exp $
./library/bootstrap/boot-stage2.factor:! $Id: boot-stage2.factor,v 1.31 2004/12/31 07:17:43 spestov Exp $
./library/bootstrap/win32-io.factor:! $Id: win32-io.factor,v 1.3 2004/12/29 07:15:59 eiz Exp $
./library/bootstrap/image.factor:! $Id: image.factor,v 1.15 2005/01/01 22:20:47 spestov Exp $
./library/bootstrap/init-stage2.factor:! $Id: init-stage2.factor,v 1.23 2004/12/29 08:35:43 spestov Exp $
./library/bootstrap/primitives.factor:! $Id: primitives.factor,v 1.11 2005/01/01 22:20:47 spestov Exp $
./library/bootstrap/init.factor:! $Id: init.factor,v 1.6 2004/12/24 04:55:21 spestov Exp $
./library/bootstrap/boot.factor:! $Id: boot.factor,v 1.16 2004/12/31 23:51:30 spestov Exp $
./library/sdl/sdl-video.factor:! $Id: sdl-video.factor,v 1.13 2004/12/25 23:08:19 spestov Exp $
./library/httpd/url-encoding.factor:! $Id: url-encoding.factor,v 1.14 2005/01/13 22:28:27 spestov Exp $
./library/inference/dataflow.factor:! $Id: dataflow.factor,v 1.23 2005/01/14 19:56:13 spestov Exp $
./library/inference/test.factor:! $Id: test.factor,v 1.2 2005/01/13 22:28:28 spestov Exp $
./library/inference/stack.factor:! $Id: stack.factor,v 1.12 2005/01/16 22:58:25 spestov Exp $
./library/inference/inference.factor:! $Id: inference.factor,v 1.35 2005/02/09 03:02:41 spestov Exp $
./library/bootstrap/win32-io.factor:! $Id: win32-io.factor,v 1.4 2005/02/07 14:46:56 eiz Exp $
./library/bootstrap/image.factor:! $Id: image.factor,v 1.25 2005/02/10 00:58:52 spestov Exp $
./library/bootstrap/init.factor:! $Id: init.factor,v 1.8 2005/02/07 23:04:34 eiz Exp $
./library/sdl/sdl-video.factor:! $Id: sdl-video.factor,v 1.14 2005/01/23 21:47:28 spestov Exp $
./library/sdl/sdl.factor:! $Id: sdl.factor,v 1.5 2004/12/18 05:38:51 spestov Exp $
./library/sdl/sdl-gfx.factor:! $Id: sdl-gfx.factor,v 1.5 2004/12/18 04:02:19 spestov Exp $
./library/sdl/sdl-utils.factor:! $Id: sdl-utils.factor,v 1.8 2004/12/26 23:52:58 spestov Exp $
./library/sdl/sdl-keysym.factor:! $Id: sdl-keysym.factor,v 1.1 2004/11/10 02:51:43 spestov Exp $
./library/sdl/sdl-keyboard.factor:! $Id: sdl-keyboard.factor,v 1.1 2004/12/26 23:52:58 spestov Exp $
./library/sdl/sdl-event.factor:! $Id: sdl-event.factor,v 1.9 2004/12/18 04:02:19 spestov Exp $
./library/tools/jedit-wire.factor:! $Id: jedit-wire.factor,v 1.10 2005/01/01 22:20:48 spestov Exp $
./library/tools/heap-stats.factor:! $Id: heap-stats.factor,v 1.6 2004/12/29 08:35:46 spestov Exp $
./library/tools/debugger.factor:! $Id: debugger.factor,v 1.20 2004/12/29 08:35:45 spestov Exp $
./library/sdl/sdl-keysym.factor:! $Id: sdl-keysym.factor,v 1.3 2005/01/14 00:49:45 spestov Exp $
./library/sdl/sdl-event.factor:! $Id: sdl-event.factor,v 1.11 2005/02/04 03:21:51 spestov Exp $
./library/tools/jedit-wire.factor:! $Id: jedit-wire.factor,v 1.12 2005/02/15 03:15:02 spestov Exp $
./library/tools/profiler.factor:! $Id: profiler.factor,v 1.2 2004/12/11 00:29:07 spestov Exp $
./library/tools/jedit.factor:! $Id: jedit.factor,v 1.3 2004/12/19 08:04:03 spestov Exp $
./library/tools/listener.factor:! $Id: listener.factor,v 1.13 2005/01/02 21:31:43 spestov Exp $
./library/tools/interpreter.factor:! $Id: interpreter.factor,v 1.13 2005/01/01 23:02:23 spestov Exp $
./library/tools/word-tools.factor:! $Id: word-tools.factor,v 1.7 2005/01/01 22:20:48 spestov Exp $
./library/tools/telnetd.factor:! $Id: telnetd.factor,v 1.5 2004/12/29 08:35:46 spestov Exp $
./library/hashtables.factor:! $Id: hashtables.factor,v 1.15 2004/12/28 05:04:19 spestov Exp $
./library/syntax/prettyprint.factor:! $Id: prettyprint.factor,v 1.12 2004/12/29 23:01:22 spestov Exp $
./library/syntax/see.factor:! $Id: see.factor,v 1.7 2004/12/30 07:40:14 spestov Exp $
./library/syntax/parse-syntax.factor:! $Id: parse-syntax.factor,v 1.7 2004/12/15 21:57:29 spestov Exp $
./library/syntax/parse-numbers.factor:! $Id: parse-numbers.factor,v 1.4 2004/12/19 04:18:32 spestov Exp $
./library/syntax/parse-stream.factor:! $Id: parse-stream.factor,v 1.4 2004/12/29 08:35:45 spestov Exp $
./library/syntax/parser.factor:! $Id: parser.factor,v 1.5 2004/12/29 08:35:45 spestov Exp $
./library/syntax/unparser.factor:! $Id: unparser.factor,v 1.8 2004/12/29 08:35:45 spestov Exp $
./library/gensym.factor:! $Id: gensym.factor,v 1.4 2004/12/29 08:35:43 spestov Exp $
./library/strings.factor:! $Id: strings.factor,v 1.29 2004/12/31 07:17:43 spestov Exp $
./library/in-thread.factor:! $Id: in-thread.factor,v 1.4 2004/12/26 02:28:46 spestov Exp $
./library/cli.factor:! $Id: cli.factor,v 1.10 2004/12/29 08:35:43 spestov Exp $
./library/eval-catch.factor:! $Id: eval-catch.factor,v 1.5 2004/12/26 02:28:46 spestov Exp $
./library/threads.factor:! $Id: threads.factor,v 1.4 2004/12/27 11:56:05 eiz Exp $
./library/sbuf.factor:! $Id: sbuf.factor,v 1.15 2004/12/19 08:04:01 spestov Exp $
./library/namespaces.factor:! $Id: namespaces.factor,v 1.21 2004/12/29 08:35:43 spestov Exp $
./library/io/vocabulary-style.factor:! $Id: vocabulary-style.factor,v 1.2 2004/12/11 00:29:04 spestov Exp $
./library/io/ansi.factor:! $Id: ansi.factor,v 1.8 2004/12/29 08:35:45 spestov Exp $
./library/io/win32-io-internals.factor:! $Id: win32-io-internals.factor,v 1.4 2004/12/29 07:16:03 eiz Exp $
./library/io/network.factor:! $Id: network.factor,v 1.5 2004/12/27 11:56:05 eiz Exp $
./library/io/win32-stream.factor:! $Id: win32-stream.factor,v 1.6 2005/01/02 21:14:21 eiz Exp $
./library/syntax/parse-stream.factor:! $Id: parse-stream.factor,v 1.6 2005/02/15 03:15:01 spestov Exp $
./library/io/vocabulary-style.factor:! $Id: vocabulary-style.factor,v 1.4 2005/02/14 21:44:15 doublec Exp $
./library/io/win32-io-internals.factor:! $Id: win32-io-internals.factor,v 1.8 2005/02/15 03:15:01 spestov Exp $
./library/io/win32-stream.factor:! $Id: win32-stream.factor,v 1.10 2005/02/18 08:48:56 eiz Exp $
./library/io/stdio-binary.factor:! $Id: stdio-binary.factor,v 1.2 2004/12/11 00:29:04 spestov Exp $
./library/io/io-internals.factor:! $Id: io-internals.factor,v 1.5 2004/12/27 11:56:05 eiz Exp $
./library/io/presentation.factor:! $Id: presentation.factor,v 1.3 2004/12/20 20:29:54 spestov Exp $
./library/io/stream-impl.factor:! $Id: stream-impl.factor,v 1.5 2004/12/11 23:18:42 spestov Exp $
./library/io/buffer.factor:! $Id: buffer.factor,v 1.4 2005/01/02 21:14:21 eiz Exp $
./library/io/stream.factor:! $Id: stream.factor,v 1.8 2004/12/29 08:35:45 spestov Exp $
./library/io/files.factor:! $Id: files.factor,v 1.5 2005/01/01 22:20:47 spestov Exp $
./library/io/logging.factor:! $Id: logging.factor,v 1.3 2004/12/11 00:29:04 spestov Exp $
./library/io/stdio.factor:! $Id: stdio.factor,v 1.8 2004/12/29 08:35:45 spestov Exp $
./library/io/win32-console.factor:! $Id: win32-console.factor,v 1.5 2004/12/29 08:35:45 spestov Exp $
./library/io/win32-server.factor:! $Id: win32-server.factor,v 1.3 2005/01/02 21:14:21 eiz Exp $
./factor/ExternalFactor.java: * $Id: ExternalFactor.java,v 1.12 2005/01/02 21:22:11 spestov Exp $
./library/io/io-internals.factor:! $Id: io-internals.factor,v 1.7 2005/02/15 03:15:01 spestov Exp $
./library/io/presentation.factor:! $Id: presentation.factor,v 1.5 2005/02/15 03:15:01 spestov Exp $
./library/io/buffer.factor:! $Id: buffer.factor,v 1.5 2005/02/12 07:23:38 eiz Exp $
./library/io/logging.factor:! $Id: logging.factor,v 1.6 2005/02/15 03:15:01 spestov Exp $
./library/io/win32-server.factor:! $Id: win32-server.factor,v 1.8 2005/02/18 08:48:56 eiz Exp $
./factor/ExternalFactor.java: * $Id: ExternalFactor.java,v 1.16 2005/02/17 02:54:35 spestov Exp $
./factor/math/Complex.java: * $Id: Complex.java,v 1.1.1.1 2004/07/16 06:26:13 spestov Exp $
./factor/math/FactorNumber.java: * $Id: FactorNumber.java,v 1.1.1.1 2004/07/16 06:26:12 spestov Exp $
./factor/math/NumberParser.java: * $Id: NumberParser.java,v 1.2 2004/08/07 22:45:47 spestov Exp $
./factor/math/Ratio.java: * $Id: Ratio.java,v 1.1.1.1 2004/07/16 06:26:13 spestov Exp $
./factor/math/FactorMath.java: * $Id: FactorMath.java,v 1.2 2004/08/26 23:37:16 spestov Exp $
./factor/FactorExternalizable.java: * $Id: FactorExternalizable.java,v 1.1.1.1 2004/07/16 06:26:06 spestov Exp $
./factor/FactorArray.java: * $Id: FactorArray.java,v 1.7 2004/11/20 21:56:59 spestov Exp $
./factor/FactorSymbolDefinition.java:* $Id: FactorSymbolDefinition.java,v 1.4 2004/12/06 00:42:55 spestov Exp $
./factor/FactorArray.java: * $Id: FactorArray.java,v 1.8 2005/01/07 19:37:20 spestov Exp $
./factor/FactorLib.java: * $Id: FactorLib.java,v 1.8 2004/11/17 04:04:50 spestov Exp $
./factor/ReadTable.java: * $Id: ReadTable.java,v 1.4 2004/09/06 00:14:36 spestov Exp $
./factor/FactorReader.java: * $Id: FactorReader.java,v 1.15 2004/12/20 21:06:42 spestov Exp $
./factor/FactorReader.java: * $Id: FactorReader.java,v 1.17 2005/01/21 04:10:37 spestov Exp $
./factor/FactorParsingDefinition.java: * $Id: FactorParsingDefinition.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/FactorTraitsDefinition.java:* $Id: FactorTraitsDefinition.java,v 1.1 2004/12/06 00:42:55 spestov Exp $
./factor/Cons.java: * $Id: Cons.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/FactorGenericDefinition.java:* $Id: FactorGenericDefinition.java,v 1.1 2004/12/06 00:42:55 spestov Exp $
./factor/FactorCompoundDefinition.java:* $Id: FactorCompoundDefinition.java,v 1.7 2004/12/06 00:42:55 spestov Exp $
./factor/DefaultVocabularyLookup.java: * $Id: DefaultVocabularyLookup.java,v 1.5 2004/12/20 00:36:10 spestov Exp $
./factor/Cons.java: * $Id: Cons.java,v 1.5 2005/01/14 00:49:42 spestov Exp $
./factor/DefaultVocabularyLookup.java: * $Id: DefaultVocabularyLookup.java,v 1.11 2005/02/17 02:54:35 spestov Exp $
./factor/parser/ComplexLiteral.java: * $Id: ComplexLiteral.java,v 1.4 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Base.java: * $Id: Base.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Symbol.java: * $Id: Symbol.java,v 1.5 2004/12/06 00:42:55 spestov Exp $
./factor/parser/NoParsing.java: * $Id: NoParsing.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Traits.java: * $Id: Traits.java,v 1.3 2004/12/20 02:07:16 spestov Exp $
./factor/parser/StringLiteral.java: * $Id: StringLiteral.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Bar.java: * $Id: Bar.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/BeginMethod.java: * $Id: BeginMethod.java,v 1.3 2004/12/23 03:16:44 spestov Exp $
./factor/parser/Def.java: * $Id: Def.java,v 1.8 2004/12/06 00:42:55 spestov Exp $
./factor/parser/BeginMethod.java: * $Id: BeginMethod.java,v 1.4 2005/01/07 19:37:21 spestov Exp $
./factor/parser/Tuple.java: * $Id: Tuple.java,v 1.2 2005/02/06 03:51:40 spestov Exp $
./factor/parser/Def.java: * $Id: Def.java,v 1.9 2005/01/07 19:37:21 spestov Exp $
./factor/parser/F.java: * $Id: F.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/CharLiteral.java: * $Id: CharLiteral.java,v 1.6 2004/11/17 04:04:50 spestov Exp $
./factor/parser/LineComment.java: * $Id: LineComment.java,v 1.4 2004/11/19 22:28:23 spestov Exp $
./factor/parser/BeginUnion.java: * $Id: BeginUnion.java,v 1.1 2005/01/07 19:37:21 spestov Exp $
./factor/parser/Using.java: * $Id: Using.java,v 1.2 2005/01/29 21:39:29 spestov Exp $
./factor/parser/T.java: * $Id: T.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/StackComment.java: * $Id: StackComment.java,v 1.4 2004/11/19 22:28:23 spestov Exp $
./factor/parser/BeginConstructor.java: * $Id: BeginConstructor.java,v 1.1 2004/12/12 21:32:46 spestov Exp $
./factor/parser/Generic.java: * $Id: Generic.java,v 1.1 2004/12/06 00:42:55 spestov Exp $
./factor/parser/BeginConstructor.java: * $Id: BeginConstructor.java,v 1.2 2005/01/07 19:37:21 spestov Exp $
./factor/parser/Definer.java: * $Id: Definer.java,v 1.1 2005/01/07 00:10:00 spestov Exp $
./factor/parser/PushWord.java: * $Id: PushWord.java,v 1.2 2004/11/17 04:04:50 spestov Exp $
./factor/parser/BeginPredicate.java: * $Id: BeginPredicate.java,v 1.1 2005/01/07 19:37:21 spestov Exp $
./factor/parser/BeginCons.java: * $Id: BeginCons.java,v 1.1 2005/01/14 00:49:43 spestov Exp $
./factor/parser/Use.java: * $Id: Use.java,v 1.4 2004/11/17 04:04:50 spestov Exp $
./factor/parser/EndVector.java: * $Id: EndVector.java,v 1.2 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Ket.java: * $Id: Ket.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Defer.java: * $Id: Defer.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/Ine.java: * $Id: Ine.java,v 1.8 2004/12/06 00:42:55 spestov Exp $
./factor/parser/Ine.java: * $Id: Ine.java,v 1.10 2005/01/07 19:37:21 spestov Exp $
./factor/parser/EndCons.java: * $Id: EndCons.java,v 1.1 2005/01/14 00:49:43 spestov Exp $
./factor/parser/Bra.java: * $Id: Bra.java,v 1.3 2004/11/17 04:04:50 spestov Exp $
./factor/parser/In.java: * $Id: In.java,v 1.5 2004/12/12 21:32:46 spestov Exp $
./factor/parser/BeginVector.java: * $Id: BeginVector.java,v 1.2 2004/11/17 04:04:50 spestov Exp $
./factor/FactorWord.java: * $Id: FactorWord.java,v 1.10 2004/12/05 23:33:19 spestov Exp $
./factor/VocabularyLookup.java: * $Id: VocabularyLookup.java,v 1.3 2004/12/20 00:36:10 spestov Exp $
./factor/jedit/FactorAsset.java: * $Id: FactorAsset.java,v 1.5 2004/11/19 22:28:23 spestov Exp $
./factor/FactorWord.java: * $Id: FactorWord.java,v 1.11 2005/01/07 00:09:59 spestov Exp $
./factor/VocabularyLookup.java: * $Id: VocabularyLookup.java,v 1.4 2005/02/17 02:54:35 spestov Exp $
./factor/jedit/AbstractCompletion.java: * $Id: AbstractCompletion.java,v 1.1 2005/02/17 02:54:36 spestov Exp $
./factor/jedit/FactorVocabCompletion.java: * $Id: FactorVocabCompletion.java,v 1.1 2005/02/17 02:54:36 spestov Exp $
./factor/jedit/FactorAsset.java: * $Id: FactorAsset.java,v 1.6 2005/01/07 00:09:59 spestov Exp $
./factor/jedit/InferBufferProcessor.java: * $Id: InferBufferProcessor.java,v 1.3 2005/01/24 02:53:55 spestov Exp $
./factor/jedit/FactorParsedData.java: * $Id: FactorParsedData.java,v 1.4 2004/12/19 06:48:31 spestov Exp $
./factor/jedit/RestartableFactorScanner.java: * $Id: RestartableFactorScanner.java,v 1.3 2004/12/12 21:32:46 spestov Exp $
./factor/jedit/FactorSideKickParser.java: * $Id: FactorSideKickParser.java,v 1.22 2004/12/24 04:55:21 spestov Exp $
./factor/jedit/EditWordDialog.java: * $Id: EditWordDialog.java,v 1.6 2004/12/20 00:36:10 spestov Exp $
./factor/jedit/FactorPlugin.java: * $Id: FactorPlugin.java,v 1.39 2005/01/02 21:31:43 spestov Exp $
./factor/jedit/FactorSideKickParser.java: * $Id: FactorSideKickParser.java,v 1.26 2005/02/17 02:54:36 spestov Exp $
./factor/jedit/EditWordDialog.java: * $Id: EditWordDialog.java,v 1.7 2005/02/17 02:54:36 spestov Exp $
./factor/jedit/FactorPlugin.java: * $Id: FactorPlugin.java,v 1.45 2005/02/18 02:19:26 spestov Exp $
./factor/jedit/FactorOptionPane.java: * $Id: FactorOptionPane.java,v 1.2 2004/11/27 03:23:55 spestov Exp $
./factor/jedit/FactorShell.java: * $Id: FactorShell.java,v 1.10 2004/12/29 23:01:22 spestov Exp $
./factor/jedit/FactorCompletion.java: * $Id: FactorCompletion.java,v 1.9 2004/12/31 01:46:19 spestov Exp $
./factor/jedit/WordPreview.java: * $Id: WordPreview.java,v 1.9 2004/12/05 23:33:19 spestov Exp $
./factor/jedit/FactorShell.java: * $Id: FactorShell.java,v 1.11 2005/02/10 22:36:19 spestov Exp $
./factor/jedit/WordPreview.java: * $Id: WordPreview.java,v 1.12 2005/02/17 02:54:36 spestov Exp $
./factor/jedit/WordListDialog.java: * $Id: WordListDialog.java,v 1.4 2004/12/20 02:06:55 spestov Exp $
./factor/jedit/WordPopup.java: * $Id: WordPopup.java,v 1.1 2004/12/20 23:02:42 spestov Exp $
./factor/jedit/ListenerAttributeSet.java: * $Id: ListenerAttributeSet.java,v 1.4 2004/11/26 04:14:16 spestov Exp $
./factor/jedit/FactorWordRenderer.java: * $Id: FactorWordRenderer.java,v 1.13 2004/12/06 00:42:55 spestov Exp $
./factor/jedit/ListenerAttributeSet.java: * $Id: ListenerAttributeSet.java,v 1.5 2005/01/07 19:37:21 spestov Exp $
./factor/jedit/FactorBufferProcessor.java: * $Id: FactorBufferProcessor.java,v 1.4 2005/01/24 02:53:55 spestov Exp $
./factor/jedit/CompileBufferProcessor.java: * $Id: CompileBufferProcessor.java,v 1.2 2005/01/24 02:53:55 spestov Exp $
./factor/jedit/FactorWordRenderer.java: * $Id: FactorWordRenderer.java,v 1.14 2005/01/07 00:10:00 spestov Exp $
./factor/jedit/TextAreaPopup.java: * $Id: TextAreaPopup.java,v 1.1 2005/01/08 05:15:35 spestov Exp $
./factor/jedit/InsertUseDialog.java: * $Id: InsertUseDialog.java,v 1.3 2004/09/04 05:05:49 spestov Exp $
./factor/FactorWordDefinition.java: * $Id: FactorWordDefinition.java,v 1.6 2004/12/06 00:42:55 spestov Exp $
./factor/jedit/FactorWordCompletion.java: * $Id: FactorWordCompletion.java,v 1.1 2005/02/17 02:54:36 spestov Exp $
./factor/FactorStream.java: * $Id: FactorStream.java,v 1.1 2004/11/19 04:23:12 spestov Exp $
./factor/FactorMethodDefinition.java: * $Id: FactorMethodDefinition.java,v 1.1 2004/12/06 00:42:55 spestov Exp $
./factor/FactorMethodDefinition.java: * $Id: FactorMethodDefinition.java,v 1.2 2005/01/07 00:09:59 spestov Exp $
./factor/FactorScanner.java: * $Id: FactorScanner.java,v 1.7 2004/12/05 23:33:19 spestov Exp $
./factor/FactorParseException.java: * $Id: FactorParseException.java,v 1.3 2004/08/13 22:43:03 spestov Exp $
./factor/FactorException.java: * $Id: FactorException.java,v 1.1.1.1 2004/07/16 06:26:06 spestov Exp $
./examples/quadratic.factor:! $Id: quadratic.factor,v 1.3 2004/12/11 02:39:27 spestov Exp $
./native/s48_bignum.c:$Id: s48_bignum.c,v 1.7 2004/12/11 02:39:45 spestov Exp $
./native/s48_bignumint.h:$Id: s48_bignumint.h,v 1.9 2004/12/11 02:46:41 spestov Exp $
./native/s48_bignumint.h:$Id: s48_bignumint.h,v 1.10 2005/01/28 01:06:10 spestov Exp $
./native/s48_bignum.h:$Id: s48_bignum.h,v 1.7 2004/12/11 02:46:41 spestov Exp $

View File

@ -1,10 +1,14 @@
CC = gcc
DEFAULT_CFLAGS = -Wall -g $(SITE_CFLAGS)
DEFAULT_CFLAGS = -Wall -Os -fomit-frame-pointer $(SITE_CFLAGS)
DEFAULT_LIBS = -lm
STRIP = strip
OBJS = native/arithmetic.o native/array.o native/bignum.o \
UNIX_OBJS = native/unix/file.o native/unix/io.o native/unix/socket.o \
native/unix/signal.o native/unix/read.o native/unix/write.o \
native/unix/ffi.o native/unix/run.o
OBJS = $(UNIX_OBJS) native/arithmetic.o native/array.o native/bignum.o \
native/s48_bignum.o \
native/complex.o native/cons.o native/error.o \
native/factor.o native/fixnum.o \
@ -17,14 +21,8 @@ OBJS = native/arithmetic.o native/array.o native/bignum.o \
native/string.o native/types.o native/vector.o \
native/word.o native/compiler.o \
native/ffi.o native/boolean.o \
native/unix/file.o \
native/unix/io.o \
native/unix/socket.o \
native/unix/signal.o \
native/unix/read.o \
native/unix/write.o \
native/unix/ffi.o \
native/debug.o
native/debug.o \
native/hashtable.o
default:
@echo "Run 'make' with one of the following parameters:"
@ -34,6 +32,7 @@ default:
@echo "linux"
@echo "macosx"
@echo "solaris"
@echo "windows"
@echo ""
@echo "Also, you might want to set the SITE_CFLAGS environment"
@echo "variable to enable some CPU-specific optimizations; this"
@ -54,12 +53,12 @@ bsd-nopthread:
macosx:
$(MAKE) f \
CFLAGS="$(DEFAULT_CFLAGS) -DFFI" \
LIBS="$(DEFAULT_LIBS)"
LIBS="$(DEFAULT_LIBS)"
linux:
$(MAKE) f \
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
LIBS="$(DEFAULT_LIBS) -ldl"
LIBS="$(DEFAULT_LIBS) -ldl"
solaris:
$(MAKE) f \
@ -68,7 +67,7 @@ solaris:
f: $(OBJS)
$(CC) $(LIBS) $(CFLAGS) -o $@ $(OBJS)
#$(STRIP) $@
$(STRIP) $@
clean:
rm -f $(OBJS)

52
Makefile.win32 Normal file
View File

@ -0,0 +1,52 @@
CC = gcc
DEFAULT_CFLAGS = -Wall -Os -fomit-frame-pointer $(SITE_CFLAGS)
DEFAULT_LIBS = -lm
STRIP = strip
WIN32_OBJS = native\win32\ffi.o native\win32\file.o native\win32\io.o \
native\win32\misc.o native\win32\read.o native\win32\write.o \
native\win32\run.o
OBJS = $(WIN32_OBJS) native\arithmetic.o native\array.o native\bignum.o \
native\s48_bignum.o \
native\complex.o native\cons.o native\error.o \
native\factor.o native\fixnum.o \
native\float.o native\gc.o \
native\image.o native\memory.o \
native\misc.o native\port.o native\primitives.o \
native\ratio.o native\relocate.o \
native\run.o \
native\sbuf.o native\stack.o \
native\string.o native\types.o native\vector.o \
native\word.o native\compiler.o \
native\ffi.o native\boolean.o \
native\debug.o \
native\hashtable.o
default:
@echo "Run 'make' with one of the following parameters:"
@echo ""
@echo "windows"
@echo ""
@echo "Also, you might want to set the SITE_CFLAGS environment"
@echo "variable to enable some CPU-specific optimizations; this"
@echo "can make a huge difference. Eg:"
@echo ""
@echo "export SITE_CFLAGS=\"-march=pentium4 -ffast-math\""
windows:
$(MAKE) -f Makefile.win32 f \
CFLAGS="$(DEFAULT_CFLAGS) -DFFI -DWIN32" \
LIBS="$(DEFAULT_LIBS)"
f: $(OBJS)
$(CC) $(LIBS) $(CFLAGS) -o $@ $(OBJS)
$(STRIP) $@
clean:
del $(OBJS)
.c.o:
$(CC) -c $(CFLAGS) -o $@ $<

View File

@ -1,20 +0,0 @@
FACTOR ON WINDOWS
The Windows port of Factor requires Windows 2000 or later. If you are
using Windows 95, 98 or NT, you might be able to get the Unix port of
Factor running inside Cygwin. Or you might not.
A precompiled factor.exe is included with the download, along with
SDL.dll and SDL_gfx.dll. The SDL libraries are required for the
interactive interpreter. Factor does not use the Windows console,
because it does not support asynchronous I/O.
To run the Windows port, open a DOS prompt and type:
cd <directory where Factor is installed>
factor.exe boot.image.le32
... Files are loaded and factor.image is written.
factor.exe factor.image
... Factor starts the SDL console now.

View File

@ -1,56 +1,63 @@
+ compiler:
72/73:
- update plugin docs
- word preview for remote words
- faster completion
- [ [ dup call ] dup call ] infer hangs
- type inference fails with some assembler words;
displaced, register and other predicates need to inherit from list
not cons, and need stronger branch partial eval
- print warning on null class
- optimize away dispatch
- getenv/setenv: if literal arg, compile as a load/store
- assembler opcodes dispatch on operand types
+ oop:
- move tuple to generic vocab
- make see work with union, builtin, predicate
- doc comments of generics
- vectors: ensure its ok with bignum indices
- code gc
- ppc register decls
+ ffi:
- #jump-f #jump-f-label
- extract word inside M:, C:, and structure browsing for these
- fix checkbox alignment
- each-slot combinator
- references primitive
- resize window: world not updated until mouse moved
- x>offset
- fix completion invoke in middle of word
- don't hardcode so many colors
- ffi unicode strings: null char security hole
- utf16 string boxing
- sdl console crash
- UI: don't roll over if mouse button is down
- more accurate types for various words
- optimize out >array, >tuple, >hashtable etc
- write read: write should flush
- figure out how to load an image referring to missing libraries
+ compiler/ffi:
- value type structs
- out parameters
- is signed -vs- unsigned pointers an issue?
- bitfields in C structs
- SDL_Rect** type
- struct membres that are not *
- FFI float types
+ listener/plugin:
+ i/o:
- WordPreview calls markTokens() -> NPE
- stream server can hang because of exception handler limitations
- listener should be multithreaded
- compile all, infer all commands
- faster completion
- errors don't always disappear
- NPE in ErrorHighlight
- maple-like: press enter at old commands to evaluate there
- completion in the listener
- special completion for USE:/IN:
- better i/o scheduler
- nicer way to combine two paths
- add a socket timeout
- unix ffi i/o
+ kernel:
- do partial objects cause problems?
- better i/o scheduler
- remove sbufs
- cat, reverse-cat primitives
- first-class hashtables
- add a socket timeout
+ misc:
- perhaps /i should work with all numbers
- unit test weirdness: 2 lines appears at end
- jedit ==> jedit-word, jedit takes a file name
- nicer way to combine two paths
- browser responder for word links in HTTPd
- generational gc
- make see work with union, builtin, predicate
- doc comments of generics
- proper ordering for classes
- make-vector and make-string should not need a reverse step
- worddef props
- prettyprint: when unparse called due to recursion, write a link
+ httpd:
- log with date
- file responder; last-modified field

View File

@ -49,7 +49,7 @@
</ACTION>
<ACTION NAME="factor-see">
<CODE>
WordPopup.showWordPopup(textArea);
FactorPlugin.factorWordPopupOp(view,"see");
</CODE>
</ACTION>
<ACTION NAME="factor-edit">
@ -82,4 +82,24 @@
FactorPlugin.extractWord(view);
</CODE>
</ACTION>
<ACTION NAME="factor-infer-effect">
<CODE>
FactorPlugin.factorWordPopupOp(view,"unit infer .");
</CODE>
</ACTION>
<ACTION NAME="factor-compile">
<CODE>
FactorPlugin.factorWordOutputOp(view,"recompile");
</CODE>
</ACTION>
<ACTION NAME="factor-infer-effects">
<CODE>
InferBufferProcessor.createInferUnitTests(view,buffer);
</CODE>
</ACTION>
<ACTION NAME="factor-compile-all">
<CODE>
new CompileBufferProcessor(view,buffer);
</CODE>
</ACTION>
</ACTIONS>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -39,7 +39,6 @@ USE: random
USE: parser
USE: html
USE: cont-responder
USE: cont-utils
USE: stdio
USE: namespaces

View File

@ -39,7 +39,7 @@
! eg.
! <cont-test-state> [ test-cont-responder ] test-cont-function
! => HTTP/1.1 302 Document Moved
! Location: 8506502852110820
! Location: ?id=8506502852110820
! Content-Length: 0
! Content-Type: text/plain
!
@ -48,12 +48,12 @@
! Content-Type: text/html
!
! <html><head><title>Page one</title></head><body>
! <h1>Page one</h1><a href='5431597582800278'>Next</a>
! <h1>Page one</h1><a href='?id=5431597582800278'>Next</a>
! </body></html>
!
! "5431597582800278" f test-cont-click
! => HTTP/1.1 302 Document Moved
! Location: 7944183606904129
! Location: ?id=7944183606904129
! Content-Length: 0
! Content-Type: text/plain
!
@ -63,14 +63,14 @@
!
! <html><head><title>Enter your name</title></head>
! <body><h1>Enter your name</h1>
! <form method='post'action='8503790719833723'>
! Name: <input type='text'name='name'size='20'>
! <input type='submit'value='Ok'>
! <form method='post' action='?id=8503790719833723'>
! Name: <input type='text' name='name'size='20'>
! <input type='submit' value='Ok'>
! </form></body></html>
!
! "8503790719833723" [ [ "name" | "Chris" ] ] alist>hash test-cont-click
! "8503790719833723" [ [[ "name" "Chris" ]] ] alist>hash test-cont-click
! => HTTP/1.1 302 Document Moved
! Location: 8879727708050260
! Location: ?id=8879727708050260
! Content-Length: 0
! Content-Type: text/plain
!
@ -80,7 +80,7 @@
!
! <html><head><title>Hello Chris</title></head>
! <body><h1>Hello Chris</h1>
! <a href='0937854264503953'>Next</a>
! <a href='?id=0937854264503953'>Next</a>
! </body></html>
!
! etc.

View File

@ -1,91 +0,0 @@
! Copyright (C) 2004 Chris Double.
!
! 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.
!
! General purpose words for display pages using the continuation
! based responder.
IN: cont-utils
USE: html
USE: cont-responder
USE: lists
USE: stdio
USE: kernel
USE: namespaces
USE: html
: simple-page ( title quot -- )
#! Call the quotation, with all output going to the
#! body of an html page with the given title.
<html>
<head> <title> swap write </title> </head>
<body> call </body>
</html> ;
: styled-page ( title stylesheet-quot quot -- )
#! Call the quotation, with all output going to the
#! body of an html page with the given title. stylesheet-quot
#! is called to generate the required stylesheet.
<html>
<head>
<title> rot write </title>
swap call
</head>
<body> call </body>
</html> ;
: paragraph ( str -- )
#! Output the string as an html paragraph
<p> write </p> ;
: show-message-page ( message -- )
#! Display the message in an HTML page with an OK button.
[
"Press OK to Continue" [
swap paragraph
<a href= a> "OK" write </a>
] simple-page
] show 2drop ;
: vertical-layout ( list -- )
#! Given a list of HTML components, arrange them vertically.
<table>
[ <tr> <td> call </td> </tr> ] each
</table> ;
: horizontal-layout ( list -- )
#! Given a list of HTML components, arrange them horizontally.
<table>
<tr valign= "top" tr> [ <td> call </td> ] each </tr>
</table> ;
: button ( label -- )
#! Output an HTML submit button with the given label.
<input type= "submit" value= input/> ;
: with-simple-html-output ( quot -- )
#! Run the quotation inside an HTML stream wrapped
#! around stdio.
<pre>
stdio get <html-stream> [
call
] with-stream
</pre> ;

View File

@ -26,7 +26,6 @@
IN: eval-responder
USE: html
USE: cont-responder
USE: cont-utils
USE: kernel
USE: stdio
USE: namespaces
@ -73,7 +72,7 @@ USE: logging
: escape-quotes ( string -- string )
#! Replace occurrences of single quotes with
#! backslash quote.
[ dup [ [ CHAR: ' | "\\'" ] [ CHAR: " | "\\\"" ] ] assoc dup rot ? ] str-map ;
[ dup [ [[ CHAR: ' "\\'" ]] [[ CHAR: " "\\\"" ]] ] assoc dup rot ? ] str-map ;
: make-eval-javascript ( string -- string )
#! Give a string return some javascript that when
@ -110,7 +109,7 @@ USE: logging
#! of the given word.
dup dup
<namespace> [
"responder" "inspect" put
"responder" "browser" put
<table border= "1" table>
<tr> <th colspan= "2" th> "Source" write </th> </tr>
<tr> <td colspan= "2" td> [ [ parse ] [ [ "No such word" write ] [ car see ] ifte ] catch ] with-simple-html-output </td> </tr>
@ -186,8 +185,8 @@ USE: logging
#! All output should go to a string which is returned on the
#! callstack along with the resulting datastack as a list.
<namespace> [
"inspect" "responder" set
1024 <string-output-stream> dup >r <html-stream> [
"browser" "responder" set
1024 <string-output> dup >r <html-stream> [
do-eval
] with-stream r> stream>str
] bind ;

View File

@ -31,7 +31,6 @@ USE: html
USE: words
USE: stdio
USE: kernel
USE: cont-utils
USE: cont-responder
USE: prettyprint
@ -39,7 +38,7 @@ USE: prettyprint
#! Given a string that is a factor word, show the
#! aporpos of that word.
<namespace> [
"responder" "inspect" put
"responder" "browser" put
<pre>
stdio get <html-stream> [
apropos.

View File

@ -35,11 +35,11 @@ USE: lists
: get-live-updater-js* ( stream -- string )
#! Read all lines from the stream, creating a string of the result.
dup freadln dup [ , "\n" , get-live-updater-js* ] [ drop fclose ] ifte ;
dup stream-readln dup [ , "\n" , get-live-updater-js* ] [ drop stream-close ] ifte ;
: get-live-updater-js ( filename -- string )
#! Return the liveUpdater javascript code as a string.
<filecr> [ get-live-updater-js* ] make-string ;
<file-reader> [ get-live-updater-js* ] make-string ;
: live-updater-url ( -- url )
#! Generate an URL to the liveUpdater.js code.
@ -47,7 +47,7 @@ USE: lists
[
"js/liveUpdater.js" get-live-updater-js write
] show
] register-continuation ;
] register-continuation id>url ;
: include-live-updater-js ( -- )
#! Write out the HTML script to include the live updater
@ -96,7 +96,7 @@ USE: lists
"document.getElementById('" write
write
"').onclick=liveUpdaterUri('" write
register-live-anchor-quot write
register-live-anchor-quot id>url write
"');" write
</script> ;
@ -153,7 +153,7 @@ USE: lists
"liveSearch('" write
write
"', '" write
register-live-search-quot write
register-live-search-quot id>url write
"');" write
</script> ;

View File

@ -33,19 +33,23 @@ USE: stdio
USE: parser
: l1
"cont-responder.factor" run-file
"cont-utils.factor" run-file ;
: l2
: l1
"cont-examples.factor" run-file
"cont-numbers-game.factor" run-file ;
: l3 "todo.factor" run-file ;
: l4 "todo-example.factor" run-file ;
: l5 "live-updater.factor" run-file ;
: l6 "eval-responder.factor" run-file ;
: l7 "live-updater-responder.factor" run-file ;
: l8 "browser.factor" run-file ;
: l9 "cont-testing.factor" run-file ;
: la ;
: l2 "todo.factor" run-file ;
: l3 "todo-example.factor" run-file ;
: l4 "live-updater.factor" run-file ;
: l5 "eval-responder.factor" run-file ;
: l6 "live-updater-responder.factor" run-file ;
: l7 "cont-testing.factor" run-file ;
: l8
#! Use for reloading and testing changes to browser responder
#! in factor core.
"../../library/httpd/browser-responder.factor" run-file ;
: l9
#! Use for reloading and testing changes to cont responder
#! in factor core.
"../../library/httpd/cont-responder.factor" run-file ;
DEFER: la
: la [ 8888 httpd ] [ dup . flush [ la ] when* ] catch ;
: lb [ la "httpd thread exited.\n" write flush ] in-thread ;

View File

@ -29,7 +29,6 @@
IN: todo-example
USE: cont-responder
USE: html
USE: cont-utils
USE: html
USE: stdio
USE: strings
@ -107,7 +106,7 @@ USE: kernel
: todo-stylesheet-url ( -- url )
#! Generate an URL for the stylesheet.
t [ [ drop todo-stylesheet write ] show ] register-continuation ;
t [ [ drop todo-stylesheet write ] show ] register-continuation id>url ;
: include-todo-stylesheet ( -- )
#! Generate HTML to include the todo stylesheet

View File

@ -91,22 +91,22 @@ USE: hashtables
: store-todo ( <todo> filename -- )
#! store the todo list in the given file.
<filecw> [ write-todo ] with-stream ;
<file-writer> [ write-todo ] with-stream ;
: read-todo ( -- <todo> )
#! Read a todo list from the current input stream.
read url-decode read url-decode <todo>
read str>number [
read-line url-decode read-line url-decode <todo>
read-line str>number [
dup
<namespace> [
read url-decode "yes" = "complete?" set
read url-decode "priority" set
read url-decode "description" set
read-line url-decode "yes" = "complete?" set
read-line url-decode "priority" set
read-line url-decode "description" set
] extend add-todo-item
] times ;
: load-todo ( filename -- <todo> )
<filecr> [ read-todo ] with-stream ;
<file-reader> [ read-todo ] with-stream ;
: password-matches? ( password <todo> -- <todo> )
#! Returns the <todo> if the password matches otherwise

View File

@ -0,0 +1,228 @@
! Copyright (C) 2005 Chris Double.
!
! 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.
!
! An interface to the sqlite database. Tested against sqlite v3.0.8.
! Remeber to pass the following to factor:
! -libraries:sqlite=libsqlite3.so
!
! Not all functions have been wrapped yet. Only those directly involving
! executing SQL calls and obtaining results.
!
IN: sqlite
USE: kernel
USE: alien
USE: compiler
USE: errors
USE: strings
USE: namespaces
BEGIN-STRUCT: sqlite3
END-STRUCT
BEGIN-STRUCT: sqlite3-indirect
FIELD: sqlite3* pointer
END-STRUCT
BEGIN-STRUCT: sqlite3-stmt
END-STRUCT
BEGIN-STRUCT: sqlite3-stmt-indirect
FIELD: sqlite3-stmt* pointer
END-STRUCT
BEGIN-STRUCT: char*-indirect
FIELD: char* pointer
END-STRUCT
! Return values from sqlite functions
: SQLITE_OK 0 ; ! Successful result
: SQLITE_ERROR 1 ; ! SQL error or missing database
: SQLITE_INTERNAL 2 ; ! An internal logic error in SQLite
: SQLITE_PERM 3 ; ! Access permission denied
: SQLITE_ABORT 4 ; ! Callback routine requested an abort
: SQLITE_BUSY 5 ; ! The database file is locked
: SQLITE_LOCKED 6 ; ! A table in the database is locked
: SQLITE_NOMEM 7 ; ! A malloc() failed
: SQLITE_READONLY 8 ; ! Attempt to write a readonly database
: SQLITE_INTERRUPT 9 ; ! Operation terminated by sqlite_interrupt()
: SQLITE_IOERR 10 ; ! Some kind of disk I/O error occurred
: SQLITE_CORRUPT 11 ; ! The database disk image is malformed
: SQLITE_NOTFOUND 12 ; ! (Internal Only) Table or record not found
: SQLITE_FULL 13 ; ! Insertion failed because database is full
: SQLITE_CANTOPEN 14 ; ! Unable to open the database file
: SQLITE_PROTOCOL 15 ; ! Database lock protocol error
: SQLITE_EMPTY 16 ; ! (Internal Only) Database table is empty
: SQLITE_SCHEMA 17 ; ! The database schema changed
: SQLITE_TOOBIG 18 ; ! Too much data for one row of a table
: SQLITE_CONSTRAINT 19 ; ! Abort due to contraint violation
: SQLITE_MISMATCH 20 ; ! Data type mismatch
: SQLITE_MISUSE 21 ; ! Library used incorrectly
: SQLITE_NOLFS 22 ; ! Uses OS features not supported on host
: SQLITE_AUTH 23 ; ! Authorization denied
: SQLITE_ROW 100 ; ! sqlite_step() has another row ready
: SQLITE_DONE 101 ; ! sqlite_step() has finished executing
! Return values from the sqlite3_column_type function
: SQLITE_INTEGER 1 ;
: SQLITE_FLOAT 2 ;
: SQLITE_TEXT 3 ;
: SQLITE_BLOB 4 ;
: SQLITE_NULL 5 ;
! Values for the 'destructor' parameter of the 'bind' routines.
: SQLITE_STATIC 0 ;
: SQLITE_TRANSIENT -1 ;
: sqlite3_open ( filename sqlite3-indirect -- result )
"int" "sqlite" "sqlite3_open" [ "char*" "sqlite3-indirect*" ] alien-invoke ; compiled
: sqlite3_close ( db -- )
"int" "sqlite" "sqlite3_close" [ "sqlite3*" ] alien-invoke ; compiled
: sqlite3_prepare ( db sql sql-len sqlite3-stmt-indirect tail -- result )
"int" "sqlite" "sqlite3_prepare" [ "sqlite3*" "char*" "int" "sqlite3-stmt-indirect*" "char*-indirect*" ] alien-invoke ; compiled
: sqlite3_finalize ( stmt -- result )
"int" "sqlite" "sqlite3_finalize" [ "sqlite3-stmt*" ] alien-invoke ; compiled
: sqlite3_reset ( stmt -- result )
"int" "sqlite" "sqlite3_reset" [ "sqlite3-stmt*" ] alien-invoke ; compiled
: sqlite3_step ( stmt -- result )
"int" "sqlite" "sqlite3_step" [ "sqlite3-stmt*" ] alien-invoke ; compiled
: sqlite3_bind_blob ( stmt index pointer len destructor -- result )
"int" "sqlite" "sqlite3_bind_blob" [ "sqlite3-stmt*" "int" "void*" "int" "int" ] alien-invoke ; compiled
: sqlite3_bind_int ( stmt index int -- result )
"int" "sqlite" "sqlite3_bind_int" [ "sqlite3-stmt*" "int" "int" ] alien-invoke ; compiled
: sqlite3_bind_null ( stmt index -- result )
"int" "sqlite" "sqlite3_bind_null" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_bind_text ( stmt index text len destructor -- result )
"int" "sqlite" "sqlite3_bind_text" [ "sqlite3-stmt*" "int" "char*" "int" "int" ] alien-invoke ; compiled
: sqlite3_column_count ( stmt -- count )
"int" "sqlite" "sqlite3_column_count" [ "sqlite3-stmt*" ] alien-invoke ; compiled
: sqlite3_column_blob ( stmt col -- void* )
"void*" "sqlite" "sqlite3_column_blob" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_column_bytes ( stmt col -- int )
"int" "sqlite" "sqlite3_column_bytes" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_column_decltype ( stmt col -- string )
"char*" "sqlite" "sqlite3_column_decltype" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_column_int ( stmt col -- int )
"int" "sqlite" "sqlite3_column_int" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_column_name ( stmt col -- string )
"char*" "sqlite" "sqlite3_column_name" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_column_text ( stmt col -- string )
"char*" "sqlite" "sqlite3_column_text" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
: sqlite3_column_type ( stmt col -- int )
"int" "sqlite" "sqlite3_column_type" [ "sqlite3-stmt*" "int" ] alien-invoke ; compiled
! High level sqlite routines
: sqlite-check-result ( result -- )
#! Check the result from a sqlite call is ok. If it is
#! return, otherwise throw an error. TODO: Throw the actual
#! error text message.
dup SQLITE_OK = [
drop
] [
"sqlite returned an error. See datastack for the error value." throw
] ifte ;
: sqlite-open ( filename -- db )
#! Open the database referenced by the filename and return
#! a handle to that database. An error is thrown if the database
#! failed to open.
<sqlite3-indirect> tuck sqlite3_open sqlite-check-result sqlite3-indirect-pointer ;
: sqlite-close ( db -- )
#! Close the given database
sqlite3_close sqlite-check-result ;
: sqlite-prepare ( db sql -- statement )
#! Prepare a SQL statement. Returns the statement which
#! can have values bound to parameters or simply executed.
#! TODO: Support multiple statements in the SQL string.
dup str-length <sqlite3-stmt-indirect> dup >r
<char*-indirect> sqlite3_prepare sqlite-check-result
r> sqlite3-stmt-indirect-pointer ;
: sqlite-finalize ( statement -- )
#! Clean up all resources related to a statement. Once called
#! the statement cannot be used. All statements must be finalized
#! before closing the database.
sqlite3_finalize sqlite-check-result ;
: sqlite-reset ( statement -- )
#! Reset a statement so it can be called again, possibly with
#! different parameters.
sqlite3_reset sqlite-check-result ;
: column-count ( statement -- int )
#! Given a prepared statement, return the number of
#! columns in each row of the result set of that statement.
sqlite3_column_count ;
: column-text ( statement column -- string )
#! Return the value of the given column, indexed
#! from zero, as a string.
sqlite3_column_text ;
: step-complete? ( step-result -- bool )
#! Return true if the result of a sqlite3_step is
#! such that the iteration has completed (ie. it is
#! SQLITE_DONE). Throw an error if an error occurs.
dup SQLITE_ROW = [
drop f
] [
dup SQLITE_DONE = [
drop t
] [
sqlite-check-result
] ifte
] ifte ;
: sqlite-each ( statement quot -- )
#! Execute the SQL statement, and call the quotation for
#! each row returned from executing the statement with the
#! statement on the top of the stack.
over sqlite3_step step-complete? [
2drop
] [
2dup 2slip sqlite-each
] ifte ;
! For comparison, here is the linrec implementation of sqlite-each
! [ drop sqlite3_step step-complete? ]
! [ 2drop ]
! [ 2dup 2slip ]
! [ ] linrec ;

View File

@ -1,8 +1,4 @@
! :folding=indent:collapseFolds=1:
! $Id$
!
! Copyright (C) 2003, 2004 Slava Pestov.
! Copyright (C) 2005 Chris Double.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met:
@ -24,42 +20,36 @@
! 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: lists
!
! Test the sqlite interface
!
! Create a test database like follows:
!
! sqlite3 test.db
! > create table test (name varchar(30), address varchar(30));
! > insert into test values('John', 'America');
! > insert into test values('Jane', 'New Zealand');
! > [eof]
!
! Then run this file.
USE: sqlite
USE: kernel
USE: namespaces
USE: stdio
USE: prettyprint
: cons@ ( x var -- )
#! Prepend x to the list stored in var.
[ cons ] change ;
: show-people ( statement -- )
dup 0 column-text write " from " write 1 column-text . ;
: unique@ ( elem var -- )
#! Prepend an element to the proper list stored in a
#! variable if it is not already contained in the list.
[ unique ] change ;
: run-test ( -- )
"test.db" sqlite-open
dup "select * from test" sqlite-prepare
dup [ show-people ] sqlite-each
sqlite-finalize
sqlite-close ;
SYMBOL: list-buffer
: run-test2 ( -- )
"test.db" sqlite-open
dup "select * from test" sqlite-prepare
dup [ show-people ] ;
: make-rlist ( quot -- list )
#! Call a quotation. The quotation can call , to prepend
#! objects to the list that is returned when the quotation
#! is done.
[ list-buffer off call list-buffer get ] with-scope ;
inline
: make-list ( quot -- list )
#! Return a list whose entries are in the same order that ,
#! was called.
make-rlist reverse ; inline
: , ( obj -- )
#! Append an object to the currently constructing list.
list-buffer cons@ ;
: unique, ( obj -- )
#! Append an object to the currently constructing list, only
#! if the object does not already occur in the list.
list-buffer unique@ ;
: append, ( list -- )
[ , ] each ;
run-test

View File

@ -8,14 +8,14 @@ its drawbacks -- namely, its not portable.
All FFI words are in the "alien" vocabulary.
The basic principle is generating machine stubs from C function
prototypes. The main entry point is the 'alien-call' word, which is
prototypes. The main entry point is the 'alien-invoke' word, which is
defined as simply throwing an error. However, it is given special
compilation behavior. This means it can only be used in compiled words.
Here is an example from sdl-video.factor:
: SDL_LockSurface ( surface -- )
"int" "sdl" "SDL_LockSurface" [ "surface*" ] alien-call ;
"int" "sdl" "SDL_LockSurface" [ "surface*" ] alien-invoke ;
The parameters are:

View File

@ -14,13 +14,10 @@ things work.
Getting Started
===============
To get started you will first need to load the 'cont-responder'
code. You will need the following as a minimum:
To get started you will first need to use the 'cont-responder'
vocabulary:
"cont-responder.factor" run-file
"cont-utils.factor" run-file
USE: cont-responder
USE: cont-utils
The responders that you will be writing will require an instance of
the httpd server to be running. It will be run in a background thread
@ -152,7 +149,7 @@ Dynamic Data
============
Adding dynamic data to the page is relatively easy. This example pulls
a information from the 'room' word which displays memory details about
information from the 'room' word which displays memory details about
the running Factor system. It also uses 'room.' which outputs these
details to standard output and this is wrapped in a <pre> tag so it is
formatted correctly.
@ -331,10 +328,10 @@ sequence the page shows. Any Factor code can be called and the
continuation based system will sequentially display each page. The
back button, browser window cloning, etc will all continue to work.
You'll notice the URL's in the browser have a number at the end of
them. This is the 'continuation identifier' which is like a session id
except that it identifies not just the data you have stored but your
location within the responder as well.
You'll notice the URL's in the browser have an 'id' query parameter with
a number as its value. This is the 'continuation identifier' which is
like a session id except that it identifies not just the data you have
stored but your location within the responder as well.
Forms and POST data
===================
@ -588,9 +585,9 @@ them and expect them to work. The 'show' call for example will fail as
it expects some continuations to in the continuation table for that
responder.
The 'cont-testing.factor' file contains some simple words that
maintains this state for you in such a way that you can test the words
from the console:
The 'cont-testing.factor' file (in the contrib/cont-responder
directory) contains some simple words that maintains this state for
you in such a way that you can test the words from the console:
"cont-testing.factor" run-file
@ -603,7 +600,7 @@ calls the code we want to test and call the 'test-cont-function' word:
<cont-test-state> [ subroutine-example1 ] test-cont-function
=>
HTTP/1.1 302 Document Moved
Location: 8209741119458310
Location: ?id=8209741119458310
Content-Length: 0
Content-Type: text/plain
@ -628,9 +625,9 @@ state on the stack:
Content-Type: text/html
<html><head><title>Subroutine Example 1</title></head>
<body><p>Please select:
<ol><li><a href='7687398605200513'>Flow1</a></li>
<li><a href='7856272029924613'>Flow2</a></li>
<li><a href='4909116160485714'>Flow3</a></li>
<ol><li><a href='?id=7687398605200513'>Flow1</a></li>
<li><a href='?id=7856272029924613'>Flow2</a></li>
<li><a href='?id=4909116160485714'>Flow3</a></li>
</ol>
</p>
</body>
@ -645,7 +642,7 @@ written previously:
<cont-test-state> [ post-example1 ] test-cont-function
=>
HTTP/1.1 302 Document Moved
Location: 5829759941409535
Location: ?id=5829759941409535
Content-Length: 0
Content-Type: text/plain
@ -658,7 +655,7 @@ Again we skip past the forward:
<html><head><title>Please enter your name</title></head>
<body>
<form action='5456539333180428' method='post'>
<form action='?id=5456539333180428' method='post'>
<p>Please enter your name:
<input type='text'size='20'name='username'>
<input type='submit'value='Ok'>

View File

@ -2526,6 +2526,365 @@ USE: vectors
10 <vector> main-menu ;
\end{verbatim}
\chapter{Working with classes}
\section{What is object oriented programming?}
Object oriented programming is a commonly-used term, however many people
define it differently. Most will agree it consists of three key ideas:
\begin{itemize}
\item Objects are small pieces of state with the required identity and
equality semantics, along with runtime information
allowing the object to reflect on itself.
\item Objects are organized in some manner, allowing one to express
that a given set of objects features common behavior or shape. Factor organizes
objects into classes and types, however its definition of these terms is
slightly different from convention.
\item Behavior can be defined on objects, and dispatched in a polymorphic way,
where invoking a generic operation on an object takes action most
appropriate to that object.
\end{itemize}
The separation into three parts is reflected in the design of the Factor
object system.
The following terminology is used in this guide:
\begin{itemize}
\item \emph{Class} -- a class is a set of objects given by a predicate
that distinglishes elements of the class from other objects, along with
some associated meta-information.
\item \emph{Type} -- a type is a concrete representation of an object
in runtime memory. There is only a fixed number of built-in types, such as
integers, strings, and arrays. Each object has a unique type it belongs to,
whereas it may be a member of an arbitrary number of classes.
\end{itemize}
In many languages, a class refers to a specific object organization,
typically a specification form for named slots that objects in the class
shall have. In Factor, the \texttt{tuple} metaclass allows one to create
such conventional objects. However, we will look at generic words
and built-in classes first.
\section{Generic words and methods}
To use the generic word system, you must put the following near the
beginning of your source file:
\begin{verbatim}
USE: generic
\end{verbatim}
The motivation for generic words is that sometimes, you want to write a word that has
differing behavior depending on the class of its argument. For example,
in a game, a \texttt{draw} word could take different action if given a ship, a
weapon, a planet, etc. Writing one large \texttt{draw} word that contains type case logic results in
unnecessary coupling -- adding support for a new type of graphical
object would require modifying the original definition of \texttt{draw}, for
example.
A generic word is a word whose behavior depends on the class of the
object at the top of the stack, however this behavior is defined in a
decentralized manner.
A new generic word is defined using the following syntax:
\begin{verbatim}
GENERIC: draw ( actor -- )
#! Draw the actor.
\end{verbatim}
A stack effect comment, as shown above, is not required but recommended.
A generic word just defined like that will simply raise an error if
invoked. Specific behavior is defined using methods.
A method associates behavior with a generic word. Methods are defined by
writing \texttt{M:}, followed by a class name, followed by the name of a
previously-defined generic word.
One of the main benefits of generic words is that each method definition
can potentially occur in a different source file. Generic word
definitions also hide conditionals.
Here are two methods for the generic \texttt{draw} word:
\begin{verbatim}
M: ship draw ( actor -- )
[
surface get screen-xy radius get color get
filledCircleColor
] bind ;
M: plasma draw ( actor -- )
[
surface get screen-xy dup len get + color get
vlineColor
] bind ;
\end{verbatim}
Here, \texttt{ship} and \texttt{class} are user-defined classes.
Every object is a member of the \texttt{object} class. If you provide a method specializing
on the \texttt{object} class for some generic word, the method will be
invoked when no other more specific method exists. For example:
\begin{verbatim}
GENERIC: describe
M: number describe "The number " write . ;
M: object describe "I don't know anything about " write . ;
\end{verbatim}
\section{Classes}
Recall that in Factor, a class is just a predicate that categorizes objects as
being a member of the class or not. To be useful, it must be consistent
-- for a given object, it must always return the same truth value.
Classes are not always subsets or supersets of types and new classes can be defined by the user. Classes can be quite arbitrary:
\begin{itemize}
\item Cons cells where both elements are integers
\item Floating point numbers between -1 and 1
\item Hash tables holding a certain key
\item Any object that occurs as a member of a certain global variable
holding a list.
\item \... and so on.
\end{itemize}
The building blocks of classes are the various built-in types, and
user-defined tupes. Tuples are covered later in this chapter.
The built-in types each get their own class whose members are precisely
the objects having that type. The following built-in classes are
defined:
\begin{itemize}
\item \texttt{alien}
\item \texttt{array}
\item \texttt{bignum}
\item \texttt{complex}
\item \texttt{cons}
\item \texttt{dll}
\item \texttt{f}
\item \texttt{fixnum}
\item \texttt{float}
\item \texttt{port}
\item \texttt{ratio}
\item \texttt{sbuf}
\item \texttt{string}
\item \texttt{t}
\item \texttt{tuple}
\item \texttt{vector}
\item \texttt{word}
\end{itemize}
Each builtin class has a corresponding membership test predicate, named
after the builtin class suffixed by \texttt{?}. For example, \texttt{cons?}, \texttt{word?}, etc. Automatically-defined predicates is a common theme, and
in fact \emph{every} class has a corresponding predicate word,
with the following
exceptions:
\begin{itemize}
\item \texttt{object} -- there is no need for a predicate word, since
every object is an instance of this class.
\item \texttt{f} -- the only instance of this class is the sigleton
\texttt{f} signifying falsity, missing value, and empty list, and the predicate testing for this is the built-in library word \texttt{not}.
\item \texttt{t} -- the only instance of this class is the canonical truth value
\texttt{t}. You can write \texttt{t =} to test for this object, however usually
any object distinct from \texttt{f} is taken as a truth value, and \texttt{t} is not tested for directly.
\end{itemize}
\section{Metaclasses}
So far, we have only seen predefined classes corresponding to built-in
types. More complicated classes are defined in terms of metaclasses.
This section will describe how to define new classes belonging to
predefined metaclasses.
Just like shared object object traits motivates the existence of classes,
common behavior shared between classes themselves motivates metaclasses.
For example, classes corresponding to built-in types, such as \texttt{fixnum}
and \texttt{string}, are instances of
the \texttt{builtin} metaclass, whereas a user-defined class is not an
instance of \texttt{builtin}.
\subsection{The \texttt{union} metaclass}
The \texttt{union} metaclass allows new classes to be
defined as aggregates of existing classes.
For example, the Factor library defines some unions over numeric types:
\begin{verbatim}
UNION: integer fixnum bignum ;
UNION: rational integer ratio ;
UNION: real rational float ;
UNION: number real complex ;
\end{verbatim}
Now, the absolute value function can be defined in an efficient manner
for real numbers, and in a more general fashion for complex numbers:
\begin{verbatim}
GENERIC: abs ( z -- |z| )
M: real abs dup 0 < [ neg ] when ;
M: complex abs >rect mag2 ;
\end{verbatim}
New unions can be defined as in the numerical classes example:
you write \texttt{UNION:} followed by the name of the union,
followed by its members. The list of members is terminated with a
semi-colon.
A predicate named after the union followed by '?' is
automatically-defined. For example, the following definition of 'real?'
was automatically created:
\begin{verbatim}
: real?
dup rational? [
drop t
] [
dup float? [
drop t
] [
drop f
] ifte
] ifte ;
\end{verbatim}
\subsection{The \texttt{complement} metaclass}
The \texttt{complement} metaclass allows you to define a class whose members
are exactly those not in another class. For example, the class of all
truth values is defined in \texttt{library/kernel.factor} by:
\begin{verbatim}
COMPLEMENT: general-t f
\end{verbatim}
\subsection{The \texttt{predicate} metaclass}
The predicate metaclass contains classes whose membership test is an
arbitrary expression. To speed up dispatch, each predicate must be
defined as a subclass of some other class. That way predicates
subclassing from disjoint builtin classes do not need to be
exhaustively tested.
The source file \texttt{library/strings.factor} defines some subclasses of \texttt{integer}
classifying ASCII characters:
\begin{verbatim}
PREDICATE: integer blank " \t\n\r" str-contains? ;
PREDICATE: integer letter CHAR: a CHAR: z between? ;
PREDICATE: integer LETTER CHAR: A CHAR: Z between? ;
PREDICATE: integer digit CHAR: 0 CHAR: 9 between? ;
PREDICATE: integer printable CHAR: \s CHAR: ~ between? ;
\end{verbatim}
Each predicate defines a corresponding predicate word whose name is
suffixed with '?'; for example, a 'digit?' word is automatically
defined:
\begin{verbatim}
: digit?
dup integer? [
CHAR: 0 CHAR: 9 between?
] [
drop f
] ifte ;
\end{verbatim}
For obvious reasons, the predicate definition must consume and produce
exactly one value on the stack.
\section{Tuples}
Tuples are user-defined classes whose objects consist of named slots.
New tuple classes are defined with the following syntax:
\begin{verbatim}
TUPLE: point x y z ;
\end{verbatim}
This defines a new class named \texttt{point}, along with the
following set of words:
\begin{verbatim}
<point> point?
point-x set-point-x
point-y set-point-y
point-z set-point-z
\end{verbatim}
The word \texttt{<point>} takes the slot values from the stack and
produces a new \texttt{point}:
\begin{alltt}
\textbf{ok} 1 2 3 <point> .
\textbf{<< point 1 2 3 >>}
\end{alltt}
As you can guess from the above, there is a literal syntax for tuples,
and the \texttt{point?}~word tests if the top of the stack is an object
belonging to that class:
\begin{alltt}
\textbf{ok} << point 1 2 3 >> point? .
\textbf{t}
\end{alltt}
The general form of the literal syntax is as follows:
\begin{alltt}
<< \emph{class} \emph{slots} \... >>
\end{alltt}
The syntax consists of the tuple class name followed by the
values of all slots. An error is raised if insufficient or extraneous slot values are specified.
As usual, the distinction between literal syntax and explicit calls is the
time the tuple is created; literals are created at parse time, whereas
explicit constructor calls creates a new object each time the code
runs.
Slots are read and written using the various automatically-defined words with names of the
form \texttt{\emph{class}-\emph{slot}} and \texttt{set-\emph{class}-\emph{slot}}.
\subsection{Constructors}
A tuple constructor is named after the tuple class surrounded in angle
brackets (\texttt{<} and \texttt{>}). A default constructor is provided
that reads slot values from the stack, however a custom constructor can
be defined using the \texttt{C:} parsing word.
\subsection{Delegation}
If a tuple defines a slot named \texttt{delegate}, any generic words called on
the tuple that are not defined for the tuple's class will be passed on
to the delegate.
This idiom is used in the I/O code for wrapper streams. For example, the
\texttt{ansi-stream} class delegates all generic words to its underlying stream,
except for \texttt{fwrite-attr}, which outputs the necessary terminal escape
codes. Another example is \texttt{stdio-stream}, which performs all I/O on its
underlying stream, except it flushes after every new line (which would
be undesirable for say, a file).
Delegation is used instead of inheritance in Factor, but it is not a
substitute; in particular, the semantics differ in that a delegated
method call receives the delegate on the stack, not the original object.
\input{new-guide.ind}
\end{document}

View File

@ -1,272 +0,0 @@
THE FACTOR GENERIC WORD SYSTEM
Factor's generic word system is a very abstract generalization of
"object oriented" features found in other programming languges.
To use the generic word system, you must put the following near the
beginning of your source file:
USE: generic
The key motivation is that sometimes, you want to write a word that has
differing behavior depending on the class of its argument. For example,
in a game, a 'draw' word could take different action if given a ship, a
weapon, a planet, etc.
Duplicating 'type case' logic is undesirable and also results in
unnecessary coupling -- adding support for a new type of graphical
object would require modifying the original definition of 'draw', for
example.
* Types
In Factor, the idea of a 'type' refers to a very concrete concept. The
type of an object is its representation in runtime object memory. Types
include fixnums, bignums, cons cells, vectors, strings, and so on. The
set of available types is fixed; adding a new type requires modifying
the runtime source written in C.
* Classes
In Factor, a 'class' is just a predicate that categorizes objects as
being a member of the class or not. To be useful, it must be consistent
-- for a given object, it must always return the same truth value.
Examples of classes might include:
- Cons cells where both elements are integers
- Floating point numbers between -1 and 1
- Hash tables holding a certain key
- Any object that occurs as a member of a certain global variable
holding a list.
- ... and so on.
As you can see, a class of objects does not need to be a subset or a
superset of a type of objects.
Classes, unlike types, can be defined by the user.
* Generic words
A generic word is a word whose behavior depends on the class of the
object at the top of the stack.
Generic words are defined using the following syntax:
GENERIC: draw ( actor -- )
#! Draw the actor.
A stack effect comment, as above, is not required but recommended.
* Methods
A method associates behavior to a generic word. Methods are defined by
writing M:, followed by a class name, followed by the name of a
previously-defined generic word.
One of the main benefits of generic words is that each method definition
can potentially occur in a different source file. Generic word
definitions also hide conditionals.
Here are two methods for the generic 'draw' word:
M: ship draw ( actor -- )
[
surface get screen-xy radius get color get
filledCircleColor
] bind ;
M: plasma draw ( actor -- )
[
surface get screen-xy dup len get + color get
vlineColor
] bind ;
Here, 'ship' and 'class' are user-defined classes.
* Metaclasses
To understand what classes already exist, and how to define your own
classes, the concept of a 'metaclass' must be grasped first. Roughly
speaking, a metaclass is a class of classes.
New metaclasses can be defined by the user, but its an involved process
that requires a deeper understanding of the generic word systsem than
can be given here.
** The object class
Every object is a member of the object class. The object class is also a
metaclass, and it is the one and only instance of itself.
Confusing? The idea is pretty simple. If you define a method on
'object', it will be called when no more specific method is available:
GENERIC: describe
M: number describe "The number " write . ;
M: object describe "I don't know anything about " write . ;
Since the only instance of the object metaclass is itself, you cannot
define new classes in the object metaclass.
** The builtin metaclass
The builtin metaclass contains precisely the following classes; each
class corresponds to a runtime type:
alien
array
bignum
complex
cons
dll
f
fixnum
float
port
ratio
sbuf
string
t
vector
word
Each builtin class has a corresponding membership test predicate, named
after the builtin class suffixed with '?'. For example, cons?, word?,
etc.
Adding new classes to the builtin metaclass requires modifications to
the C code comprising Factor's runtime.
** The union metaclass
The union metaclass contains classes whose members are defined to be the
aggregate of the members of a list of existing classes.
For example, the Factor library defines some unions over numeric types:
UNION: integer fixnum bignum ;
UNION: rational integer ratio ;
UNION: real rational float ;
UNION: number real complex ;
Now, the absolute value function can be defined in an efficient manner
for real numbers, and in a more general fashion for complex numbers:
GENERIC: abs ( z -- |z| )
M: real abs dup 0 < [ neg ] when ;
M: complex abs >rect mag2 ;
New unions can be defined by you, and the numerical types example above
gives the syntax: you write UNION: followed by the name of the union,
followed by its members. The list of members is terminated with a
semi-colon.
A predicate named after the union followed by '?' is
automatically-defined. For example, the following definition of 'real?'
was automatically created:
: real?
dup rational? [
drop t
] [
dup float? [
drop t
] [
drop f
] ifte
] ifte ;
** The predicate metaclass
The predicate metaclass contains classes whose membership test is an
arbitrary expression. To speed up dispatch, each predicate must be
defined as a subclass of some other class. That way predicates
subclassing from disjoint builtin classes do not need to be
simultaenously tested.
The library/strings.factor module defines some subclasses of integer,
classifying the different types of ASCII characters:
PREDICATE: integer blank " \t\n\r" str-contains? ;
PREDICATE: integer letter CHAR: a CHAR: z between? ;
PREDICATE: integer LETTER CHAR: A CHAR: Z between? ;
PREDICATE: integer digit CHAR: 0 CHAR: 9 between? ;
PREDICATE: integer printable CHAR: \s CHAR: ~ between? ;
Each predicate defines a corresponding predicate word whose name is
suffixed with '?'; for example, a 'digit?' word is automatically
defined:
: digit?
dup integer? [
CHAR: 0 CHAR: 9 between?
] [
drop f
] ifte ;
For obvious reasons, the predicate definition must consume and produce
exactly one value on the stack.
** The traits metaclass
(The name for this metaclass is wrong and will change eventually. The
original idea was to allow an object to inherit any number of 'traits',
thus they would behave like mixins. This never materialized.)
The traits metaclass allows one to associate more fine-grained behavior,
specifically with hashtables.
New classes can be defined like so:
TRAITS: plasma
In terms of behavior, this is actually identical to the following:
PREDICATE: hashtable plasma \ traits swap hash plasma = ;
However, it is far more efficient (and less verbose).
You can define methods as usual:
GENERIC: collide ( actor1 actor2 -- )
M: plasma collide ( actor1 actor2 -- )
#! Remove the other actor.
deactivate deactivate ;
How does one actually get an object that plasma? responds with t to? You
define a constructor word by writing C: followed by the class name:
C: plasma ( actor dy -- plasma )
[
velocity set
actor-xy
blue color set
10 len set
5 radius set
active on
] extend ;
The constructor word is named after the class, surrounded in angle
brackets (< and >). For example, the above actually creates a word named
<plasma>.
The constructor's definition begins with the parameters given by the
user, underneath a blank plasma object.
That is, a dummy constructor just returns a blank hashtable that
responds t to the corresponding membership predicate:
TRAITS: foo
C: foo ;
<foo> foo? .
==> t
"hello" foo? .
==> f

View File

@ -4,7 +4,7 @@
!
! ./f boot.image.le32
! -libraries:sdl:name=libSDL.so
! -libraries:sdl-gfx:name=libSDL_gfx.
! -libraries:sdl-gfx:name=libSDL_gfx.so
!
! (But all on one line)
!
@ -36,10 +36,7 @@ SYMBOL: d
: next-x ( x y -- x ) a get * sin swap b get * cos - ;
: next-y ( x y -- y ) swap c get * sin swap d get * cos - ;
: white ( -- rgb )
HEX: ffffffff ;
: pixel ( #{ x y } color -- )
: pixel ( #{ x y }# color -- )
>r >r surface get r> >rect r> pixelColor ;
: iterate-dejong ( x y -- x y )
@ -51,21 +48,21 @@ SYMBOL: d
: draw-dejong ( x0 y0 iterations -- )
[
iterate-dejong 2dup scale-dejong rect> white pixel
] times 2drop ;
iterate-dejong 2dup scale-dejong rect> white rgb pixel
] times 2drop ; compiled
: dejong ( -- )
! Fiddle with these four values!
1.4 a set
-2.3 b set
2.4 c set
1.0 a set
-1.3 b set
0.8 c set
-2.1 d set
640 480 32 SDL_HWSURFACE [
[ 0 0 100000 draw-dejong ] with-surface
1024 768 0 SDL_HWSURFACE [
[ 0 0 200000 [ draw-dejong ] time ] with-surface
<event> event-loop
SDL_Quit
] with-screen ; compiled
] with-screen ;
[ dejong ] time
dejong

View File

@ -1,336 +0,0 @@
! A simple space shooter.
!
! To run this code, bootstrap Factor like so:
!
! ./f boot.image.le32
! -libraries:sdl:name=libSDL.so
! -libraries:sdl-gfx:name=libSDL_gfx.
!
! (But all on one line)
!
! Then, start Factor as usual (./f factor.image) and enter this
! at the listener:
!
! "examples/factoroids.factor" run-file
IN: factoroids
USE: errors
USE: hashtables
USE: kernel
USE: lists
USE: logic
USE: math
USE: namespaces
USE: generic
USE: random
USE: sdl
USE: sdl-event
USE: sdl-gfx
USE: sdl-keysym
USE: sdl-video
! Game objects
GENERIC: draw ( actor -- )
#! Draw the actor.
GENERIC: tick ( actor -- ? )
#! Return f if the actor should be removed.
GENERIC: collide ( actor1 actor2 -- )
#! Handle collision of two actors.
! Actor attributes
SYMBOL: position
SYMBOL: radius
SYMBOL: len
SYMBOL: velocity
SYMBOL: color
SYMBOL: active
! The list of actors is divided into layers. Note that an
! actor's tick method can only add actors to layers other than
! the actor's layer. The player layer only has one actor.
SYMBOL: player
SYMBOL: enemies
SYMBOL: player-shots
SYMBOL: enemy-shots
: player-actor ( -- player )
player get dup [ car ] when ;
: x-in-screen? ( x -- ? ) 0 width get between? ;
: y-in-screen? ( y -- ? ) 0 height get between? ;
: in-screen? ( actor -- ? )
#! Is the actor in the screen?
[
position get >rect y-in-screen? swap x-in-screen? and
] bind ;
: move ( -- )
#! Add velocity vector to current actor's position vector.
velocity get position [ + ] change ;
: active? ( actor -- ? )
#! Push f if the actor should be removed.
[ active get ] bind ;
: deactivate ( actor -- )
#! Cause the actor to be removed in the next tick cycle.
[ active off ] bind ;
: screen-xy ( -- x y )
position get >rect swap >fixnum swap >fixnum ;
: actor-xy ( actor -- )
#! Copy actor's x/y co-ordinates to this namespace.
[ position get ] bind position set ;
! Collision detection
: distance ( actor1 actor2 -- x )
#! Distance between two actor's positions.
>r [ position get ] bind r> [ position get ] bind - abs ;
: min-distance ( actor1 actor2 -- )
#! Minimum distance before there is a collision.
>r [ radius get ] bind r> [ radius get ] bind + ;
: collision? ( actor1 actor2 -- ? )
2dup distance >r min-distance r> > ;
: check-collision ( actor1 actor2 -- )
2dup collision? [ collide ] [ 2drop ] ifte ;
: layer-actor-collision ( actor layer -- )
#! The layer is a list of actors.
[ dupd check-collision ] each drop ;
: layer-collision ( layer layer -- )
swap [ over layer-actor-collision ] each drop ;
: collisions ( -- )
#! Only collisions we allow are player colliding with an
#! enemy shot, and player shot colliding with enemy.
player get enemy-shots get layer-collision
enemies get player-shots get layer-collision ;
! The player's ship
TRAITS: ship
M: ship draw ( actor -- )
[
surface get screen-xy radius get color get
filledCircleColor
] bind ;
M: ship tick ( actor -- ? ) dup [ move ] bind active? ;
C: ship ( -- ship )
[
width get 2 /i height get 50 - rect> position set
white color set
10 radius set
0 velocity set
active on
] extend ;
! Projectiles
TRAITS: plasma
M: plasma draw ( actor -- )
[
surface get screen-xy dup len get + color get
vlineColor
] bind ;
M: plasma tick ( actor -- ? )
dup [ move ] bind dup in-screen? swap active? and ;
M: plasma collide ( actor1 actor2 -- )
#! Remove the other actor.
deactivate deactivate ;
C: plasma ( actor dy -- plasma )
[
velocity set
actor-xy
blue color set
10 len set
5 radius set
active on
] extend ;
: player-fire ( -- )
#! Do nothing if player is dead.
player-actor [
#{ 0 -6 } <plasma> player-shots cons@
] when* ;
: enemy-fire ( actor -- )
#{ 0 5 } <plasma> enemy-shots cons@ ;
! Background of stars
TRAITS: particle
M: particle draw ( actor -- )
[ surface get screen-xy color get pixelColor ] bind ;
: wrap ( -- )
#! If current actor has gone beyond screen bounds, move it
#! back.
position get >rect
swap >fixnum width get rem
swap >fixnum height get rem
rect> position set ;
M: particle tick ( actor -- )
[ move wrap t ] bind ;
C: particle ;
SYMBOL: stars
: star-count 100 ;
: random-x 0 width get random-int ;
: random-y 0 height get random-int ;
: random-position random-x random-y rect> ;
: random-byte 0 255 random-int ;
: random-color random-byte random-byte random-byte 255 rgba ;
: random-velocity 0 10 20 random-int 10 /f rect> ;
: random-star ( -- star )
<particle> [
random-position position set
random-color color set
random-velocity velocity set
active on
] extend ;
: init-stars ( -- )
#! Generate random background of scrolling stars.
[ ] star-count [ random-star swons ] times stars set ;
: draw-stars ( -- )
stars get [ draw ] each ;
: tick-stars ( -- )
stars get [ tick drop ] each ;
! Enemies
: enemy-chance 50 ;
TRAITS: enemy
M: enemy draw ( actor -- )
[
surface get screen-xy radius get color get
filledCircleColor
] bind ;
: attack-chance 30 ;
: chance ( n -- boolean )
#! Returns true with a 1/n probability, false with a (n-1)/n
#! probability.
1 swap random-int 1 = ;
: attack ( actor -- )
#! Fire a shot some of the time.
attack-chance chance [ enemy-fire ] [ drop ] ifte ;
SYMBOL: wiggle-x
: wiggle ( -- )
#! Wiggle from left to right.
-3 3 random-int wiggle-x [ + ] change
wiggle-x get sgn 1 rect> velocity set ;
M: enemy tick ( actor -- )
dup attack
dup [ wiggle move position get imaginary ] bind
y-in-screen? swap active? and ;
C: enemy ;
: spawn-enemy ( -- )
<enemy> [
random-x 10 rect> position set
red color set
0 wiggle-x set
0 velocity set
10 radius set
active on
] extend ;
: spawn-enemies ( -- )
enemy-chance chance [ spawn-enemy enemies cons@ ] when ;
! Event handling
SYMBOL: event
: mouse-motion-event ( event -- )
motion-event-x player-actor dup [
[ position get imaginary rect> position set ] bind
] [
2drop
] ifte ;
: mouse-down-event ( event -- )
drop player-fire ;
: handle-event ( event -- ? )
#! Return if we should continue or stop.
[
[ event-type SDL_MOUSEBUTTONDOWN = ] [ mouse-down-event t ]
[ event-type SDL_MOUSEMOTION = ] [ mouse-motion-event t ]
[ event-type SDL_QUIT = ] [ drop f ]
[ drop t ] [ drop t ]
] cond ;
: check-event ( -- ? )
#! Check if there is a pending event.
#! Return if we should continue or stop.
event get dup SDL_PollEvent [
handle-event [ check-event ] [ f ] ifte
] [
drop t
] ifte ;
! Game loop
: init-game ( -- )
#! Init game objects.
init-stars
<ship> unit player set
<event> event set ;
: each-layer ( quot -- )
#! Apply quotation to each layer.
[ enemies enemy-shots player player-shots ] swap each ;
: draw-actors ( -- )
[ get [ draw ] each ] each-layer ;
: tick-actors ( -- )
#! Advance game state by one frame. Actors whose tick word
#! returns f are removed from the layer.
[ dup get [ tick ] subset put ] each-layer ;
: render ( -- )
#! Draw the scene.
[ black clear-surface draw-stars draw-actors ] with-surface ;
: advance ( -- )
#! Advance game state by one frame.
tick-actors tick-stars spawn-enemies ;
: game-loop ( -- )
#! Render, advance game state, repeat.
render advance collisions check-event [ game-loop ] when ;
: factoroids ( -- )
#! Main word.
640 480 32 SDL_HWSURFACE [
"Factoroids" "Factoroids" SDL_WM_SetCaption
init-game game-loop
] with-screen ;
factoroids

39
examples/format.factor Normal file
View File

@ -0,0 +1,39 @@
IN: format
USE: kernel
USE: math
USE: namespaces
USE: strings
USE: test
: decimal-split ( string -- string string )
#! Split a string before and after the decimal point.
dup "." index-of dup -1 = [ drop f ] [ str// ] ifte ;
: decimal-tail ( count str -- string )
#! Given a decimal, trims all but a count of decimal places.
[ str-length min ] keep str-head ;
: decimal-cat ( before after -- string )
#! If after is of zero length, return before, otherwise
#! return "before.after".
dup str-length 0 = [
drop
] [
"." swap cat3
] ifte ;
: decimal-places ( num count -- string )
#! Trims the number to a count of decimal places.
>r decimal-split dup [
r> swap decimal-tail decimal-cat
] [
r> 2drop
] ifte ;
[ "123" ] [ 4 "123" decimal-tail ] unit-test
[ "12" ] [ 2 "123" decimal-tail ] unit-test
[ "123" ] [ "123" 2 decimal-places ] unit-test
[ "123.12" ] [ "123.12" 2 decimal-places ] unit-test
[ "123.123" ] [ "123.123" 5 decimal-places ] unit-test
[ "123" ] [ "123.123" 0 decimal-places ] unit-test

View File

@ -0,0 +1,89 @@
! TrueType font rendering demo.
!
! To run this code, bootstrap Factor like so:
!
! ./f boot.image.le32
! -libraries:sdl:name=libSDL.so
! -libraries:sdl-gfx:name=libSDL_gfx.so
! -libraries:sdl-ttf:name=libSDL_ttf.so
!
! (But all on one line)
!
! Then, start Factor as usual (./f factor.image) and enter this
! at the listener:
!
! "examples/text-demo.factor" run-file
IN: text-demo
USE: streams
USE: sdl
USE: sdl-event
USE: sdl-gfx
USE: sdl-video
USE: sdl-ttf
USE: namespaces
USE: math
USE: kernel
USE: test
USE: compiler
USE: strings
USE: alien
USE: prettyprint
USE: lists
USE: gadgets
USE: generic
USE: stdio
USE: prettyprint
USE: words
: grab ( gadget hand -- )
[ swap screen-pos swap screen-pos - >rect ] 2keep
>r [ move-gadget ] keep r> add-gadget ;
: release ( gadget world -- )
>r dup screen-pos >r
dup unparent
r> >rect pick move-gadget
r> add-gadget ;
: moving-actions
{{
[[ [ button-down 1 ] [ my-hand grab ] ]]
[[ [ button-up 1 ] [ world get release ] ]]
}} swap set-gadget-gestures ;
: filled? "filled" get checkbox-selected? ;
: <funny-rect>
filled? [ <plain-rect> ] [ <hollow-rect> ] ifte <gadget> dup moving-actions ;
: <funny-ellipse>
filled? [ <plain-ellipse> ] [ <hollow-ellipse> ] ifte <gadget> dup moving-actions ;
: <funny-line>
<line> <gadget> dup moving-actions ;
: make-shapes ( -- )
f world get set-gadget-children
default-gap <pile> "pile" set
default-gap <shelf> "shelf" set
"Close" [ "dialog" get world get remove-gadget ] <button> "shelf" get add-gadget
"New Rectangle" [ drop 100 100 100 100 <funny-rect> dup [ 255 255 0 ] background set-paint-property world get add-gadget ] <button> "shelf" get add-gadget
"New Ellipse" [ drop 100 100 200 100 <funny-ellipse> dup [ 0 255 0 ] background set-paint-property world get add-gadget ] <button> "shelf" get add-gadget
"New Line" [ drop 100 100 200 100 <funny-line> dup [ 255 0 0 ] background set-paint-property world get add-gadget ] <button> "shelf" get add-gadget
"Filled?" <checkbox> dup "filled" set "shelf" get add-gadget
"shelf" get "pile" get add-gadget
"Welcome to Factor " version cat2 <label> "pile" get add-gadget
"A field." <field> "pile" get add-gadget
"Another field." <field> "pile" get add-gadget
"pile" get bevel-border dup "dialog" set dup
moving-actions
world get add-gadget ;
: gadget-demo ( -- )
make-shapes
start-world ;
gadget-demo

View File

@ -14,7 +14,7 @@ SYMBOL: exprs
DEFER: infix
: >e exprs get vector-push ;
: e> exprs get vector-pop ;
: e@ exprs get dup vector-empty? [ drop f ] [ vector-peek ] ifte ;
: e@ exprs get dup vector-length 0 = [ drop f ] [ vector-peek ] ifte ;
: e, ( obj -- ) dup cons? [ [ e, ] each ] [ , ] ifte ;
: end ( -- ) exprs get [ e, ] vector-each ;
: >postfix ( op -- ) e@ word? [ e> e> -rot 3list ] when >e ;

View File

@ -17,8 +17,10 @@ SYMBOL: channels
SYMBOL: channel
SYMBOL: nickname
: irc-write ( s -- ) irc-stream get fwrite ;
: irc-print ( s -- ) irc-stream get fprint irc-stream get fflush ;
: irc-write ( s -- ) irc-stream get stream-write ;
: irc-print ( s -- )
irc-stream get stream-print
irc-stream get stream-flush ;
: nick ( nick -- )
dup nickname set "NICK " irc-write irc-print ;
@ -32,13 +34,13 @@ SYMBOL: nickname
: write-highlighted ( line -- )
dup nickname get index-of -1 =
f [ [ "ansi-fg" | "3" ] ] ? write-attr ;
f [ [[ "ansi-fg" "3" ]] ] ? write-attr ;
: extract-nick ( line -- nick )
"!" split1 drop ;
: write-nick ( line -- )
"!" split1 drop [ [ "bold" | t ] ] write-attr ;
"!" split1 drop [ [[ "bold" t ]] ] write-attr ;
GENERIC: irc-display
PREDICATE: string privmsg "PRIVMSG" index-of -1 > ;
@ -58,10 +60,10 @@ M: privmsg irc-display ( line -- )
! write-highlighted terpri flush ;
: in-loop ( -- )
irc-stream get freadln [ irc-display in-loop ] when* ;
irc-stream get stream-readln [ irc-display in-loop ] when* ;
: input-thread ( -- ) [ in-loop ] in-thread ;
: disconnect ( -- ) irc-stream get fclose ;
: disconnect ( -- ) irc-stream get stream-close ;
: command ( line -- )
#! IRC /commands are just words.

14
examples/lcd.factor Normal file
View File

@ -0,0 +1,14 @@
USING: vectors kernel math stdio strings ;
: lcd-digit ( digit row -- str )
{
" _ _ _ _ _ _ _ _ "
" | | | _| _| |_| |_ |_ | |_| |_| "
" |_| | |_ _| | _| |_| | |_| | "
} vector-nth >r 4 * dup 4 + r> substring ;
: lcd-row ( num row -- )
swap [ CHAR: 0 - over lcd-digit write ] str-each drop ;
: lcd ( num -- str )
3 [ 2dup lcd-row terpri ] repeat drop ;

View File

@ -32,7 +32,7 @@ USE: test
: scale 255 * >fixnum ;
: scale-rgba ( r g b -- n )
: scale-rgb ( r g b a -- n )
scale
swap scale 8 shift bitor
swap scale 16 shift bitor
@ -44,10 +44,10 @@ USE: test
: <color-map> ( nb-cols -- map )
[
dup [
360 * over 1 + / 360 / sat val
hsv>rgb 1.0 scale-rgba ,
] times*
] make-list list>vector nip ;
dup 360 * pick 1 + / 360 / sat val
hsv>rgb 1.0 scale-rgb ,
] repeat
] make-vector nip ;
: absq >rect swap sq swap sq + ; inline
@ -72,15 +72,15 @@ SYMBOL: center
height get 150000 zoom-fact get * / y-inc set
nb-iter get max-color min <color-map> cols set ;
: c ( #{ i j } -- c )
>rect >r
: c ( i j -- c )
>r
x-inc get * center get real x-inc get width get 2 / * - + >float
r>
y-inc get * center get imaginary y-inc get height get 2 / * - + >float
rect> ;
: render ( -- )
width get height get [
[
c 0 nb-iter get iter dup 0 = [
drop 0
] [
@ -89,7 +89,7 @@ SYMBOL: center
] with-pixels ; compiled
: mandel ( -- )
640 480 32 SDL_HWSURFACE [
640 480 0 SDL_HWSURFACE [
[
0.8 zoom-fact set
-0.65 center set

View File

@ -72,10 +72,10 @@ USE: namespaces
unit-test
[
[ 10 | t ]
[ 20 | f ]
[ 30 | "monkey" ]
[ 24 | 1/2 ]
[[ 10 t ]]
[[ 20 f ]]
[[ 30 "monkey" ]]
[[ 24 1/2 ]]
[ 13 | { "Hello" "Banana" } ]
] "random-pairs" set

View File

@ -1,21 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "factor", "factor.vcproj", "{3AE5FAF6-99AC-4B8F-9107-8A346B3D87A4}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{3AE5FAF6-99AC-4B8F-9107-8A346B3D87A4}.Debug.ActiveCfg = Debug|Win32
{3AE5FAF6-99AC-4B8F-9107-8A346B3D87A4}.Debug.Build.0 = Debug|Win32
{3AE5FAF6-99AC-4B8F-9107-8A346B3D87A4}.Release.ActiveCfg = Release|Win32
{3AE5FAF6-99AC-4B8F-9107-8A346B3D87A4}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@ -1,492 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="factor"
ProjectGUID="{3AE5FAF6-99AC-4B8F-9107-8A346B3D87A4}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="FFI;WIN32;F_DEBUG"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="1"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/factor.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/factor.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="3"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
PreprocessorDefinitions="FFI;WIN32;F_DEBUG"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/factor.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="native\arithmetic.c">
</File>
<File
RelativePath="native\array.c">
</File>
<File
RelativePath="native\bignum.c">
</File>
<File
RelativePath="native\boolean.c">
</File>
<File
RelativePath="native\compiler.c">
</File>
<File
RelativePath="native\complex.c">
</File>
<File
RelativePath="native\cons.c">
</File>
<File
RelativePath=".\native\debug.c">
</File>
<File
RelativePath="native\error.c">
</File>
<File
RelativePath="native\factor.c">
</File>
<File
RelativePath="native\ffi.c">
</File>
<File
RelativePath="native\fixnum.c">
</File>
<File
RelativePath="native\float.c">
</File>
<File
RelativePath="native\gc.c">
</File>
<File
RelativePath="native\image.c">
</File>
<File
RelativePath="native\memory.c">
</File>
<File
RelativePath="native\misc.c">
</File>
<File
RelativePath="native\port.c">
</File>
<File
RelativePath="native\primitives.c">
</File>
<File
RelativePath="native\ratio.c">
</File>
<File
RelativePath="native\relocate.c">
</File>
<File
RelativePath="native\run.c">
</File>
<File
RelativePath="native\s48_bignum.c">
</File>
<File
RelativePath="native\sbuf.c">
</File>
<File
RelativePath="native\stack.c">
</File>
<File
RelativePath="native\string.c">
</File>
<File
RelativePath="native\types.c">
</File>
<File
RelativePath="native\vector.c">
</File>
<File
RelativePath="native\word.c">
</File>
<Filter
Name="win32"
Filter="">
<File
RelativePath=".\native\win32\ffi.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)2.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)2.obj"/>
</FileConfiguration>
</File>
<File
RelativePath="native\win32\file.c">
</File>
<File
RelativePath="native\win32\io.c">
</File>
<File
RelativePath=".\native\win32\misc.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath="native\win32\read.c">
</File>
<File
RelativePath="native\win32\write.c">
</File>
</Filter>
<Filter
Name="unix"
Filter="">
<File
RelativePath=".\native\unix\ffi.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath="native\unix\file.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath="native\unix\io.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath="native\unix\read.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath="native\unix\signal.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
</File>
<File
RelativePath="native\unix\socket.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
</File>
<File
RelativePath="native\unix\write.c">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="native\arithmetic.h">
</File>
<File
RelativePath="native\array.h">
</File>
<File
RelativePath="native\bignum.h">
</File>
<File
RelativePath="native\boolean.h">
</File>
<File
RelativePath="native\compiler.h">
</File>
<File
RelativePath="native\complex.h">
</File>
<File
RelativePath="native\cons.h">
</File>
<File
RelativePath=".\native\debug.h">
</File>
<File
RelativePath="native\error.h">
</File>
<File
RelativePath="native\factor.h">
</File>
<File
RelativePath="native\ffi.h">
</File>
<File
RelativePath="native\file.h">
</File>
<File
RelativePath="native\fixnum.h">
</File>
<File
RelativePath="native\float.h">
</File>
<File
RelativePath="native\gc.h">
</File>
<File
RelativePath="native\image.h">
</File>
<File
RelativePath="native\io.h">
</File>
<File
RelativePath="native\memory.h">
</File>
<File
RelativePath="native\misc.h">
</File>
<File
RelativePath="native\port.h">
</File>
<File
RelativePath="native\primitives.h">
</File>
<File
RelativePath="native\ratio.h">
</File>
<File
RelativePath="native\read.h">
</File>
<File
RelativePath="native\relocate.h">
</File>
<File
RelativePath="native\run.h">
</File>
<File
RelativePath="native\s48_bignum.h">
</File>
<File
RelativePath="native\s48_bignumint.h">
</File>
<File
RelativePath="native\sbuf.h">
</File>
<File
RelativePath="native\signal.h">
</File>
<File
RelativePath="native\socket.h">
</File>
<File
RelativePath="native\stack.h">
</File>
<File
RelativePath="native\string.h">
</File>
<File
RelativePath="native\types.h">
</File>
<File
RelativePath="native\vector.h">
</File>
<File
RelativePath="native\word.h">
</File>
<File
RelativePath="native\write.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2003, 2004 Slava Pestov.
* Copyright (C) 2003, 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -30,7 +30,7 @@
package factor;
/**
* Used to build up linked lists.
* Used to build up linked lists in Factor style.
*/
public class Cons implements FactorExternalizable
{
@ -50,41 +50,53 @@ public class Cons implements FactorExternalizable
return (Cons)cdr;
} //}}}
//{{{ contains() method
public boolean contains(Object obj)
//{{{ isList() method
public static boolean isList(Object list)
{
Cons iter = this;
while(iter != null)
{
if(FactorLib.objectsEqual(obj,iter.car))
return true;
iter = iter.next();
}
return false;
if(list == null)
return true;
else if(list instanceof Cons)
return isList(((Cons)list).cdr);
else
return false;
} //}}}
//{{{ contains() method
public static boolean contains(Cons list, Object obj)
{
if(list == null)
return false;
else
return list.contains(obj);
while(list != null)
{
if(FactorLib.objectsEqual(obj,list.car))
return true;
list = list.next();
}
return false;
} //}}}
//{{{ length() method
public int length()
public static int length(Cons list)
{
int size = 0;
Cons iter = this;
while(iter != null)
while(list != null)
{
iter = (Cons)iter.cdr;
size++;
list = list.next();
}
return size;
} //}}}
//{{{ reverse() method
public static Cons reverse(Cons list)
{
Cons reversed = null;
while(list != null)
{
reversed = new Cons(list.car,reversed);
list = list.next();
}
return reversed;
} //}}}
//{{{ elementsToString() method
/**
* Returns a whitespace separated string of the unparseObject() of each
@ -97,20 +109,8 @@ public class Cons implements FactorExternalizable
while(iter != null)
{
buf.append(FactorReader.unparseObject(iter.car));
if(iter.cdr instanceof Cons)
{
buf.append(' ');
iter = (Cons)iter.cdr;
continue;
}
else if(iter.cdr == null)
break;
else
{
buf.append(" | ");
buf.append(FactorReader.unparseObject(iter.cdr));
iter = null;
}
buf.append(' ');
iter = iter.next();
}
return buf.toString();
@ -122,7 +122,14 @@ public class Cons implements FactorExternalizable
*/
public String toString()
{
return "[ " + elementsToString() + " ]";
if(isList(this))
return "[ " + elementsToString() + " ]";
else
{
return "[[ " + FactorReader.unparseObject(car)
+ " " + FactorReader.unparseObject(cdr)
+ " ]]";
}
} //}}}
//{{{ toArray() method

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2004 Slava Pestov.
* Copyright (C) 2004, 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -68,15 +68,19 @@ public class DefaultVocabularyLookup implements VocabularyLookup
FactorWord f = define("syntax","f");
f.parsing = new F(f);
FactorWord complex = define("syntax","#{");
complex.parsing = new ComplexLiteral(complex,"}");
complex.parsing = new ComplexLiteral(complex,"}#");
/* lists */
FactorWord bra = define("syntax","[");
bra.parsing = new Bra(bra);
FactorWord ket = define("syntax","]");
ket.parsing = new Ket(bra,ket);
FactorWord bar = define("syntax","|");
bar.parsing = new Bar(bar);
/* conses */
FactorWord beginCons = define("syntax","[[");
beginCons.parsing = new BeginCons(beginCons);
FactorWord endCons = define("syntax","]]");
endCons.parsing = new EndCons(beginCons,endCons);
/* vectors */
FactorWord beginVector = define("syntax","{");
@ -89,9 +93,9 @@ public class DefaultVocabularyLookup implements VocabularyLookup
def.parsing = new Def(def);
def.docComment = true;
FactorWord ine = define("syntax",";");
ine.parsing = new Ine(def,ine);
ine.parsing = new Ine(ine);
FactorWord symbol = define("syntax","SYMBOL:");
symbol.parsing = new Symbol(symbol);
symbol.parsing = new Definer(symbol);
/* reading numbers with another base */
FactorWord bin = define("syntax","BIN:");
@ -105,24 +109,32 @@ public class DefaultVocabularyLookup implements VocabularyLookup
FactorWord noParsing = define("syntax","POSTPONE:");
noParsing.parsing = new NoParsing(noParsing);
FactorWord defer = define("syntax","DEFER:");
defer.parsing = new Defer(defer);
defer.parsing = new Definer(defer);
FactorWord in = define("syntax","IN:");
in.parsing = new In(in);
FactorWord use = define("syntax","USE:");
use.parsing = new Use(use);
FactorWord using = define("syntax","USING:");
using.parsing = new Using(using);
FactorWord pushWord = define("syntax","\\");
pushWord.parsing = new PushWord(pushWord);
/* OOP */
FactorWord generic = define("generic","GENERIC:");
generic.parsing = new Generic(generic);
generic.parsing = new Definer(generic);
FactorWord traits = define("generic","TRAITS:");
traits.parsing = new Traits(traits);
traits.parsing = new Definer(traits);
FactorWord beginMethod = define("generic","M:");
beginMethod.parsing = new BeginMethod(beginMethod,def);
beginMethod.parsing = new BeginMethod(beginMethod);
FactorWord beginConstructor = define("generic","C:");
beginConstructor.parsing = new BeginConstructor(beginConstructor,def);
beginConstructor.parsing = new BeginConstructor(beginConstructor);
FactorWord beginPredicate = define("generic","PREDICATE:");
beginPredicate.parsing = new BeginPredicate(beginPredicate);
FactorWord beginUnion = define("generic","UNION:");
beginUnion.parsing = new BeginUnion(beginUnion);
FactorWord tuple = define("generic","TUPLE:");
tuple.parsing = new Tuple(tuple);
} //}}}
//{{{ getVocabulary() method
@ -206,7 +218,7 @@ public class DefaultVocabularyLookup implements VocabularyLookup
return vocabs;
} //}}}
//{{{ getCompletions() method
//{{{ getWordCompletions() method
/**
* @param use A list of vocabularies.
* @param word A substring of the word name to complete
@ -214,19 +226,36 @@ public class DefaultVocabularyLookup implements VocabularyLookup
* returned; otherwise, only matches from beginning.
* @param completions Set to add completions to
*/
public void getCompletions(Cons use, String word, boolean anywhere,
public void getWordCompletions(Cons use, String word, boolean anywhere,
Set completions) throws Exception
{
while(use != null)
{
String vocab = (String)use.car;
getCompletions(vocab,word,anywhere,completions);
getWordCompletions(vocab,word,anywhere,completions);
use = use.next();
}
} //}}}
//{{{ getCompletions() method
public void getCompletions(String vocab, String word, boolean anywhere,
//{{{ isCompletion() method
public boolean isCompletion(String match, String against, boolean anywhere)
{
if(anywhere)
{
if(against.indexOf(match) != -1)
return true;
}
else
{
if(against.startsWith(match))
return true;
}
return false;
} //}}}
//{{{ getWordCompletions() method
public void getWordCompletions(String vocab, String word, boolean anywhere,
Set completions) throws Exception
{
Map v = (Map)vocabularies.get(vocab);
@ -242,21 +271,35 @@ public class DefaultVocabularyLookup implements VocabularyLookup
{
if(!completions.contains(w))
{
if(anywhere)
{
if(w.name.indexOf(word) != -1)
completions.add(w);
}
else
{
if(w.name.startsWith(word))
completions.add(w);
}
if(isCompletion(word,w.name,anywhere))
completions.add(w);
}
}
}
} //}}}
//{{{ getVocabCompletions() method
/**
* @param vocab A string to complete
* @param anywhere If true, matches anywhere in the vocab name are
* returned; otherwise, only matches from beginning.
*/
public String[] getVocabCompletions(String vocab, boolean anywhere)
throws Exception
{
List completions = new ArrayList();
Cons vocabs = getVocabularies();
while(vocabs != null)
{
String v = (String)vocabs.car;
if(isCompletion(vocab,v,anywhere))
completions.add(v);
vocabs = vocabs.next();
}
return (String[])completions.toArray(new String[completions.size()]);
} //}}}
//{{{ parseObject() method
public Cons parseObject(String source) throws Exception
{

View File

@ -63,8 +63,7 @@ public class ExternalFactor extends DefaultVocabularyLookup
}
Log.log(Log.ERROR,this,"Cannot connect to Factor on port " + port);
if(in != null && out != null)
close();
close();
} //}}}
//{{{ openWireSocket() method
@ -104,7 +103,7 @@ public class ExternalFactor extends DefaultVocabularyLookup
byte[] discard = new byte[2048];
int len = in.read(discard,0,discard.length);
discardStr = new String(discard,0,len);
Log.log(Log.DEBUG,this,"Waiting for ACK: " + discardStr);
// Log.log(Log.DEBUG,this,"Waiting for ACK: " + discardStr);
}
} //}}}
@ -123,6 +122,9 @@ public class ExternalFactor extends DefaultVocabularyLookup
*/
public synchronized String eval(String cmd) throws IOException
{
if(isClosed())
throw new IOException("ExternalFactor stream closed");
try
{
waitForAck();
@ -236,11 +238,11 @@ public class ExternalFactor extends DefaultVocabularyLookup
}
} //}}}
//{{{ getCompletions() method
public synchronized void getCompletions(Cons use, String word,
//{{{ getWordCompletions() method
public synchronized void getWordCompletions(Cons use, String word,
boolean anywhere, Set completions) throws Exception
{
super.getCompletions(use,word,anywhere,completions);
super.getWordCompletions(use,word,anywhere,completions);
if(closed)
return;
@ -277,21 +279,26 @@ public class ExternalFactor extends DefaultVocabularyLookup
closed = true;
try
if(out != null)
{
/* don't care about response */
sendEval("0 exit*");
}
catch(Exception e)
{
// We don't care...
Log.log(Log.DEBUG,this,e);
try
{
/* don't care about response */
sendEval("0 exit*");
}
catch(Exception e)
{
// We don't care...
Log.log(Log.DEBUG,this,e);
}
}
try
{
in.close();
out.close();
if(in != null)
in.close();
if(out != null)
out.close();
}
catch(Exception e)
{

View File

@ -53,7 +53,7 @@ public class FactorArray implements FactorExternalizable
//{{{ FactorArray constructor
public FactorArray(Cons list)
{
this(list == null ? 0 : list.length());
this(Cons.length(list));
int i = 0;
while(list != null)

View File

@ -1,54 +0,0 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* 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:
*
* 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.
*/
package factor;
/**
* : name ... ;
*/
public class FactorCompoundDefinition extends FactorWordDefinition
{
public Cons definition;
//{{{ FactorCompoundDefinition constructor
/**
* A new definition.
*/
public FactorCompoundDefinition(FactorWord word, Cons definition)
{
super(word);
this.definition = definition;
} //}}}
//{{{ toList() method
public Cons toList()
{
return definition;
} //}}}
}

View File

@ -1,45 +0,0 @@
/* :folding=explicit: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.
*/
package factor;
/**
* GENERIC: name
*/
public class FactorGenericDefinition extends FactorWordDefinition
{
//{{{ FactorGenericDefinition constructor
/**
* A new definition.
*/
public FactorGenericDefinition(FactorWord word)
{
super(word);
} //}}}
}

View File

@ -32,15 +32,16 @@ package factor;
/**
* M: type generic ... ;M
*/
public class FactorMethodDefinition extends FactorWordDefinition
public class FactorMethodDefinition
{
private FactorWord type;
private FactorWord generic;
private Cons def;
public FactorMethodDefinition(FactorWord type,
FactorWord generic, Cons def)
{
super(generic);
this.generic = generic;
this.type = type;
this.def = def;
}

View File

@ -241,10 +241,7 @@ public class FactorReader
FactorWord word;
if(define)
{
word = lookup.define(getIn(),name);
definedWords = new Cons(word,definedWords);
}
else
{
word = searchVocabulary(getUse(),name);
@ -258,7 +255,7 @@ public class FactorReader
//{{{ getDefinedWords() method
public Cons getDefinedWords()
{
return definedWords;
return Cons.reverse(definedWords);
} //}}}
//{{{ nextWord() method
@ -283,6 +280,7 @@ public class FactorReader
FactorWord w = intern((String)next,define);
if(define && w != null)
{
definedWords = new Cons(w,definedWords);
w.line = line;
w.col = col;
w.file = scanner.getFileName();
@ -381,12 +379,14 @@ public class FactorReader
/**
* Pop a parser state, throw exception if it doesn't match the
* parameter.
* @param start The start parameter that must match. If this is null,
* any start is acceptable.
*/
public ParseState popState(FactorWord start, FactorWord end)
throws FactorParseException
{
ParseState state = getCurrentState();
if(state.start != start)
if(start != null && state.start != start)
scanner.error(end + " does not close " + state.start);
if(states.next() != null)
states = states.next();

View File

@ -1,50 +0,0 @@
/* :folding=explicit: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.
*/
package factor;
/**
* SYMBOL: name
*
* Pushes word named.
*/
public class FactorSymbolDefinition extends FactorWordDefinition
{
public Object symbol;
//{{{ FactorSymbolDefinition constructor
/**
* A new definition.
*/
public FactorSymbolDefinition(FactorWord word, Object symbol)
{
super(word);
this.symbol = symbol;
} //}}}
}

View File

@ -1,41 +0,0 @@
/* :folding=explicit: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.
*/
package factor;
/**
* TRAITS: type
*/
public class FactorTraitsDefinition extends FactorSymbolDefinition
{
public FactorTraitsDefinition(FactorWord word)
{
super(word,word);
}
}

View File

@ -42,9 +42,9 @@ public class FactorWord implements FactorExternalizable
public FactorParsingDefinition parsing;
/**
* Stub for interpreter definition.
* For browsing, the parsing word that was used to define this word.
*/
public FactorWordDefinition def;
private FactorWord definer;
/**
* Should the parser keep doc comments?
@ -70,4 +70,19 @@ public class FactorWord implements FactorExternalizable
{
return name == null ? "#<unnamed>" : name;
} //}}}
//{{{ getDefiner() method
public FactorWord getDefiner()
{
if(definer == null)
return new FactorWord(null,"DEFER:");
else
return definer;
} //}}}
//{{{ setDefiner() method
public void setDefiner(FactorWord definer)
{
this.definer = definer;
} //}}}
}

View File

@ -49,9 +49,17 @@ public interface VocabularyLookup
* returned; otherwise, only matches from beginning.
* @param completions Set to add completions to
*/
public void getCompletions(Cons use, String word, boolean anywhere,
public void getWordCompletions(Cons use, String word, boolean anywhere,
Set completions) throws Exception;
/**
* @param vocab A string to complete
* @param anywhere If true, matches anywhere in the vocab name are
* returned; otherwise, only matches from beginning.
*/
public String[] getVocabCompletions(String vocab, boolean anywhere)
throws Exception;
/**
* @param vocab The vocabulary name
* @param word A substring of the word name to complete
@ -59,7 +67,7 @@ public interface VocabularyLookup
* the beginning of the name.
* @param completions Set to add completions to
*/
public void getCompletions(String vocab, String word, boolean anywhere,
public void getWordCompletions(String vocab, String word, boolean anywhere,
Set completions) throws Exception;
public Cons getVocabularies() throws Exception;

View File

@ -0,0 +1,81 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2004, 2005 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.
*/
package factor.jedit;
import factor.*;
import java.util.*;
import javax.swing.ListCellRenderer;
import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*;
import sidekick.*;
public abstract class AbstractCompletion extends SideKickCompletion
{
protected View view;
protected JEditTextArea textArea;
protected FactorParsedData data;
//{{{ AbstractCompletion constructor
public AbstractCompletion(View view, Object[] items,
FactorParsedData data)
{
this.view = view;
textArea = view.getTextArea();
this.items = Arrays.asList(items);
this.data = data;
} //}}}
//{{{ getLongestPrefix() method
public String getLongestPrefix()
{
return MiscUtilities.getLongestPrefix(items,false);
} //}}}
//{{{ handleKeystroke() method
public boolean handleKeystroke(int selectedIndex, char keyChar)
{
if(keyChar == '\t' || keyChar == '\n')
{
insert(selectedIndex);
return false;
}
else if(keyChar == ' ')
{
insert(selectedIndex);
textArea.userInput(' ');
return false;
}
else
{
textArea.userInput(keyChar);
return true;
}
} //}}}
}

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2003, 2004 Slava Pestov.
* Copyright (C) 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -27,36 +27,33 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package factor;
package factor.jedit;
import java.io.*;
import console.Output;
import factor.*;
import java.io.IOException;
import java.util.*;
import org.gjt.sp.jedit.*;
import org.gjt.sp.util.*;
/**
* A word definition.
*/
public abstract class FactorWordDefinition
public class CompileBufferProcessor extends FactorBufferProcessor
{
public FactorWord word;
//{{{ FactorWordDefinition constructor
//{{{ CompileBufferProcessor constructor
public CompileBufferProcessor(View view, Buffer buffer)
throws Exception
{
super(view,buffer,true);
} //}}}
//{{{ processWord() method
/**
* A new definition.
* @return Code to process the word.
*/
public FactorWordDefinition(FactorWord word)
public String processWord(FactorWord word)
{
this.word = word;
} //}}}
//{{{ toList() method
public Cons toList()
{
return null;
} //}}}
//{{{ toString() method
public String toString()
{
return getClass().getName() + ": " + word;
StringBuffer expression = new StringBuffer();
expression.append(FactorPlugin.factorWord(word));
expression.append(" try-compile");
return expression.toString();
} //}}}
}

View File

@ -118,7 +118,7 @@ public class EditWordDialog extends WordListDialog
private void updateList()
{
FactorWord[] completions = FactorPlugin.toWordArray(
FactorPlugin.getCompletions(
FactorPlugin.getWordCompletions(
field.getText(),true));
list.setListData(completions);
if(completions.length != 0)

View File

@ -30,7 +30,6 @@
package factor.jedit;
import factor.FactorWord;
import factor.FactorWordDefinition;
import javax.swing.Icon;
import javax.swing.text.Position;
import org.gjt.sp.jedit.Buffer;

View File

@ -0,0 +1,80 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2005 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.
*/
package factor.jedit;
import factor.*;
import org.gjt.sp.jedit.Buffer;
import org.gjt.sp.jedit.View;
/**
* A class used to compile all words in a file, or infer stack effects of all
* words in a file, etc.
*/
public abstract class FactorBufferProcessor
{
private String results;
//{{{ FactorBufferProcessor constructor
public FactorBufferProcessor(View view, Buffer buffer,
boolean evalInListener) throws Exception
{
StringBuffer buf = new StringBuffer();
Cons words = (Cons)buffer.getProperty(
FactorSideKickParser.WORDS_PROPERTY);
Cons wordCodeMap = null;
while(words != null)
{
FactorWord word = (FactorWord)words.car;
String expr = processWord(word);
buf.append("! ");
buf.append(expr);
buf.append('\n');
if(evalInListener)
FactorPlugin.evalInListener(view,expr);
else
buf.append(FactorPlugin.evalInWire(expr));
words = words.next();
}
results = buf.toString();
} //}}}
/**
* @return Code to process the word.
*/
public abstract String processWord(FactorWord word);
//{{{ getResults() method
public String getResults()
{
return results;
} //}}}
}

View File

@ -33,6 +33,7 @@ import factor.*;
import java.io.*;
import java.util.*;
import org.gjt.sp.jedit.gui.*;
import org.gjt.sp.jedit.syntax.*;
import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*;
import org.gjt.sp.util.Log;
@ -129,6 +130,10 @@ public class FactorPlugin extends EditPlugin
.getParentOfPath(imagePath)));
external = new ExternalFactor(PORT);
process.getOutputStream().close();
process.getInputStream().close();
process.getErrorStream().close();
}
catch(Exception e)
{
@ -154,7 +159,8 @@ public class FactorPlugin extends EditPlugin
*/
public static void stopExternalInstance()
{
getFactorShell().closeStreams();
if(getFactorShell() != null)
getFactorShell().closeStreams();
if(external != null)
{
@ -193,6 +199,16 @@ public class FactorPlugin extends EditPlugin
"sidekick.SideKickParser","factor");
} //}}}
//{{{ getParsedData() method
public static FactorParsedData getParsedData(View view)
{
SideKickParsedData data = SideKickParsedData.getParsedData(view);
if(data instanceof FactorParsedData)
return (FactorParsedData)data;
else
return null;
} //}}}
//{{{ evalInListener() method
public static void evalInListener(View view, String cmd)
{
@ -214,14 +230,11 @@ public class FactorPlugin extends EditPlugin
*/
public static FactorWord lookupWord(View view, String word)
{
SideKickParsedData data = SideKickParsedData.getParsedData(view);
if(data instanceof FactorParsedData)
{
FactorParsedData fdata = (FactorParsedData)data;
return getExternalInstance().searchVocabulary(fdata.use,word);
}
else
FactorParsedData fdata = getParsedData(view);
if(fdata == null)
return null;
else
return getExternalInstance().searchVocabulary(fdata.use,word);
} //}}}
//{{{ factorWord() method
@ -230,18 +243,14 @@ public class FactorPlugin extends EditPlugin
*/
public static String factorWord(View view, String word)
{
SideKickParsedData data = SideKickParsedData
.getParsedData(view);
if(data instanceof FactorParsedData)
{
FactorParsedData fdata = (FactorParsedData)data;
return "\""
+ FactorReader.charsToEscapes(word)
+ "\" " + FactorReader.unparseObject(fdata.use)
+ " search";
}
else
FactorParsedData fdata = getParsedData(view);
if(fdata == null)
return null;
return "\""
+ FactorReader.charsToEscapes(word)
+ "\" " + FactorReader.unparseObject(fdata.use)
+ " search";
} //}}}
//{{{ factorWord() method
@ -295,6 +304,22 @@ public class FactorPlugin extends EditPlugin
evalInWire(word + " " + op);
} //}}}
//{{{ factorWordPopupOp() method
/**
* Apply a Factor word to the selected word.
*/
public static void factorWordPopupOp(View view, String op) throws IOException
{
String word = factorWord(view);
if(word == null)
view.getToolkit().beep();
else
{
new TextAreaPopup(view.getTextArea(),
evalInWire(word + " " + op).trim());
}
} //}}}
//{{{ toWordArray() method
public static FactorWord[] toWordArray(Set completions)
{
@ -305,19 +330,20 @@ public class FactorPlugin extends EditPlugin
return w;
} //}}}
//{{{ getCompletions() method
//{{{ getWordCompletions() method
/**
* Returns all words in all vocabularies.
* Returns all words in all vocabularies whose name starts with
* <code>word</code>.
*
* @param anywhere If true, matches anywhere in the word name are
* returned; otherwise, only matches from beginning.
*/
public static Set getCompletions(String word, boolean anywhere)
public static Set getWordCompletions(String word, boolean anywhere)
{
try
{
Set completions = new HashSet();
getExternalInstance().getCompletions(
getExternalInstance().getWordCompletions(
getExternalInstance().getVocabularies(),
word,
anywhere,
@ -330,6 +356,27 @@ public class FactorPlugin extends EditPlugin
}
} //}}}
//{{{ getVocabCompletions() method
/**
* Returns all vocabularies whose name starts with
* <code>vocab</code>.
*
* @param anywhere If true, matches anywhere in the word name are
* returned; otherwise, only matches from beginning.
*/
public static String[] getVocabCompletions(String vocab, boolean anywhere)
{
try
{
return getExternalInstance().getVocabCompletions(
vocab,anywhere);
}
catch(Exception e)
{
throw new RuntimeException(e);
}
} //}}}
//{{{ getWordStartIndex() method
public static int getWordStartOffset(String line, int caret)
{
@ -403,16 +450,14 @@ public class FactorPlugin extends EditPlugin
//{{{ isUsed() method
public static boolean isUsed(View view, String vocab)
{
SideKickParsedData data = SideKickParsedData
.getParsedData(view);
if(data instanceof FactorParsedData)
FactorParsedData fdata = getParsedData(view);
if(fdata == null)
return false;
else
{
FactorParsedData fdata = (FactorParsedData)data;
Cons use = fdata.use;
return Cons.contains(use,vocab);
}
else
return false;
} //}}}
//{{{ findAllWordsNamed() method
@ -455,6 +500,109 @@ public class FactorPlugin extends EditPlugin
}
} //}}}
//{{{ findUse() method
/**
* Find an existing USING: declaration.
*/
private static int findUse(Buffer buffer)
{
for(int i = 0; i < buffer.getLineCount(); i++)
{
String text = buffer.getLineText(i);
int index = text.indexOf("USING:");
if(index != -1)
return buffer.getLineStartOffset(i) + index;
}
return -1;
} //}}}
//{{{ createUse() method
/**
* No USING: declaration exists, so add a new one.
*/
private static void createUse(Buffer buffer, String vocab)
{
String decl = "USING: " + vocab + " ;";
int offset = 0;
boolean leadingNewline = false;
boolean trailingNewline = true;
for(int i = 0; i < buffer.getLineCount(); i++)
{
String text = buffer.getLineText(i).trim();
if(text.startsWith("IN:"))
{
offset = buffer.getLineEndOffset(i) - 1;
leadingNewline = true;
}
else if(text.startsWith("!"))
{
offset = buffer.getLineEndOffset(i) - 1;
leadingNewline = true;
}
else if(text.length() == 0)
{
if(i == 0)
offset = 0;
else
offset = buffer.getLineEndOffset(i - 1) - 1;
leadingNewline = true;
trailingNewline = false;
}
else
break;
}
decl = (leadingNewline ? "\n" : "") + decl
+ (trailingNewline ? "\n" : "");
buffer.insert(offset,decl);
} //}}}
//{{{ updateUse() method
private static void updateUse(Buffer buffer, String vocab, int offset)
{
String text = buffer.getText(0,buffer.getLength());
int end = text.indexOf(";",offset);
if(end == -1)
end = buffer.getLength();
String decl = text.substring(offset + "USING:".length(),end);
List declList = new ArrayList();
StringTokenizer st = new StringTokenizer(decl);
while(st.hasMoreTokens())
declList.add(st.nextToken());
declList.add(vocab);
Collections.sort(declList);
StringBuffer buf = new StringBuffer("USING: ");
Iterator iter = declList.iterator();
while(iter.hasNext())
{
buf.append(iter.next());
buf.append(' ');
}
/* format() strips trailing whitespace */
decl = TextUtilities.format(buf.toString(),
buffer.getIntegerProperty("maxLineLen",64),
buffer.getTabSize()) + " ";
try
{
buffer.beginCompoundEdit();
buffer.remove(offset,end - offset);
buffer.insert(offset,decl);
}
finally
{
buffer.endCompoundEdit();
}
} //}}}
//{{{ insertUse() method
public static void insertUse(View view, String vocab)
{
@ -465,44 +613,14 @@ public class FactorPlugin extends EditPlugin
}
Buffer buffer = view.getBuffer();
int lastUseOffset = 0;
boolean leadingNewline = false;
boolean seenUse = false;
int offset = findUse(buffer);
for(int i = 0; i < buffer.getLineCount(); i++)
{
String text = buffer.getLineText(i).trim();
if(text.startsWith("IN:") || text.startsWith("USE:"))
{
lastUseOffset = buffer.getLineEndOffset(i) - 1;
leadingNewline = true;
seenUse = true;
}
else if(text.startsWith("!") && !seenUse)
{
lastUseOffset = buffer.getLineEndOffset(i) - 1;
leadingNewline = true;
}
else if(text.length() == 0 && !seenUse)
{
if(i == 0)
lastUseOffset = 0;
else
lastUseOffset = buffer.getLineEndOffset(i - 1) - 1;
}
else
{
break;
}
}
if(offset == -1)
createUse(buffer,vocab);
else
updateUse(buffer,vocab,offset);
String decl = "USE: " + vocab;
if(leadingNewline)
decl = "\n" + decl;
if(lastUseOffset == 0)
decl = decl + "\n";
buffer.insert(lastUseOffset,decl);
showStatus(view,"inserted-use",decl);
showStatus(view,"inserted-use",vocab);
} //}}}
//{{{ extractWord() method
@ -514,9 +632,8 @@ public class FactorPlugin extends EditPlugin
if(selection == null)
selection = "";
SideKickParsedData data = SideKickParsedData
.getParsedData(view);
if(!(data instanceof FactorParsedData))
FactorParsedData data = getParsedData(view);
if(data == null)
{
view.getToolkit().beep();
return;
@ -552,8 +669,16 @@ public class FactorPlugin extends EditPlugin
try
{
buffer.beginCompoundEdit();
int firstLine = buffer.getLineOfOffset(start);
buffer.insert(start,newDef);
int lastLine = buffer.getLineOfOffset(start
+ newDef.length());
buffer.indentLines(firstLine,lastLine);
textArea.setSelectedText(newWord);
}
finally
@ -561,4 +686,27 @@ public class FactorPlugin extends EditPlugin
buffer.endCompoundEdit();
}
} //}}}
//{{{ getRulesetAtOffset() method
public static String getRulesetAtOffset(JEditTextArea textArea, int caret)
{
int line = textArea.getLineOfOffset(caret);
DefaultTokenHandler h = new DefaultTokenHandler();
textArea.getBuffer().markTokens(line,h);
Token tokens = h.getTokens();
int offset = caret - textArea.getLineStartOffset(line);
int len = textArea.getLineLength(line);
if(len == 0)
return null;
if(offset == len)
offset--;
Token token = TextUtilities.getTokenAtOffset(tokens,offset);
return token.rules.getName();
} //}}}
}

View File

@ -2,7 +2,7 @@
plugin.factor.jedit.FactorPlugin.activate=startup
plugin.factor.jedit.FactorPlugin.name=Factor
plugin.factor.jedit.FactorPlugin.version=0.71
plugin.factor.jedit.FactorPlugin.version=0.72
plugin.factor.jedit.FactorPlugin.author=Slava Pestov
plugin.factor.jedit.FactorPlugin.docs=/doc/jedit/index.html
@ -29,6 +29,12 @@ plugin.factor.jedit.FactorPlugin.menu=factor-listener \
- \
factor-extract-word \
- \
factor-infer-effect \
factor-infer-effects \
- \
factor-compile \
factor-compile-all \
- \
factor-restart
factor-listener.label=Listener
@ -41,6 +47,10 @@ factor-edit.label=Edit word at caret
factor-edit-dialog.label=Edit word...
factor-usages.label=Word usages at caret
factor-extract-word.label=Extract word...
factor-infer-effect.label=Infer word at caret
factor-infer-effects.label=Infer all words in buffer
factor-compile.label=Compile word at caret
factor-compile-all.label=Compile all words in buffer
factor-restart.label=Restart Factor
# SideKick stuff
@ -48,15 +58,12 @@ sidekick.parser.factor.label=Factor
mode.factor.sidekick.parser=factor
factor.completion.in=<font color="#a0a0a0">IN: {0}</font>\
factor.completion.colon=: <b>{0}</b>
factor.completion.defer=DEFER: <b>{0}</b>
factor.completion.parsing=PARSING: <b>{0}</b>
factor.completion.symbol=SYMBOL: <b>{0}</b>
factor.completion.def={0} <b>{1}</b>
factor.completion.stack={0} ( {1})
# Dialog boxes
factor.status.inserted-use=Inserted {0}
factor.status.already-used=Already used {0}
factor.status.inserted-use=Using {0}
factor.status.already-used=Already using {0}
factor.insert-use.title=Insert USE: Declaration
factor.insert-use.caption=There are multiple words named "{0}". Select the one to use:

View File

@ -203,7 +203,11 @@ public class FactorShell extends Shell
output.print(console.getInfoColor(),
jEdit.getProperty("factor.shell.opening"));
stream = FactorPlugin.getExternalInstance().openStream();
stream = null;
ExternalFactor external = FactorPlugin.getExternalInstance();
if(external != null)
stream = external.openStream();
if(stream == null)
{
output.print(console.getInfoColor(),

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2004 Slava Pestov.
* Copyright (C) 2004, 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -130,12 +130,12 @@ public class FactorSideKickParser extends SideKickParser
errorSource);
r = new FactorReader(scanner,false,FactorPlugin.getExternalInstance());
Cons parsed = r.parse();
r.parse();
d.in = r.getIn();
d.use = r.getUse();
addWordDefNodes(d,parsed,buffer);
addWordDefNodes(d,r.getDefinedWords(),buffer);
}
catch(FactorParseException pe)
{
@ -172,38 +172,31 @@ public class FactorSideKickParser extends SideKickParser
} //}}}
//{{{ addWordDefNodes() method
private void addWordDefNodes(FactorParsedData d, Cons parsed, Buffer buffer)
private void addWordDefNodes(FactorParsedData d, Cons words, Buffer buffer)
{
FactorAsset last = null;
while(parsed != null)
while(words != null)
{
if(parsed.car instanceof FactorWordDefinition)
{
FactorWordDefinition def
= (FactorWordDefinition)
parsed.car;
FactorWord word = (FactorWord)words.car;
FactorWord word = def.word;
/* word lines are indexed from 1 */
int startLine = Math.max(0,Math.min(
buffer.getLineCount() - 1,
word.line - 1));
int startLineLength = buffer.getLineLength(startLine);
int startCol = Math.min(word.col,startLineLength);
/* word lines are indexed from 1 */
int startLine = Math.max(0,Math.min(
buffer.getLineCount() - 1,
word.line - 1));
int startLineLength = buffer.getLineLength(startLine);
int startCol = Math.min(word.col,startLineLength);
int start = buffer.getLineStartOffset(startLine)
+ startCol;
int start = buffer.getLineStartOffset(startLine)
+ startCol;
if(last != null)
last.end = buffer.createPosition(Math.max(0,start - 1));
if(last != null)
last.end = buffer.createPosition(Math.max(0,start - 1));
last = new FactorAsset(word,buffer.createPosition(start));
d.root.add(new DefaultMutableTreeNode(last));
last = new FactorAsset(word,buffer.createPosition(start));
d.root.add(new DefaultMutableTreeNode(last));
}
parsed = parsed.next();
words = words.next();
}
if(last != null)
@ -252,11 +245,16 @@ public class FactorSideKickParser extends SideKickParser
*/
public SideKickCompletion complete(EditPane editPane, int caret)
{
SideKickParsedData _data = SideKickParsedData
.getParsedData(editPane.getView());
if(!(_data instanceof FactorParsedData))
FactorParsedData data = FactorPlugin.getParsedData(
editPane.getView());
if(data == null)
return null;
String ruleset = FactorPlugin.getRulesetAtOffset(
editPane.getTextArea(),caret);
if(ruleset == null)
return null;
FactorParsedData data = (FactorParsedData)_data;
Buffer buffer = editPane.getBuffer();
@ -291,14 +289,40 @@ public class FactorSideKickParser extends SideKickParser
if(word.length() == 0)
return null;
FactorWord[] completions = FactorPlugin.toWordArray(
FactorPlugin.getCompletions(word,false));
if(ruleset.equals("factor::USING"))
return vocabComplete(editPane,data,word,caret);
else
return wordComplete(editPane,data,word,caret);
} //}}}
//{{{ vocabComplete() method
private SideKickCompletion vocabComplete(EditPane editPane,
FactorParsedData data, String vocab, int caret)
{
String[] completions = FactorPlugin.getVocabCompletions(
vocab,false);
if(completions.length == 0)
return null;
else
{
return new FactorCompletion(editPane.getView(),
return new FactorVocabCompletion(editPane.getView(),
completions,vocab,data);
}
} //}}}
//{{{ wordComplete() method
private SideKickCompletion wordComplete(EditPane editPane,
FactorParsedData data, String word, int caret)
{
FactorWord[] completions = FactorPlugin.toWordArray(
FactorPlugin.getWordCompletions(word,false));
if(completions.length == 0)
return null;
else
{
return new FactorWordCompletion(editPane.getView(),
completions,word,data);
}
} //}}}

View File

@ -0,0 +1,95 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2004, 2005 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.
*/
package factor.jedit;
import factor.*;
import java.util.*;
import javax.swing.*;
import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*;
import sidekick.*;
public class FactorVocabCompletion extends AbstractCompletion
{
private String vocab;
//{{{ FactorVocabCompletion constructor
public FactorVocabCompletion(View view, String[] items,
String vocab, FactorParsedData data)
{
super(view,items,data);
this.vocab = vocab;
} //}}}
public String getLongestPrefix()
{
return MiscUtilities.getLongestPrefix(items,false);
}
public void insert(int index)
{
String selected = ((String)get(index));
String insert = selected.substring(vocab.length());
Buffer buffer = textArea.getBuffer();
textArea.setSelectedText(insert);
}
public int getTokenLength()
{
return vocab.length();
}
public boolean handleKeystroke(int selectedIndex, char keyChar)
{
if(keyChar == '\t' || keyChar == '\n')
{
insert(selectedIndex);
return false;
}
else if(keyChar == ' ')
{
insert(selectedIndex);
textArea.userInput(' ');
return false;
}
else
{
textArea.userInput(keyChar);
return true;
}
}
public ListCellRenderer getRenderer()
{
return new DefaultListCellRenderer();
}
}

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2004 Slava Pestov.
* Copyright (C) 2004, 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -36,29 +36,18 @@ import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*;
import sidekick.*;
public class FactorCompletion extends SideKickCompletion
public class FactorWordCompletion extends AbstractCompletion
{
private View view;
private JEditTextArea textArea;
private String word;
private FactorParsedData data;
//{{{ FactorCompletion constructor
public FactorCompletion(View view, FactorWord[] items,
//{{{ FactorWordCompletion constructor
public FactorWordCompletion(View view, FactorWord[] items,
String word, FactorParsedData data)
{
this.view = view;
textArea = view.getTextArea();
this.items = Arrays.asList(items);
super(view,items,data);
this.word = word;
this.data = data;
} //}}}
public String getLongestPrefix()
{
return MiscUtilities.getLongestPrefix(items,false);
}
public void insert(int index)
{
FactorWord selected = ((FactorWord)get(index));
@ -85,26 +74,6 @@ public class FactorCompletion extends SideKickCompletion
return word.length();
}
public boolean handleKeystroke(int selectedIndex, char keyChar)
{
if(keyChar == '\t' || keyChar == '\n')
{
insert(selectedIndex);
return false;
}
else if(keyChar == ' ')
{
insert(selectedIndex);
textArea.userInput(' ');
return false;
}
else
{
textArea.userInput(keyChar);
return true;
}
}
public ListCellRenderer getRenderer()
{
return new FactorWordRenderer(data.parser,false);

View File

@ -39,19 +39,12 @@ public class FactorWordRenderer extends DefaultListCellRenderer
//{{{ getWordHTMLString() method
public static String getWordHTMLString(FactorWord word, boolean showIn)
{
String prop = "factor.completion.colon";
/* if(def == null)
{
if(word.parsing != null)
prop = "factor.completion.parsing";
else
prop = "factor.completion.defer";
}
else if(def instanceof FactorSymbolDefinition)
{
prop = "factor.completion.symbol";
} */
String defStr = jEdit.getProperty(
"factor.completion.def",
new String[] {
MiscUtilities.charsToEntities(word.getDefiner().name),
MiscUtilities.charsToEntities(word.name)
});
String in;
if(showIn)
@ -64,8 +57,8 @@ public class FactorWordRenderer extends DefaultListCellRenderer
else
in = "";
String html = "<html>" + in + jEdit.getProperty(prop,
new Object[] { MiscUtilities.charsToEntities(word.name) });
String html = "<html>" + in + defStr;
if(word.stackEffect != null)
{
html = jEdit.getProperty("factor.completion.stack",

View File

@ -0,0 +1,89 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2005 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.
*/
package factor.jedit;
import factor.*;
import java.io.IOException;
import java.util.*;
import org.gjt.sp.jedit.io.VFSManager;
import org.gjt.sp.jedit.*;
import org.gjt.sp.util.*;
/**
* A class used to compile all words in a file, or infer stack effects of all
* words in a file, etc.
*/
public class InferBufferProcessor extends FactorBufferProcessor
{
//{{{ createInferUnitTests() method
public static void createInferUnitTests(View view,
final Buffer buffer)
throws Exception
{
final String results = new InferBufferProcessor(view,buffer)
.getResults();
final Buffer newBuffer = jEdit.newFile(view);
VFSManager.runInAWTThread(new Runnable()
{
public void run()
{
newBuffer.setMode("factor");
try
{
newBuffer.insert(0,results);
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
}
}
});
} //}}}
//{{{ InferBufferProcessor constructor
public InferBufferProcessor(View view, Buffer buffer)
throws Exception
{
super(view,buffer,false);
} //}}}
//{{{ processWord() method
/**
* @return Code to process the word.
*/
public String processWord(FactorWord word)
{
StringBuffer expression = new StringBuffer();
expression.append(FactorPlugin.factorWord(word));
expression.append(" unit infer>test print");
return expression.toString();
} //}}}
}

View File

@ -87,10 +87,7 @@ public class ListenerAttributeSet extends SimpleAttributeSet
//{{{ createActionsMenu() method
private Action[] createActionsMenu(Cons alist)
{
if(alist == null)
return null;
int length = alist.length();
int length = Cons.length(alist);
int i = 0;
Action[] actions = new Action[length];
while(alist != null)

View File

@ -38,48 +38,16 @@ import org.gjt.sp.jedit.textarea.JEditTextArea;
import org.gjt.sp.jedit.*;
import org.gjt.sp.util.Log;
public class WordPopup extends JWindow
public class TextAreaPopup extends JWindow
{
private View view;
private JTextArea preview;
//{{{ showWordPopup() method
public static void showWordPopup(JEditTextArea textArea)
//{{{ TextAreaPopup constructor
public TextAreaPopup(JEditTextArea textArea, String text)
{
View view = GUIUtilities.getView(textArea);
String def;
try
{
def = FactorPlugin.evalInWire(
FactorPlugin.factorWord(view)
+ " see").trim();
}
catch(IOException io)
{
def = io.toString();
Log.log(Log.ERROR,WordPopup.class,io);
}
WordPopup popup = new WordPopup(view,def);
int line = textArea.getCaretLine();
String lineText = textArea.getLineText(line);
int caret = textArea.getCaretPosition()
- textArea.getLineStartOffset(line);
int start = FactorPlugin.getWordStartOffset(lineText,caret);
Point loc = textArea.offsetToXY(line,start);
loc.y += textArea.getPainter().getFontMetrics().getHeight();
SwingUtilities.convertPointToScreen(loc,textArea.getPainter());
popup.setLocation(loc);
popup.show();
} //}}}
//{{{ WordPopup constructor
public WordPopup(View view, String text)
{
super(view);
this.view = view;
super(GUIUtilities.getView(textArea));
this.view = GUIUtilities.getView(textArea);
preview = new JTextArea(text);
preview.setEditable(false);
getContentPane().add(BorderLayout.CENTER,new JScrollPane(preview));
@ -91,6 +59,23 @@ public class WordPopup extends JWindow
view.setKeyEventInterceptor(keyHandler);
GUIUtilities.requestFocus(this,preview);
positionAtCaret(textArea);
setVisible(true);
} //}}}
//{{{ positionAtCaret() method
private void positionAtCaret(JEditTextArea textArea)
{
int line = textArea.getCaretLine();
String lineText = textArea.getLineText(line);
int caret = textArea.getCaretPosition()
- textArea.getLineStartOffset(line);
int start = FactorPlugin.getWordStartOffset(lineText,caret);
Point loc = textArea.offsetToXY(line,start);
loc.y += textArea.getPainter().getFontMetrics().getHeight();
SwingUtilities.convertPointToScreen(loc,textArea.getPainter());
setLocation(loc);
} //}}}
//{{{ KeyHandler class

View File

@ -91,26 +91,11 @@ public class WordPreview implements ActionListener, CaretListener
private FactorWord getWordAtCaret(FactorParsedData fdata)
throws IOException
{
int line = textArea.getCaretLine();
int caret = textArea.getCaretPosition();
DefaultTokenHandler h = new DefaultTokenHandler();
textArea.getBuffer().markTokens(line,h);
Token tokens = h.getTokens();
int offset = caret - textArea.getLineStartOffset(line);
int len = textArea.getLineLength(line);
if(len == 0)
String name = FactorPlugin.getRulesetAtOffset(textArea,
textArea.getCaretPosition());
if(name == null)
return null;
if(offset == len)
offset--;
Token token = TextUtilities.getTokenAtOffset(tokens,offset);
String name = token.rules.getName();
for(int i = 0; i < IGNORED_RULESETS.length; i++)
{
if(name.equals(IGNORED_RULESETS[i]))
@ -134,10 +119,13 @@ public class WordPreview implements ActionListener, CaretListener
if(SideKickPlugin.isParsingBuffer(view.getBuffer()))
return;
SideKickParsedData data = SideKickParsedData.getParsedData(view);
if(data instanceof FactorParsedData)
if(!view.getBuffer().isLoaded())
return;
FactorParsedData data = FactorPlugin.getParsedData(view);
if(data != null)
{
FactorWord w = getWordAtCaret((FactorParsedData)data);
FactorWord w = getWordAtCaret(data);
if(w != null)
{
view.getStatus().setMessageAndClear(

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2004 Slava Pestov.
* Copyright (C) 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -31,20 +31,15 @@ package factor.parser;
import factor.*;
public class Defer extends FactorParsingDefinition
public class BeginCons extends FactorParsingDefinition
{
//{{{ Defer constructor
/**
* A new definition.
*/
public Defer(FactorWord word)
public BeginCons(FactorWord word)
{
super(word);
} //}}}
}
public void eval(FactorReader reader)
throws Exception
{
reader.nextWord(true);
reader.pushState(word,null);
}
}

View File

@ -33,12 +33,9 @@ import factor.*;
public class BeginConstructor extends FactorParsingDefinition
{
private FactorWord colon;
public BeginConstructor(FactorWord word, FactorWord colon)
public BeginConstructor(FactorWord word)
{
super(word);
this.colon = colon;
}
public void eval(FactorReader reader)
@ -48,6 +45,8 @@ public class BeginConstructor extends FactorParsingDefinition
if(type == null)
return;
reader.pushExclusiveState(colon,type);
reader.intern("<" + type + ">",true);
reader.pushExclusiveState(word,type);
}
}

View File

@ -33,12 +33,9 @@ import factor.*;
public class BeginMethod extends FactorParsingDefinition
{
private FactorWord colon;
public BeginMethod(FactorWord word, FactorWord colon)
public BeginMethod(FactorWord word)
{
super(word);
this.colon = colon;
}
public void eval(FactorReader reader)
@ -48,10 +45,10 @@ public class BeginMethod extends FactorParsingDefinition
if(type == null)
return;
FactorWord generic = reader.nextWord(false);
if(generic == null)
FactorWord newWord = reader.nextWord(false);
if(newWord == null)
return;
reader.pushExclusiveState(colon,generic);
reader.pushExclusiveState(word,newWord);
}
}

View File

@ -31,9 +31,9 @@ package factor.parser;
import factor.*;
public class Symbol extends FactorParsingDefinition
public class BeginPredicate extends FactorParsingDefinition
{
public Symbol(FactorWord word)
public BeginPredicate(FactorWord word)
{
super(word);
}
@ -41,8 +41,18 @@ public class Symbol extends FactorParsingDefinition
public void eval(FactorReader reader)
throws Exception
{
FactorWord w = reader.nextWord(true);
w.def = new FactorSymbolDefinition(w,w);
reader.append(w.def);
FactorWord supertype = reader.nextWord(false);
if(supertype == null)
return;
FactorWord type = reader.nextWord(true);
if(type == null)
return;
type.setDefiner(word);
reader.intern(type + "?",true);
reader.pushExclusiveState(word,type);
}
}

View File

@ -31,9 +31,9 @@ package factor.parser;
import factor.*;
public class Generic extends FactorParsingDefinition
public class BeginUnion extends FactorParsingDefinition
{
public Generic(FactorWord word)
public BeginUnion(FactorWord word)
{
super(word);
}
@ -41,8 +41,14 @@ public class Generic extends FactorParsingDefinition
public void eval(FactorReader reader)
throws Exception
{
FactorWord w = reader.nextWord(true);
w.def = new FactorGenericDefinition(w);
reader.append(w.def);
FactorWord type = reader.nextWord(true);
if(type == null)
return;
type.setDefiner(word);
reader.intern(type + "?",true);
reader.pushExclusiveState(word,type);
}
}

View File

@ -43,9 +43,10 @@ public class Def extends FactorParsingDefinition
{
FactorWord newWord = reader.nextWord(true);
if(newWord == null)
return;
reader.pushExclusiveState(word,newWord);
if(newWord != null)
{
newWord.setDefiner(word);
reader.pushExclusiveState(word,newWord);
}
}
}

View File

@ -31,9 +31,13 @@ package factor.parser;
import factor.*;
public class Traits extends FactorParsingDefinition
/**
* A definer where the word name to be defined follows the parsing word.
* Eg, DEFER: SYMBOL: GENERIC: etc.
*/
public class Definer extends FactorParsingDefinition
{
public Traits(FactorWord word)
public Definer(FactorWord word)
{
super(word);
}
@ -42,12 +46,9 @@ public class Traits extends FactorParsingDefinition
throws Exception
{
FactorWord w = reader.nextWord(true);
if(w == null)
return;
w.def = new FactorTraitsDefinition(w);
reader.intern("<" + w.name + ">",true);
reader.intern(w.name + "?",true);
reader.append(w.def);
/* Only ever null with restartable scanner;
error already logged, so give up */
if(w != null)
w.setDefiner(word);
}
}

View File

@ -0,0 +1,51 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2005 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.
*/
package factor.parser;
import factor.*;
public class EndCons extends FactorParsingDefinition
{
public FactorWord start;
public EndCons(FactorWord start, FactorWord end)
{
super(end);
this.start = start;
}
public void eval(FactorReader reader) throws FactorParseException
{
Cons list = reader.popState(start,word).first;
if(Cons.length(list) != 2)
reader.getScanner().error("Exactly two objects must be between [[ and ]]");
reader.append(new Cons(list.car,list.next().car));
}
}

View File

@ -33,25 +33,16 @@ import factor.*;
public class Ine extends FactorParsingDefinition
{
public FactorWord start;
public Ine(FactorWord start, FactorWord end)
public Ine(FactorWord end)
{
super(end);
this.start = start;
}
public void eval(FactorReader reader)
throws Exception
{
FactorReader.ParseState state = reader.popState(start,word);
FactorWord w = state.defining;
/* Only ever null with restartable scanner;
error already logged, so give up */
if(w == null)
return;
w.def = new FactorCompoundDefinition(w,state.first);
reader.append(w.def);
FactorReader.ParseState state = reader.popState(null,word);
if(state.defining == null)
reader.getScanner().error(word + " does not close " + state.start);
}
}

72
factor/parser/Tuple.java Normal file
View File

@ -0,0 +1,72 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2005 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.
*/
package factor.parser;
import factor.*;
public class Tuple extends FactorParsingDefinition
{
public Tuple(FactorWord word)
{
super(word);
}
public void eval(FactorReader reader)
throws Exception
{
Object next = reader.nextNonEOL(false,false);
if(!(next instanceof String))
{
reader.getScanner().error("Missing tuple name");
return;
}
String tupleName = (String)next;
reader.intern(tupleName,true);
reader.intern("<" + tupleName + ">",true);
for(;;)
{
next = reader.next(false,false);
if(next == FactorScanner.EOF)
{
reader.getScanner().error("Expected ;");
break;
}
else if(next.equals(";"))
break;
else if(next instanceof String)
{
reader.intern(tupleName + "-" + next,true);
reader.intern("set-" + tupleName + "-" + next,true);
}
}
}
}

View File

@ -3,7 +3,7 @@
/*
* $Id$
*
* Copyright (C) 2004 Slava Pestov.
* Copyright (C) 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -31,23 +31,25 @@ package factor.parser;
import factor.*;
public class Bar extends FactorParsingDefinition
public class Using extends FactorParsingDefinition
{
//{{{ Bar constructor
/**
* A new definition.
*/
public Bar(FactorWord word)
public Using(FactorWord word)
{
super(word);
} //}}}
}
public void eval(FactorReader reader)
throws Exception
{
FactorReader.ParseState state = reader.getCurrentState();
if(state.start != reader.intern("[",false))
reader.error("| only allowed inside [ ... ]");
reader.bar();
for(;;)
{
Object next = reader.next(false,false);
if(next == FactorScanner.EOF)
reader.getScanner().error("Expected ;");
if(next.equals(";"))
break;
else if(next instanceof String)
reader.addUse((String)next);
}
}
}

BIN
fonts/Vera.ttf Normal file

Binary file not shown.

BIN
fonts/VeraBI.ttf Normal file

Binary file not shown.

BIN
fonts/VeraBd.ttf Normal file

Binary file not shown.

BIN
fonts/VeraIt.ttf Normal file

Binary file not shown.

BIN
fonts/VeraMoBI.ttf Normal file

Binary file not shown.

BIN
fonts/VeraMoBd.ttf Normal file

Binary file not shown.

BIN
fonts/VeraMoIt.ttf Normal file

Binary file not shown.

BIN
fonts/VeraMono.ttf Normal file

Binary file not shown.

BIN
fonts/VeraSe.ttf Normal file

Binary file not shown.

BIN
fonts/VeraSeBd.ttf Normal file

Binary file not shown.

39
library/arrays.factor Normal file
View File

@ -0,0 +1,39 @@
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel-internals
USING: generic math-internals kernel lists vectors ;
! An array is a range of memory storing pointers to other
! objects. Arrays are not used directly, and their access words
! are not bounds checked. Examples of abstractions built on
! arrays include vectors, hashtables, and tuples.
! These words are unsafe. I'd say "do not call them", but that
! Java-esque. By all means, do use arrays if you need something
! low-level... but be aware that vectors are usually a better
! choice.
BUILTIN: array 8
DEFER: %fixnum
: array-capacity ( array -- n ) 1 slot %fixnum ; inline
: vector-array ( vec -- array ) >vector 2 slot %array ; inline
: set-vector-array ( array vec -- ) >vector 2 set-slot ; inline
: array-nth ( n array -- obj )
swap 2 fixnum+ slot ; inline
: set-array-nth ( obj n array -- )
swap 2 fixnum+ set-slot ; inline
: (array>list) ( n i array -- list )
pick pick fixnum<= [
3drop [ ]
] [
2dup array-nth >r >r 1 fixnum+ r> (array>list) r>
swap cons
] ifte ;
: array>list ( n array -- list )
0 swap (array>list) ;

View File

@ -1,32 +1,6 @@
! :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: lists
USE: kernel
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: lists USING: kernel ;
! An association list is a list of conses where the car of each
! cons is a key, and the cdr is a value. See the Factor
@ -36,22 +10,18 @@ USE: kernel
#! Push if the list appears to be an alist.
dup list? [ [ cons? ] all? ] [ drop f ] ifte ;
: assoc* ( key alist -- [ key | value ] )
: assoc* ( key alist -- [[ key value ]] )
#! Looks up the key in an alist. Push the key/value pair.
#! Most of the time you want to use assoc not assoc*.
dup [
2dup car car = [ nip car ] [ cdr assoc* ] ifte
] [
2drop f
] ifte ;
[ car = ] some-with? dup [ car ] when ;
: assoc ( key alist -- value )
#! Looks up the key in an alist.
assoc* dup [ cdr ] when ;
assoc* dup [ cdr ] when ;
: remove-assoc ( key alist -- alist )
#! Remove all key/value pairs with this key.
[ dupd car = not ] subset nip ;
[ car = not ] subset-with ;
: acons ( value key alist -- alist )
#! Adds the key/value pair to the alist. Existing pairs with
@ -70,11 +40,7 @@ USE: kernel
#! corresponding quotation, the value is popped off the
#! stack.
swap [
unswons rot assoc* dup [
cdr call
] [
2drop
] ifte
unswons rot assoc* dup [ cdr call ] [ 2drop ] ifte
] each-with ;
: 2cons ( car1 car2 cdr1 cdr2 -- cons1 cons2 )
@ -83,11 +49,7 @@ USE: kernel
: zip ( list list -- list )
#! Make a new list containing pairs of corresponding
#! elements from the two given lists.
dup [
2uncons zip >r cons r> cons
] [
2drop [ ]
] ifte ;
dup [ 2uncons zip >r cons r> cons ] [ 2drop [ ] ] ifte ;
: unzip ( assoc -- keys values )
#! Split an association list into two lists of keys and

View File

@ -1,55 +1,23 @@
! :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: init
USE: kernel
USE: lists
USE: parser
USE: stdio
USE: words
USE: namespaces
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
USING: kernel lists parser stdio words namespaces ;
"Cold boot in progress..." print
! vocabularies get [
! "generic" off
! ] bind
[
"/library/generic/generic.factor"
"/library/generic/object.factor"
"/library/generic/null.factor"
"/library/generic/builtin.factor"
"/library/generic/predicate.factor"
"/library/generic/union.factor"
"/library/generic/traits.factor"
"/library/generic/complement.factor"
"/library/generic/tuple.factor"
"/version.factor"
"/library/stack.factor"
"/library/combinators.factor"
"/library/arrays.factor"
"/library/kernel.factor"
"/library/cons.factor"
"/library/assoc.factor"
@ -58,14 +26,13 @@ USE: namespaces
"/library/math/ratio.factor"
"/library/math/float.factor"
"/library/math/complex.factor"
"/library/words.factor"
"/library/math/math-combinators.factor"
"/library/lists.factor"
"/library/dlists.factor"
"/library/vectors.factor"
"/library/strings.factor"
"/library/hashtables.factor"
"/library/words.factor"
"/library/namespaces.factor"
"/library/list-namespaces.factor"
"/library/sbuf.factor"
"/library/errors.factor"
"/library/continuations.factor"
@ -83,84 +50,99 @@ USE: namespaces
"/library/io/presentation.factor"
"/library/io/vocabulary-style.factor"
"/library/syntax/prettyprint.factor"
"/library/syntax/see.factor"
"/library/tools/debugger.factor"
"/library/math/constants.factor"
"/library/math/pow.factor"
"/library/math/trig-hyp.factor"
"/library/math/arc-trig-hyp.factor"
"/library/in-thread.factor"
"/library/io/network.factor"
"/library/io/logging.factor"
"/library/random.factor"
"/library/io/stdio-binary.factor"
"/library/io/files.factor"
"/library/eval-catch.factor"
"/library/tools/memory.factor"
"/library/tools/listener.factor"
"/library/tools/word-tools.factor"
"/library/test/test.factor"
"/library/io/ansi.factor"
"/library/tools/telnetd.factor"
"/library/tools/jedit-wire.factor"
"/library/tools/profiler.factor"
"/library/tools/heap-stats.factor"
"/library/gensym.factor"
"/library/tools/interpreter.factor"
! Inference needs to know primitive stack effects at load time
"/library/primitives.factor"
"/library/inference/dataflow.factor"
"/library/inference/inference.factor"
"/library/inference/branches.factor"
"/library/inference/words.factor"
"/library/inference/stack.factor"
"/library/inference/types.factor"
"/library/compiler/assembler.factor"
"/library/compiler/xt.factor"
"/library/compiler/optimizer.factor"
"/library/compiler/linearizer.factor"
"/library/compiler/simplifier.factor"
"/library/compiler/generator.factor"
"/library/compiler/compiler.factor"
"/library/compiler/alien-types.factor"
"/library/compiler/alien.factor"
"/library/sdl/sdl.factor"
"/library/sdl/sdl-video.factor"
"/library/sdl/sdl-event.factor"
"/library/sdl/sdl-gfx.factor"
"/library/sdl/sdl-keysym.factor"
"/library/sdl/sdl-keyboard.factor"
"/library/sdl/sdl-utils.factor"
"/library/sdl/hsv.factor"
"/library/sdl/console.factor"
"/library/bootstrap/image.factor"
"/library/httpd/url-encoding.factor"
"/library/httpd/html-tags.factor"
"/library/httpd/html.factor"
"/library/httpd/http-common.factor"
"/library/httpd/responder.factor"
"/library/httpd/httpd.factor"
"/library/httpd/file-responder.factor"
"/library/httpd/test-responder.factor"
"/library/httpd/quit-responder.factor"
"/library/httpd/resource-responder.factor"
"/library/httpd/default-responders.factor"
"/library/tools/jedit.factor"
"/library/cli.factor"
] [
dup print
run-resource
dup print run-resource
] each
IN: command-line DEFER: parse-command-line
parse-command-line
! Dummy defs for mini bootstrap
IN: compiler : compile-all ;
IN: assembler : init-assembler ;
IN: alien : add-library 3drop ;
"mini" get [
[
"/library/math/constants.factor"
"/library/math/pow.factor"
"/library/math/trig-hyp.factor"
"/library/math/arc-trig-hyp.factor"
"/library/syntax/see.factor"
"/library/gensym.factor"
"/library/in-thread.factor"
"/library/io/network.factor"
"/library/io/logging.factor"
"/library/random.factor"
"/library/io/stdio-binary.factor"
"/library/tools/word-tools.factor"
"/library/test/test.factor"
"/library/io/ansi.factor"
"/library/tools/telnetd.factor"
"/library/tools/jedit-wire.factor"
"/library/tools/profiler.factor"
"/library/tools/interpreter.factor"
"/library/inference/dataflow.factor"
"/library/inference/inference.factor"
"/library/inference/branches.factor"
"/library/inference/words.factor"
"/library/inference/stack.factor"
"/library/inference/types.factor"
"/library/inference/test.factor"
"/library/compiler/assembler.factor"
"/library/compiler/xt.factor"
"/library/compiler/optimizer.factor"
"/library/compiler/linearizer.factor"
"/library/compiler/simplifier.factor"
"/library/compiler/generator.factor"
"/library/compiler/compiler.factor"
"/library/compiler/alien-types.factor"
"/library/compiler/alien.factor"
"/library/sdl/sdl.factor"
"/library/sdl/sdl-video.factor"
"/library/sdl/sdl-event.factor"
"/library/sdl/sdl-gfx.factor"
"/library/sdl/sdl-keysym.factor"
"/library/sdl/sdl-keyboard.factor"
"/library/sdl/sdl-ttf.factor"
"/library/sdl/sdl-utils.factor"
"/library/sdl/hsv.factor"
"/library/bootstrap/image.factor"
"/library/httpd/url-encoding.factor"
"/library/httpd/html-tags.factor"
"/library/httpd/html.factor"
"/library/httpd/http-common.factor"
"/library/httpd/responder.factor"
"/library/httpd/httpd.factor"
"/library/httpd/file-responder.factor"
"/library/httpd/test-responder.factor"
"/library/httpd/quit-responder.factor"
"/library/httpd/resource-responder.factor"
"/library/httpd/cont-responder.factor"
"/library/httpd/browser-responder.factor"
"/library/httpd/default-responders.factor"
"/library/tools/jedit.factor"
] [
dup print run-resource
] each
] unless
os "win32" = [
[
"/library/io/buffer.factor"
@ -170,17 +152,32 @@ os "win32" = [
"/library/io/win32-io-internals.factor"
"/library/io/win32-stream.factor"
"/library/io/win32-server.factor"
"/library/io/win32-console.factor"
] [
dup print
run-resource
] each
] when
cpu "x86" = [
cpu "x86" = "mini" get not and [
[
"/library/compiler/assembly-x86.factor"
"/library/compiler/generator-x86.factor"
"/library/compiler/x86/assembler.factor"
"/library/compiler/x86/stack.factor"
"/library/compiler/x86/generator.factor"
"/library/compiler/x86/fixnum.factor"
"/library/ui/line-editor.factor"
"/library/ui/console.factor"
"/library/ui/shapes.factor"
"/library/ui/gadgets.factor"
"/library/ui/paint.factor"
"/library/ui/gestures.factor"
"/library/ui/hand.factor"
"/library/ui/layouts.factor"
"/library/ui/world.factor"
"/library/ui/labels.factor"
"/library/ui/buttons.factor"
"/library/ui/fields.factor"
"/library/ui/events.factor"
] [
dup print
run-resource

View File

@ -1,39 +1,7 @@
! :folding=none: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.
USE: lists
USE: image
USE: parser
USE: namespaces
USE: stdio
USE: kernel
USE: vectors
USE: words
USE: hashtables
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
USING: lists image parser namespaces stdio kernel vectors
words hashtables ;
"/library/bootstrap/primitives.factor" run-resource
@ -42,6 +10,7 @@ USE: hashtables
"/version.factor" parse-resource append,
"/library/stack.factor" parse-resource append,
"/library/combinators.factor" parse-resource append,
"/library/arrays.factor" parse-resource append,
"/library/kernel.factor" parse-resource append,
"/library/cons.factor" parse-resource append,
"/library/assoc.factor" parse-resource append,
@ -50,14 +19,13 @@ USE: hashtables
"/library/math/ratio.factor" parse-resource append,
"/library/math/float.factor" parse-resource append,
"/library/math/complex.factor" parse-resource append,
"/library/words.factor" parse-resource append,
"/library/math/math-combinators.factor" parse-resource append,
"/library/lists.factor" parse-resource append,
"/library/dlists.factor" parse-resource append,
"/library/vectors.factor" parse-resource append,
"/library/strings.factor" parse-resource append,
"/library/hashtables.factor" parse-resource append,
"/library/words.factor" parse-resource append,
"/library/namespaces.factor" parse-resource append,
"/library/list-namespaces.factor" parse-resource append,
"/library/sbuf.factor" parse-resource append,
"/library/errors.factor" parse-resource append,
"/library/continuations.factor" parse-resource append,
@ -70,8 +38,9 @@ USE: hashtables
"/library/syntax/parse-numbers.factor" parse-resource append,
"/library/syntax/parser.factor" parse-resource append,
"/library/syntax/parse-stream.factor" parse-resource append,
"/library/syntax/generic.factor" parse-resource append,
"/library/syntax/parse-syntax.factor" parse-resource append,
"traits" [ "generic" ] search
"delegate" [ "generic" ] search
"object" [ "generic" ] search
@ -79,17 +48,17 @@ USE: hashtables
reveal
reveal
reveal
"/library/generic/generic.factor" parse-resource append,
"/library/generic/object.factor" parse-resource append,
"/library/generic/null.factor" parse-resource append,
"/library/generic/builtin.factor" parse-resource append,
"/library/generic/predicate.factor" parse-resource append,
"/library/generic/union.factor" parse-resource append,
"/library/generic/traits.factor" parse-resource append,
"/library/generic/complement.factor" parse-resource append,
"/library/generic/tuple.factor" parse-resource append,
"/library/bootstrap/init.factor" parse-resource append,
"/library/syntax/parse-syntax.factor" parse-resource append,
] make-list
"boot" [ "kernel" ] search swons

View File

@ -2,7 +2,7 @@
! $Id$
!
! Copyright (C) 2004 Slava Pestov.
! Copyright (C) 2004, 2005 Slava Pestov.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met:
@ -41,6 +41,7 @@
IN: image
USE: errors
USE: generic
USE: kernel-internals
USE: hashtables
USE: kernel
USE: lists
@ -82,36 +83,28 @@ SYMBOL: boot-quot
: tag ( cell -- tag ) tag-mask bitand ;
: fixnum-tag BIN: 000 ; inline
: word-tag BIN: 001 ; inline
: bignum-tag BIN: 001 ; inline
: cons-tag BIN: 010 ; inline
: object-tag BIN: 011 ; inline
: ratio-tag BIN: 100 ; inline
: complex-tag BIN: 101 ; inline
: header-tag BIN: 110 ; inline
: f-type 6 ; inline
: t-type 7 ; inline
: array-type 8 ; inline
: bignum-type 9 ; inline
: float-type 10 ; inline
: vector-type 11 ; inline
: string-type 12 ; inline
: sbuf-type 13 ; inline
: port-type 14 ; inline
: dll-type 15 ; inline
: alien-type 16 ; inline
: t-type 7 ; inline
: array-type 8 ; inline
: hashtable-type 10 ; inline
: vector-type 11 ; inline
: string-type 12 ; inline
: word-type 17 ; inline
: immediate ( x tag -- tagged ) swap tag-bits shift bitor ;
: >header ( id -- tagged ) header-tag immediate ;
: >header ( id -- tagged ) object-tag immediate ;
( Image header )
: base
#! We relocate the image to after the header, and leaving
#! two empty cells. This lets us differentiate an F pointer
#! some empty cells. This lets us differentiate an F pointer
#! (0/tag 3) from a pointer to the first object in the
#! image.
2 cell * ;
64 cell * ;
: header ( -- )
image-magic emit
@ -150,19 +143,21 @@ GENERIC: ' ( obj -- ptr )
( Fixnums )
: emit-fixnum ( n -- ) fixnum-tag immediate emit ;
M: fixnum ' ( n -- tagged ) fixnum-tag immediate ;
( Bignums )
M: bignum ' ( bignum -- tagged )
#! This can only emit 0, -1 and 1.
object-tag here-as >r
bignum-type >header emit
bignum-tag here-as >r
bignum-tag >header emit
[
[ 0 | [ 1 0 ] ]
[ -1 | [ 2 1 1 ] ]
[ 1 | [ 2 0 1 ] ]
] assoc [ emit ] each align-here r> ;
[[ 0 [ 1 0 ] ]]
[[ -1 [ 2 1 1 ] ]]
[[ 1 [ 2 0 1 ] ]]
] assoc unswons emit-fixnum [ emit ] each align-here r> ;
( Special objects )
@ -183,7 +178,7 @@ M: f ' ( obj -- ptr )
: -1, -1 >bignum ' drop ;
( Beginning of the image )
! The image proper begins with the header, then T,
! The image begins with the header, then T,
! and the bignums 0, 1, and -1.
: begin ( -- ) header t, 0, 1, -1, ;
@ -192,16 +187,16 @@ M: f ' ( obj -- ptr )
: word, ( word -- )
[
word-tag >header ,
word-type >header ,
dup hashcode fixnum-tag immediate ,
0 ,
dup word-primitive ,
dup word-parameter ' ,
dup word-plist ' ,
dup word-props ' ,
0 ,
0 ,
] make-list
swap word-tag here-as pool-object
swap object-tag here-as pool-object
[ emit ] each ;
: word-error ( word msg -- )
@ -215,18 +210,10 @@ M: f ' ( obj -- ptr )
: transfer-word ( word -- word )
#! This is a hack. See doc/bootstrap.txt.
dup dup word-name swap word-vocabulary unit search
dup [
nip
] [
drop "Missing DEFER: " word-error
] ifte ;
[ dup "Missing DEFER: " word-error ] ?unless ;
: fixup-word ( word -- offset )
dup pooled-object dup [
nip
] [
drop "Not in image: " word-error
] ifte ;
dup pooled-object [ "Not in image: " word-error ] ?unless ;
: fixup-words ( -- )
image get [
@ -265,18 +252,16 @@ M: cons ' ( c -- tagged )
object-tag here-as swap
string-type >header emit
dup str-length emit
dup hashcode fixnum-tag immediate emit
pack-string
dup hashcode emit-fixnum
"\0" cat2 pack-string
align-here ;
M: string ' ( string -- pointer )
#! We pool strings so that each string is only written once
#! to the image
dup pooled-object dup [
nip
] [
drop dup emit-string dup >r pool-object r>
] ifte ;
dup pooled-object [
dup emit-string dup >r pool-object r>
] ?unless ;
( Arrays and vectors )
@ -284,7 +269,7 @@ M: string ' ( string -- pointer )
[ ' ] map
object-tag here-as >r
array-type >header emit
dup length emit
dup length emit-fixnum
( elements -- ) [ emit ] each
align-here r> ;
@ -292,37 +277,40 @@ M: string ' ( string -- pointer )
dup vector>list emit-array swap vector-length
object-tag here-as >r
vector-type >header emit
emit ( length )
emit-fixnum ( length )
emit ( array ptr )
align-here r> ;
M: vector ' ( vector -- pointer )
emit-vector ;
: rehash ( hashtable -- )
! Now make a rehashing boot quotation
dup hash>alist [
>r dup vector-length [
f swap pick set-vector-nth
] times* r>
[ unswons rot set-hash ] each-with
] cons cons
boot-quot [ append ] change ;
! : rehash ( hashtable -- )
! ! Now make a rehashing boot quotation
! dup hash>alist [
! over hash-clear
! [ unswons rot set-hash ] each-with
! ] cons cons
! boot-quot [ append ] change ;
: emit-hashtable ( hash -- pointer )
dup buckets>list emit-array swap hash>alist length
object-tag here-as >r
hashtable-type >header emit
emit-fixnum ( length )
emit ( array ptr )
align-here r> ;
M: hashtable ' ( hashtable -- pointer )
#! Only hashtables are pooled, not vectors!
dup pooled-object dup [
nip
] [
drop [ dup emit-vector [ pool-object ] keep ] keep
rehash
] ifte ;
dup pooled-object [
dup emit-hashtable [ pool-object ] keep
] ?unless ;
( End of the image )
: vocabularies, ( vocabularies -- )
[
cdr dup vector? [
cdr dup hashtable? [
[
cdr dup word? [ word, ] [ drop ] ifte
] hash-each
@ -364,16 +352,15 @@ M: hashtable ' ( hashtable -- pointer )
] ifte ;
: write-image ( image file -- )
<filebw> [ [ write-word ] vector-each ] with-stream ;
<file-writer> [ [ write-word ] vector-each ] with-stream ;
: with-minimal-image ( quot -- image )
[
300000 <vector> image set
521 <hashtable> "objects" set
<namespace> "objects" set
! Note that this is a vector that we can side-effect,
! since ; ends up using this variable from nested
! parser namespaces.
1000 <vector> "word-fixups" set
call
image get
] with-scope ;

View File

@ -1,49 +1,9 @@
! :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.
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel
USE: alien
USE: compiler
USE: errors
USE: inference
USE: command-line
USE: listener
USE: lists
USE: math
USE: namespaces
USE: parser
USE: random
USE: streams
USE: stdio
USE: presentation
USE: words
USE: unparser
USE: kernel-internals
USE: console
USING: alien compiler errors inference command-line listener
lists math namespaces parser random streams stdio presentation
words unparser kernel-internals console assembler memory ;
: default-cli-args
#! Some flags are *on* by default, unless user specifies
@ -53,16 +13,12 @@ USE: console
"smart-terminal" on
"verbose-compile" on
"compile" on
os "win32" = [
"sdl" "shell" set
] [
"ansi" "shell" set
] ifte ;
os "win32" = "sdl" "ansi" ? "shell" set ;
: warm-boot ( -- )
#! A fully bootstrapped image has this as the boot
#! quotation.
boot
init-assembler
init-error-handler
init-random
default-cli-args
@ -73,6 +29,7 @@ USE: console
[ "shells" ] search execute ;
[
boot
warm-boot
garbage-collection
run-user-init
@ -80,60 +37,22 @@ USE: console
0 exit*
] set-boot
init-error-handler
warm-boot
! An experiment gone wrong...
! : usage+ ( key -- )
! dup "usages" word-property
! [ succ ] [ 1 ] ifte*
! "usages" set-word-property ;
!
! GENERIC: count-usages ( quot -- )
! M: object count-usages drop ;
! M: word count-usages usage+ ;
! M: cons count-usages unswons count-usages count-usages ;
!
! : tally-usages ( -- )
! [ f "usages" set-word-property ] each-word
! [ word-parameter count-usages ] each-word ;
!
! : auto-inline ( count -- )
! #! Automatically inline all words called less than a count
! #! number of times.
! [
! 2dup "usages" word-property dup 0 ? >= [
! t "inline" set-word-property
! ] [
! drop
! ] ifte
! ] each-word drop ;
! "Counting word usages..." print
! tally-usages
!
! "Automatically inlining words called " write
! auto-inline-count unparse write
! " or less times..." print
! auto-inline-count auto-inline
default-cli-args
parse-command-line
os "win32" = "compile" get and [
"kernel32" "kernel32.dll" "stdcall" add-library
"user32" "user32.dll" "stdcall" add-library
"gdi32" "gdi32.dll" "stdcall" add-library
"winsock" "ws2_32.dll" "stdcall" add-library
"mswsock" "mswsock.dll" "stdcall" add-library
"libc" "msvcrt.dll" "cdecl" add-library
"sdl" "SDL.dll" "cdecl" add-library
"sdl-gfx" "SDL_gfx.dll" "cdecl" add-library
os "win32" = [
"kernel32" "kernel32.dll" "stdcall" add-library
"user32" "user32.dll" "stdcall" add-library
"gdi32" "gdi32.dll" "stdcall" add-library
"winsock" "ws2_32.dll" "stdcall" add-library
"mswsock" "mswsock.dll" "stdcall" add-library
"libc" "msvcrt.dll" "cdecl" add-library
"sdl" "SDL.dll" "cdecl" add-library
"sdl-gfx" "SDL_gfx.dll" "cdecl" add-library
"sdl-ttf" "SDL_ttf.dll" "cdecl" add-library
! FIXME: KLUDGE to get FFI-based IO going in Windows.
"/library/bootstrap/win32-io.factor" run-resource
] when
! FIXME: KLUDGE to get FFI-based IO going in Windows.
os "win32" = [ "/library/bootstrap/win32-io.factor" run-resource ] when
"Compiling system..." print
"compile" get [ compile-all ] when
@ -154,6 +73,5 @@ unparse write " words total" print
! Save a bit of space
global [ stdio off ] bind
garbage-collection
"factor.image" save-image
0 exit*

View File

@ -1,40 +1,11 @@
! :folding=none: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.
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: image
USE: kernel
USE: lists
USE: math
USE: namespaces
USE: parser
USE: words
USE: vectors
USE: hashtables
USE: generic
USING: kernel lists math memory namespaces parser words vectors
hashtables generic alien assembler compiler errors files generic
io-internals kernel kernel-internals lists math math-internals
parser profiler random strings unparser vectors words
hashtables ;
! Bring up a bare cross-compiling vocabulary.
"syntax" vocab
@ -54,177 +25,189 @@ vocabularies get [
<namespace> classes set
2 [
[ "words" | "execute" ]
[ "kernel" | "call" ]
[ "kernel" | "ifte" ]
[ "lists" | "cons" ]
[ "vectors" | "<vector>" ]
[ "vectors" | "vector-nth" ]
[ "vectors" | "set-vector-nth" ]
[ "strings" | "str-nth" ]
[ "strings" | "str-compare" ]
[ "strings" | "str=" ]
[ "strings" | "index-of*" ]
[ "strings" | "substring" ]
[ "strings" | "str-reverse" ]
[ "strings" | "<sbuf>" ]
[ "strings" | "sbuf-length" ]
[ "strings" | "set-sbuf-length" ]
[ "strings" | "sbuf-nth" ]
[ "strings" | "set-sbuf-nth" ]
[ "strings" | "sbuf-append" ]
[ "strings" | "sbuf>str" ]
[ "strings" | "sbuf-reverse" ]
[ "strings" | "sbuf-clone" ]
[ "strings" | "sbuf=" ]
[ "strings" | "sbuf-hashcode" ]
[ "math-internals" | "arithmetic-type" ]
[ "math" | ">fixnum" ]
[ "math" | ">bignum" ]
[ "math" | ">float" ]
[ "math-internals" | "(fraction>)" ]
[ "parser" | "str>float" ]
[ "unparser" | "(unparse-float)" ]
[ "math-internals" | "(rect>)" ]
[ "math-internals" | "fixnum=" ]
[ "math-internals" | "fixnum+" ]
[ "math-internals" | "fixnum-" ]
[ "math-internals" | "fixnum*" ]
[ "math-internals" | "fixnum/i" ]
[ "math-internals" | "fixnum/f" ]
[ "math-internals" | "fixnum-mod" ]
[ "math-internals" | "fixnum/mod" ]
[ "math-internals" | "fixnum-bitand" ]
[ "math-internals" | "fixnum-bitor" ]
[ "math-internals" | "fixnum-bitxor" ]
[ "math-internals" | "fixnum-bitnot" ]
[ "math-internals" | "fixnum-shift" ]
[ "math-internals" | "fixnum<" ]
[ "math-internals" | "fixnum<=" ]
[ "math-internals" | "fixnum>" ]
[ "math-internals" | "fixnum>=" ]
[ "math-internals" | "bignum=" ]
[ "math-internals" | "bignum+" ]
[ "math-internals" | "bignum-" ]
[ "math-internals" | "bignum*" ]
[ "math-internals" | "bignum/i" ]
[ "math-internals" | "bignum/f" ]
[ "math-internals" | "bignum-mod" ]
[ "math-internals" | "bignum/mod" ]
[ "math-internals" | "bignum-bitand" ]
[ "math-internals" | "bignum-bitor" ]
[ "math-internals" | "bignum-bitxor" ]
[ "math-internals" | "bignum-bitnot" ]
[ "math-internals" | "bignum-shift" ]
[ "math-internals" | "bignum<" ]
[ "math-internals" | "bignum<=" ]
[ "math-internals" | "bignum>" ]
[ "math-internals" | "bignum>=" ]
[ "math-internals" | "float=" ]
[ "math-internals" | "float+" ]
[ "math-internals" | "float-" ]
[ "math-internals" | "float*" ]
[ "math-internals" | "float/f" ]
[ "math-internals" | "float<" ]
[ "math-internals" | "float<=" ]
[ "math-internals" | "float>" ]
[ "math-internals" | "float>=" ]
[ "math-internals" | "facos" ]
[ "math-internals" | "fasin" ]
[ "math-internals" | "fatan" ]
[ "math-internals" | "fatan2" ]
[ "math-internals" | "fcos" ]
[ "math-internals" | "fexp" ]
[ "math-internals" | "fcosh" ]
[ "math-internals" | "flog" ]
[ "math-internals" | "fpow" ]
[ "math-internals" | "fsin" ]
[ "math-internals" | "fsinh" ]
[ "math-internals" | "fsqrt" ]
[ "words" | "<word>" ]
[ "words" | "update-xt" ]
[ "profiler" | "call-profiling" ]
[ "profiler" | "allot-profiling" ]
[ "words" | "compiled?" ]
[ "kernel" | "drop" ]
[ "kernel" | "dup" ]
[ "kernel" | "swap" ]
[ "kernel" | "over" ]
[ "kernel" | "pick" ]
[ "kernel" | ">r" ]
[ "kernel" | "r>" ]
[ "kernel" | "eq?" ]
[ "kernel-internals" | "getenv" ]
[ "kernel-internals" | "setenv" ]
[ "io-internals" | "open-file" ]
[ "files" | "stat" ]
[ "files" | "(directory)" ]
[ "kernel" | "garbage-collection" ]
[ "kernel" | "gc-time" ]
[ "kernel" | "save-image" ]
[ "kernel" | "datastack" ]
[ "kernel" | "callstack" ]
[ "kernel" | "set-datastack" ]
[ "kernel" | "set-callstack" ]
[ "kernel" | "exit*" ]
[ "io-internals" | "client-socket" ]
[ "io-internals" | "server-socket" ]
[ "io-internals" | "close-port" ]
[ "io-internals" | "add-accept-io-task" ]
[ "io-internals" | "accept-fd" ]
[ "io-internals" | "can-read-line?" ]
[ "io-internals" | "add-read-line-io-task" ]
[ "io-internals" | "read-line-fd-8" ]
[ "io-internals" | "can-read-count?" ]
[ "io-internals" | "add-read-count-io-task" ]
[ "io-internals" | "read-count-fd-8" ]
[ "io-internals" | "can-write?" ]
[ "io-internals" | "add-write-io-task" ]
[ "io-internals" | "write-fd-8" ]
[ "io-internals" | "add-copy-io-task" ]
[ "io-internals" | "pending-io-error" ]
[ "io-internals" | "next-io-task" ]
[ "kernel" | "room" ]
[ "kernel" | "os-env" ]
[ "kernel" | "millis" ]
[ "random" | "init-random" ]
[ "random" | "(random-int)" ]
[ "kernel" | "type" ]
[ "files" | "cwd" ]
[ "files" | "cd" ]
[ "compiler" | "compiled-offset" ]
[ "compiler" | "set-compiled-offset" ]
[ "compiler" | "literal-top" ]
[ "compiler" | "set-literal-top" ]
[ "kernel" | "address" ]
[ "alien" | "dlopen" ]
[ "alien" | "dlsym" ]
[ "alien" | "dlclose" ]
[ "alien" | "<alien>" ]
[ "alien" | "<local-alien>" ]
[ "alien" | "alien-cell" ]
[ "alien" | "set-alien-cell" ]
[ "alien" | "alien-4" ]
[ "alien" | "set-alien-4" ]
[ "alien" | "alien-2" ]
[ "alien" | "set-alien-2" ]
[ "alien" | "alien-1" ]
[ "alien" | "set-alien-1" ]
[ "kernel" | "heap-stats" ]
[ "errors" | "throw" ]
[ "kernel-internals" | "string>memory" ]
[ "kernel-internals" | "memory>string" ]
[ "alien" | "local-alien?" ]
[ "alien" | "alien-address" ]
[ "lists" | ">cons" ]
[ "vectors" | ">vector" ]
[ "strings" | ">string" ]
[ "words" | ">word" ]
[ "kernel-internals" | "slot" ]
[ "kernel-internals" | "set-slot" ]
[ "kernel-internals" | "integer-slot" ]
[ "kernel-internals" | "set-integer-slot" ]
[ "kernel-internals" | "grow-array" ]
] [
unswons create swap 1 + [ f define ] keep
[ "execute" "words" " word -- " ]
[ "call" "kernel" [ [ general-list ] [ ] ] ]
[ "ifte" "kernel" [ [ object general-list general-list ] [ ] ] ]
[ "cons" "lists" [ [ object object ] [ cons ] ] ]
[ "<vector>" "vectors" [ [ integer ] [ vector ] ] ]
[ "str-nth" "strings" [ [ integer string ] [ integer ] ] ]
[ "str-compare" "strings" [ [ string string ] [ integer ] ] ]
[ "str=" "strings" [ [ string string ] [ boolean ] ] ]
[ "index-of*" "strings" [ [ integer string text ] [ integer ] ] ]
[ "substring" "strings" [ [ integer integer string ] [ string ] ] ]
[ "str-reverse" "strings" [ [ string ] [ string ] ] ]
[ "<sbuf>" "strings" [ [ integer ] [ sbuf ] ] ]
[ "sbuf-length" "strings" [ [ sbuf ] [ integer ] ] ]
[ "set-sbuf-length" "strings" [ [ integer sbuf ] [ ] ] ]
[ "sbuf-nth" "strings" [ [ integer sbuf ] [ integer ] ] ]
[ "set-sbuf-nth" "strings" [ [ integer integer sbuf ] [ ] ] ]
[ "sbuf-append" "strings" [ [ text sbuf ] [ ] ] ]
[ "sbuf>str" "strings" [ [ sbuf ] [ string ] ] ]
[ "sbuf-reverse" "strings" [ [ sbuf ] [ ] ] ]
[ "sbuf-clone" "strings" [ [ sbuf ] [ sbuf ] ] ]
[ "sbuf=" "strings" [ [ sbuf sbuf ] [ boolean ] ] ]
[ "sbuf-hashcode" "strings" [ [ sbuf ] [ fixnum ] ] ]
[ "arithmetic-type" "math-internals" [ [ object object ] [ object object fixnum ] ] ]
[ ">fixnum" "math" [ [ number ] [ fixnum ] ] ]
[ ">bignum" "math" [ [ number ] [ bignum ] ] ]
[ ">float" "math" [ [ number ] [ float ] ] ]
[ "(fraction>)" "math-internals" [ [ integer integer ] [ rational ] ] ]
[ "str>float" "parser" [ [ string ] [ float ] ] ]
[ "(unparse-float)" "unparser" [ [ float ] [ string ] ] ]
[ "<complex>" "math-internals" [ [ real real ] [ number ] ] ]
[ "fixnum=" "math-internals" [ [ fixnum fixnum ] [ boolean ] ] ]
[ "fixnum+" "math-internals" [ [ fixnum fixnum ] [ integer ] ] ]
[ "fixnum-" "math-internals" [ [ fixnum fixnum ] [ integer ] ] ]
[ "fixnum*" "math-internals" [ [ fixnum fixnum ] [ integer ] ] ]
[ "fixnum/i" "math-internals" [ [ fixnum fixnum ] [ integer ] ] ]
[ "fixnum/f" "math-internals" [ [ fixnum fixnum ] [ integer ] ] ]
[ "fixnum-mod" "math-internals" [ [ fixnum fixnum ] [ fixnum ] ] ]
[ "fixnum/mod" "math-internals" [ [ fixnum fixnum ] [ integer fixnum ] ] ]
[ "fixnum-bitand" "math-internals" [ [ fixnum fixnum ] [ fixnum ] ] ]
[ "fixnum-bitor" "math-internals" [ [ fixnum fixnum ] [ fixnum ] ] ]
[ "fixnum-bitxor" "math-internals" [ [ fixnum fixnum ] [ fixnum ] ] ]
[ "fixnum-bitnot" "math-internals" [ [ fixnum ] [ fixnum ] ] ]
[ "fixnum-shift" "math-internals" [ [ fixnum fixnum ] [ fixnum ] ] ]
[ "fixnum<" "math-internals" [ [ fixnum fixnum ] [ boolean ] ] ]
[ "fixnum<=" "math-internals" [ [ fixnum fixnum ] [ boolean ] ] ]
[ "fixnum>" "math-internals" [ [ fixnum fixnum ] [ boolean ] ] ]
[ "fixnum>=" "math-internals" [ [ fixnum fixnum ] [ boolean ] ] ]
[ "bignum=" "math-internals" [ [ bignum bignum ] [ boolean ] ] ]
[ "bignum+" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum-" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum*" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum/i" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum/f" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum-mod" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum/mod" "math-internals" [ [ bignum bignum ] [ bignum bignum ] ] ]
[ "bignum-bitand" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum-bitor" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum-bitxor" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum-bitnot" "math-internals" [ [ bignum ] [ bignum ] ] ]
[ "bignum-shift" "math-internals" [ [ bignum bignum ] [ bignum ] ] ]
[ "bignum<" "math-internals" [ [ bignum bignum ] [ boolean ] ] ]
[ "bignum<=" "math-internals" [ [ bignum bignum ] [ boolean ] ] ]
[ "bignum>" "math-internals" [ [ bignum bignum ] [ boolean ] ] ]
[ "bignum>=" "math-internals" [ [ bignum bignum ] [ boolean ] ] ]
[ "float=" "math-internals" [ [ bignum bignum ] [ boolean ] ] ]
[ "float+" "math-internals" [ [ float float ] [ float ] ] ]
[ "float-" "math-internals" [ [ float float ] [ float ] ] ]
[ "float*" "math-internals" [ [ float float ] [ float ] ] ]
[ "float/f" "math-internals" [ [ float float ] [ float ] ] ]
[ "float<" "math-internals" [ [ float float ] [ boolean ] ] ]
[ "float<=" "math-internals" [ [ float float ] [ boolean ] ] ]
[ "float>" "math-internals" [ [ float float ] [ boolean ] ] ]
[ "float>=" "math-internals" [ [ float float ] [ boolean ] ] ]
[ "facos" "math-internals" [ [ real ] [ float ] ] ]
[ "fasin" "math-internals" [ [ real ] [ float ] ] ]
[ "fatan" "math-internals" [ [ real ] [ float ] ] ]
[ "fatan2" "math-internals" [ [ real real ] [ float ] ] ]
[ "fcos" "math-internals" [ [ real ] [ float ] ] ]
[ "fexp" "math-internals" [ [ real ] [ float ] ] ]
[ "fcosh" "math-internals" [ [ real ] [ float ] ] ]
[ "flog" "math-internals" [ [ real ] [ float ] ] ]
[ "fpow" "math-internals" [ [ real real ] [ float ] ] ]
[ "fsin" "math-internals" [ [ real ] [ float ] ] ]
[ "fsinh" "math-internals" [ [ real ] [ float ] ] ]
[ "fsqrt" "math-internals" [ [ real ] [ float ] ] ]
[ "<word>" "words" [ [ ] [ word ] ] ]
[ "update-xt" "words" [ [ word ] [ ] ] ]
[ "call-profiling" "profiler" [ [ integer ] [ ] ] ]
[ "allot-profiling" "profiler" [ [ integer ] [ ] ] ]
[ "compiled?" "words" [ [ word ] [ boolean ] ] ]
[ "drop" "kernel" [ [ object ] [ ] ] ]
[ "dup" "kernel" [ [ object ] [ object object ] ] ]
[ "swap" "kernel" [ [ object object ] [ object object ] ] ]
[ "over" "kernel" [ [ object object ] [ object object object ] ] ]
[ "pick" "kernel" [ [ object object object ] [ object object object object ] ] ]
[ ">r" "kernel" [ [ object ] [ ] ] ]
[ "r>" "kernel" [ [ ] [ object ] ] ]
[ "eq?" "kernel" [ [ object object ] [ boolean ] ] ]
[ "getenv" "kernel-internals" [ [ fixnum ] [ object ] ] ]
[ "setenv" "kernel-internals" [ [ object fixnum ] [ ] ] ]
[ "open-file" "io-internals" [ [ string object object ] [ port ] ] ]
[ "stat" "files" [ [ string ] [ general-list ] ] ]
[ "(directory)" "files" [ [ string ] [ general-list ] ] ]
[ "garbage-collection" "memory" [ [ ] [ ] ] ]
[ "gc-time" "memory" [ [ string ] [ ] ] ]
[ "save-image" "memory" [ [ string ] [ ] ] ]
[ "datastack" "kernel" " -- ds " ]
[ "callstack" "kernel" " -- cs " ]
[ "set-datastack" "kernel" " ds -- " ]
[ "set-callstack" "kernel" " cs -- " ]
[ "exit*" "kernel" [ [ integer ] [ ] ] ]
[ "client-socket" "io-internals" [ [ string integer ] [ port port ] ] ]
[ "server-socket" "io-internals" [ [ integer ] [ port ] ] ]
[ "close-port" "io-internals" [ [ port ] [ ] ] ]
[ "add-accept-io-task" "io-internals" [ [ port general-list ] [ ] ] ]
[ "accept-fd" "io-internals" [ [ port ] [ string integer port port ] ] ]
[ "can-read-line?" "io-internals" [ [ port ] [ boolean ] ] ]
[ "add-read-line-io-task" "io-internals" [ [ port general-list ] [ ] ] ]
[ "read-line-fd-8" "io-internals" [ [ port ] [ sbuf ] ] ]
[ "can-read-count?" "io-internals" [ [ integer port ] [ boolean ] ] ]
[ "add-read-count-io-task" "io-internals" [ [ integer port general-list ] [ ] ] ]
[ "read-count-fd-8" "io-internals" [ [ integer port ] [ sbuf ] ] ]
[ "can-write?" "io-internals" [ [ integer port ] [ boolean ] ] ]
[ "add-write-io-task" "io-internals" [ [ port general-list ] [ ] ] ]
[ "write-fd-8" "io-internals" [ [ text port ] [ ] ] ]
[ "add-copy-io-task" "io-internals" [ [ port port general-list ] [ ] ] ]
[ "pending-io-error" "io-internals" [ [ ] [ ] ] ]
[ "next-io-task" "io-internals" [ [ ] [ general-list ] ] ]
[ "room" "memory" [ [ ] [ integer integer integer integer ] ] ]
[ "os-env" "kernel" [ [ string ] [ object ] ] ]
[ "millis" "kernel" [ [ ] [ integer ] ] ]
[ "init-random" "random" [ [ ] [ ] ] ]
[ "(random-int)" "random" [ [ ] [ integer ] ] ]
[ "type" "kernel" [ [ object ] [ fixnum ] ] ]
[ "cwd" "files" [ [ ] [ string ] ] ]
[ "cd" "files" [ [ string ] [ ] ] ]
[ "compiled-offset" "assembler" [ [ ] [ integer ] ] ]
[ "set-compiled-offset" "assembler" [ [ integer ] [ ] ] ]
[ "literal-top" "assembler" [ [ ] [ integer ] ] ]
[ "set-literal-top" "assembler" [ [ integer ] [ ] ] ]
[ "address" "memory" [ [ object ] [ integer ] ] ]
[ "dlopen" "alien" [ [ string ] [ dll ] ] ]
[ "dlsym" "alien" [ [ string object ] [ integer ] ] ]
[ "dlclose" "alien" [ [ dll ] [ ] ] ]
[ "<alien>" "alien" [ [ integer ] [ alien ] ] ]
[ "<local-alien>" "alien" [ [ integer ] [ alien ] ] ]
[ "alien-cell" "alien" [ [ alien integer ] [ integer ] ] ]
[ "set-alien-cell" "alien" [ [ integer alien integer ] [ ] ] ]
[ "alien-4" "alien" [ [ alien integer ] [ integer ] ] ]
[ "set-alien-4" "alien" [ [ integer alien integer ] [ ] ] ]
[ "alien-2" "alien" [ [ alien integer ] [ fixnum ] ] ]
[ "set-alien-2" "alien" [ [ integer alien integer ] [ ] ] ]
[ "alien-1" "alien" [ [ alien integer ] [ fixnum ] ] ]
[ "set-alien-1" "alien" [ [ integer alien integer ] [ ] ] ]
[ "throw" "errors" [ [ object ] [ ] ] ]
[ "string>memory" "kernel-internals" [ [ string integer ] [ ] ] ]
[ "memory>string" "kernel-internals" [ [ integer integer ] [ string ] ] ]
[ "local-alien?" "alien" [ [ alien ] [ object ] ] ]
[ "alien-address" "alien" [ [ alien ] [ integer ] ] ]
[ ">cons" "lists" [ [ object ] [ cons ] ] ]
[ ">vector" "vectors" [ [ object ] [ vector ] ] ]
[ ">string" "strings" [ [ object ] [ string ] ] ]
[ ">word" "words" [ [ object ] [ word ] ] ]
[ ">hashtable" "hashtables" [ [ object ] [ hashtable ] ] ]
[ "slot" "kernel-internals" [ [ object fixnum ] [ object ] ] ]
[ "set-slot" "kernel-internals" [ [ object object fixnum ] [ ] ] ]
[ "integer-slot" "kernel-internals" [ [ object fixnum ] [ integer ] ] ]
[ "set-integer-slot" "kernel-internals" [ [ integer object fixnum ] [ ] ] ]
[ "grow-array" "kernel-internals" [ [ integer array ] [ object ] ] ]
[ "<hashtable>" "hashtables" [ [ number ] [ hashtable ] ] ]
[ "<array>" "kernel-internals" [ [ number ] [ array ] ] ]
[ "<tuple>" "kernel-internals" [ [ number ] [ tuple ] ] ]
[ ">array" "kernel-internals" [ [ object ] [ array ] ] ]
[ ">tuple" "kernel-internals" [ [ object ] [ tuple ] ] ]
[ "begin-scan" "memory" [ [ ] [ ] ] ]
[ "next-object" "memory" [ [ ] [ object ] ] ]
[ "end-scan" "memory" [ [ ] [ object ] ] ]
[ "size" "memory" [ [ ] [ object ] ] ]
] [
3unlist >r create >r 1 + r> 2dup swap f define r>
dup string? [
"stack-effect" set-word-property
] [
"infer-effect" set-word-property
] ifte
] each drop

View File

@ -52,8 +52,8 @@ USE: win32-io-internals
USE: win32-stream
USE: win32-api
: <filecr> <win32-filecr> ;
: <filecw> <win32-filecw> ;
: <file-reader> <win32-file-reader> ;
: <file-writer> <win32-file-writer> ;
: <server> <win32-server> ;
: init-stdio ( -- )

View File

@ -1,46 +1,8 @@
! :folding=indent:collapseFolds=1:
! $Id$
!
! 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:
!
! 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.
! See http://factor.sf.net/license.txt for BSD license.
IN: command-line
USE: compiler
USE: errors
USE: files
USE: listener
USE: kernel
USE: lists
USE: namespaces
USE: parser
USE: prettyprint
USE: random
USE: stdio
USE: streams
USE: strings
USE: words
USE: kernel-internals
USING: files kernel lists namespaces parser strings
kernel-internals ;
! This file is run as the last stage of boot.factor; it relies
! on all other words already being defined.

View File

@ -1,30 +1,5 @@
! :folding=indent:collapseFolds=1:
! $Id$
!
! 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:
!
! 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.
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel
: slip ( quot x -- x )
@ -54,7 +29,17 @@ IN: kernel
#! If the condition is not f, execute the 'true' quotation,
#! with the condition on the stack. Otherwise, pop the
#! condition and execute the 'false' quotation.
pick [ drop call ] [ nip nip call ] ifte ; inline
pick [ drop call ] [ 2nip call ] ifte ; inline
: ?ifte ( default cond true false -- )
#! If cond is true, drop default and apply true
#! quotation to cond. Otherwise, drop cond, and apply false
#! to default.
>r >r dup [
nip r> r> drop call
] [
drop r> drop r> call
] ifte ; inline
: unless ( cond quot -- )
#! Execute a quotation only when the condition is f. The
@ -72,6 +57,12 @@ IN: kernel
#! value than it produces.
over [ drop ] [ nip call ] ifte ; inline
: ?unless ( default cond false -- )
#! If cond is true, drop default and leave cond on the
#! stack. Otherwise, drop default, and apply false
#! quotation to default.
>r dup [ nip r> drop ] [ drop r> call ] ifte ; inline
: when ( cond quot -- )
#! Execute a quotation only when the condition is not f. The
#! condition is popped off the stack.
@ -89,6 +80,12 @@ IN: kernel
#! value than it produces.
dupd [ drop ] ifte ; inline
: ?when ( default cond true -- )
#! If cond is true, drop default and apply true
#! quotation to cond. Otherwise, drop cond, and leave
#! default on the stack.
>r dup [ nip r> call ] [ r> 2drop ] ifte ; inline
: forever ( quot -- )
#! The code is evaluated in an infinite loop. Typically, a
#! continuation is used to escape the infinite loop.

View File

@ -1,41 +1,8 @@
! :folding=indent:collapseFolds=0:
! $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.
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: alien
USE: compiler
USE: errors
USE: hashtables
USE: kernel
USE: lists
USE: math
USE: namespaces
USE: parser
USE: strings
USE: words
USING: assembler compiler errors hashtables kernel lists math
namespaces parser strings words ;
! Some code for interfacing with C structures.
@ -72,11 +39,9 @@ USE: words
: c-type ( name -- type )
global [
dup "c-types" get hash dup [
nip
] [
drop "No such C type: " swap cat2 throw f
] ifte
dup "c-types" get hash [
"No such C type: " swap cat2 throw f
] ?unless
] bind ;
: size ( name -- size )
@ -88,13 +53,13 @@ USE: words
: define-getter ( offset type name -- )
#! Define a word with stack effect ( alien -- obj ) in the
#! current 'in' vocabulary.
"in" get create >r
create-in >r
[ "getter" get ] bind cons r> swap define-compound ;
: define-setter ( offset type name -- )
#! Define a word with stack effect ( obj alien -- ) in the
#! current 'in' vocabulary.
"set-" swap cat2 "in" get create >r
"set-" swap cat2 create-in >r
[ "setter" get ] bind cons r> swap define-compound ;
: define-field ( offset type name -- offset )
@ -113,7 +78,7 @@ USE: words
#! Used for C functions that expect you to pass in a struct.
[ <local-alien> ] cons
[ "<" , "struct-name" get , ">" , ] make-string
"in" get create swap
create-in swap
define-compound ;
: define-struct-type ( width -- )
@ -154,6 +119,15 @@ global [ <namespace> "c-types" set ] bind
"unbox_alien" "unboxer" set
] "void*" define-c-type
! FIXME
[
[ alien-4 ] "getter" set
[ set-alien-4 ] "setter" set
4 "width" set
"box_integer" "boxer" set
"unbox_integer" "unboxer" set
] "long" define-c-type
[
[ alien-4 ] "getter" set
[ set-alien-4 ] "setter" set
@ -182,8 +156,8 @@ global [ <namespace> "c-types" set ] bind
[ alien-2 ] "getter" set
[ set-alien-2 ] "setter" set
2 "width" set
"box_cell" "boxer" set
"unbox_cell" "unboxer" set
"box_unsigned_2" "boxer" set
"unbox_unsigned_2" "unboxer" set
] "ushort" define-c-type
[
@ -198,8 +172,8 @@ global [ <namespace> "c-types" set ] bind
[ alien-1 ] "getter" set
[ set-alien-1 ] "setter" set
1 "width" set
"box_cell" "boxer" set
"unbox_cell" "unboxer" set
"box_unsigned_1" "boxer" set
"unbox_unsigned_1" "unboxer" set
] "uchar" define-c-type
[
@ -210,6 +184,14 @@ global [ <namespace> "c-types" set ] bind
"unbox_c_string" "unboxer" set
] "char*" define-c-type
[
[ alien-4 ] "getter" set
[ set-alien-4 ] "setter" set
cell "width" set
"box_utf16_string" "boxer" set
"unbox_utf16_string" "unboxer" set
] "ushort*" define-c-type
[
[ alien-4 0 = not ] "getter" set
[ 1 0 ? set-alien-4 ] "setter" set

View File

@ -1,58 +1,20 @@
! :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.
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: alien
USE: compiler
USE: errors
USE: generic
USE: inference
USE: interpreter
USE: kernel
USE: lists
USE: math
USE: namespaces
USE: parser
USE: words
USE: hashtables
USE: strings
USING: assembler compiler errors generic inference interpreter
kernel lists math namespaces parser words hashtables strings
unparser ;
! Command line parameters specify libraries to load.
!
! -library:<foo>:name=<soname> -- define a library <foo>, to be
! -libraries:<foo>:name=<soname> -- define a library <foo>, to be
! loaded from the <soname> DLL.
!
! -library:<foo>:abi=stdcall -- define a library using the
! -libraries:<foo>:abi=stdcall -- define a library using the
! stdcall ABI. This ABI is usually used on Win32. Any other abi
! parameter, or a missing abi parameter indicates the cdecl ABI
! should be used, which is common on Unix.
BUILTIN: dll 15
BUILTIN: alien 16
M: alien hashcode ( obj -- n )
alien-address >fixnum ;
@ -67,6 +29,15 @@ M: alien = ( obj obj -- ? )
2drop f
] ifte ;
M: alien unparse ( obj -- str )
[
"#<" ,
dup local-alien? "local-alien" "alien" ? ,
" @ " ,
alien-address unparse ,
">" ,
] make-string ;
: library ( name -- object )
dup [ "libraries" get hash ] when ;

View File

@ -2,7 +2,7 @@
! $Id$
!
! Copyright (C) 2004 Slava Pestov.
! Copyright (C) 2004, 2005 Slava Pestov.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met:
@ -25,12 +25,8 @@
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: compiler
USE: alien
USE: math
USE: kernel
USE: hashtables
USE: namespaces
IN: assembler
USING: alien math memory kernel hashtables namespaces ;
SYMBOL: interned-literals
@ -47,16 +43,14 @@ SYMBOL: interned-literals
compiled-offset cell 2 * align set-compiled-offset ; inline
: intern-literal ( obj -- lit# )
dup interned-literals get hash dup [
nip
] [
drop [
dup interned-literals get hash [
[
address
literal-top set-compiled-cell
literal-top dup cell + set-literal-top
dup
] keep interned-literals get set-hash
] ifte ;
] ?unless ;
: compile-byte ( n -- )
compiled-offset set-compiled-byte
@ -71,4 +65,5 @@ SYMBOL: interned-literals
compiled-offset 0 compile-cell
compiled-offset 0 compile-cell ;
global [ <namespace> interned-literals set ] bind
: init-assembler ( -- )
global [ <namespace> interned-literals set ] bind ;

View File

@ -1,229 +0,0 @@
! :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: compiler
USE: kernel
USE: compiler
USE: math
: EAX 0 ;
: ECX 1 ;
: EDX 2 ;
: EBX 3 ;
: ESP 4 ;
: EBP 5 ;
: ESI 6 ;
: EDI 7 ;
: byte? -128 127 between? ;
: eax/other ( reg quot quot -- )
#! Execute first quotation if reg is EAX, second quotation
#! otherwise, leaving reg on the stack.
pick EAX = [ drop nip call ] [ nip call ] ifte ; inline
: byte/eax/cell ( imm reg byte eax cell -- )
#! Assemble an instruction with 3 forms; byte operand, any
#! register; eax register, cell operand; other register,
#! cell operand.
>r >r >r >r dup byte? [
r> r> call r> drop r> drop compile-byte
] [
r> dup EAX = [
drop r> drop r> call r> drop compile-cell
] [
r> drop r> drop r> call compile-cell
] ifte
] ifte ; inline
: MOD-R/M ( r/m reg/opcode mod -- )
#! MOD-R/M is MOD REG/OPCODE R/M
6 shift swap 3 shift bitor bitor compile-byte ;
: PUSH-R ( reg -- )
HEX: 50 + compile-byte ;
: PUSH-[R] ( reg -- )
HEX: ff compile-byte BIN: 110 0 MOD-R/M ;
: PUSH-I ( imm -- )
HEX: 68 compile-byte compile-cell ;
: PUSH-I/PARTIAL ( -- fixup )
#! This is potentially bad. In the compilation of
#! #return-to, we need to push something which is
#! only known later.
#!
#! Returns address of 32-bit immediate.
HEX: 68 compile-byte compiled-offset 0 compile-cell ;
: POP-R ( reg -- )
HEX: 58 + compile-byte ;
: LEAVE ( -- )
HEX: c9 compile-byte ;
: I>R ( imm reg -- )
#! MOV <imm> TO <reg>
HEX: b8 + compile-byte compile-cell ;
: [I]>R ( imm reg -- )
#! MOV INDIRECT <imm> TO <reg>
[
HEX: a1 compile-byte
] [
HEX: 8b compile-byte
BIN: 101 swap 0 MOD-R/M
] eax/other compile-cell ;
: I>[R] ( imm reg -- )
#! MOV <imm> TO INDIRECT <reg>
HEX: c7 compile-byte compile-byte compile-cell ;
: R>[I] ( reg imm -- )
#! MOV <reg> TO INDIRECT <imm>.
swap [
HEX: a3 compile-byte
] [
HEX: 89 compile-byte
BIN: 101 swap 0 MOD-R/M
] eax/other compile-cell ;
: R>R ( reg reg -- )
#! MOV <reg> TO <reg>.
HEX: 89 compile-byte swap BIN: 11 MOD-R/M ;
: [R]>R ( reg reg -- )
#! MOV INDIRECT <reg> TO <reg>.
HEX: 8b compile-byte 0 MOD-R/M ;
: D[R]>R ( disp reg reg -- )
#! MOV INDIRECT DISPLACED <reg> TO <reg>.
HEX: 8b compile-byte 1 MOD-R/M compile-byte ;
: R>[R] ( reg reg -- )
#! MOV <reg> TO INDIRECT <reg>.
HEX: 89 compile-byte swap 0 MOD-R/M ;
: I+[I] ( imm addr -- )
#! ADD <imm> TO ADDRESS <addr>
HEX: 81 compile-byte
BIN: 101 0 0 MOD-R/M
compile-cell
compile-cell ;
: EAX+/PARTIAL ( -- fixup )
#! This is potentially bad. In the compilation of
#! generic and 2generic, we need to add something which is
#! only known later.
#!
#! Returns address of 32-bit immediate.
HEX: 05 compile-byte compiled-offset 0 compile-cell ;
: R+I ( imm reg -- )
#! ADD <imm> TO <reg>, STORE RESULT IN <reg>
[
HEX: 83 compile-byte
0 BIN: 11 MOD-R/M
] [
HEX: 05 compile-byte
] [
HEX: 81 compile-byte
0 BIN: 11 MOD-R/M
] byte/eax/cell ;
: R-I ( imm reg -- )
#! SUBTRACT <imm> FROM <reg>, STORE RESULT IN <reg>
[
HEX: 83 compile-byte
BIN: 101 BIN: 11 MOD-R/M
] [
HEX: 2d compile-byte
] [
HEX: 81 compile-byte
BIN: 101 BIN: 11 MOD-R/M
] byte/eax/cell ;
: R<<I ( imm reg -- )
#! SHIFT <reg> BY <imm>, STORE RESULT IN <reg>
HEX: c1 compile-byte
BIN: 100 BIN: 11 MOD-R/M
compile-byte ;
: R>>I ( imm reg -- )
#! SHIFT <reg> BY <imm>, STORE RESULT IN <reg>
HEX: c1 compile-byte
BIN: 111 BIN: 11 MOD-R/M
compile-byte ;
: CMP-I-R ( imm reg -- )
#! There are three forms of CMP we assemble
#! 83 f8 03 cmpl $0x3,%eax
#! 81 fa 33 33 33 00 cmpl $0x333333,%edx
#! 3d 33 33 33 00 cmpl $0x333333,%eax
[
HEX: 83 compile-byte
BIN: 111 BIN: 11 MOD-R/M
] [
HEX: 3d compile-byte
] [
HEX: 81 compile-byte
BIN: 111 BIN: 11 MOD-R/M
] byte/eax/cell ;
: JUMP-FIXUP ( addr where -- )
#! Encode a relative offset to addr from where at where.
#! Add 4 because addr is relative to *after* insn.
dup >r 4 + - r> set-compiled-cell ;
: (JUMP) ( xt -- fixup )
#! addr is relative to *after* insn
compiled-offset 0 compile-cell ;
: JUMP ( -- fixup )
#! Push address of branch for fixup
HEX: e9 compile-byte (JUMP) ;
: JUMP-[R] ( reg -- )
#! JUMP TO INDIRECT <reg>.
HEX: ff compile-byte BIN: 100 0 MOD-R/M ;
: CALL ( -- fixup )
HEX: e8 compile-byte (JUMP) ;
: CALL-[R] ( reg -- )
#! CALL INDIRECT <reg>.
HEX: ff compile-byte BIN: 10 0 MOD-R/M ;
: JE ( -- fixup )
HEX: 0f compile-byte HEX: 84 compile-byte (JUMP) ;
: JNE ( -- fixup )
HEX: 0f compile-byte HEX: 85 compile-byte (JUMP) ;
: RET ( -- )
HEX: c3 compile-byte ;

View File

@ -102,3 +102,9 @@ M: compound (compile) ( word -- )
] [
"Unsupported CPU" print
] ifte ;
: decompile ( word -- )
[ word-primitive ] keep set-word-primitive ;
: recompile ( word -- )
dup decompile compile ;

Some files were not shown because too many files have changed in this diff Show More