Class Interpreter

java.lang.Object
org.stringtemplate.v4.Interpreter

public class Interpreter extends Object
This class knows how to execute template bytecodes relative to a particular STGroup. To execute the byte codes, we need an output stream and a reference to an ST instance. That instance's ST.impl field points at a CompiledST, which contains all of the byte codes and other information relevant to execution.

This interpreter is a stack-based bytecode interpreter. All operands go onto an operand stack.

If debug set, we track interpreter events. For now, I am only tracking instance creation events. These are used by STViz to pair up output chunks with the template expressions that generate them.

We create a new interpreter for each invocation of ST.render(), ST.inspect(), or ST.getEvents().

  • Field Details

    • DEFAULT_OPERAND_STACK_SIZE

      public static final int DEFAULT_OPERAND_STACK_SIZE
      See Also:
    • predefinedAnonSubtemplateAttributes

      public static final Set<String> predefinedAnonSubtemplateAttributes
    • operands

      Object[] operands
      Operand stack, grows upwards.
    • sp

      int sp
      Stack pointer register.
    • nwline

      int nwline
      The number of characters written on this template line so far.
    • group

      STGroup group
      Render template with respect to this group.
      See Also:
    • locale

      Locale locale
      For renderers, we have to pass in the locale.
    • errMgr

      ErrorManager errMgr
    • trace

      public static boolean trace
      Dump bytecode instructions as they are executed. This field is mostly for StringTemplate development.
    • executeTrace

      protected List<String> executeTrace
      If trace is true, track trace here.
    • debug

      public boolean debug
      When true, track events inside templates and in events.
    • events

      protected List<InterpEvent> events
      Track everything happening in interpreter across all templates if debug. The last event in this field is the EvalTemplateEvent for the root template.
  • Constructor Details

    • Interpreter

      public Interpreter(STGroup group, boolean debug)
    • Interpreter

      public Interpreter(STGroup group, Locale locale, boolean debug)
    • Interpreter

      public Interpreter(STGroup group, ErrorManager errMgr, boolean debug)
    • Interpreter

      public Interpreter(STGroup group, Locale locale, ErrorManager errMgr, boolean debug)
  • Method Details