Package sanskrit

Class Interp

java.lang.Object
sanskrit.Interp

public final class Interp extends Object
The interpreter: runs compiled code on a stack machine. One instance holds the global variables, the output sink and the limits of one program.
  • Constructor Details

  • Method Details

    • addModule

      public void addModule(PyModule m)
      Makes a module importable (import name). Done by the host, before running anything.
    • getModule

      public PyModule getModule(String name)
      A builtin module (math, json, or one added by addModule(sanskrit.PyModule)), or null.
    • setGlobal

      public void setGlobal(String name, Object value)
      Defines a global variable: a module, or a member of a module such as PyModule.get(java.lang.String).
    • setClock

      public void setClock(Interp.Clock clock)
      Replaces the clock (the system clock by default), e.g. by a fixed one for deterministic tests.
    • setMaxSteps

      public void setMaxSteps(long n)
    • setMaxDepth

      public void setMaxDepth(int n)
    • getSteps

      public long getSteps()
      Number of steps (backward jumps and calls) executed so far.
    • compile

      public static Code compile(String source, String filename)
      Compiles a program.
    • run

      public void run(String source, String filename)
      Compiles and runs a program in this interpreter's global scope.
    • run

      public void run(Code code)
    • getGlobalAsString

      public String getGlobalAsString(String name)
      The value of a global variable converted for display, or null if it is not defined.
    • callFunction

      public Object callFunction(Object fn, Object[] args, Map<String,Object> kwargs)
      Calls a Python callable from the host, with positional arguments and keyword arguments (Python values; kwargs may be null). A Python exception is thrown as a PyError; the call counts against the limits.
    • isCallable

      public static boolean isCallable(Object v)
      True for what Python's callable() accepts.
    • functionName

      public static String functionName(Object v)
      The __name__ of a function, a builtin function or a method; null for anything else.
    • isNone

      public static boolean isNone(Object v)
      True for the Python value None.
    • str

      public static String str(Object v)
      str(v), for the host.