add support for nested lambdas

This commit was merged in pull request #12.
This commit is contained in:
2025-10-01 12:37:59 +03:00
committed by Pavel Kulyov
parent 442f663635
commit 775e321597
2 changed files with 10 additions and 3 deletions

View File

@@ -28,4 +28,11 @@
(return (+ a b 100))) (return (+ a b 100)))
a b)) a b))
(var (fn int ((int))) l-1
(lambda int ((int a)) ()
(var (fn int ((int))) l-2
(lambda int ((int a)) ()
(return (+ 60 a))))
(return (+ 600 (l-2 a)))))
(printf "Calling nested lambdas: %d\n" (l-1 6))
(return 0)) (return 0))

View File

@@ -134,8 +134,8 @@
(let ((lambda-name (semen-make-lambda-name (hash-table-ref env :fn-name) (let ((lambda-name (semen-make-lambda-name (hash-table-ref env :fn-name)
(hash-table-ref env :lambda-counter)))) (hash-table-ref env :lambda-counter))))
(set! (hash-table-ref env :lambda-aux-code) (set! (hash-table-ref env :lambda-aux-code)
(cons (semen-make-aux-lambda-struct lambda-name form) (append (semen-make-aux-lambda-struct lambda-name form)
(hash-table-ref env :lambda-aux-code))) (hash-table-ref env :lambda-aux-code)))
(set! (hash-table-ref env :lambda-counter) (set! (hash-table-ref env :lambda-counter)
(+ (hash-table-ref env :lambda-counter) 1)) (+ (hash-table-ref env :lambda-counter) 1))
lambda-name) lambda-name)
@@ -150,7 +150,7 @@
(('lambda ret-type arglist captures . body) (('lambda ret-type arglist captures . body)
;; Captures are ignored for now, but ;; Captures are ignored for now, but
;; we'll need them for TODO: closures support ;; we'll need them for TODO: closures support
`(fn ,ret-type ,name ,arglist ,@body)) (process-fn `(fn ,ret-type ,name ,arglist ,@body) (list)))
(else (assert #f (fmt #f "Malformed lambda " form))))) (else (assert #f (fmt #f "Malformed lambda " form)))))
;;; Struct ;;; Struct