public class Interpreter extends Object
A simple interpreter for WyIL bytecodes. The purpose of this interpreter is to provide a reference implementation for the semantics of WyIL bytecodes.
The interpreter is not intended to be time or space efficient. It also assume the underlying WyIL bytecodes are well formed and does not attempt to check them. Thus, malformed bytecodes can reuslt in the interpreter executing in an unpredictable fashion.
| Modifier and Type | Class and Description |
|---|---|
static class |
Interpreter.ConstantLambda
Represents an object allocated on the heap.
|
static class |
Interpreter.ConstantObject
Represents an object allocated on the heap.
|
static interface |
Interpreter.InternalFunction
An internal function is simply a named internal function.
|
| Constructor and Description |
|---|
Interpreter(wybs.lang.Build.Project project,
PrintStream debug) |
| Modifier and Type | Method and Description |
|---|---|
void |
checkInvariants(Constant[] frame,
List<SyntaxTree.Location<Bytecode.Expr>> invariants)
Evaluate zero or more conditional expressions, and check whether any is
false.
|
void |
checkInvariants(Constant[] frame,
SyntaxTree.Location<Bytecode.Expr>... invariants)
Evaluate zero or more conditional expressions, and check whether any is
false.
|
static <T extends Constant> |
checkType(Constant operand,
wybs.lang.SyntacticElement context,
Class<T>... types)
Check that a given operand value matches an expected type.
|
static Object |
error(String msg,
wybs.lang.SyntacticElement context)
This method is provided as a generic mechanism for reporting runtime
errors within the interpreter.
|
Constant[] |
execute(wybs.lang.NameID nid,
Type.FunctionOrMethod sig,
Constant... args)
Execute a function or method identified by a name and type signature with
the given arguments, producing a return value or null (if none).
|
TypeSystem |
getTypeSystem() |
SyntaxTree.Location<Bytecode.VariableDeclaration> |
getVariableDeclaration(SyntaxTree.Location<?> decl) |
boolean |
isMemberOfType(Constant value,
Type type,
wybs.lang.SyntacticElement context)
Determine whether a given value is a member of a given type.
|
public Interpreter(wybs.lang.Build.Project project,
PrintStream debug)
public TypeSystem getTypeSystem()
public Constant[] execute(wybs.lang.NameID nid, Type.FunctionOrMethod sig, Constant... args)
nid - The fully qualified identifier of the function or methodsig - The exact type signature identifying the method.args - The supplied argumentspublic boolean isMemberOfType(Constant value, Type type, wybs.lang.SyntacticElement context) throws wybs.util.ResolveError
value - type - context - --- Context in which bytecodes are executedwybs.util.ResolveError - If a named type within the given type cannot be resolved
within the enclosing project.public void checkInvariants(Constant[] frame, List<SyntaxTree.Location<Bytecode.Expr>> invariants)
frame - context - invariants - public void checkInvariants(Constant[] frame, SyntaxTree.Location<Bytecode.Expr>... invariants)
frame - context - invariants - @SafeVarargs public static <T extends Constant> T checkType(Constant operand, wybs.lang.SyntacticElement context, Class<T>... types)
operand - --- bytecode operand to be checkedcontext - --- Context in which bytecodes are executedtypes - --- Types to be checked againstpublic static Object error(String msg, wybs.lang.SyntacticElement context)
msg - --- Message to be printed when error arises.context - --- Context in which bytecodes are executedpublic SyntaxTree.Location<Bytecode.VariableDeclaration> getVariableDeclaration(SyntaxTree.Location<?> decl)
Copyright © 2017. All rights reserved.