   compileNode: (o) ->
     console.log "Compiling module name: #{@name}"
 
-    o.indent  += TAB
-    actualCode = @code.compileRoot { bare: yes }
+    # assign name if there isn't one
+    if @name
+      check = o.root.declareModule @name
+      if !check
+        # show error!
+        console.log "error! duplicate module name: #{@name}"
+    else
+      @name = o.root.assignModuleName()
+
+    # create a new scope (hence overwriting the present, inherited scope)
+    o.scope = new Scope null, this, null
+    o.level = LEVEL_TOP
+    o.indent = ''
+    # o.bare = yes
+
+    # o.indent  += TAB
+    actualCode = @code.compile o
 
     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"
+
+    o.root.storeModuleCode @name, actualCode
 
     # attach this.onmessage and stuff
 

#### CS399 extensions: ExternalModule
exports.ExternalModule = class ExternalModule extends Base
  constructor: (@name, @code) ->

    # assign name if there isn't one
    if !@name
      @name = "\"unnamed-module.js\""

    # add .js extension if there isn't one


  # 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
