]> gitweb.factorcode.org Git - factor.git/commitdiff
started with SYMBOL: for java factor
authorSlava Pestov <slava@factorcode.org>
Tue, 5 Oct 2004 03:06:18 +0000 (03:06 +0000)
committerSlava Pestov <slava@factorcode.org>
Tue, 5 Oct 2004 03:06:18 +0000 (03:06 +0000)
factor/FactorInterpreter.java
factor/FactorSymbolDefinition.java [new file with mode: 0644]
factor/parser/Symbol.java [new file with mode: 0644]
library/platform/jvm/prettyprint.factor
library/platform/jvm/words.factor

index ba2a9682414046a136254adfad6d41aa6aa59a88..4d3cab3a20470aef38bc597cc51928d4818289eb 100644 (file)
@@ -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 (file)
index 0000000..083a440
--- /dev/null
@@ -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 (file)
index 0000000..6f94797
--- /dev/null
@@ -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));
+       }
+}
index 082f407934e6938a26b7b8fcbb31191fa7276d73..9b19aa3ab8826093d313149bf039d47b6e761994 100644 (file)
@@ -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 ;
index 80aea3af15138c895ec9d9ff1893bd8be04e2bbd..693928598012944db45b719d91dd1e217713c724 100644 (file)
@@ -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 ;