       prelude = "#{@compileNode merge(o, indent: '')}\n" if preludeExps.length
       @expressions = rest
     code = @compileWithDeclarations o
-    return code if o.bare
-    "#{prelude}(function() {\n#{code}\n}).call(this);\n"
+
+    # CS399
+    # emit module prelude
+    modulePrelude += "# CS399 module prelude\n\n"
+    console.log "emitted module prelude, module codes: #{JSON.stringify @moduleCode}"
+
+    # CS399
+    # return code if o.bare
+    # "#{prelude}(function() {\n#{code}\n}).call(this);\n"
+    return "#{modulePrelude}code" if o.bare
+    "#{modulePrelude}#{prelude}(function() {\n#{code}\n}).call(this);\n"
+
 
   # Compile the expressions body for the contents of a function, with
   # declarations of all inner variables pushed up to the top.

  compileNode: (o) ->
    console.log "Compiling module name: #{@name}"

    o.indent  += TAB
    actualCode = @code.compileRoot { bare: yes }

    console.log "using HTML5 worker" if o.worker
    console.log "using node.js process" if o.nodejsprocess
    console.log "emitting actual code:\n###################\n#{actualCode}\n###################\n"

    # attach this.onmessage and stuff


  # It would be better not to generate them in the first place, but for now,
  # clean up obvious double-parentheses.
  compileRoot: (o) ->
    # CS399
    console.log "root options received: #{JSON.stringify o}"
    o.root    = this
    @moduleNames = {}
    @moduleCode = {}
    modulePrelude = ""

    o.indent  = if o.bare then '' else TAB
    o.scope   = new Scope null, this, null
    o.level   = LEVEL_TOP
