diff --git a/factor/FactorInterpreter.java b/factor/FactorInterpreter.java index ba2a968241..4d3cab3a20 100644 --- a/factor/FactorInterpreter.java +++ b/factor/FactorInterpreter.java @@ -193,6 +193,8 @@ public class FactorInterpreter implements FactorObject, Runnable ine.parsing = new Ine(def,ine); FactorWord shuffle = define("syntax","~<<"); shuffle.parsing = new Shuffle(shuffle,">>~"); + FactorWord symbol = define("syntax","SYMBOL:"); + symbol.parsing = new Symbol(symbol); /* reading numbers with another base */ FactorWord bin = define("syntax","BIN:"); diff --git a/factor/FactorSymbolDefinition.java b/factor/FactorSymbolDefinition.java new file mode 100644 index 0000000000..083a44002e --- /dev/null +++ b/factor/FactorSymbolDefinition.java @@ -0,0 +1,96 @@ +/* :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; + +import factor.compiler.*; +import org.objectweb.asm.*; + +/** + * 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; + } //}}} + + //{{{ eval() method + public void eval(FactorInterpreter interp) + throws Exception + { + interp.datastack.push(symbol); + } //}}} + + //{{{ getStackEffect() method + public void getStackEffect(RecursiveState recursiveCheck, + FactorCompiler compiler) throws Exception + { + compiler.pushLiteral(symbol,recursiveCheck); + } //}}} + + //{{{ compile() method + /** + * Compile the given word, returning a new word definition. + */ + FactorWordDefinition compile(FactorInterpreter interp, + RecursiveState recursiveCheck) throws Exception + { + return this; + } //}}} + + //{{{ compileCallTo() method + public void compileCallTo(CodeVisitor mw, FactorCompiler compiler, + RecursiveState recursiveCheck) throws FactorStackException + { + compiler.pushLiteral(symbol,recursiveCheck); + } //}}} + + //{{{ fromList() method + public void fromList(Cons definition, FactorInterpreter interp) + { + this.symbol = definition.car; + } //}}} + + //{{{ toList() method + public Cons toList(FactorInterpreter interp) + { + return new Cons(symbol,null); + } //}}} +} diff --git a/factor/parser/Symbol.java b/factor/parser/Symbol.java new file mode 100644 index 0000000000..6f94797170 --- /dev/null +++ b/factor/parser/Symbol.java @@ -0,0 +1,55 @@ +/* :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.parser; + +import factor.*; + +public class Symbol extends FactorParsingDefinition +{ + //{{{ Symbol constructor + /** + * A new definition. + */ + public Symbol(FactorWord word) + throws Exception + { + super(word); + } //}}} + + public void eval(FactorInterpreter interp, FactorReader reader) + throws Exception + { + FactorWord w = reader.nextWord(true); + reader.append(w.vocabulary); + reader.append(w.name); + reader.append(new FactorSymbolDefinition(w,w)); + reader.append(reader.intern("define",false)); + } +} diff --git a/library/platform/jvm/prettyprint.factor b/library/platform/jvm/prettyprint.factor index 082f407934..9b19aa3ab8 100644 --- a/library/platform/jvm/prettyprint.factor +++ b/library/platform/jvm/prettyprint.factor @@ -62,5 +62,6 @@ USE: words [ compound-or-compiled? ] [ word-parameter prettyprint-:; ] [ shuffle? ] [ word-parameter prettyprint-~<<>>~ ] [ primitive? ] [ "PRIMITIVE: " write unparse write drop ] + [ symbol? ] [ "SYMBOL: " write drop unparse write ] [ drop t ] [ 2drop "Not defined" write ] ] cond prettyprint-newline ; diff --git a/library/platform/jvm/words.factor b/library/platform/jvm/words.factor index 80aea3af15..6939285980 100644 --- a/library/platform/jvm/words.factor +++ b/library/platform/jvm/words.factor @@ -51,18 +51,21 @@ USE: stack : redefine ( word def -- ) swap [ "def" set ] bind ; -: word? ( obj -- boolean ) +: word? ( obj -- ? ) "factor.FactorWord" is ; -: compiled? ( worddef -- boolean ) +: compiled? ( worddef -- ? ) "factor.compiler.CompiledDefinition" is ; -: compound? ( worddef -- boolean ) +: compound? ( worddef -- ? ) "factor.FactorCompoundDefinition" is ; : compound-or-compiled? ( worddef -- ? ) dup compiled? swap compound? or ; +: symbol? ( worddef -- ? ) + "factor.FactorSymbolDefinition" is ; + : comment? ( obj -- ? ) "factor.FactorDocComment" is ;