#lang s-exp "../lang.ss"
(require "../../collects/moby/runtime/stx.ss")
(define-struct linfo (return raise))
(define gensym-counter 0)
(define (gensym)
(begin (set! gensym-counter (add1 gensym-counter))
(sub1 gensym-counter)))
(define (reset-gensym)
(set! gensym-counter 0))
(define (list-of pred)
(lambda (dat)
(and (list? dat)
(andmap pred dat))))
(define (sexp? expr)
(or (string? expr)
(symbol? expr)
(number? expr)
(boolean? expr)
(char? expr)
((list-of sexp?) expr)))
(define (ensugar a-def)
(if (stx-begins-with? a-def 'define)
(let ([stx-list (stx-e a-def)])
(if (and (stx:atom? (second stx-list))
(stx-begins-with? (third stx-list) 'lambda))
(datum->stx false
(list (first stx-list)
(cons (second stx-list)
(stx-e (second (stx-e (third stx-list)))))
(third (stx-e (third stx-list))))
(stx-loc a-def))
a-def))
(error 'ensugar (format "expected definition as syntax, found: ~a" a-def))))
(define (get-struct-procs struct-def)
(list* (string->symbol (format "make-~a" (second struct-def)))
(string->symbol (format "~a?" (second struct-def)))
(foldl (lambda (elt rest-procs)
(list* (string->symbol (format "~a-~a" (second struct-def) elt))
(string->symbol (format "set-~a-~a!"
(second struct-def)
elt))
rest-procs))
empty
(third struct-def))))
(provide/contract
[struct linfo ([return (or/c stx? (list-of stx?))]
[raise list?])]
[gensym ( -> number?)]
[reset-gensym ( -> void?)]
[sexp? (any/c . -> . boolean?)]
[ensugar (stx? . -> . stx?)]
[get-struct-procs (sexp? . -> . (list-of symbol?))])