#lang racket/base (require "assemble.rkt" "quote-cdata.rkt" "../make.rkt" "../make-structs.rkt" "get-runtime.rkt" (prefix-in racket: racket/base)) (provide package package-anonymous package-standalone-xhtml) ;; Packager: produce single .js files to be included to execute a ;; program. Follows module dependencies. (define (package-anonymous source-code #:should-follow? should-follow? #:output-port op) (fprintf op "(function() {\n") (package source-code #:should-follow? should-follow? #:output-port op) (fprintf op " return invoke; })\n")) ;; package: Source (path -> boolean) output-port -> void ;; Compile package for the given source program. should-follow? ;; indicates whether we should continue following module paths. ;; ;; The generated output defines a function called 'invoke' with ;; four arguments (MACHINE, SUCCESS, FAIL, PARAMS). When called, it'll ;; execute the code to either run standalone expressions or ;; load in modules. (define (package source-code #:should-follow? should-follow? #:output-port op) (define packaging-configuration (make-Configuration should-follow? ;; on (lambda (ast stmts) (assemble/write-invoke stmts op) (fprintf op "(MACHINE, function() { ")) ;; after (lambda (ast stmts) (fprintf op " }, FAIL, PARAMS);")) ;; last (lambda () (fprintf op "SUCCESS();")))) (fprintf op "var invoke = (function(MACHINE, SUCCESS, FAIL, PARAMS) {") (make (cons only-bootstrapped-code (list (make-MainModuleSource source-code))) packaging-configuration) (fprintf op "});\n")) ;; package-standalone-xhtml: X output-port -> void (define (package-standalone-xhtml source-code op) (display *header* op) (display (quote-cdata (get-runtime)) op) (display (quote-cdata (get-code source-code)) op) (display *footer* op)) (define *header* #< Example EOF )