From 3bb53fa7d7ccef05485f521c62e6f0153faa25d0 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 22 Oct 2021 17:17:48 -0400 Subject: [PATCH] objectWith macro --- src/kiss/Macros.hx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/kiss/Macros.hx b/src/kiss/Macros.hx index 80fa1a8..0dc6164 100644 --- a/src/kiss/Macros.hx +++ b/src/kiss/Macros.hx @@ -771,10 +771,34 @@ class Macros { // their original call stacks. This is more convenient for debugging than trying to // comment out the "try" and its catches, and re-balance parens macros["letThrow"] = (wholeExp:ReaderExp, exps:Array, k:KissState) -> { - wholeExp.checkNumArgs(1, null, "(letThrow [thing] [catches...])"); + wholeExp.checkNumArgs(1, null, "(letThrow )"); exps[0]; }; + macros["objectWith"] = (wholeExp:ReaderExp, exps:Array, k:KissState) -> { + wholeExp.checkNumArgs(1, null, "(objectWith )"); + var objectExps = try { + var l = Helpers.bindingList(exps[0], "field bindings for objectWith", true); + exps.shift(); + l; + } catch (_notABindingList) { + []; + } + + for (exp in exps) { + switch (exp.def) { + case Symbol(_): + objectExps.push(exp); + objectExps.push(exp); + default: + throw CompileError.fromExp(exp, "invalid expression in (objectWith)"); + } + } + + var b = wholeExp.expBuilder(); + b.callSymbol("object", objectExps); + } + // The wildest code in Kiss to date // TODO test exprCase!! macros["exprCase"] = (wholeExp:ReaderExp, exps:Array, k:KissState) -> {