Fix: Use NOP instead of void in unless macro
The `unless` macro's expansion was updated to use `...` (NOP) instead of `void`. This change also involved removing the `void` keyword from the parser, as it is no longer used.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
;; Benchmark: 100ns
|
;; Benchmark: 100ns
|
||||||
;; Classic "unless" macro example
|
;; Classic "unless" macro example
|
||||||
;; Demonstrates simple template substitution.
|
;; Demonstrates simple template substitution.
|
||||||
;; Output: 42
|
;; Output: 42
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(macro unless [c b] `(if ~c void ~b))
|
(macro unless [c b] `(if ~c ... ~b))
|
||||||
(unless false 42))
|
(unless false 42))
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ mod tests {
|
|||||||
fn test_macro_expansion_unless() {
|
fn test_macro_expansion_unless() {
|
||||||
let source = "
|
let source = "
|
||||||
(do
|
(do
|
||||||
(macro unless [c b] `(if ~c void ~b))
|
(macro unless [c b] `(if ~c ... ~b))
|
||||||
(unless false 42))
|
(unless false 42))
|
||||||
";
|
";
|
||||||
let mut parser = Parser::new(source).unwrap();
|
let mut parser = Parser::new(source).unwrap();
|
||||||
@@ -496,7 +496,7 @@ mod tests {
|
|||||||
if let UntypedKind::Identifier(sym) = &cond.kind {
|
if let UntypedKind::Identifier(sym) = &cond.kind {
|
||||||
assert_eq!(sym.name.as_ref(), "false");
|
assert_eq!(sym.name.as_ref(), "false");
|
||||||
} else { panic!("Expected identifier 'false', got {:?}", cond.kind); }
|
} else { panic!("Expected identifier 'false', got {:?}", cond.kind); }
|
||||||
assert!(matches!(then_br.kind, UntypedKind::Constant(Value::Void)));
|
assert!(matches!(then_br.kind, UntypedKind::Nop));
|
||||||
if let Some(eb) = else_br {
|
if let Some(eb) = else_br {
|
||||||
if let UntypedKind::Constant(Value::Int(n)) = &eb.kind {
|
if let UntypedKind::Constant(Value::Int(n)) = &eb.kind {
|
||||||
assert_eq!(*n, 42);
|
assert_eq!(*n, 42);
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ impl<'a> Parser<'a> {
|
|||||||
TokenKind::Identifier(id) => {
|
TokenKind::Identifier(id) => {
|
||||||
match id.as_ref() {
|
match id.as_ref() {
|
||||||
"..." => UntypedKind::Nop,
|
"..." => UntypedKind::Nop,
|
||||||
"void" => UntypedKind::Constant(Value::Void),
|
|
||||||
_ => UntypedKind::Identifier(id.into()),
|
_ => UntypedKind::Identifier(id.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user