started with SYMBOL: for java factor

cvs
Slava Pestov 2004-10-05 03:06:18 +00:00
parent 5b10aac530
commit 35261e5232
5 changed files with 160 additions and 3 deletions

View 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:");

View File

@ -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);
} //}}}
}

55
factor/parser/Symbol.java Normal file
View File

@ -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));
}
}

View 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 ;

View 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 ;