ref: 886ae13525ade62f45bffd74a207145f0410971e
parent: ab59d89cf6abdc08488d8ecfa9111d240ef902b8
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Nov 25 13:11:13 EST 2024
small fixups
--- a/compiler.lsp
+++ b/compiler.lsp
@@ -256,9 +256,13 @@
(emit g 'jmp top)
(mark-label g end)))
+(define (is-lambda? a)
+ (or (eq? a 'λ)
+ (eq? a 'lambda)))
+
(define (1arg-lambda? func)
(and (pair? func)
- (or (eq? (car func) 'λ) (eq? (car func) 'lambda))
+ (is-lambda? (car func))
(pair? (cdr func))
(pair? (cadr func))
(length= (cadr func) 1)))
@@ -465,10 +469,6 @@
(string-sub s 0 (1- (string-length s)))))
k))
-(define (lambda-arg-names argl)
- (map! (λ (s) (if (pair? s) (keyword->symbol (car s)) s))
- (to-proper argl)))
-
(define (lambda-vars l)
(define (check-formals l o opt kw)
(cond ((or (null? l) (symbol? l)) #t)
@@ -497,7 +497,8 @@
(error "compile error: invalid formal argument " l
" in list " o)))))
(check-formals l l #f #f)
- (lambda-arg-names l))
+ (map (λ (s) (if (pair? s) (keyword->symbol (car s)) s))
+ (to-proper l)))
(define (emit-optional-arg-inits g env opta vars i)
; i is the lexical var index of the opt arg to process next
--- a/flisp.boot
+++ b/flisp.boot
@@ -39,7 +39,7 @@
with-bindings
*output-stream*
#fn(copy-list))) catch #fn("7000n220>215061:" #(#fn("@000n120F210e12223240e225260e22728e2e325290e2Ae3e42:0e22;0e2e4e3e3:" #(trycatch
- λ if and pair? eq car quote thrown-value cadr caddr raise))
+ λ if and pair? eq? car quote thrown-value cadr caddr raise))
#fn(gensym))) let* #fn("A000|10H3E02021e1qe12215153e1:2021e173051e1e1220=B3H02024e10=e12215153e1@301515375051e2:" #(#fn(nconc)
λ #fn(copy-list) caar let* cadar)) letrec #fn("?000|1202021e12223052e122240522515154e1222605262:" #(#fn(nconc)
λ #fn(map) #.car #fn("9000n12021e12205162:" #(#fn(nconc) set! #fn(copy-list)))
@@ -54,7 +54,7 @@
- #fn(nconc) λ #fn(copy-list))))) throw #fn(":000n220212223e201e4e2:" #(raise
list quote thrown-value)))
1+ #fn("7000n10KM:" #() 1+) 1-
- #fn("7000n10K\x80:" #() 1-) 1arg-lambda? #fn("8000n10B;3^040<20Q;I8040<20Q;3J040=B;3B040TB;3:04710TK62:" #(λ
+ #fn("7000n10K\x80:" #() 1-) 1arg-lambda? #fn("8000n10B;3U04700<51;3J040=B;3B040TB;3:04710TK62:" #(is-lambda?
length=) 1arg-lambda?)
<= #fn("7000n210L;IB0470051;380470151S:" #(nan?) <=) >
#fn("7000n210L:" #() >) >= #fn("7000n201L;IB0470051;380470151S:" #(nan?) >=)
@@ -285,19 +285,19 @@
#fn(iostream->string))) #fn(buffer)) io-readall)
io-readline #fn("8000n12002162:" #(#fn(io-readuntil) #\newline) io-readline)
io-readlines #fn("8000n17071062:" #(read-all-of io-readline) io-readlines)
- iota #fn("8000n17071062:" #(map-int identity) iota) keyword->symbol
- #fn("9000n1200513@02122230515161:0:" #(#fn(keyword?)
- #fn(symbol)
- #fn(";000n1200E71220515163:" #(#fn(string-sub)
- 1- #fn(string-length))) #fn(string)) keyword->symbol)
+ iota #fn("8000n17071062:" #(map-int identity) iota) is-lambda?
+ #fn("7000n1020Q;I704020Q:" #(λ) is-lambda?) keyword->symbol #fn("9000n1200513@02122230515161:0:" #(#fn(keyword?)
+ #fn(symbol) #fn(";000n1200E71220515163:" #(#fn(string-sub) 1- #fn(string-length)))
+ #fn(string)) keyword->symbol)
keyword-arg? #fn("7000n10B;3904200<61:" #(#fn(keyword?)) keyword-arg?)
lambda-arg-names #fn("9000n170217205162:" #(map! #fn("7000n10B390700<61:0:" #(keyword->symbol))
to-proper) lambda-arg-names)
- lambda-vars #fn("7000n120>D61:" #(#fn(":000n120>?040AAOO54471A61:" #(#fn(";000n40V;I5040R340D:0B;36040<R3S082;I504833<0702112263:A0=1828364:0B;36040<B3\x870730<r252;390474051R360O@=070250<2615442774051513<0A0=182D64:833<0702112863:A0=1D8364:0B3>070290<26164:01C:07021162:7029026164:" #(error
+ lambda-vars #fn("7000n120>D61:" #(#fn(":000n120>?040AAOO544212273A5162:" #(#fn(";000n40V;I5040R340D:0B;36040<R3S082;I504833<0702112263:A0=1828364:0B;36040<B3\x870730<r252;390474051R360O@=070250<2615442774051513<0A0=182D64:833<0702112863:A0=1D8364:0B3>070290<26164:01C:07021162:7029026164:" #(error
"compile error: invalid argument list "
". optional arguments must come after required." length= caar "compile error: invalid optional argument "
" in list " #fn(keyword?) ". keyword arguments must come last."
- "compile error: invalid formal argument ") check-formals) lambda-arg-names))) lambda-vars)
+ "compile error: invalid formal argument ") check-formals)
+ #fn(map) #fn("7000n10B390700<61:0:" #(keyword->symbol)) to-proper))) lambda-vars)
last-pair #fn("7000n10=H3400:700=61:" #(last-pair) last-pair)
lastcdr #fn("7000n10H3400:70051=:" #(last-pair) lastcdr) length=
#fn("9000n21EL340O:1El3500H:0H3601El:700=1K\x8062:" #(length=) length=)
--- a/gen.lsp
+++ b/gen.lsp
@@ -98,14 +98,9 @@
OP_EOF_OBJECT dummy_eof #f 0
))
-(define (drop lst n)
- (if (<= n 0) lst
- (drop (cdr lst) (1- n))))
-
(define (for-each-n f lst n)
- (if (<= n 0) ()
- (if (pair? lst) (begin (apply f (list-head lst n))
- (for-each-n f (drop lst n) n)))))
+ (when (and (> n 0) (pair? lst)) (begin (apply f (list-head lst n))
+ (for-each-n f (list-tail lst n) n))))
(let ((c-header (file "opcodes.h" :write :create :truncate))
(instructions (file "instructions.lsp" :write :create :truncate))