Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ opentelemetry_sdk = {version = "0.32", features = ["rt-tokio"]}
opfs = "0.2.0"
percent-encoding = "2.3.2"
proptest = "1.11"
rand = "0.9.4"
rand = "0.10.1"
rayon = "1.11.0"
regex-lite = "0.1.9"
reqwest = {version = "0.13"}
Expand Down
2 changes: 1 addition & 1 deletion crates/mq-lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uuid = {workspace = true, features = ["v4", "v7"]}
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["console"] }
uuid = {workspace = true, features = ["js"]}
getrandom = { version = "0.3", features = ["wasm_js"] }
getrandom = { version = "0.4", features = ["wasm_js"] }

[features]
ast-json = ["smallvec/serde", "smol_str/serde"]
Expand Down
48 changes: 24 additions & 24 deletions crates/mq-lang/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,30 @@ fn resolve(ident: &str, env: &Shared<SharedCell<Env>>) -> Result<RuntimeValue, E
}
}

/// Implementation of MacroEvaluator trait for Evaluator.
/// This allows the macro expander to evaluate macro bodies during collection.
impl<T: ModuleResolver> MacroEvaluator for Evaluator<T> {
fn eval_macro_body(&mut self, body: &Shared<ast::Node>, _token_id: TokenId) -> Result<RuntimeValue, RuntimeError> {
let value = self.eval_macro(body);

// If the result is already an AST (from quote), return it as-is
// If the result is None (e.g., from if(false) without else), return None to indicate removal
// Otherwise, wrap the body itself as an AST (for macros without quote)
match value {
Ok(RuntimeValue::Ast(ast)) => Ok(RuntimeValue::Ast(ast)),
Ok(RuntimeValue::None) => {
// Return None instead of empty block - this will cause the macro to be skipped
Ok(RuntimeValue::None)
}
Ok(_) | Err(_) => {
// Return the body as AST, not the evaluated result
// This allows macros without quote to work
Ok(RuntimeValue::Ast(Shared::clone(body)))
}
}
}
}

#[cfg(test)]
mod tests {
use std::f64::consts::PI;
Expand Down Expand Up @@ -7745,30 +7769,6 @@ mod tests {
}
}

/// Implementation of MacroEvaluator trait for Evaluator.
/// This allows the macro expander to evaluate macro bodies during collection.
impl<T: ModuleResolver> MacroEvaluator for Evaluator<T> {
fn eval_macro_body(&mut self, body: &Shared<ast::Node>, _token_id: TokenId) -> Result<RuntimeValue, RuntimeError> {
let value = self.eval_macro(body);

// If the result is already an AST (from quote), return it as-is
// If the result is None (e.g., from if(false) without else), return None to indicate removal
// Otherwise, wrap the body itself as an AST (for macros without quote)
match value {
Ok(RuntimeValue::Ast(ast)) => Ok(RuntimeValue::Ast(ast)),
Ok(RuntimeValue::None) => {
// Return None instead of empty block - this will cause the macro to be skipped
Ok(RuntimeValue::None)
}
Ok(_) | Err(_) => {
// Return the body as AST, not the evaluated result
// This allows macros without quote to work
Ok(RuntimeValue::Ast(Shared::clone(body)))
}
}
}
}

#[cfg(test)]
#[cfg(all(feature = "debugger", feature = "sync"))]
mod debugger_tests {
Expand Down
2 changes: 1 addition & 1 deletion crates/mq-lang/src/eval/builtin/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! use a purpose-built secret-generation API for that.

use crate::RuntimeValue;
use rand::Rng;
use rand::RngExt;
use rand::seq::SliceRandom;

/// Returns a pseudo-random `f64` uniformly distributed in `[0, 1)`.
Expand Down