Inside the Jennifer interpreter

Jennifer

From source text to a running program: the pipeline, the runtime, and why the rules are what they are.

November 2026, by @mplx.
Based on Jennifer 0.26.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 20

Six stages, one binary

file.j
  reqcheck     # pragma-jennifer-* header    internal/reqcheck
  lexer        []Token, trivia kept          internal/lexer
  preproc      include spliced in            internal/preproc
  parser       *Program, the AST             internal/parser
  resolver     (Depth, Slot), name errors    internal/parser
  interpreter  tree-walking evaluator        internal/interpreter
  libraries    io, json, net, ...            internal/lib/<name>

cmd/jennifer/main.go runs the stages; jennifer tokens and jennifer ast stop after the lexer and after the resolver.

2 / 20

Before the lexer: the requirement header

# pragma-jennifer-version: >=0.25.0 <0.26.0
jennifer: upper.j: requires jennifer >=0.25.0 <0.26.0,
  but this build is 0.26.0-dev+1.6bf51fa3

# pragma-jennifer-verison: >=0.25.0
jennifer: typo.j:1: unknown pragma key "verison"
if isDevVersion(Version) {   // internal/version/version.go, AtLeast
    return true, nil
}
3 / 20

The lexer: jennifer tokens

def x as int init 41;
def y as int init $x + 1;
2:1   DEF
2:5   IDENT     "y"
2:7   AS
2:10  INT_TYPE
2:14  INIT
2:19  VARREF    "x"
2:22  PLUS
2:24  INT       "1"
4 / 20

Reserved words are one table in the lexer

var keywords = map[string]TokenType{   // internal/lexer/token.go
    "def":      TOKEN_DEFINE,
    // ... 48 entries in all, including
    "list":     TOKEN_LIST,
    "of":       TOKEN_OF,
    "to":       TOKEN_TO,
1:24  TO
kw.j: parse error at kw.j:1:24: expected IDENT for parameter name,
  got TO ("to") - `to` is a reserved word and cannot be used as a name
5 / 20

The parser: jennifer ast

$ jennifer ast tok.j | grep '"type"'
  "type": "Program",
      "type": "DefineStmt",
        "type": "IntLit",
      "type": "DefineStmt",
        "type": "BinaryExpr",
          "type": "VarExpr",
          "type": "IntLit",

A recursive-descent parser in internal/parser/parser.go; the JSON emitter is hand-written in cmd/jennifer/astjson.go.

6 / 20

The resolver: errors before anything runs

$ jennifer ast undef.j
undef.j: parse error at undef.j:2:19: undefined variable "count"
  io.printf("%d\n", $count);
                    ^
type VarExpr struct {   // internal/parser/ast.go
    pos
    Name  string // without the leading $
    Depth int
    Slot  int
    Move  bool
7 / 20

Resolver and runtime must agree

case *TryStmt:   // internal/parser/resolver.go
    // The try body is its own block scope (its own runtime frame at
    // execTry). Its `def`s do not leak into the enclosing frame ...
    bodyFrame := &scopeFrame{slots: map[string]slotInfo{}}
    r.push(bodyFrame)
bodyEnv := borrowBlockEnv(env, st.Body.NumSlots)   // execTry

Spawn bodies are not resolved at all: they run against a snapshot.

8 / 20

One struct for every value

type Value struct {   // internal/interpreter/value.go
    Kind     ValueKind
    Bool     bool
    // ... unexported caches
    Int      int64
    Float    float64
    Str      string
    List     []Value
    Map      []MapEntry
    Bytes    []byte
    Fields   []StructField
    ElemTyp  *parser.Type
9 / 20

Types travel with the value

def nums as list of int init [];
def words as list of string init [];
$words = $nums;      # in a try
$nums[] = "two";     # in a try
cannot assign list to list of string variable "words"
cannot append string to list of declared element type int

stampDeclaredType writes ElemTyp, KeyTyp and ValTyp at every binding.

10 / 20

Value semantics: a copy at every store

use io;

func addOne(xs as list of int) {
    $xs[] = 1;
    return $xs;
}

def a as list of int init [7];
def b as list of int init addOne($a);
io.printf("%v %v\n", $a, $b);
[7] [7, 1]
11 / 20

The copies the interpreter leaves out

if c.MoveArg == idx+1 {   // internal/interpreter/interpreter.go
    // The caller's binding is dead after this call ...
    bound = stampDeclaredType(v, p.Type)
} else {
    argBorrow := borrowCtx && (c.ArgSnap == nil || !c.ArgSnap[idx])
    bound = i.bindArg(v, p, argBorrow)
}
12 / 20

Measuring it: profile --allocs and L205

$a = addOne($a);     # grow.j:9, moved: no copy
$b = addOne($a);     # grow.j:17, argument copied
$a = $b;             # grow.j:18, assignment copied
  COUNT     BYTES   TYPE         POSITION
   1000  129.8 MiB  list of int  grow.j:18:9
   1000  129.6 MiB  list of int  grow.j:17:21

jennifer lint flags addOne as L205, a copy-in / copy-out accumulator.

13 / 20

Why there are no closures

// releaseBlockEnv returns a previously-borrowed Environment to the
// pool. Only safe to call when no code retains a pointer to `e` - the
// interpreter's block frames satisfy this because Jennifer has no
// closure form that could capture the env.
14 / 20

Why strings take slices, not positions

func indexInto(parent *Value, idx Value,
    st positioned) (*Value, error)   // interpreter.go
s := coll.Str               // evalSlice, KindString
if len(s) == n {
    // Pure ASCII (byte length equals rune count): rune offsets
    // are byte offsets, so slice the backing directly. ...
    return StringVal(s[lo:hi]), nil
}
// Non-ASCII: find the byte offsets of rune lo and rune hi by
// decoding forward, rather than materialising the whole string
15 / 20

Two builds from one source

use io;
use meta;
io.printf("%s %s %v\n", meta.VERSION, meta.BUILD, meta.CAPABILITIES);
$ jennifer run build.j
0.26.0-dev+1.6bf51fa3 go ["exec", "net", "sql"]
$ jennifer-tiny run build.j
0.26.0-dev+1.6bf51fa3 tinygo []

Dev builds 23.3 MB and 10.4 MB; release builds stripped, 16.0 MB and 4.5 MB.

16 / 20

What jennifer-tiny cannot do

runtime | net.connect: `jennifer-tiny` (TinyGo build) does not include
  a network stack; use the default `jennifer` binary for network I/O
jennifer: cap.j: needs capability "net", unavailable in this build
  (jennifer-tiny)
limit | call stack too deep: exceeded the depth limit of 120 nested
  calls, blocks, and expressions (possible infinite recursion)

Stubbed: os.run, net, httpd, term, sql, serial, spi, i2c, gpio, RSA and ECDSA in crypto, and the dev commands tokens to test.

17 / 20

Reading the source

PathWhat lives there
cmd/jennifer/the CLI, tokens / ast, fmt, lint, profile, test
internal/lexer/, preproc/, reqcheck/the front of the pipeline
internal/parser/parser, resolver, folding, ownership analysis
internal/interpreter/values, environments, evaluator, modules
internal/lib/<name>/one Go package per library
internal/libsig/the signature table lint and the checker use
modules/the bundled .j modules
18 / 20

Making a first fix

go test ./internal/parser -run TestName -count=1
go test ./...      # CI also runs go vet ./... and gofmt -l .
make build         # both binaries; then run your case on each
19 / 20

Read more

Based on Jennifer 0.26.0, November 2026.

20 / 20