Skip to content

Repository files navigation

sw-cor24-snobol4

A SNOBOL4-inspired language implementation written in PL/SW, targeting the COR24 24-bit emulator first, with a later retargeting path to a 24-bit S/370-ish operating system.

Introduction

SNOBOL4 is a string-oriented language from the 1960s famous for its pattern matching, dynamic typing, and unusual statement-level control flow (success / failure gotos). This project reimagines a practical subset of SNOBOL4 as a bytecode interpreter implemented entirely in PL/SW — a small systems language that compiles for the COR24 architecture.

The goal is twofold:

  1. Exercise PL/SW as a serious implementation language by building a non-trivial dynamic-language runtime on top of it.
  2. Bring a usable SNOBOL4 to the COR24 emulator (and eventually a 24-bit S/370-ish host), including strings, patterns, variables, control flow, user-defined functions, and a growing set of builtins.

Summary

The implementation is structured as a classic layered interpreter:

  • Lexer / parser — reads SNOBOL4 source, including * comments and continuation lines, producing an internal representation.
  • Compiler — lowers statements to a compact bytecode with opcodes for arithmetic, string ops, assignment, branching, pattern matching, and builtin dispatch (e.g. OP_MOD for REMDR).
  • VM — a stack/register-style interpreter that executes the bytecode, manages the value heap, and handles SNOBOL4's success/failure control flow (:(label), :S(label), :F(label)).
  • Runtime / builtins — string, numeric, and I/O primitives (SIZE, REMDR, DUPL, pattern constructors, etc.).
  • Host layer — COR24 I/O, memory, and program loading via PL/SW.

See examples/ for runnable SNOBOL4 programs, including fizzbuzz.sno, factorial.sno, pattern.sno, and dating.sno.

Documentation

Detailed design and process docs live under docs/:

Building and running

The project uses just as its task runner. See justfile for available recipes, and docs/running-plsw-compiler.md for details on invoking the PL/SW compiler and running programs on the COR24 emulator.

Toolchain (devgroup-shared)

The build relies on the shared COR24 toolchain installed on $PATH for every d* user — no sibling clones, no $HOME/... paths:

Binary Use
pl-sw PL/SW compiler (cor24-emu --lgo plsw.lgo)
cor24-asm Assembler: .s.lgo / .bin / .lst
cor24-emu Runtime emulator
link24 Module linker (combines per-module .bins)
meta-gen EXPORT/FIXUP metadata generator for link24

The PL/SW compiler image is shipped at /disk1/github/softwarewrighter/devgroup/work/lib/cor24/plsw.lgo; you do not need to rebuild it.

Recipes

  • just build — modular build → build/snobol4.bin (loadable via cor24-emu --load-binary build/snobol4.bin@0 --entry 0).
  • just rebuild — same, ignoring the dep manifest.
  • just build-lgo — produces the canonical shippable build/snobol4.lgo by wrapping the linked .bin as L-record text. Mike installs this to work/lib/cor24/snobol4.lgo for downstream consumers (e.g. dcftn's Fortran compiler).
  • just hello, just count, just span, etc. — run individual demos.
  • just demos — run the full demo suite.

Known cor24-emu limitation

cor24-emu --lgo <file> currently ignores any --load-binary arguments on the same command line (the lgo dispatch arm doesn't call load_binaries_and_patches). Because the SNOBOL4 interpreter expects its program source loaded at memory 0x080000, the snobol4.lgo artifact cannot yet be invoked via the planned exec cor24-emu --lgo snobol4.lgo "$@" wrapper. Until cor24-emu is fixed (see brief tools/briefs/dcemu-lgo-load-binary-merge.md), the working invocation is:

cor24-emu --load-binary build/snobol4.bin@0 \
          --load-binary <prog>.sno@0x080000 \
          --entry 0

(This is what scripts/run-snobol4.sh already does.)

Copyright

Copyright (c) 2026 Michael A Wright

(See COPYRIGHT.)

License

Released under the MIT License. See LICENSE for the full text.

About

Using PL/SW as SIL to implement SNOBOL4 on COR24 ISA

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages