Merge pull request #539 from justinethier/issue-537-apply-in-icyc

Issue 537 apply in icyc
This commit is contained in:
Justin Ethier 2024-05-21 21:59:37 -04:00 committed by GitHub
commit 645683937f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -4,6 +4,7 @@
Bug Fixes Bug Fixes
- Fixed a bug in `apply` where an error may be raised when processing quoted sub-expressions. For example the following would throw an error: `(apply cons '(5 (1 2)))`. Thanks to @srgx for the bug report!
- Fixed a beta expansion optimization bug where code such as the following would cause the compiler to hang. Thanks to Yorick Hardy for the bug report: - Fixed a beta expansion optimization bug where code such as the following would cause the compiler to hang. Thanks to Yorick Hardy for the bug report:
(define (compile-forever x) x (compile-forever x)) (define (compile-forever x) x (compile-forever x))

View file

@ -89,17 +89,26 @@
((analyze exp *global-environment* rename-env '()) *global-environment*) ((analyze exp *global-environment* rename-env '()) *global-environment*)
((analyze exp (car env) rename-env '()) (car env)))) ((analyze exp (car env) rename-env '()) (car env))))
;; Called from the C runtime to support apply
(define (eval-from-c exp . _env) (define (eval-from-c exp . _env)
(let ((env (if (null? _env) *global-environment* (car _env)))) (let ((env (if (null? _env) *global-environment* (car _env))))
(eval (wrapc exp) env))) (eval (wrapc exp) env)))
;; Expressions received from C code are already evaluated, but sometimes too much so. ;; Helper function for eval-from-c
;; Try to wrap ;;
;; Expressions received from C code are already evaluated,
;; however any quoted expressions will have the quotes
;; stripped off. This is a problem for expressions that
;; aren't self evaluating - like (1 2) - so we re-quote
;; the expressions here so a subsequent eval will work.
;;
(define (wrapc exp) (define (wrapc exp)
(cond (cond
((application? exp) ((application? exp)
(cond (cond
((compound-procedure? (car exp)) ((or (primitive-procedure? (car exp))
(compound-procedure? (car exp))
(procedure? (car exp)))
(cons (cons
(car exp) (car exp)
(map (map