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/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.6 2004/12/17 00:57:03 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.8 2004/12/25 07:55:03 spestov Exp $ ./library/compiler/assembler.factor:! $Id: assembler.factor,v 1.12 2005/02/15 02:58:05 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.factor:! $Id: generator.factor,v 1.13 2005/01/17 20:32:56 spestov Exp $
./library/compiler/generator-x86.factor:! $Id: generator-x86.factor,v 1.19 2004/12/31 07:17:43 spestov Exp $ ./library/compiler/x86/assembler.factor:! $Id: assembler.factor,v 1.3 2005/01/16 22:57:59 spestov Exp $
./library/compiler/alien-types.factor:! $Id: alien-types.factor,v 1.17 2004/12/29 08:35:44 spestov Exp $ ./library/compiler/x86/fixnum.factor:! $Id: fixnum.factor,v 1.6 2005/02/17 04:24:35 spestov Exp $
./library/compiler/generator.factor:! $Id: generator.factor,v 1.9 2004/12/31 07:17:43 spestov Exp $ ./library/compiler/optimizer.factor:! $Id: optimizer.factor,v 1.19 2005/01/20 02:01:46 spestov Exp $
./library/compiler/alien.factor:! $Id: alien.factor,v 1.22 2004/12/31 07:17:43 spestov Exp $ ./library/compiler/compiler.factor:! $Id: compiler.factor,v 1.33 2005/01/07 00:10:00 spestov Exp $
./library/compiler/optimizer.factor:! $Id: optimizer.factor,v 1.14 2005/01/01 22:20:47 spestov Exp $ ./library/compiler/linearizer.factor:! $Id: linearizer.factor,v 1.22 2005/02/18 00:01:10 spestov Exp $
./library/compiler/compiler.factor:! $Id: compiler.factor,v 1.32 2004/12/27 20:27:17 spestov Exp $ ./library/ui/line-editor.factor:! $Id: line-editor.factor,v 1.3 2005/01/04 05:41:14 spestov Exp $
./library/compiler/linearizer.factor:! $Id: linearizer.factor,v 1.19 2005/01/01 22:20:47 spestov Exp $ ./library/ui/console.factor:! $Id: console.factor,v 1.17 2005/02/15 03:15:02 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/win32/win32-io.factor:! $Id: win32-io.factor,v 1.3 2004/12/29 07:16:03 eiz 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/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.2 2004/12/29 07:16:03 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.16 2004/12/19 08:04:02 spestov 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.17 2004/12/19 08:04:02 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.6 2004/12/11 00:29:03 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.18 2004/12/11 00:29:03 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/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/default-responders.factor:! $Id: default-responders.factor,v 1.13 2005/02/14 21:44:15 doublec Exp $
./library/httpd/html.factor:! $Id: html.factor,v 1.22 2004/12/24 07:52:00 spestov Exp $
./library/httpd/test-responder.factor:! $Id: test-responder.factor,v 1.5 2004/12/11 00:29:03 spestov 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.14 2005/01/13 22:28:27 spestov Exp $
./library/httpd/url-encoding.factor:! $Id: url-encoding.factor,v 1.13 2004/12/29 08:35:44 spestov Exp $ ./library/inference/dataflow.factor:! $Id: dataflow.factor,v 1.23 2005/01/14 19:56:13 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/inference/test.factor:! $Id: test.factor,v 1.2 2005/01/13 22:28:28 spestov Exp $
./library/math/float.factor:! $Id: float.factor,v 1.1 2004/12/19 04:18:31 spestov Exp $ ./library/inference/stack.factor:! $Id: stack.factor,v 1.12 2005/01/16 22:58:25 spestov Exp $
./library/math/complex.factor:! $Id: complex.factor,v 1.6 2004/12/31 07:17:45 spestov Exp $ ./library/inference/inference.factor:! $Id: inference.factor,v 1.35 2005/02/09 03:02:41 spestov Exp $
./library/math/constants.factor:! $Id: constants.factor,v 1.2 2004/09/19 02:29:28 spestov Exp $ ./library/bootstrap/win32-io.factor:! $Id: win32-io.factor,v 1.4 2005/02/07 14:46:56 eiz Exp $
./library/math/integer.factor:! $Id: integer.factor,v 1.4 2004/12/31 01:46:20 spestov Exp $ ./library/bootstrap/image.factor:! $Id: image.factor,v 1.25 2005/02/10 00:58:52 spestov Exp $
./library/math/math-combinators.factor:! $Id: math-combinators.factor,v 1.11 2004/12/29 08:35:45 spestov Exp $ ./library/bootstrap/init.factor:! $Id: init.factor,v 1.8 2005/02/07 23:04:34 eiz Exp $
./library/math/pow.factor:! $Id: pow.factor,v 1.9 2004/12/11 00:29:04 spestov Exp $ ./library/sdl/sdl-video.factor:! $Id: sdl-video.factor,v 1.14 2005/01/23 21:47:28 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/sdl/sdl.factor:! $Id: sdl.factor,v 1.5 2004/12/18 05:38:51 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-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.3 2005/01/14 00:49:45 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-event.factor:! $Id: sdl-event.factor,v 1.11 2005/02/04 03:21:51 spestov Exp $
./library/sdl/sdl-keyboard.factor:! $Id: sdl-keyboard.factor,v 1.1 2004/12/26 23:52:58 spestov Exp $ ./library/tools/jedit-wire.factor:! $Id: jedit-wire.factor,v 1.12 2005/02/15 03:15:02 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/tools/profiler.factor:! $Id: profiler.factor,v 1.2 2004/12/11 00:29:07 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-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/parse-stream.factor:! $Id: parse-stream.factor,v 1.6 2005/02/15 03:15:01 spestov Exp $
./library/syntax/parser.factor:! $Id: parser.factor,v 1.5 2004/12/29 08:35:45 spestov Exp $ ./library/io/vocabulary-style.factor:! $Id: vocabulary-style.factor,v 1.4 2005/02/14 21:44:15 doublec Exp $
./library/syntax/unparser.factor:! $Id: unparser.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.8 2005/02/15 03:15:01 spestov Exp $
./library/gensym.factor:! $Id: gensym.factor,v 1.4 2004/12/29 08:35:43 spestov Exp $ ./library/io/win32-stream.factor:! $Id: win32-stream.factor,v 1.10 2005/02/18 08:48:56 eiz 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/io/stdio-binary.factor:! $Id: stdio-binary.factor,v 1.2 2004/12/11 00:29:04 spestov 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/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.3 2004/12/20 20:29:54 spestov Exp $ ./library/io/presentation.factor:! $Id: presentation.factor,v 1.5 2005/02/15 03:15:01 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.5 2005/02/12 07:23:38 eiz Exp $
./library/io/buffer.factor:! $Id: buffer.factor,v 1.4 2005/01/02 21:14:21 eiz Exp $ ./library/io/logging.factor:! $Id: logging.factor,v 1.6 2005/02/15 03:15:01 spestov Exp $
./library/io/stream.factor:! $Id: stream.factor,v 1.8 2004/12/29 08:35:45 spestov Exp $ ./library/io/win32-server.factor:! $Id: win32-server.factor,v 1.8 2005/02/18 08:48:56 eiz Exp $
./library/io/files.factor:! $Id: files.factor,v 1.5 2005/01/01 22:20:47 spestov Exp $ ./factor/ExternalFactor.java: * $Id: ExternalFactor.java,v 1.16 2005/02/17 02:54:35 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 $
./factor/math/Complex.java: * $Id: Complex.java,v 1.1.1.1 2004/07/16 06:26:13 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/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/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/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/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/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/FactorArray.java: * $Id: FactorArray.java,v 1.8 2005/01/07 19:37:20 spestov Exp $
./factor/FactorSymbolDefinition.java:* $Id: FactorSymbolDefinition.java,v 1.4 2004/12/06 00:42:55 spestov Exp $
./factor/FactorLib.java: * $Id: FactorLib.java,v 1.8 2004/11/17 04:04:50 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/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/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.5 2005/01/14 00:49:42 spestov Exp $
./factor/Cons.java: * $Id: Cons.java,v 1.3 2004/11/17 04:04:50 spestov Exp $ ./factor/DefaultVocabularyLookup.java: * $Id: DefaultVocabularyLookup.java,v 1.11 2005/02/17 02:54:35 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/parser/ComplexLiteral.java: * $Id: ComplexLiteral.java,v 1.4 2004/11/17 04:04:50 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/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/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/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.4 2005/01/07 19:37:21 spestov Exp $
./factor/parser/BeginMethod.java: * $Id: BeginMethod.java,v 1.3 2004/12/23 03:16:44 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.8 2004/12/06 00:42:55 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/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/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/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/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/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/BeginConstructor.java: * $Id: BeginConstructor.java,v 1.2 2005/01/07 19:37:21 spestov Exp $
./factor/parser/Generic.java: * $Id: Generic.java,v 1.1 2004/12/06 00:42:55 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/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/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/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/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.10 2005/01/07 19:37:21 spestov Exp $
./factor/parser/Ine.java: * $Id: Ine.java,v 1.8 2004/12/06 00:42:55 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/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/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/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/FactorWord.java: * $Id: FactorWord.java,v 1.11 2005/01/07 00:09:59 spestov Exp $
./factor/VocabularyLookup.java: * $Id: VocabularyLookup.java,v 1.3 2004/12/20 00:36:10 spestov Exp $ ./factor/VocabularyLookup.java: * $Id: VocabularyLookup.java,v 1.4 2005/02/17 02:54:35 spestov Exp $
./factor/jedit/FactorAsset.java: * $Id: FactorAsset.java,v 1.5 2004/11/19 22:28:23 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/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/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/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.6 2004/12/20 00:36:10 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.39 2005/01/02 21:31:43 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/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/FactorShell.java: * $Id: FactorShell.java,v 1.11 2005/02/10 22:36:19 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.12 2005/02/17 02:54:36 spestov Exp $
./factor/jedit/WordPreview.java: * $Id: WordPreview.java,v 1.9 2004/12/05 23:33:19 spestov Exp $
./factor/jedit/WordListDialog.java: * $Id: WordListDialog.java,v 1.4 2004/12/20 02:06:55 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.5 2005/01/07 19:37:21 spestov Exp $
./factor/jedit/ListenerAttributeSet.java: * $Id: ListenerAttributeSet.java,v 1.4 2004/11/26 04:14:16 spestov Exp $ ./factor/jedit/FactorBufferProcessor.java: * $Id: FactorBufferProcessor.java,v 1.4 2005/01/24 02:53:55 spestov Exp $
./factor/jedit/FactorWordRenderer.java: * $Id: FactorWordRenderer.java,v 1.13 2004/12/06 00:42: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/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/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/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/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 $ ./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 $ ./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_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 $ ./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 CC = gcc
DEFAULT_CFLAGS = -Wall -g $(SITE_CFLAGS) DEFAULT_CFLAGS = -Wall -Os -fomit-frame-pointer $(SITE_CFLAGS)
DEFAULT_LIBS = -lm DEFAULT_LIBS = -lm
STRIP = strip 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/s48_bignum.o \
native/complex.o native/cons.o native/error.o \ native/complex.o native/cons.o native/error.o \
native/factor.o native/fixnum.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/string.o native/types.o native/vector.o \
native/word.o native/compiler.o \ native/word.o native/compiler.o \
native/ffi.o native/boolean.o \ native/ffi.o native/boolean.o \
native/unix/file.o \ native/debug.o \
native/unix/io.o \ native/hashtable.o
native/unix/socket.o \
native/unix/signal.o \
native/unix/read.o \
native/unix/write.o \
native/unix/ffi.o \
native/debug.o
default: default:
@echo "Run 'make' with one of the following parameters:" @echo "Run 'make' with one of the following parameters:"
@ -34,6 +32,7 @@ default:
@echo "linux" @echo "linux"
@echo "macosx" @echo "macosx"
@echo "solaris" @echo "solaris"
@echo "windows"
@echo "" @echo ""
@echo "Also, you might want to set the SITE_CFLAGS environment" @echo "Also, you might want to set the SITE_CFLAGS environment"
@echo "variable to enable some CPU-specific optimizations; this" @echo "variable to enable some CPU-specific optimizations; this"
@ -68,7 +67,7 @@ solaris:
f: $(OBJS) f: $(OBJS)
$(CC) $(LIBS) $(CFLAGS) -o $@ $(OBJS) $(CC) $(LIBS) $(CFLAGS) -o $@ $(OBJS)
#$(STRIP) $@ $(STRIP) $@
clean: clean:
rm -f $(OBJS) 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 - 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 - vectors: ensure its ok with bignum indices
- doc comments of generics - 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? - is signed -vs- unsigned pointers an issue?
- bitfields in C structs - bitfields in C structs
- SDL_Rect** type - SDL_Rect** type
- struct membres that are not * - struct membres that are not *
- FFI float types - FFI float types
+ listener/plugin: + i/o:
- WordPreview calls markTokens() -> NPE
- stream server can hang because of exception handler limitations - stream server can hang because of exception handler limitations
- listener should be multithreaded - better i/o scheduler
- compile all, infer all commands - nicer way to combine two paths
- faster completion - add a socket timeout
- errors don't always disappear - unix ffi i/o
- NPE in ErrorHighlight
- maple-like: press enter at old commands to evaluate there
- completion in the listener
- special completion for USE:/IN:
+ kernel: + kernel:
- do partial objects cause problems?
- better i/o scheduler
- remove sbufs
- cat, reverse-cat primitives - cat, reverse-cat primitives
- first-class hashtables - generational gc
- add a socket timeout - make see work with union, builtin, predicate
- doc comments of generics
+ misc: - proper ordering for classes
- make-vector and make-string should not need a reverse step
- 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
- worddef props - 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>
<ACTION NAME="factor-see"> <ACTION NAME="factor-see">
<CODE> <CODE>
WordPopup.showWordPopup(textArea); FactorPlugin.factorWordPopupOp(view,"see");
</CODE> </CODE>
</ACTION> </ACTION>
<ACTION NAME="factor-edit"> <ACTION NAME="factor-edit">
@ -82,4 +82,24 @@
FactorPlugin.extractWord(view); FactorPlugin.extractWord(view);
</CODE> </CODE>
</ACTION> </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> </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: parser
USE: html USE: html
USE: cont-responder USE: cont-responder
USE: cont-utils
USE: stdio USE: stdio
USE: namespaces USE: namespaces

View File

@ -39,7 +39,7 @@
! eg. ! eg.
! <cont-test-state> [ test-cont-responder ] test-cont-function ! <cont-test-state> [ test-cont-responder ] test-cont-function
! => HTTP/1.1 302 Document Moved ! => HTTP/1.1 302 Document Moved
! Location: 8506502852110820 ! Location: ?id=8506502852110820
! Content-Length: 0 ! Content-Length: 0
! Content-Type: text/plain ! Content-Type: text/plain
! !
@ -48,12 +48,12 @@
! Content-Type: text/html ! Content-Type: text/html
! !
! <html><head><title>Page one</title></head><body> ! <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> ! </body></html>
! !
! "5431597582800278" f test-cont-click ! "5431597582800278" f test-cont-click
! => HTTP/1.1 302 Document Moved ! => HTTP/1.1 302 Document Moved
! Location: 7944183606904129 ! Location: ?id=7944183606904129
! Content-Length: 0 ! Content-Length: 0
! Content-Type: text/plain ! Content-Type: text/plain
! !
@ -63,14 +63,14 @@
! !
! <html><head><title>Enter your name</title></head> ! <html><head><title>Enter your name</title></head>
! <body><h1>Enter your name</h1> ! <body><h1>Enter your name</h1>
! <form method='post'action='8503790719833723'> ! <form method='post' action='?id=8503790719833723'>
! Name: <input type='text'name='name'size='20'> ! Name: <input type='text' name='name'size='20'>
! <input type='submit'value='Ok'> ! <input type='submit' value='Ok'>
! </form></body></html> ! </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 ! => HTTP/1.1 302 Document Moved
! Location: 8879727708050260 ! Location: ?id=8879727708050260
! Content-Length: 0 ! Content-Length: 0
! Content-Type: text/plain ! Content-Type: text/plain
! !
@ -80,7 +80,7 @@
! !
! <html><head><title>Hello Chris</title></head> ! <html><head><title>Hello Chris</title></head>
! <body><h1>Hello Chris</h1> ! <body><h1>Hello Chris</h1>
! <a href='0937854264503953'>Next</a> ! <a href='?id=0937854264503953'>Next</a>
! </body></html> ! </body></html>
! !
! etc. ! 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 IN: eval-responder
USE: html USE: html
USE: cont-responder USE: cont-responder
USE: cont-utils
USE: kernel USE: kernel
USE: stdio USE: stdio
USE: namespaces USE: namespaces
@ -73,7 +72,7 @@ USE: logging
: escape-quotes ( string -- string ) : escape-quotes ( string -- string )
#! Replace occurrences of single quotes with #! Replace occurrences of single quotes with
#! backslash quote. #! backslash quote.
[ dup [ [ CHAR: ' | "\\'" ] [ CHAR: " | "\\\"" ] ] assoc dup rot ? ] str-map ; [ dup [ [[ CHAR: ' "\\'" ]] [[ CHAR: " "\\\"" ]] ] assoc dup rot ? ] str-map ;
: make-eval-javascript ( string -- string ) : make-eval-javascript ( string -- string )
#! Give a string return some javascript that when #! Give a string return some javascript that when
@ -110,7 +109,7 @@ USE: logging
#! of the given word. #! of the given word.
dup dup dup dup
<namespace> [ <namespace> [
"responder" "inspect" put "responder" "browser" put
<table border= "1" table> <table border= "1" table>
<tr> <th colspan= "2" th> "Source" write </th> </tr> <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> <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 #! All output should go to a string which is returned on the
#! callstack along with the resulting datastack as a list. #! callstack along with the resulting datastack as a list.
<namespace> [ <namespace> [
"inspect" "responder" set "browser" "responder" set
1024 <string-output-stream> dup >r <html-stream> [ 1024 <string-output> dup >r <html-stream> [
do-eval do-eval
] with-stream r> stream>str ] with-stream r> stream>str
] bind ; ] bind ;

View File

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

View File

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

View File

@ -34,18 +34,22 @@ USE: stdio
USE: parser USE: parser
: l1 : l1
"cont-responder.factor" run-file
"cont-utils.factor" run-file ;
: l2
"cont-examples.factor" run-file "cont-examples.factor" run-file
"cont-numbers-game.factor" run-file ; "cont-numbers-game.factor" run-file ;
: l3 "todo.factor" run-file ; : l2 "todo.factor" run-file ;
: l4 "todo-example.factor" run-file ; : l3 "todo-example.factor" run-file ;
: l5 "live-updater.factor" run-file ; : l4 "live-updater.factor" run-file ;
: l6 "eval-responder.factor" run-file ; : l5 "eval-responder.factor" run-file ;
: l7 "live-updater-responder.factor" run-file ; : l6 "live-updater-responder.factor" run-file ;
: l8 "browser.factor" run-file ; : l7 "cont-testing.factor" run-file ;
: l9 "cont-testing.factor" run-file ; : l8
: la ; #! 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 ; : la [ 8888 httpd ] [ dup . flush [ la ] when* ] catch ;
: lb [ la "httpd thread exited.\n" write flush ] in-thread ; : lb [ la "httpd thread exited.\n" write flush ] in-thread ;

View File

@ -29,7 +29,6 @@
IN: todo-example IN: todo-example
USE: cont-responder USE: cont-responder
USE: html USE: html
USE: cont-utils
USE: html USE: html
USE: stdio USE: stdio
USE: strings USE: strings
@ -107,7 +106,7 @@ USE: kernel
: todo-stylesheet-url ( -- url ) : todo-stylesheet-url ( -- url )
#! Generate an URL for the stylesheet. #! 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 ( -- ) : include-todo-stylesheet ( -- )
#! Generate HTML to include the todo stylesheet #! Generate HTML to include the todo stylesheet

View File

@ -91,22 +91,22 @@ USE: hashtables
: store-todo ( <todo> filename -- ) : store-todo ( <todo> filename -- )
#! store the todo list in the given file. #! store the todo list in the given file.
<filecw> [ write-todo ] with-stream ; <file-writer> [ write-todo ] with-stream ;
: read-todo ( -- <todo> ) : read-todo ( -- <todo> )
#! Read a todo list from the current input stream. #! Read a todo list from the current input stream.
read url-decode read url-decode <todo> read-line url-decode read-line url-decode <todo>
read str>number [ read-line str>number [
dup dup
<namespace> [ <namespace> [
read url-decode "yes" = "complete?" set read-line url-decode "yes" = "complete?" set
read url-decode "priority" set read-line url-decode "priority" set
read url-decode "description" set read-line url-decode "description" set
] extend add-todo-item ] extend add-todo-item
] times ; ] times ;
: load-todo ( filename -- <todo> ) : load-todo ( filename -- <todo> )
<filecr> [ read-todo ] with-stream ; <file-reader> [ read-todo ] with-stream ;
: password-matches? ( password <todo> -- <todo> ) : password-matches? ( password <todo> -- <todo> )
#! Returns the <todo> if the password matches otherwise #! 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: ! Copyright (C) 2005 Chris Double.
! $Id$
!
! Copyright (C) 2003, 2004 Slava Pestov.
! !
! Redistribution and use in source and binary forms, with or without ! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met: ! modification, are permitted provided that the following conditions are met:
@ -24,42 +20,36 @@
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! 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: kernel
USE: namespaces USE: stdio
USE: prettyprint
: cons@ ( x var -- ) : show-people ( statement -- )
#! Prepend x to the list stored in var. dup 0 column-text write " from " write 1 column-text . ;
[ cons ] change ;
: unique@ ( elem var -- ) : run-test ( -- )
#! Prepend an element to the proper list stored in a "test.db" sqlite-open
#! variable if it is not already contained in the list. dup "select * from test" sqlite-prepare
[ unique ] change ; 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 ) run-test
#! 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 ;

View File

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

View File

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

View File

@ -2526,6 +2526,365 @@ USE: vectors
10 <vector> main-menu ; 10 <vector> main-menu ;
\end{verbatim} \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} \input{new-guide.ind}
\end{document} \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 ! ./f boot.image.le32
! -libraries:sdl:name=libSDL.so ! -libraries:sdl:name=libSDL.so
! -libraries:sdl-gfx:name=libSDL_gfx. ! -libraries:sdl-gfx:name=libSDL_gfx.so
! !
! (But all on one line) ! (But all on one line)
! !
@ -36,10 +36,7 @@ SYMBOL: d
: next-x ( x y -- x ) a get * sin swap b get * cos - ; : 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 - ; : next-y ( x y -- y ) swap c get * sin swap d get * cos - ;
: white ( -- rgb ) : pixel ( #{ x y }# color -- )
HEX: ffffffff ;
: pixel ( #{ x y } color -- )
>r >r surface get r> >rect r> pixelColor ; >r >r surface get r> >rect r> pixelColor ;
: iterate-dejong ( x y -- x y ) : iterate-dejong ( x y -- x y )
@ -51,21 +48,21 @@ SYMBOL: d
: draw-dejong ( x0 y0 iterations -- ) : draw-dejong ( x0 y0 iterations -- )
[ [
iterate-dejong 2dup scale-dejong rect> white pixel iterate-dejong 2dup scale-dejong rect> white rgb pixel
] times 2drop ; ] times 2drop ; compiled
: dejong ( -- ) : dejong ( -- )
! Fiddle with these four values! ! Fiddle with these four values!
1.4 a set 1.0 a set
-2.3 b set -1.3 b set
2.4 c set 0.8 c set
-2.1 d set -2.1 d set
640 480 32 SDL_HWSURFACE [ 1024 768 0 SDL_HWSURFACE [
[ 0 0 100000 draw-dejong ] with-surface [ 0 0 200000 [ draw-dejong ] time ] with-surface
<event> event-loop <event> event-loop
SDL_Quit 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 DEFER: infix
: >e exprs get vector-push ; : >e exprs get vector-push ;
: e> exprs get vector-pop ; : 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 ; : e, ( obj -- ) dup cons? [ [ e, ] each ] [ , ] ifte ;
: end ( -- ) exprs get [ e, ] vector-each ; : end ( -- ) exprs get [ e, ] vector-each ;
: >postfix ( op -- ) e@ word? [ e> e> -rot 3list ] when >e ; : >postfix ( op -- ) e@ word? [ e> e> -rot 3list ] when >e ;

View File

@ -17,8 +17,10 @@ SYMBOL: channels
SYMBOL: channel SYMBOL: channel
SYMBOL: nickname SYMBOL: nickname
: irc-write ( s -- ) irc-stream get fwrite ; : irc-write ( s -- ) irc-stream get stream-write ;
: irc-print ( s -- ) irc-stream get fprint irc-stream get fflush ; : irc-print ( s -- )
irc-stream get stream-print
irc-stream get stream-flush ;
: nick ( nick -- ) : nick ( nick -- )
dup nickname set "NICK " irc-write irc-print ; dup nickname set "NICK " irc-write irc-print ;
@ -32,13 +34,13 @@ SYMBOL: nickname
: write-highlighted ( line -- ) : write-highlighted ( line -- )
dup nickname get index-of -1 = dup nickname get index-of -1 =
f [ [ "ansi-fg" | "3" ] ] ? write-attr ; f [ [[ "ansi-fg" "3" ]] ] ? write-attr ;
: extract-nick ( line -- nick ) : extract-nick ( line -- nick )
"!" split1 drop ; "!" split1 drop ;
: write-nick ( line -- ) : write-nick ( line -- )
"!" split1 drop [ [ "bold" | t ] ] write-attr ; "!" split1 drop [ [[ "bold" t ]] ] write-attr ;
GENERIC: irc-display GENERIC: irc-display
PREDICATE: string privmsg "PRIVMSG" index-of -1 > ; PREDICATE: string privmsg "PRIVMSG" index-of -1 > ;
@ -58,10 +60,10 @@ M: privmsg irc-display ( line -- )
! write-highlighted terpri flush ; ! write-highlighted terpri flush ;
: in-loop ( -- ) : 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 ; : input-thread ( -- ) [ in-loop ] in-thread ;
: disconnect ( -- ) irc-stream get fclose ; : disconnect ( -- ) irc-stream get stream-close ;
: command ( line -- ) : command ( line -- )
#! IRC /commands are just words. #! 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 255 * >fixnum ;
: scale-rgba ( r g b -- n ) : scale-rgb ( r g b a -- n )
scale scale
swap scale 8 shift bitor swap scale 8 shift bitor
swap scale 16 shift bitor swap scale 16 shift bitor
@ -44,10 +44,10 @@ USE: test
: <color-map> ( nb-cols -- map ) : <color-map> ( nb-cols -- map )
[ [
dup [ dup [
360 * over 1 + / 360 / sat val dup 360 * pick 1 + / 360 / sat val
hsv>rgb 1.0 scale-rgba , hsv>rgb 1.0 scale-rgb ,
] times* ] repeat
] make-list list>vector nip ; ] make-vector nip ;
: absq >rect swap sq swap sq + ; inline : absq >rect swap sq swap sq + ; inline
@ -72,15 +72,15 @@ SYMBOL: center
height get 150000 zoom-fact get * / y-inc set height get 150000 zoom-fact get * / y-inc set
nb-iter get max-color min <color-map> cols set ; nb-iter get max-color min <color-map> cols set ;
: c ( #{ i j } -- c ) : c ( i j -- c )
>rect >r >r
x-inc get * center get real x-inc get width get 2 / * - + >float x-inc get * center get real x-inc get width get 2 / * - + >float
r> r>
y-inc get * center get imaginary y-inc get height get 2 / * - + >float y-inc get * center get imaginary y-inc get height get 2 / * - + >float
rect> ; rect> ;
: render ( -- ) : render ( -- )
width get height get [ [
c 0 nb-iter get iter dup 0 = [ c 0 nb-iter get iter dup 0 = [
drop 0 drop 0
] [ ] [
@ -89,7 +89,7 @@ SYMBOL: center
] with-pixels ; compiled ] with-pixels ; compiled
: mandel ( -- ) : mandel ( -- )
640 480 32 SDL_HWSURFACE [ 640 480 0 SDL_HWSURFACE [
[ [
0.8 zoom-fact set 0.8 zoom-fact set
-0.65 center set -0.65 center set

View File

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

View File

@ -3,7 +3,7 @@
/* /*
* $Id$ * $Id$
* *
* Copyright (C) 2004 Slava Pestov. * Copyright (C) 2004, 2005 Slava Pestov.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -68,15 +68,19 @@ public class DefaultVocabularyLookup implements VocabularyLookup
FactorWord f = define("syntax","f"); FactorWord f = define("syntax","f");
f.parsing = new F(f); f.parsing = new F(f);
FactorWord complex = define("syntax","#{"); FactorWord complex = define("syntax","#{");
complex.parsing = new ComplexLiteral(complex,"}"); complex.parsing = new ComplexLiteral(complex,"}#");
/* lists */ /* lists */
FactorWord bra = define("syntax","["); FactorWord bra = define("syntax","[");
bra.parsing = new Bra(bra); bra.parsing = new Bra(bra);
FactorWord ket = define("syntax","]"); FactorWord ket = define("syntax","]");
ket.parsing = new Ket(bra,ket); 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 */ /* vectors */
FactorWord beginVector = define("syntax","{"); FactorWord beginVector = define("syntax","{");
@ -89,9 +93,9 @@ public class DefaultVocabularyLookup implements VocabularyLookup
def.parsing = new Def(def); def.parsing = new Def(def);
def.docComment = true; def.docComment = true;
FactorWord ine = define("syntax",";"); FactorWord ine = define("syntax",";");
ine.parsing = new Ine(def,ine); ine.parsing = new Ine(ine);
FactorWord symbol = define("syntax","SYMBOL:"); FactorWord symbol = define("syntax","SYMBOL:");
symbol.parsing = new Symbol(symbol); symbol.parsing = new Definer(symbol);
/* reading numbers with another base */ /* reading numbers with another base */
FactorWord bin = define("syntax","BIN:"); FactorWord bin = define("syntax","BIN:");
@ -105,24 +109,32 @@ public class DefaultVocabularyLookup implements VocabularyLookup
FactorWord noParsing = define("syntax","POSTPONE:"); FactorWord noParsing = define("syntax","POSTPONE:");
noParsing.parsing = new NoParsing(noParsing); noParsing.parsing = new NoParsing(noParsing);
FactorWord defer = define("syntax","DEFER:"); FactorWord defer = define("syntax","DEFER:");
defer.parsing = new Defer(defer); defer.parsing = new Definer(defer);
FactorWord in = define("syntax","IN:"); FactorWord in = define("syntax","IN:");
in.parsing = new In(in); in.parsing = new In(in);
FactorWord use = define("syntax","USE:"); FactorWord use = define("syntax","USE:");
use.parsing = new Use(use); use.parsing = new Use(use);
FactorWord using = define("syntax","USING:");
using.parsing = new Using(using);
FactorWord pushWord = define("syntax","\\"); FactorWord pushWord = define("syntax","\\");
pushWord.parsing = new PushWord(pushWord); pushWord.parsing = new PushWord(pushWord);
/* OOP */ /* OOP */
FactorWord generic = define("generic","GENERIC:"); FactorWord generic = define("generic","GENERIC:");
generic.parsing = new Generic(generic); generic.parsing = new Definer(generic);
FactorWord traits = define("generic","TRAITS:"); FactorWord traits = define("generic","TRAITS:");
traits.parsing = new Traits(traits); traits.parsing = new Definer(traits);
FactorWord beginMethod = define("generic","M:"); FactorWord beginMethod = define("generic","M:");
beginMethod.parsing = new BeginMethod(beginMethod,def); beginMethod.parsing = new BeginMethod(beginMethod);
FactorWord beginConstructor = define("generic","C:"); 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 //{{{ getVocabulary() method
@ -206,7 +218,7 @@ public class DefaultVocabularyLookup implements VocabularyLookup
return vocabs; return vocabs;
} //}}} } //}}}
//{{{ getCompletions() method //{{{ getWordCompletions() method
/** /**
* @param use A list of vocabularies. * @param use A list of vocabularies.
* @param word A substring of the word name to complete * @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. * returned; otherwise, only matches from beginning.
* @param completions Set to add completions to * @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 Set completions) throws Exception
{ {
while(use != null) while(use != null)
{ {
String vocab = (String)use.car; String vocab = (String)use.car;
getCompletions(vocab,word,anywhere,completions); getWordCompletions(vocab,word,anywhere,completions);
use = use.next(); use = use.next();
} }
} //}}} } //}}}
//{{{ getCompletions() method //{{{ isCompletion() method
public void getCompletions(String vocab, String word, boolean anywhere, 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 Set completions) throws Exception
{ {
Map v = (Map)vocabularies.get(vocab); Map v = (Map)vocabularies.get(vocab);
@ -242,21 +271,35 @@ public class DefaultVocabularyLookup implements VocabularyLookup
{ {
if(!completions.contains(w)) if(!completions.contains(w))
{ {
if(anywhere) if(isCompletion(word,w.name,anywhere))
{ completions.add(w);
if(w.name.indexOf(word) != -1)
completions.add(w);
}
else
{
if(w.name.startsWith(word))
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 //{{{ parseObject() method
public Cons parseObject(String source) throws Exception 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); Log.log(Log.ERROR,this,"Cannot connect to Factor on port " + port);
if(in != null && out != null) close();
close();
} //}}} } //}}}
//{{{ openWireSocket() method //{{{ openWireSocket() method
@ -104,7 +103,7 @@ public class ExternalFactor extends DefaultVocabularyLookup
byte[] discard = new byte[2048]; byte[] discard = new byte[2048];
int len = in.read(discard,0,discard.length); int len = in.read(discard,0,discard.length);
discardStr = new String(discard,0,len); 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 public synchronized String eval(String cmd) throws IOException
{ {
if(isClosed())
throw new IOException("ExternalFactor stream closed");
try try
{ {
waitForAck(); waitForAck();
@ -236,11 +238,11 @@ public class ExternalFactor extends DefaultVocabularyLookup
} }
} //}}} } //}}}
//{{{ getCompletions() method //{{{ getWordCompletions() method
public synchronized void getCompletions(Cons use, String word, public synchronized void getWordCompletions(Cons use, String word,
boolean anywhere, Set completions) throws Exception boolean anywhere, Set completions) throws Exception
{ {
super.getCompletions(use,word,anywhere,completions); super.getWordCompletions(use,word,anywhere,completions);
if(closed) if(closed)
return; return;
@ -277,21 +279,26 @@ public class ExternalFactor extends DefaultVocabularyLookup
closed = true; closed = true;
try if(out != null)
{ {
/* don't care about response */ try
sendEval("0 exit*"); {
} /* don't care about response */
catch(Exception e) sendEval("0 exit*");
{ }
// We don't care... catch(Exception e)
Log.log(Log.DEBUG,this,e); {
// We don't care...
Log.log(Log.DEBUG,this,e);
}
} }
try try
{ {
in.close(); if(in != null)
out.close(); in.close();
if(out != null)
out.close();
} }
catch(Exception e) catch(Exception e)
{ {

View File

@ -53,7 +53,7 @@ public class FactorArray implements FactorExternalizable
//{{{ FactorArray constructor //{{{ FactorArray constructor
public FactorArray(Cons list) public FactorArray(Cons list)
{ {
this(list == null ? 0 : list.length()); this(Cons.length(list));
int i = 0; int i = 0;
while(list != null) 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 * M: type generic ... ;M
*/ */
public class FactorMethodDefinition extends FactorWordDefinition public class FactorMethodDefinition
{ {
private FactorWord type; private FactorWord type;
private FactorWord generic;
private Cons def; private Cons def;
public FactorMethodDefinition(FactorWord type, public FactorMethodDefinition(FactorWord type,
FactorWord generic, Cons def) FactorWord generic, Cons def)
{ {
super(generic); this.generic = generic;
this.type = type; this.type = type;
this.def = def; this.def = def;
} }

View File

@ -241,10 +241,7 @@ public class FactorReader
FactorWord word; FactorWord word;
if(define) if(define)
{
word = lookup.define(getIn(),name); word = lookup.define(getIn(),name);
definedWords = new Cons(word,definedWords);
}
else else
{ {
word = searchVocabulary(getUse(),name); word = searchVocabulary(getUse(),name);
@ -258,7 +255,7 @@ public class FactorReader
//{{{ getDefinedWords() method //{{{ getDefinedWords() method
public Cons getDefinedWords() public Cons getDefinedWords()
{ {
return definedWords; return Cons.reverse(definedWords);
} //}}} } //}}}
//{{{ nextWord() method //{{{ nextWord() method
@ -283,6 +280,7 @@ public class FactorReader
FactorWord w = intern((String)next,define); FactorWord w = intern((String)next,define);
if(define && w != null) if(define && w != null)
{ {
definedWords = new Cons(w,definedWords);
w.line = line; w.line = line;
w.col = col; w.col = col;
w.file = scanner.getFileName(); w.file = scanner.getFileName();
@ -381,12 +379,14 @@ public class FactorReader
/** /**
* Pop a parser state, throw exception if it doesn't match the * Pop a parser state, throw exception if it doesn't match the
* parameter. * parameter.
* @param start The start parameter that must match. If this is null,
* any start is acceptable.
*/ */
public ParseState popState(FactorWord start, FactorWord end) public ParseState popState(FactorWord start, FactorWord end)
throws FactorParseException throws FactorParseException
{ {
ParseState state = getCurrentState(); ParseState state = getCurrentState();
if(state.start != start) if(start != null && state.start != start)
scanner.error(end + " does not close " + state.start); scanner.error(end + " does not close " + state.start);
if(states.next() != null) if(states.next() != null)
states = states.next(); 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; 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? * Should the parser keep doc comments?
@ -70,4 +70,19 @@ public class FactorWord implements FactorExternalizable
{ {
return name == null ? "#<unnamed>" : name; 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. * returned; otherwise, only matches from beginning.
* @param completions Set to add completions to * @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; 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 vocab The vocabulary name
* @param word A substring of the word name to complete * @param word A substring of the word name to complete
@ -59,7 +67,7 @@ public interface VocabularyLookup
* the beginning of the name. * the beginning of the name.
* @param completions Set to add completions to * @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; Set completions) throws Exception;
public Cons getVocabularies() 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$ * $Id$
* *
* Copyright (C) 2003, 2004 Slava Pestov. * Copyright (C) 2005 Slava Pestov.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -27,36 +27,33 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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 java.util.*;
import org.gjt.sp.jedit.*;
import org.gjt.sp.util.*;
/** public class CompileBufferProcessor extends FactorBufferProcessor
* A word definition.
*/
public abstract class FactorWordDefinition
{ {
public FactorWord word; //{{{ CompileBufferProcessor constructor
public CompileBufferProcessor(View view, Buffer buffer)
throws Exception
{
super(view,buffer,true);
} //}}}
//{{{ FactorWordDefinition constructor //{{{ processWord() method
/** /**
* A new definition. * @return Code to process the word.
*/ */
public FactorWordDefinition(FactorWord word) public String processWord(FactorWord word)
{ {
this.word = word; StringBuffer expression = new StringBuffer();
} //}}} expression.append(FactorPlugin.factorWord(word));
expression.append(" try-compile");
//{{{ toList() method return expression.toString();
public Cons toList()
{
return null;
} //}}}
//{{{ toString() method
public String toString()
{
return getClass().getName() + ": " + word;
} //}}} } //}}}
} }

View File

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

View File

@ -30,7 +30,6 @@
package factor.jedit; package factor.jedit;
import factor.FactorWord; import factor.FactorWord;
import factor.FactorWordDefinition;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.text.Position; import javax.swing.text.Position;
import org.gjt.sp.jedit.Buffer; 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.io.*;
import java.util.*; import java.util.*;
import org.gjt.sp.jedit.gui.*; import org.gjt.sp.jedit.gui.*;
import org.gjt.sp.jedit.syntax.*;
import org.gjt.sp.jedit.textarea.*; import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*; import org.gjt.sp.jedit.*;
import org.gjt.sp.util.Log; import org.gjt.sp.util.Log;
@ -129,6 +130,10 @@ public class FactorPlugin extends EditPlugin
.getParentOfPath(imagePath))); .getParentOfPath(imagePath)));
external = new ExternalFactor(PORT); external = new ExternalFactor(PORT);
process.getOutputStream().close();
process.getInputStream().close();
process.getErrorStream().close();
} }
catch(Exception e) catch(Exception e)
{ {
@ -154,7 +159,8 @@ public class FactorPlugin extends EditPlugin
*/ */
public static void stopExternalInstance() public static void stopExternalInstance()
{ {
getFactorShell().closeStreams(); if(getFactorShell() != null)
getFactorShell().closeStreams();
if(external != null) if(external != null)
{ {
@ -193,6 +199,16 @@ public class FactorPlugin extends EditPlugin
"sidekick.SideKickParser","factor"); "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 //{{{ evalInListener() method
public static void evalInListener(View view, String cmd) 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) public static FactorWord lookupWord(View view, String word)
{ {
SideKickParsedData data = SideKickParsedData.getParsedData(view); FactorParsedData fdata = getParsedData(view);
if(data instanceof FactorParsedData) if(fdata == null)
{
FactorParsedData fdata = (FactorParsedData)data;
return getExternalInstance().searchVocabulary(fdata.use,word);
}
else
return null; return null;
else
return getExternalInstance().searchVocabulary(fdata.use,word);
} //}}} } //}}}
//{{{ factorWord() method //{{{ factorWord() method
@ -230,18 +243,14 @@ public class FactorPlugin extends EditPlugin
*/ */
public static String factorWord(View view, String word) public static String factorWord(View view, String word)
{ {
SideKickParsedData data = SideKickParsedData FactorParsedData fdata = getParsedData(view);
.getParsedData(view); if(fdata == null)
if(data instanceof FactorParsedData)
{
FactorParsedData fdata = (FactorParsedData)data;
return "\""
+ FactorReader.charsToEscapes(word)
+ "\" " + FactorReader.unparseObject(fdata.use)
+ " search";
}
else
return null; return null;
return "\""
+ FactorReader.charsToEscapes(word)
+ "\" " + FactorReader.unparseObject(fdata.use)
+ " search";
} //}}} } //}}}
//{{{ factorWord() method //{{{ factorWord() method
@ -295,6 +304,22 @@ public class FactorPlugin extends EditPlugin
evalInWire(word + " " + op); 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 //{{{ toWordArray() method
public static FactorWord[] toWordArray(Set completions) public static FactorWord[] toWordArray(Set completions)
{ {
@ -305,19 +330,20 @@ public class FactorPlugin extends EditPlugin
return w; 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 * @param anywhere If true, matches anywhere in the word name are
* returned; otherwise, only matches from beginning. * returned; otherwise, only matches from beginning.
*/ */
public static Set getCompletions(String word, boolean anywhere) public static Set getWordCompletions(String word, boolean anywhere)
{ {
try try
{ {
Set completions = new HashSet(); Set completions = new HashSet();
getExternalInstance().getCompletions( getExternalInstance().getWordCompletions(
getExternalInstance().getVocabularies(), getExternalInstance().getVocabularies(),
word, word,
anywhere, 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 //{{{ getWordStartIndex() method
public static int getWordStartOffset(String line, int caret) public static int getWordStartOffset(String line, int caret)
{ {
@ -403,16 +450,14 @@ public class FactorPlugin extends EditPlugin
//{{{ isUsed() method //{{{ isUsed() method
public static boolean isUsed(View view, String vocab) public static boolean isUsed(View view, String vocab)
{ {
SideKickParsedData data = SideKickParsedData FactorParsedData fdata = getParsedData(view);
.getParsedData(view); if(fdata == null)
if(data instanceof FactorParsedData) return false;
else
{ {
FactorParsedData fdata = (FactorParsedData)data;
Cons use = fdata.use; Cons use = fdata.use;
return Cons.contains(use,vocab); return Cons.contains(use,vocab);
} }
else
return false;
} //}}} } //}}}
//{{{ findAllWordsNamed() method //{{{ 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 //{{{ insertUse() method
public static void insertUse(View view, String vocab) public static void insertUse(View view, String vocab)
{ {
@ -465,44 +613,14 @@ public class FactorPlugin extends EditPlugin
} }
Buffer buffer = view.getBuffer(); Buffer buffer = view.getBuffer();
int lastUseOffset = 0; int offset = findUse(buffer);
boolean leadingNewline = false;
boolean seenUse = false;
for(int i = 0; i < buffer.getLineCount(); i++) if(offset == -1)
{ createUse(buffer,vocab);
String text = buffer.getLineText(i).trim(); else
if(text.startsWith("IN:") || text.startsWith("USE:")) updateUse(buffer,vocab,offset);
{
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;
}
}
String decl = "USE: " + vocab; showStatus(view,"inserted-use",vocab);
if(leadingNewline)
decl = "\n" + decl;
if(lastUseOffset == 0)
decl = decl + "\n";
buffer.insert(lastUseOffset,decl);
showStatus(view,"inserted-use",decl);
} //}}} } //}}}
//{{{ extractWord() method //{{{ extractWord() method
@ -514,9 +632,8 @@ public class FactorPlugin extends EditPlugin
if(selection == null) if(selection == null)
selection = ""; selection = "";
SideKickParsedData data = SideKickParsedData FactorParsedData data = getParsedData(view);
.getParsedData(view); if(data == null)
if(!(data instanceof FactorParsedData))
{ {
view.getToolkit().beep(); view.getToolkit().beep();
return; return;
@ -553,7 +670,15 @@ public class FactorPlugin extends EditPlugin
{ {
buffer.beginCompoundEdit(); buffer.beginCompoundEdit();
int firstLine = buffer.getLineOfOffset(start);
buffer.insert(start,newDef); buffer.insert(start,newDef);
int lastLine = buffer.getLineOfOffset(start
+ newDef.length());
buffer.indentLines(firstLine,lastLine);
textArea.setSelectedText(newWord); textArea.setSelectedText(newWord);
} }
finally finally
@ -561,4 +686,27 @@ public class FactorPlugin extends EditPlugin
buffer.endCompoundEdit(); 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.activate=startup
plugin.factor.jedit.FactorPlugin.name=Factor 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.author=Slava Pestov
plugin.factor.jedit.FactorPlugin.docs=/doc/jedit/index.html plugin.factor.jedit.FactorPlugin.docs=/doc/jedit/index.html
@ -29,6 +29,12 @@ plugin.factor.jedit.FactorPlugin.menu=factor-listener \
- \ - \
factor-extract-word \ factor-extract-word \
- \ - \
factor-infer-effect \
factor-infer-effects \
- \
factor-compile \
factor-compile-all \
- \
factor-restart factor-restart
factor-listener.label=Listener factor-listener.label=Listener
@ -41,6 +47,10 @@ factor-edit.label=Edit word at caret
factor-edit-dialog.label=Edit word... factor-edit-dialog.label=Edit word...
factor-usages.label=Word usages at caret factor-usages.label=Word usages at caret
factor-extract-word.label=Extract word... 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 factor-restart.label=Restart Factor
# SideKick stuff # SideKick stuff
@ -48,15 +58,12 @@ sidekick.parser.factor.label=Factor
mode.factor.sidekick.parser=factor mode.factor.sidekick.parser=factor
factor.completion.in=<font color="#a0a0a0">IN: {0}</font>\ factor.completion.in=<font color="#a0a0a0">IN: {0}</font>\
factor.completion.colon=: <b>{0}</b> factor.completion.def={0} <b>{1}</b>
factor.completion.defer=DEFER: <b>{0}</b>
factor.completion.parsing=PARSING: <b>{0}</b>
factor.completion.symbol=SYMBOL: <b>{0}</b>
factor.completion.stack={0} ( {1}) factor.completion.stack={0} ( {1})
# Dialog boxes # Dialog boxes
factor.status.inserted-use=Inserted {0} factor.status.inserted-use=Using {0}
factor.status.already-used=Already used {0} factor.status.already-used=Already using {0}
factor.insert-use.title=Insert USE: Declaration factor.insert-use.title=Insert USE: Declaration
factor.insert-use.caption=There are multiple words named "{0}". Select the one to use: 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(), output.print(console.getInfoColor(),
jEdit.getProperty("factor.shell.opening")); jEdit.getProperty("factor.shell.opening"));
stream = FactorPlugin.getExternalInstance().openStream(); stream = null;
ExternalFactor external = FactorPlugin.getExternalInstance();
if(external != null)
stream = external.openStream();
if(stream == null) if(stream == null)
{ {
output.print(console.getInfoColor(), output.print(console.getInfoColor(),

View File

@ -3,7 +3,7 @@
/* /*
* $Id$ * $Id$
* *
* Copyright (C) 2004 Slava Pestov. * Copyright (C) 2004, 2005 Slava Pestov.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -130,12 +130,12 @@ public class FactorSideKickParser extends SideKickParser
errorSource); errorSource);
r = new FactorReader(scanner,false,FactorPlugin.getExternalInstance()); r = new FactorReader(scanner,false,FactorPlugin.getExternalInstance());
Cons parsed = r.parse(); r.parse();
d.in = r.getIn(); d.in = r.getIn();
d.use = r.getUse(); d.use = r.getUse();
addWordDefNodes(d,parsed,buffer); addWordDefNodes(d,r.getDefinedWords(),buffer);
} }
catch(FactorParseException pe) catch(FactorParseException pe)
{ {
@ -172,38 +172,31 @@ public class FactorSideKickParser extends SideKickParser
} //}}} } //}}}
//{{{ addWordDefNodes() method //{{{ addWordDefNodes() method
private void addWordDefNodes(FactorParsedData d, Cons parsed, Buffer buffer) private void addWordDefNodes(FactorParsedData d, Cons words, Buffer buffer)
{ {
FactorAsset last = null; FactorAsset last = null;
while(parsed != null) while(words != null)
{ {
if(parsed.car instanceof FactorWordDefinition) FactorWord word = (FactorWord)words.car;
{
FactorWordDefinition def
= (FactorWordDefinition)
parsed.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 start = buffer.getLineStartOffset(startLine)
int startLine = Math.max(0,Math.min( + startCol;
buffer.getLineCount() - 1,
word.line - 1));
int startLineLength = buffer.getLineLength(startLine);
int startCol = Math.min(word.col,startLineLength);
int start = buffer.getLineStartOffset(startLine) if(last != null)
+ startCol; last.end = buffer.createPosition(Math.max(0,start - 1));
if(last != null) last = new FactorAsset(word,buffer.createPosition(start));
last.end = buffer.createPosition(Math.max(0,start - 1)); d.root.add(new DefaultMutableTreeNode(last));
last = new FactorAsset(word,buffer.createPosition(start)); words = words.next();
d.root.add(new DefaultMutableTreeNode(last));
}
parsed = parsed.next();
} }
if(last != null) if(last != null)
@ -252,11 +245,16 @@ public class FactorSideKickParser extends SideKickParser
*/ */
public SideKickCompletion complete(EditPane editPane, int caret) public SideKickCompletion complete(EditPane editPane, int caret)
{ {
SideKickParsedData _data = SideKickParsedData FactorParsedData data = FactorPlugin.getParsedData(
.getParsedData(editPane.getView()); editPane.getView());
if(!(_data instanceof FactorParsedData)) if(data == null)
return null;
String ruleset = FactorPlugin.getRulesetAtOffset(
editPane.getTextArea(),caret);
if(ruleset == null)
return null; return null;
FactorParsedData data = (FactorParsedData)_data;
Buffer buffer = editPane.getBuffer(); Buffer buffer = editPane.getBuffer();
@ -291,14 +289,40 @@ public class FactorSideKickParser extends SideKickParser
if(word.length() == 0) if(word.length() == 0)
return null; return null;
FactorWord[] completions = FactorPlugin.toWordArray( if(ruleset.equals("factor::USING"))
FactorPlugin.getCompletions(word,false)); 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) if(completions.length == 0)
return null; return null;
else 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); 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$ * $Id$
* *
* Copyright (C) 2004 Slava Pestov. * Copyright (C) 2004, 2005 Slava Pestov.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 org.gjt.sp.jedit.*;
import sidekick.*; import sidekick.*;
public class FactorCompletion extends SideKickCompletion public class FactorWordCompletion extends AbstractCompletion
{ {
private View view;
private JEditTextArea textArea;
private String word; private String word;
private FactorParsedData data;
//{{{ FactorCompletion constructor //{{{ FactorWordCompletion constructor
public FactorCompletion(View view, FactorWord[] items, public FactorWordCompletion(View view, FactorWord[] items,
String word, FactorParsedData data) String word, FactorParsedData data)
{ {
this.view = view; super(view,items,data);
textArea = view.getTextArea();
this.items = Arrays.asList(items);
this.word = word; this.word = word;
this.data = data;
} //}}} } //}}}
public String getLongestPrefix()
{
return MiscUtilities.getLongestPrefix(items,false);
}
public void insert(int index) public void insert(int index)
{ {
FactorWord selected = ((FactorWord)get(index)); FactorWord selected = ((FactorWord)get(index));
@ -85,26 +74,6 @@ public class FactorCompletion extends SideKickCompletion
return word.length(); 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() public ListCellRenderer getRenderer()
{ {
return new FactorWordRenderer(data.parser,false); return new FactorWordRenderer(data.parser,false);

View File

@ -39,19 +39,12 @@ public class FactorWordRenderer extends DefaultListCellRenderer
//{{{ getWordHTMLString() method //{{{ getWordHTMLString() method
public static String getWordHTMLString(FactorWord word, boolean showIn) public static String getWordHTMLString(FactorWord word, boolean showIn)
{ {
String prop = "factor.completion.colon"; String defStr = jEdit.getProperty(
"factor.completion.def",
/* if(def == null) new String[] {
{ MiscUtilities.charsToEntities(word.getDefiner().name),
if(word.parsing != null) MiscUtilities.charsToEntities(word.name)
prop = "factor.completion.parsing"; });
else
prop = "factor.completion.defer";
}
else if(def instanceof FactorSymbolDefinition)
{
prop = "factor.completion.symbol";
} */
String in; String in;
if(showIn) if(showIn)
@ -64,8 +57,8 @@ public class FactorWordRenderer extends DefaultListCellRenderer
else else
in = ""; in = "";
String html = "<html>" + in + jEdit.getProperty(prop, String html = "<html>" + in + defStr;
new Object[] { MiscUtilities.charsToEntities(word.name) });
if(word.stackEffect != null) if(word.stackEffect != null)
{ {
html = jEdit.getProperty("factor.completion.stack", 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 //{{{ createActionsMenu() method
private Action[] createActionsMenu(Cons alist) private Action[] createActionsMenu(Cons alist)
{ {
if(alist == null) int length = Cons.length(alist);
return null;
int length = alist.length();
int i = 0; int i = 0;
Action[] actions = new Action[length]; Action[] actions = new Action[length];
while(alist != null) 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.jedit.*;
import org.gjt.sp.util.Log; import org.gjt.sp.util.Log;
public class WordPopup extends JWindow public class TextAreaPopup extends JWindow
{ {
private View view; private View view;
private JTextArea preview; private JTextArea preview;
//{{{ showWordPopup() method //{{{ TextAreaPopup constructor
public static void showWordPopup(JEditTextArea textArea) public TextAreaPopup(JEditTextArea textArea, String text)
{ {
View view = GUIUtilities.getView(textArea); super(GUIUtilities.getView(textArea));
String def; this.view = GUIUtilities.getView(textArea);
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;
preview = new JTextArea(text); preview = new JTextArea(text);
preview.setEditable(false); preview.setEditable(false);
getContentPane().add(BorderLayout.CENTER,new JScrollPane(preview)); getContentPane().add(BorderLayout.CENTER,new JScrollPane(preview));
@ -91,6 +59,23 @@ public class WordPopup extends JWindow
view.setKeyEventInterceptor(keyHandler); view.setKeyEventInterceptor(keyHandler);
GUIUtilities.requestFocus(this,preview); 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 //{{{ KeyHandler class

View File

@ -91,26 +91,11 @@ public class WordPreview implements ActionListener, CaretListener
private FactorWord getWordAtCaret(FactorParsedData fdata) private FactorWord getWordAtCaret(FactorParsedData fdata)
throws IOException throws IOException
{ {
int line = textArea.getCaretLine(); String name = FactorPlugin.getRulesetAtOffset(textArea,
int caret = textArea.getCaretPosition(); textArea.getCaretPosition());
if(name == null)
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; 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++) for(int i = 0; i < IGNORED_RULESETS.length; i++)
{ {
if(name.equals(IGNORED_RULESETS[i])) if(name.equals(IGNORED_RULESETS[i]))
@ -134,10 +119,13 @@ public class WordPreview implements ActionListener, CaretListener
if(SideKickPlugin.isParsingBuffer(view.getBuffer())) if(SideKickPlugin.isParsingBuffer(view.getBuffer()))
return; return;
SideKickParsedData data = SideKickParsedData.getParsedData(view); if(!view.getBuffer().isLoaded())
if(data instanceof FactorParsedData) return;
FactorParsedData data = FactorPlugin.getParsedData(view);
if(data != null)
{ {
FactorWord w = getWordAtCaret((FactorParsedData)data); FactorWord w = getWordAtCaret(data);
if(w != null) if(w != null)
{ {
view.getStatus().setMessageAndClear( view.getStatus().setMessageAndClear(

View File

@ -3,7 +3,7 @@
/* /*
* $Id$ * $Id$
* *
* Copyright (C) 2004 Slava Pestov. * Copyright (C) 2005 Slava Pestov.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -31,20 +31,15 @@ package factor.parser;
import factor.*; import factor.*;
public class Defer extends FactorParsingDefinition public class BeginCons extends FactorParsingDefinition
{ {
//{{{ Defer constructor public BeginCons(FactorWord word)
/**
* A new definition.
*/
public Defer(FactorWord word)
{ {
super(word); super(word);
} //}}} }
public void eval(FactorReader reader) 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 public class BeginConstructor extends FactorParsingDefinition
{ {
private FactorWord colon; public BeginConstructor(FactorWord word)
public BeginConstructor(FactorWord word, FactorWord colon)
{ {
super(word); super(word);
this.colon = colon;
} }
public void eval(FactorReader reader) public void eval(FactorReader reader)
@ -48,6 +45,8 @@ public class BeginConstructor extends FactorParsingDefinition
if(type == null) if(type == null)
return; 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 public class BeginMethod extends FactorParsingDefinition
{ {
private FactorWord colon; public BeginMethod(FactorWord word)
public BeginMethod(FactorWord word, FactorWord colon)
{ {
super(word); super(word);
this.colon = colon;
} }
public void eval(FactorReader reader) public void eval(FactorReader reader)
@ -48,10 +45,10 @@ public class BeginMethod extends FactorParsingDefinition
if(type == null) if(type == null)
return; return;
FactorWord generic = reader.nextWord(false); FactorWord newWord = reader.nextWord(false);
if(generic == null) if(newWord == null)
return; return;
reader.pushExclusiveState(colon,generic); reader.pushExclusiveState(word,newWord);
} }
} }

View File

@ -31,9 +31,9 @@ package factor.parser;
import factor.*; import factor.*;
public class Symbol extends FactorParsingDefinition public class BeginPredicate extends FactorParsingDefinition
{ {
public Symbol(FactorWord word) public BeginPredicate(FactorWord word)
{ {
super(word); super(word);
} }
@ -41,8 +41,18 @@ public class Symbol extends FactorParsingDefinition
public void eval(FactorReader reader) public void eval(FactorReader reader)
throws Exception throws Exception
{ {
FactorWord w = reader.nextWord(true); FactorWord supertype = reader.nextWord(false);
w.def = new FactorSymbolDefinition(w,w); if(supertype == null)
reader.append(w.def); 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.*; import factor.*;
public class Generic extends FactorParsingDefinition public class BeginUnion extends FactorParsingDefinition
{ {
public Generic(FactorWord word) public BeginUnion(FactorWord word)
{ {
super(word); super(word);
} }
@ -41,8 +41,14 @@ public class Generic extends FactorParsingDefinition
public void eval(FactorReader reader) public void eval(FactorReader reader)
throws Exception throws Exception
{ {
FactorWord w = reader.nextWord(true); FactorWord type = reader.nextWord(true);
w.def = new FactorGenericDefinition(w); if(type == null)
reader.append(w.def); 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); FactorWord newWord = reader.nextWord(true);
if(newWord == null) if(newWord != null)
return; {
newWord.setDefiner(word);
reader.pushExclusiveState(word,newWord); reader.pushExclusiveState(word,newWord);
}
} }
} }

View File

@ -31,9 +31,13 @@ package factor.parser;
import factor.*; 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); super(word);
} }
@ -42,12 +46,9 @@ public class Traits extends FactorParsingDefinition
throws Exception throws Exception
{ {
FactorWord w = reader.nextWord(true); FactorWord w = reader.nextWord(true);
if(w == null) /* Only ever null with restartable scanner;
return; error already logged, so give up */
if(w != null)
w.def = new FactorTraitsDefinition(w); w.setDefiner(word);
reader.intern("<" + w.name + ">",true);
reader.intern(w.name + "?",true);
reader.append(w.def);
} }
} }

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

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$ * $Id$
* *
* Copyright (C) 2004 Slava Pestov. * Copyright (C) 2005 Slava Pestov.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -31,23 +31,25 @@ package factor.parser;
import factor.*; import factor.*;
public class Bar extends FactorParsingDefinition public class Using extends FactorParsingDefinition
{ {
//{{{ Bar constructor public Using(FactorWord word)
/**
* A new definition.
*/
public Bar(FactorWord word)
{ {
super(word); super(word);
} //}}} }
public void eval(FactorReader reader) public void eval(FactorReader reader)
throws Exception throws Exception
{ {
FactorReader.ParseState state = reader.getCurrentState(); for(;;)
if(state.start != reader.intern("[",false)) {
reader.error("| only allowed inside [ ... ]"); Object next = reader.next(false,false);
reader.bar(); 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: ! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
! $Id$ IN: lists USING: kernel ;
!
! 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
! An association list is a list of conses where the car of each ! 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 ! 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. #! Push if the list appears to be an alist.
dup list? [ [ cons? ] all? ] [ drop f ] ifte ; 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. #! Looks up the key in an alist. Push the key/value pair.
#! Most of the time you want to use assoc not assoc*. #! Most of the time you want to use assoc not assoc*.
dup [ [ car = ] some-with? dup [ car ] when ;
2dup car car = [ nip car ] [ cdr assoc* ] ifte
] [
2drop f
] ifte ;
: assoc ( key alist -- value ) : assoc ( key alist -- value )
#! Looks up the key in an alist. #! Looks up the key in an alist.
assoc* dup [ cdr ] when ; assoc* dup [ cdr ] when ;
: remove-assoc ( key alist -- alist ) : remove-assoc ( key alist -- alist )
#! Remove all key/value pairs with this key. #! Remove all key/value pairs with this key.
[ dupd car = not ] subset nip ; [ car = not ] subset-with ;
: acons ( value key alist -- alist ) : acons ( value key alist -- alist )
#! Adds the key/value pair to the alist. Existing pairs with #! 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 #! corresponding quotation, the value is popped off the
#! stack. #! stack.
swap [ swap [
unswons rot assoc* dup [ unswons rot assoc* dup [ cdr call ] [ 2drop ] ifte
cdr call
] [
2drop
] ifte
] each-with ; ] each-with ;
: 2cons ( car1 car2 cdr1 cdr2 -- cons1 cons2 ) : 2cons ( car1 car2 cdr1 cdr2 -- cons1 cons2 )
@ -83,11 +49,7 @@ USE: kernel
: zip ( list list -- list ) : zip ( list list -- list )
#! Make a new list containing pairs of corresponding #! Make a new list containing pairs of corresponding
#! elements from the two given lists. #! elements from the two given lists.
dup [ dup [ 2uncons zip >r cons r> cons ] [ 2drop [ ] ] ifte ;
2uncons zip >r cons r> cons
] [
2drop [ ]
] ifte ;
: unzip ( assoc -- keys values ) : unzip ( assoc -- keys values )
#! Split an association list into two lists of keys and #! Split an association list into two lists of keys and

View File

@ -1,55 +1,23 @@
! :folding=indent:collapseFolds=1: ! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
! $Id$ USING: kernel lists parser stdio words namespaces ;
!
! 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
"Cold boot in progress..." print "Cold boot in progress..." print
! vocabularies get [
! "generic" off
! ] bind
[ [
"/library/generic/generic.factor" "/library/generic/generic.factor"
"/library/generic/object.factor" "/library/generic/object.factor"
"/library/generic/null.factor"
"/library/generic/builtin.factor" "/library/generic/builtin.factor"
"/library/generic/predicate.factor" "/library/generic/predicate.factor"
"/library/generic/union.factor" "/library/generic/union.factor"
"/library/generic/traits.factor" "/library/generic/complement.factor"
"/library/generic/tuple.factor"
"/version.factor" "/version.factor"
"/library/stack.factor" "/library/stack.factor"
"/library/combinators.factor" "/library/combinators.factor"
"/library/arrays.factor"
"/library/kernel.factor" "/library/kernel.factor"
"/library/cons.factor" "/library/cons.factor"
"/library/assoc.factor" "/library/assoc.factor"
@ -58,14 +26,13 @@ USE: namespaces
"/library/math/ratio.factor" "/library/math/ratio.factor"
"/library/math/float.factor" "/library/math/float.factor"
"/library/math/complex.factor" "/library/math/complex.factor"
"/library/words.factor"
"/library/math/math-combinators.factor"
"/library/lists.factor" "/library/lists.factor"
"/library/dlists.factor"
"/library/vectors.factor" "/library/vectors.factor"
"/library/strings.factor" "/library/strings.factor"
"/library/hashtables.factor" "/library/hashtables.factor"
"/library/words.factor"
"/library/namespaces.factor" "/library/namespaces.factor"
"/library/list-namespaces.factor"
"/library/sbuf.factor" "/library/sbuf.factor"
"/library/errors.factor" "/library/errors.factor"
"/library/continuations.factor" "/library/continuations.factor"
@ -83,84 +50,99 @@ USE: namespaces
"/library/io/presentation.factor" "/library/io/presentation.factor"
"/library/io/vocabulary-style.factor" "/library/io/vocabulary-style.factor"
"/library/syntax/prettyprint.factor" "/library/syntax/prettyprint.factor"
"/library/syntax/see.factor"
"/library/tools/debugger.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/io/files.factor"
"/library/eval-catch.factor" "/library/eval-catch.factor"
"/library/tools/memory.factor"
"/library/tools/listener.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" "/library/cli.factor"
] [ ] [
dup print dup print run-resource
run-resource
] each ] 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" = [ os "win32" = [
[ [
"/library/io/buffer.factor" "/library/io/buffer.factor"
@ -170,17 +152,32 @@ os "win32" = [
"/library/io/win32-io-internals.factor" "/library/io/win32-io-internals.factor"
"/library/io/win32-stream.factor" "/library/io/win32-stream.factor"
"/library/io/win32-server.factor" "/library/io/win32-server.factor"
"/library/io/win32-console.factor"
] [ ] [
dup print dup print
run-resource run-resource
] each ] each
] when ] when
cpu "x86" = [ cpu "x86" = "mini" get not and [
[ [
"/library/compiler/assembly-x86.factor" "/library/compiler/x86/assembler.factor"
"/library/compiler/generator-x86.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 dup print
run-resource run-resource

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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