This commit is contained in:
2026-01-25 20:43:12 +01:00
parent b1a982aaa0
commit ac83ceb2cb
6 changed files with 176 additions and 23 deletions

View File

@@ -1,4 +1,5 @@
use super::ops::Op;
use super::theory;
use super::types::{Dictionary, SourceSpan};
pub enum WordCompile {
@@ -281,16 +282,9 @@ pub const WORDS: &[Word] = &[
// Randomness
Word {
name: "rand",
stack: "(min max -- f)",
desc: "Random float in range",
example: "0 1 rand => 0.42",
compile: Simple,
},
Word {
name: "rrand",
stack: "(min max -- n)",
desc: "Random int in range",
example: "1 6 rrand => 4",
stack: "(min max -- n|f)",
desc: "Random in range. Int if both args are int, float otherwise",
example: "1 6 rand => 4 | 0.0 1.0 rand => 0.42",
compile: Simple,
},
Word {
@@ -1537,7 +1531,6 @@ pub(super) fn simple_op(name: &str) -> Option<Op> {
"sound" => Op::NewCmd,
"emit" => Op::Emit,
"rand" => Op::Rand,
"rrand" => Op::Rrand,
"seed" => Op::Seed,
"cycle" => Op::Cycle,
"pcycle" => Op::PCycle,
@@ -1573,6 +1566,7 @@ pub(super) fn simple_op(name: &str) -> Option<Op> {
"noise" => Op::Noise,
"chain" => Op::Chain,
"loop" => Op::Loop,
"oct" => Op::Oct,
_ => return None,
})
}
@@ -1633,7 +1627,7 @@ fn parse_interval(name: &str) -> Option<i64> {
"M6" => 9,
"m7" => 10,
"M7" => 11,
"P8" | "oct" => 12,
"P8" => 12,
// Compound intervals (octave + simple)
"m9" => 13,
"M9" => 14,
@@ -1660,6 +1654,11 @@ pub(super) fn compile_word(name: &str, span: Option<SourceSpan>, ops: &mut Vec<O
_ => {}
}
if let Some(pattern) = theory::lookup(name) {
ops.push(Op::Degree(pattern));
return true;
}
for word in WORDS {
if word.name == name {
match &word.compile {