Skip to content

Commit

Permalink
guile: Fix crash/exception on literal empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
dubek committed Mar 30, 2016
1 parent 6f8a5d0 commit 81eabb9
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions guile/step3_env.scm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
(else (lp (cddr next) (cons (car next) k) (cons (cadr next) v))))))
(match ast
((? (lambda (x) (not (list? x)))) (eval_ast ast env))
(() ast)
(('def! k v) ((env 'set) k (EVAL v env)))
(('let* kvs body)
(let* ((new-env (make-Env #:outer env))
Expand Down
1 change: 1 addition & 0 deletions guile/step4_if_fn_do.scm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
((null? (cdr next)) (throw 'mal-error "let*: Invalid binding form" kvs))
(else (lp (cddr next) (cons (car next) k) (cons (cadr next) v))))))
(match ast
(() ast)
(('def! k v) ((env 'set) k (EVAL v env)))
(('let* kvs body)
(let* ((new-env (make-Env #:outer env))
Expand Down
1 change: 1 addition & 0 deletions guile/step5_tco.scm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
;; If you're Lispy enough, there's no recursive at all while you saw named let loop.
(let tco-loop((ast ast) (env env))
(match ast
(() ast)
(('def! k v) ((env 'set) k (EVAL v env)))
(('let* kvs body)
(let* ((new-env (make-Env #:outer env))
Expand Down
1 change: 1 addition & 0 deletions guile/step6_file.scm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
;; If you're Lispy enough, there's no recursive at all while you saw named let loop.
(let tco-loop((ast ast) (env env))
(match ast
(() ast)
(('def! k v) ((env 'set) k (EVAL v env)))
(('let* kvs body)
(let* ((new-env (make-Env #:outer env))
Expand Down
1 change: 1 addition & 0 deletions guile/step7_quote.scm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
;; If you're Lispy enough, there's no recursive at all while you saw named let loop.
(let tco-loop((ast ast) (env env))
(match ast
(() ast)
(('quote obj) obj)
(('quasiquote obj) (EVAL (_quasiquote (->list obj)) env))
(('def! k v) ((env 'set) k (EVAL v env)))
Expand Down
2 changes: 2 additions & 0 deletions guile/step8_macros.scm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

(define (is_macro_call ast env)
(and (list? ast)
(> (length ast) 0)
(and=> (env-check (car ast) env) is-macro?)))

(define (_macroexpand ast env)
Expand Down Expand Up @@ -91,6 +92,7 @@
(let ((ast (_macroexpand ast env)))
(match ast
((? non-list?) (eval_ast ast env))
(() ast)
(('defmacro! k v)
(let ((c (EVAL v env)))
(callable-is_macro-set! c #t)
Expand Down
2 changes: 2 additions & 0 deletions guile/step9_try.scm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

(define (is_macro_call ast env)
(and (list? ast)
(> (length ast) 0)
(and=> (env-check (car ast) env) is-macro?)))

(define (_macroexpand ast env)
Expand Down Expand Up @@ -95,6 +96,7 @@
(let ((ast (_macroexpand ast env)))
(match ast
((? non-list?) (eval_ast ast env))
(() ast)
(('defmacro! k v)
(let ((c (EVAL v env)))
(callable-is_macro-set! c #t)
Expand Down
2 changes: 2 additions & 0 deletions guile/stepA_mal.scm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

(define (is_macro_call ast env)
(and (list? ast)
(> (length ast) 0)
(and=> (env-check (car ast) env) is-macro?)))

(define (_macroexpand ast env)
Expand Down Expand Up @@ -107,6 +108,7 @@
(let ((ast (_macroexpand ast env)))
(match ast
((? non-list?) (eval_ast ast env))
(() ast)
(('defmacro! k v)
(let ((c (EVAL v env)))
(callable-is_macro-set! c #t)
Expand Down

0 comments on commit 81eabb9

Please sign in to comment.