From 3c37c164fe76518837f5a22d9a5f18e808a5c55f Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 18 Apr 2019 12:57:26 -0400 Subject: [PATCH] Be more careful about identifying macros The validation for number of function arguments was modified previously to filter-out macros, but the logic was not good enough. For some reason (need to track it down) non-macros are showing up in the macro environment. So additional logic is needed to confirm whether a given symbol is in fact a macro. --- scheme/cyclone/cps-optimizations.sld | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index 1d58f191..b4bd737f 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -2388,14 +2388,22 @@ ;; FUTURE (?): Does given symbol define a procedure? ;(define (avld:procedure? sym) #f) +;; Predicate: Does given symbol refer to a macro? +(define (is-macro? sym) + (and-let* ((val (env:lookup sym (macro:get-env) #f))) + (or (tagged-list? 'macro val) + (Cyc-macro? val)))) + ;; Does the given function call pass enough arguments? (define (validate:num-function-args ast) + ;;(trace:error `(validate:num-function-args ,(car ast) ,ast ,(env:lookup (car ast) (macro:get-env) #f))) (and-let* (((app? ast)) ;; Prims are checked elsewhere ((not (prim? (car ast)))) ((ref? (car ast))) ;; Do not validate macros - ((not (env:lookup (car ast) (macro:get-env) #f))) + ((not (is-macro? (car ast)))) + ;; Extract lambda definition (var (adb:get/default (car ast) #f)) (lam* (adbv:assigned-value var)) ((pair? lam*))