private/runtime/function.ss
#lang scheme/base

(require "../syntax/parse.ss"
         "exceptions.ss")
(require (for-syntax scheme/base)
         (for-syntax "../compiler/compile.ss")
         (for-syntax "../compiler/context.ss"))

(provide function-begin eval-function-constructor)

(define (eval-function-constructor formals body)
  (with-syntax ([ast (with-handlers ([exn:fail:syntax?
                                      (lambda (exn)
                                        (raise-runtime-exception here (exn-message exn)))])
                       (parse-function-constructor formals body))])
    (eval #'(function-begin ast))))

(define-syntax (function-begin stx)
  (syntax-case stx ()
    [(function-begin ast)
     (parameterize ([current-eval-context #'here]
                    [current-compilation-context 'eval]
                    [current-source-syntax stx])
       (compile-function-expression (syntax->datum #'ast)))]))