#lang racket/base
(require racket/contract)
(provide/contract [compile-an-interaction
(any/c #:language-module module-path? . -> . bytes?)])
(define ns (make-base-empty-namespace))
(define (compile-an-interaction x #:language-module
(language-module 'racket/base))
(let ([module-namespace
(parameterize ([current-namespace ns])
(dynamic-require language-module #f)
(module->namespace language-module))])
(parameterize ([current-namespace module-namespace])
(serialize-compiled-code
(compile (namespace-syntax-introduce
(datum->syntax #f (cons '#%top-interaction x))))))))
(define (serialize-compiled-code a-compiled-code)
(let ([op (open-output-bytes)])
(write a-compiled-code op)
(get-output-bytes op)))
(zo-parse (open-input-bytes
(serialize-compiled-code (compile-an-interaction 'x))))