This commit is contained in:
Justin Ethier 2019-09-04 18:45:54 -04:00
parent b0acafbee8
commit 5f5363a8e2

View file

@ -1,3 +1,8 @@
(import
(scheme base)
(scheme read)
(scheme cyclone pretty-print)
(scheme cyclone util))
;; TODO: a temporary file to develop a transform pass that validates the number of arguments passed to ;; TODO: a temporary file to develop a transform pass that validates the number of arguments passed to
;; built-in forms, and throws an error if any issues are found. The goal is to provide friendlier validation ;; built-in forms, and throws an error if any issues are found. The goal is to provide friendlier validation
;; for the compiler ;; for the compiler
@ -6,47 +11,67 @@
;; TODO: will relocate this to another place, probably a separate file in scheme/cyclone ;; TODO: will relocate this to another place, probably a separate file in scheme/cyclone
(define (validate-syntax exp) (define (validate-syntax exp)
'TODO ;; Only need to track local vars if they shadow one of our keywords
) (define (include-var? v)
(member v '(define set! if lambda let)))
;; free-vars : exp -> sorted-set[var] (define (check-if exp)
;(define (free-vars ast . opts) (let ((args (length exp)))
; (define let-vars '()) (cond
; (define bound-only? ((< args 3)
; (and (not (null? opts)) (error "Not enough arguments" exp))
; (car opts))) ((> args 4)
; (error "Too many arguments" exp)))))
; (define (search exp)
; (cond (define (search exp vars)
; ; Core forms: ;(pretty-print `(search ,exp))(newline)
; ((ast:lambda? exp) (cond
; (difference (reduce union (map search (ast:lambda-body exp)) '()) ;((ast:lambda? exp) 'TODO)
; (ast:lambda-formals->list exp))) ((const? exp) #f)
; ((const? exp) '()) ((quote? exp) #f)
; ((quote? exp) '()) ((ref? exp) #f)
; ((ref? exp) ((lambda? exp)
; (cond ;(difference (reduce union (map search (lambda->exp exp)) '())
; ((prim? exp) ; (lambda-formals->list exp))
; '())
; (else ;; TODO: validation checks
; (if (member exp let-vars)
; '() (for-each
; (if bound-only? '() (list exp)))))) (lambda (e)
; ((lambda? exp) (search e vars))
; (difference (reduce union (map search (lambda->exp exp)) '()) (lambda-formals->list exp))
; (lambda-formals->list exp))) )
; ((if-syntax? exp) (union (search (if->condition exp)) ((if? exp)
; (union (search (if->then exp)) (check-if exp)
; (search (if->else exp))))) (search (if->condition exp) vars)
; ((define? exp) (union (list (define->var exp)) (search (if->then exp) vars)
; (search (define->exp exp)))) (search (if->else exp) vars))
; ((define-c? exp) (list (define->var exp))) ((define? exp)
; ((set!? exp) (union (list (set!->var exp)) ;; TODO: validation
; (search (set!->exp exp)))) (search (define->var exp) vars)
; ((tagged-list? 'let exp) (for-each
; (set! let-vars (append (map car (cadr exp)) let-vars)) (lambda (e)
; (search (cdr exp))) (search e vars))
; ; Application: (define->exp exp)))
; ((app? exp) (reduce union (map search exp) '())) ((define-c? exp) #f)
; (else (error "unknown expression: " exp)))) ((set!? exp)
; (search ast)) (search (set!->var exp) vars)
(search (set!->exp exp) vars))
;((tagged-list? 'let exp)
; (set! let-vars (append (map car (cadr exp)) let-vars))
; (search (cdr exp)))
; Application:
((app? exp)
(for-each
(lambda (e)
(search e vars))
exp))
(else
(error "unknown expression: " exp))))
(search exp '()))
;(if)
;(if 1 2 3 4)
(let ((sexp (read-all (open-input-file "validation.scm"))))
(validate-syntax sexp))