From 6193a317f3e1a4b90cb35d2f35a447e895b76a15 Mon Sep 17 00:00:00 2001 From: gilch Date: Mon, 29 May 2023 20:24:12 -0600 Subject: [PATCH 1/3] Fix method arity calculation --- src/hissp/macros.lissp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hissp/macros.lissp b/src/hissp/macros.lissp index cd1a89ce..5e6ce545 100644 --- a/src/hissp/macros.lissp +++ b/src/hissp/macros.lissp @@ -2230,9 +2230,8 @@ except ModuleNotFoundError:pass" `(op#getitem (.pop ,'$#stack) ,obj) obj) (if-else (|| (depth Y) (not (method? obj))) - `(,obj ,@(XYZW#.#"(X+1-Y-Z)*W" + `(,obj ,@(XYZ#.#"(X+1-Y)*Z" (depth Y) - (method? obj) (kwargs? Y) `((.pop ,'$#stack ,(op#sub -1 (kwargs? Y))))) From 22d6c1a90ba4c03177dac329bdf521ed84f9df3d Mon Sep 17 00:00:00 2001 From: gilch Date: Mon, 29 May 2023 20:50:07 -0600 Subject: [PATCH 2/3] Handle some edge cases better Literal :. Some macros could work like callables. --- src/hissp/macros.lissp | 75 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/hissp/macros.lissp b/src/hissp/macros.lissp index 5e6ce545..224f70e8 100644 --- a/src/hissp/macros.lissp +++ b/src/hissp/macros.lissp @@ -2218,43 +2218,44 @@ except ModuleNotFoundError:pass" (let ($#stack (list $#args)) (.reverse $#stack) ,@(i#starmap - XY#(case X (let (obj (next (.reads reader (.replace X "`" "")))) - `(.append ,'$#stack - ,(if-else (|| (literal? obj) - (.startswith Y ",") - (hissp.reader..is_lissp_string obj) - (control-word? obj) - (module-handle? obj) - (quotation? obj)) - (if-else (depth Y) - `(op#getitem (.pop ,'$#stack) ,obj) - obj) - (if-else (|| (depth Y) (not (method? obj))) - `(,obj ,@(XYZ#.#"(X+1-Y)*Z" - (depth Y) - (kwargs? Y) - `((.pop ,'$#stack - ,(op#sub -1 (kwargs? Y))))) - : ,@(when (kwargs? Y) - `(:** (dict (.pop ,'$#stack))))) - `((op#attrgetter ',.#"obj[1:]") - (.pop ,'$#stack)))))) - .#"/" `(.pop ,'$#stack ,(op#sub -1 (depth Y))) - .#"&" `(.append ,'$#stack (,'XY#.#"X[-1-Y]" ,'$#stack ,(depth Y))) - .#"@" `(.append ,'$#stack (.pop ,'$#stack ,(op#sub -2 (depth Y)))) - .#"[" `(.append ,'$#stack - (-<>> (tuple (iter ,'$#stack.pop - (getattr unittest.mock..sentinel - "hissp.]"))) - ,@(when Y `(op#itemgetter - (:<> (,'$#stack.pop)))))) - .#"]" `(.insert ,'$#stack - (op#sub (len ,'$#stack) ,(depth Y)) - (getattr unittest.mock..sentinel "hissp.]")) - .#"*" `(.extend ,'$#stack - (reversed (tuple (.pop ,'$#stack - ,(op#sub -1 (depth Y)))))) - : ()) + XY#(case X + (let (obj (next (.reads reader (.replace X "`" "")))) + `(.append ,'$#stack + : :? ,(if-else (|| (literal? obj) + (.startswith Y ",") + (hissp.reader..is_lissp_string obj) + (control-word? obj) + (module-handle? obj) + (quotation? obj)) + (if-else (depth Y) + `(op#getitem (.pop ,'$#stack) ,obj) + obj) + (if-else (|| (depth Y) (not (method? obj))) + `(,obj ,@(XYZ#.#"(X+1-Y)*Z" + (depth Y) + (kwargs? Y) + `((.pop ,'$#stack + ,(op#sub -1 (kwargs? Y))))) + ,@(when (kwargs? Y) + `(: :** (dict (.pop ,'$#stack))))) + `((op#attrgetter ',.#"obj[1:]") + (.pop ,'$#stack)))))) + .#"/" `(.pop ,'$#stack ,(op#sub -1 (depth Y))) + .#"&" `(.append ,'$#stack (,'XY#.#"X[-1-Y]" ,'$#stack ,(depth Y))) + .#"@" `(.append ,'$#stack (.pop ,'$#stack ,(op#sub -2 (depth Y)))) + .#"[" `(.append ,'$#stack + (-<>> (tuple (iter ,'$#stack.pop + (getattr unittest.mock..sentinel + "hissp.]"))) + ,@(when Y `(op#itemgetter + (:<> (,'$#stack.pop)))))) + .#"]" `(.insert ,'$#stack + (op#sub (len ,'$#stack) ,(depth Y)) + (getattr unittest.mock..sentinel "hissp.]")) + .#"*" `(.extend ,'$#stack + (reversed (tuple (.pop ,'$#stack + ,(op#sub -1 (depth Y)))))) + : ()) (reversed (re..findall "([/&@[\]*:]|(?:[^,%^`/&@[\]*:]|`[,%^/&@[\]*:])+)(%?,?\^*)" (hissp..demunge s)))) From 7a4b80aea04d1b94091c566df6fbfdec9ebcb919 Mon Sep 17 00:00:00 2001 From: gilch Date: Mon, 29 May 2023 21:02:36 -0600 Subject: [PATCH 3/3] Eliminate inject --- src/hissp/macros.lissp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hissp/macros.lissp b/src/hissp/macros.lissp index 224f70e8..aa1665ca 100644 --- a/src/hissp/macros.lissp +++ b/src/hissp/macros.lissp @@ -2238,7 +2238,7 @@ except ModuleNotFoundError:pass" ,(op#sub -1 (kwargs? Y))))) ,@(when (kwargs? Y) `(: :** (dict (.pop ,'$#stack))))) - `((op#attrgetter ',.#"obj[1:]") + `((op#attrgetter ',([#1:] obj)) (.pop ,'$#stack)))))) .#"/" `(.pop ,'$#stack ,(op#sub -1 (depth Y))) .#"&" `(.append ,'$#stack (,'XY#.#"X[-1-Y]" ,'$#stack ,(depth Y)))