Package gnu.expr

Class Expression

All Implemented Interfaces:
gnu.kawa.format.Printable, Named, SourceLocator, SourceLocator, Locator
Direct Known Subclasses:
AccessExp, ApplyExp, BeginExp, BlockExp, CaseExp, ErrorExp, ExitExp, IfExp, LangExp, QuoteExp, ScopeExp, SynchronizedExp, TryExp

public abstract class Expression extends Procedure implements gnu.kawa.format.Printable, SourceLocator
Abstract class for syntactic forms that evaluate to a value. Scheme S-expressions get re-written to these before evaluation.
  • Field Details

    • applyMethodExpression

      public static final MethodHandle applyMethodExpression
    • noExpressions

      public static final Expression[] noExpressions
    • type

      protected Type type
    • flags

      protected int flags
    • VALIDATED

      public static final int VALIDATED
      See Also:
    • NEXT_AVAIL_FLAG

      protected static final int NEXT_AVAIL_FLAG
      See Also:
  • Constructor Details

    • Expression

      public Expression()
  • Method Details

    • applyMethodExpression

      public static Object applyMethodExpression(Procedure proc, CallContext ctx) throws Throwable
      Throws:
      Throwable
    • eval

      public final Object eval(CallContext ctx) throws Throwable
      Throws:
      Throwable
    • eval

      public final Object eval(Environment env) throws Throwable
      Throws:
      Throwable
    • mustCompile

      protected abstract boolean mustCompile()
    • numArgs

      public int numArgs()
      Description copied from class: Procedure
      Return minArgs()|(maxArgs<<12). We use a single virtual function to reduce the number of methods in the system, as well as the number of virtual method table entries. We shift by 12 so the number can normally be represented using a sipush instruction, without requiring a constant pool entry.
      Overrides:
      numArgs in class Procedure
    • apply

      public void apply(CallContext ctx) throws Throwable
      Evaluate the expression. This is named apply rather than eval so it is compatible with the full-tail-call calling convention, and we can stash an Expression in CallContext's proc field. FIXME - are we making use of this?
      Throws:
      Throwable
    • print

      public final void print(Consumer out)
      Specified by:
      print in interface gnu.kawa.format.Printable
    • print

      public abstract void print(gnu.kawa.io.OutPort ps)
    • printLineColumn

      public void printLineColumn(gnu.kawa.io.OutPort out)
      Print line and column number if specified. This is a helper routine intended for use by print(OutPort).
    • compile

      public abstract void compile(Compilation comp, Target target)
    • compileWithPosition

      public final void compileWithPosition(Compilation comp, Target target)
      Same as compile, but emit line number beforehard.
    • compileWithPosition

      public final void compileWithPosition(Compilation comp, Target target, Expression position)
      Same as 2-argument compileWithPosition, but use some other Expression's line number.
    • compile

      public final void compile(Compilation comp, Type type)
    • compile

      public final void compile(Compilation comp, Declaration lhs)
      Compile an expression with checking suitable for a known Declaration. Leaves the result on the stack (i.e. does not assign to the lhs). It does coerce the value to a suitable type for the lhs, and throw a hopefully-informative WrongType exception on failure.
    • deepCopy

      public static Expression deepCopy(Expression exp, IdentityHashTable mapper)
      Make a deep copy of this expression, if possible.
      Parameters:
      mapper - used to lookup parts (expressions, declarations) that have been translated in the parent. Needed for copied Declarations and BlockExps.
      Returns:
      a copy, or null if we can't copy.
    • deepCopy

      public static Expression[] deepCopy(Expression[] exps, IdentityHashTable mapper)
    • deepCopy

      protected static Expression deepCopy(Expression exp)
    • deepCopy

      protected Expression deepCopy(IdentityHashTable mapper)
    • visit

      protected <R, D> R visit(ExpVisitor<R,D> visitor, D d)
    • visitChildren

      protected <R, D> void visitChildren(ExpVisitor<R,D> visitor, D d)
    • validateApply

      public Expression validateApply(ApplyExp exp, InlineCalls visitor, Type required, Declaration decl)
      Apply inlining transformations on a given ApplyExp. Assumes the ApplyExp's function is this expression, or can be optimized to this expression.
      Parameters:
      exp - an application whose function expression can be simplified to this expression.
      visitor - the context for the current inlining pass
      decl - if non-null, a Declaration bound to this expression.
      Returns:
      an Expression equivalent to the passed-in exp.
    • makeWhile

      public static Expression makeWhile(Object cond, Object body, Compilation parser)
      Helper method to create a `while' statement.
    • setLocation

      public final void setLocation(SourceLocator location)
      Copies the current location.
    • setLine

      public final Expression setLine(Expression old)
    • maybeSetLine

      public final Expression maybeSetLine(Expression old)
    • setFile

      public final void setFile(String filename)
    • setLine

      public final void setLine(int startLine, int startColumn, int endLine, int endColumn)
    • setLine

      public final void setLine(int lineno, int colno)
    • setLine

      public final void setLine(int lineno)
    • getFileName

      public final String getFileName()
      Description copied from interface: SourceLocator
      Normally same as getSystemId.
      Specified by:
      getFileName in interface SourceLocator
    • setLine

      public void setLine(Compilation comp)
      Set line number from current position in Compilation.
    • getPublicId

      public String getPublicId()
      Specified by:
      getPublicId in interface Locator
      Specified by:
      getPublicId in interface SourceLocator
      Specified by:
      getPublicId in interface SourceLocator
    • getSystemId

      public String getSystemId()
      Specified by:
      getSystemId in interface Locator
      Specified by:
      getSystemId in interface SourceLocator
      Specified by:
      getSystemId in interface SourceLocator
    • getLineNumber

      public final int getLineNumber()
      Description copied from interface: SourceLocator
      Return current line number. Normally the same as getStartLine(). The "first" line is line 1; unknown is -1.
      Specified by:
      getLineNumber in interface Locator
      Specified by:
      getLineNumber in interface SourceLocator
      Specified by:
      getLineNumber in interface SourceLocator
    • getColumnNumber

      public final int getColumnNumber()
      Description copied from interface: SourceLocator
      Return current column number. Normally the same as getStartColumn(). The "first" column is column 1; unknown is -1.
      Specified by:
      getColumnNumber in interface Locator
      Specified by:
      getColumnNumber in interface SourceLocator
      Specified by:
      getColumnNumber in interface SourceLocator
    • getStartLine

      public final int getStartLine()
      Description copied from interface: SourceLocator
      Line number (one-origin) of start of range; unknown/unspecified is -1.
      Specified by:
      getStartLine in interface SourceLocator
    • getStartColumn

      public final int getStartColumn()
      Description copied from interface: SourceLocator
      Column (one-origin) of start of range; unknown/unspecified is -1.
      Specified by:
      getStartColumn in interface SourceLocator
    • getEndLine

      public final int getEndLine()
      Description copied from interface: SourceLocator
      Line number (one-origin) of end of range; unknown/unspecified is -1.
      Specified by:
      getEndLine in interface SourceLocator
    • getEndColumn

      public final int getEndColumn()
      Description copied from interface: SourceLocator
      Column (one-origin) of end of range; unknown/unspecified is -1.
      Specified by:
      getEndColumn in interface SourceLocator
    • isStableSourceLocation

      public boolean isStableSourceLocation()
      Description copied from interface: SourceLocator
      True if position is unlikely to change. True for an expression but not an input file.
      Specified by:
      isStableSourceLocation in interface SourceLocator
    • getType

      public final Type getType()
      Return the Type used to represent the values of this Expression.
    • calculateType

      protected Type calculateType()
    • getTypeRaw

      public final Type getTypeRaw()
    • setType

      public void setType(Type type)
    • neverReturns

      public boolean neverReturns()
      True if the expression provably never returns. Currently, this is very limited, not handling infinite recursion (tail- or otherwise), but better analysis is planned.
    • checkLiteralKeyword

      public Keyword checkLiteralKeyword()
      Is this a keyword argument? In the future this will return non-null only for explicit literal non-quoted Keywords.
    • isSingleValue

      public boolean isSingleValue()
    • valueIfConstant

      public Object valueIfConstant()
      Return value if it is constant, or null if non-constant or unknown.
    • setFlag

      public void setFlag(boolean setting, int flag)
    • setFlag

      public void setFlag(int flag)
    • getFlags

      public int getFlags()
    • getFlag

      public boolean getFlag(int flag)
    • side_effects

      public boolean side_effects()
      True if evaluating may have side-effects.
    • toString

      public String toString()
      Overrides:
      toString in class Procedure