ModuLisp/src/signal_engine/symbols.def

312 lines
18 KiB
Modula-2
Raw Normal View History

// symbols.def — X-macro symbol table for the signal engine graph builder.
// Each line: SYM(field_name, "lisp-string", category)
//
// Categories:
// none — bare symbol, no special dispatch
// arith — variadic arithmetic operator
// cmp — comparison operator
// logic — logic operator
// unary — unary math function
// binary — binary math function
// ternary — ternary math function
// time_warp — time transform
// control — control flow
// signal — domain signal function with custom compilation
// side_effect — side-effect forms (error in signal context)
// waveform — unary phase-to-value waveform functions
//
// Namespace metadata is declared with OP_META after the symbol inventory.
// Each row: OP_META(field, input-domain, output-range, regime,
// cold-evaluable, bare-identity)
// The compiler and reference-data generator derive namespace applicability
// from these declarations; neither owns a hand-curated applicability list.
// ── Temporal / time symbols ────────────────────────────────────────────────
SYM(t, "t", none)
SYM(beat, "beat", none)
SYM(bar, "bar", none)
SYM(phrase, "phrase", none)
SYM(section, "section", none)
SYM(beat_num, "beat-num", none)
SYM(bar_num, "bar-num", none)
// ── Timing parameters ──────────────────────────────────────────────────────
SYM(bpm, "bpm", none)
SYM(beats_per_bar, "beats-per-bar", none)
SYM(bars_per_phrase, "bars-per-phrase", none)
SYM(phrases_per_section, "phrases-per-section", none)
// ── Arithmetic operators ───────────────────────────────────────────────────
SYM(plus, "+", arith)
SYM(minus, "-", arith)
SYM(star, "*", arith)
SYM(slash, "/", arith)
SYM(mod_pct, "%", arith)
// ── Comparison operators ───────────────────────────────────────────────────
SYM(gt, ">", cmp)
SYM(lt, "<", cmp)
SYM(ge, ">=", cmp)
SYM(le, "<=", cmp)
SYM(eq, "=", cmp)
// ── Logic operators ────────────────────────────────────────────────────────
SYM(not_, "not", logic)
SYM(and_, "and", logic)
SYM(or_, "or", logic)
// ── Time transforms ────────────────────────────────────────────────────────
SYM(time_as, "time-as", time_warp)
SYM(fast, "fast", time_warp)
SYM(slow, "slow", time_warp)
SYM(offset, "offset", time_warp)
SYM(shift, "shift", time_warp)
// ── Control flow ───────────────────────────────────────────────────────────
SYM(if_, "if", control)
SYM(let_, "let", control)
SYM(do_, "do", control)
SYM(for_, "for", control)
SYM(while_, "while", control)
SYM(fn, "fn", control)
SYM(lambda, "lambda", control)
SYM(scope, "scope", control)
// ── Unary math functions ───────────────────────────────────────────────────
SYM(sin_, "sin", unary)
SYM(cos_, "cos", unary)
SYM(tan_, "tan", unary)
SYM(abs_, "abs", unary)
SYM(floor_, "floor", unary)
SYM(ceil_, "ceil", unary)
SYM(sqrt_, "sqrt", unary)
SYM(neg, "neg", unary)
SYM(frac_, "frac", unary)
SYM(bsin, "bsin", unary)
SYM(bcos, "bcos", unary)
SYM(bi_to_uni, "bi-to-uni", unary)
SYM(b_to_u, "b>u", unary)
SYM(uni_to_bi, "uni-to-bi", unary)
SYM(u_to_b, "u>b", unary)
// ── Binary math functions ──────────────────────────────────────────────────
SYM(min_, "min", arith)
SYM(max_, "max", arith)
SYM(pow_, "pow", binary)
SYM(expt, "expt", binary)
SYM(mod_, "mod", binary)
SYM(pulse, "pulse", binary)
// ── Ternary math functions ─────────────────────────────────────────────────
SYM(clamp, "clamp", ternary)
SYM(lerp, "lerp", ternary)
SYM(scale, "scale", ternary)
// ── Unary phase-to-value waveform functions ────────────────────────────────
SYM(tri, "tri", waveform)
SYM(sqr, "sqr", waveform)
SYM(saw, "saw", waveform)
// ── Domain signal functions ────────────────────────────────────────────────
SYM(step, "step", signal)
SYM(gates, "gates", signal)
SYM(trigs, "trigs", signal)
SYM(euclid, "euclid", signal)
SYM(eu, "eu", signal)
SYM(seq, "seq", signal)
SYM(from_list, "from-list", signal)
SYM(interp, "interp", signal)
SYM(flatseq, "flatseq", signal)
SYM(dm, "dm", signal)
SYM(range, "range", signal)
SYM(gatesw, "gatesw", signal)
SYM(random_, "random", signal)
SYM(index_rand, "index-rand", signal)
SYM(loop_at, "loop-at", signal)
SYM(eval_at_time, "eval-at-time", signal)
SYM(rpulse, "rpulse", signal)
SYM(rstep, "rstep", signal)
SYM(ridx, "ridx", signal)
SYM(rwarp, "rwarp", signal)
// ── State forms ────────────────────────────────────────────────────────────
SYM(defstate, "defstate", side_effect)
SYM(integrate, "integrate", signal)
SYM(dt, "dt", none)
// ── UGen forms (state-bearing unit generators) ─────────────────────────────
// Primary names
SYM(phasor_, "phasor", signal)
SYM(lfo, "lfo", signal)
SYM(blfo, "blfo", signal)
SYM(slew, "slew", signal)
SYM(one_pole, "one-pole", signal)
SYM(env_follow, "env-follow", signal)
SYM(sah, "sah", signal)
SYM(noise, "noise", signal)
SYM(toggle, "toggle", signal)
SYM(count, "count", signal)
// Compatibility aliases unrelated to the v1.2 namespace cut.
SYM(envelope_follower, "envelope-follower", signal)
SYM(latch, "latch", signal)
// UGen keyword symbols
SYM(kw_wave, ":wave", none)
SYM(kw_phase, ":phase", none)
SYM(kw_pw, ":pw", none)
SYM(kw_id, ":id", none)
SYM(kw_fresh, ":fresh", none)
SYM(kw_offset, ":offset", none)
SYM(kw_attack, ":attack", none)
SYM(kw_release, ":release", none)
SYM(kw_reset, ":reset", none)
SYM(kw_sin, ":sin", none)
SYM(kw_cos, ":cos", none)
SYM(kw_tri, ":tri", none)
SYM(kw_saw_kw, ":saw", none)
SYM(kw_sqr, ":sqr", none)
// ── Side-effect forms (error in signal context) ────────────────────────────
SYM(define, "define", side_effect)
SYM(def, "def", side_effect)
SYM(defn, "defn", side_effect)
SYM(defun, "defun", side_effect)
SYM(defs, "defs", side_effect)
SYM(set, "set", side_effect)
SYM(unassign, "unassign", side_effect)
SYM(zeros_, "zeros", side_effect)
SYM(get_expr, "get-expr", side_effect)
SYM(set_bpm, "set-bpm", side_effect)
SYM(set_time_sig, "set-time-sig", side_effect)
SYM(useq_clear, "useq-clear", side_effect)
SYM(set_time_offset, "useq-set-time-offset", side_effect)
SYM(nudge_time, "useq-nudge-time", side_effect)
SYM(useq_play, "useq-play", side_effect)
SYM(useq_pause, "useq-pause", side_effect)
SYM(useq_stop, "useq-stop", side_effect)
SYM(useq_rewind, "useq-rewind", side_effect)
SYM(set_clock_ext, "set-clock-ext", side_effect)
SYM(set_clock_int, "set-clock-int", side_effect)
SYM(get_clock_source, "get-clock-source", side_effect)
SYM(reset_clock_ext, "reset-clock-ext", side_effect)
SYM(reset_clock_int, "reset-clock-int", side_effect)
// ── Derived timing ─────────────────────────────────────────────────────────
SYM(beat_dur, "beat-dur", none)
SYM(bar_dur, "bar-dur", none)
// ── Output feedback ────────────────────────────────────────────────────────
SYM(prev, "prev", none)
// ── Live-edit ──────────────────────────────────────────────────────────────
SYM(live_edit, "live-edit", signal)
// ── Misc ───────────────────────────────────────────────────────────────────
SYM(input, "input", none)
SYM(quote, "quote", none)
#if USEQ_HAS_SYNTH_ENGINE
// ── Synth form (top-level only, synth-nodes.md) ────────────────────────────
// `synth` is a top-level declaration form, not a signal-context operator.
// Inside a signal expression it is a Boundary-category error
// (VAL-COMP-007). Keywords :freq / :amp / :name / :version / :id parameterise
// the declaration; :id is the hidden-identity injection point supplied by
// the editor payload builder.
SYM(synth, "synth", side_effect)
SYM(kw_freq, ":freq", none)
SYM(kw_amp, ":amp", none)
SYM(kw_name, ":name", none)
SYM(kw_version, ":version", none)
#endif
// Live-edit-only metadata. These are explicit inventory entries even though
// the generic symbol interner would otherwise create them on demand.
SYM(kw_min, ":min", none)
SYM(kw_max, ":max", none)
SYM(kw_options, ":options", none)
SYM(kw_step, ":step", none)
SYM(kw_precision, ":precision", none)
// ── Operator namespace metadata ───────────────────────────────────────────
// Tokens map directly to the enum members in graph_builder.h and to the
// generator's string vocabulary. Undeclared axes are `None`; `Native` means
// the bare spelling keeps the engine-native lowering.
#ifndef OP_META
#define OP_META(field, domain, range, regime, cold, identity)
#define USEQ_SYMBOLS_DEF_UNDEF_OP_META
#endif
OP_META(plus, None, None, Pure, Yes, Native)
OP_META(minus, None, None, Pure, Yes, Native)
OP_META(star, None, None, Pure, Yes, Native)
OP_META(slash, None, None, Pure, Yes, Native)
OP_META(mod_pct, None, None, Pure, Yes, Native)
OP_META(min_, None, None, Pure, Yes, Native)
OP_META(max_, None, None, Pure, Yes, Native)
OP_META(gt, None, Unipolar, Pure, Yes, Native)
OP_META(lt, None, Unipolar, Pure, Yes, Native)
OP_META(ge, None, Unipolar, Pure, Yes, Native)
OP_META(le, None, Unipolar, Pure, Yes, Native)
OP_META(eq, None, Unipolar, Pure, Yes, Native)
OP_META(not_, None, Unipolar, Pure, Yes, Native)
OP_META(and_, None, Unipolar, Pure, Yes, Native)
OP_META(or_, None, Unipolar, Pure, Yes, Native)
OP_META(sin_, Phase, Bipolar, PureShaper, Yes, NormalizedUnipolar)
OP_META(cos_, Phase, Bipolar, PureShaper, Yes, NormalizedUnipolar)
OP_META(bsin, Phase, Bipolar, PureShaper, Yes, NormalizedBipolar)
OP_META(bcos, Phase, Bipolar, PureShaper, Yes, NormalizedBipolar)
OP_META(tan_, Angle, None, Pure, Yes, Native)
OP_META(abs_, Scalar, None, Pure, Yes, Native)
OP_META(floor_, Scalar, None, Pure, Yes, Native)
OP_META(ceil_, Scalar, None, Pure, Yes, Native)
OP_META(sqrt_, Scalar, None, Pure, Yes, Native)
OP_META(neg, Scalar, None, Pure, Yes, Native)
OP_META(frac_, Scalar, Unipolar, Pure, Yes, Native)
OP_META(bi_to_uni, Scalar, Unipolar, Pure, Yes, Native)
OP_META(b_to_u, Scalar, Unipolar, Pure, Yes, Native)
OP_META(uni_to_bi, Scalar, Bipolar, Pure, Yes, Native)
OP_META(u_to_b, Scalar, Bipolar, Pure, Yes, Native)
OP_META(pow_, Scalar, None, Pure, Yes, Native)
OP_META(expt, Scalar, None, Pure, Yes, Native)
OP_META(mod_, Scalar, None, Pure, Yes, Native)
OP_META(pulse, Phase, Unipolar, PureShaper, Yes, UnipolarShaper)
OP_META(clamp, Scalar, None, Pure, Yes, Native)
OP_META(lerp, Scalar, None, Pure, Yes, Native)
OP_META(scale, Scalar, None, Pure, Yes, Native)
OP_META(tri, Phase, Unipolar, PureShaper, Yes, UnipolarShaper)
OP_META(sqr, Phase, Unipolar, PureShaper, Yes, UnipolarShaper)
OP_META(saw, Phase, Unipolar, PureShaper, Yes, UnipolarShaper)
OP_META(random_, None, Unipolar, Pure, Yes, Native)
OP_META(index_rand, Scalar, Unipolar, Pure, Yes, Native)
OP_META(phasor_, Scalar, Unipolar, Stateful, No, Native)
OP_META(lfo, Scalar, Unipolar, Stateful, No, LfoUnipolar)
OP_META(blfo, Scalar, Bipolar, Stateful, No, LfoBipolar)
OP_META(slew, Scalar, None, Stateful, No, Native)
OP_META(one_pole, Scalar, None, Stateful, No, Native)
OP_META(env_follow, Scalar, Unipolar, Stateful, No, Native)
OP_META(sah, Scalar, None, Stateful, No, Native)
OP_META(noise, None, Bipolar, Stateful, No, Native)
OP_META(toggle, Scalar, Unipolar, Stateful, No, Native)
OP_META(count, Scalar, None, Stateful, No, Native)
#ifdef USEQ_SYMBOLS_DEF_UNDEF_OP_META
#undef OP_META
#undef USEQ_SYMBOLS_DEF_UNDEF_OP_META
#endif
#if USEQ_HAS_SYNTH_ENGINE
// ── State-identity wrapper (state-identity.md §6.3) ────────────────────────
// `(with-state-id "<id>" <form>)` is the hidden identity wrapper the editor
// payload builder injects around anonymous stateful forms. The runtime
// treats it as a transparent passthrough: the wrapper evaluates its second
// argument (the wrapped form) and ignores the identity string, which has
// already been used by the editor to assign stable identity. Without this
// passthrough every anonymous synth form would compile as "Unknown name".
SYM(with_state_id, "with-state-id", control)
#endif