   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


  @wrap: (nodes) ->
    return nodes[0] if nodes.length is 1 and nodes[0] instanceof Block
    new Block nodes

  # CS399
  declareModule: (name) ->
    console.log "declared module: #{name}"
    if @moduleNames[name]
      return no
    @moduleNames[name] = yes
    yes

  # CS399
  assignModuleName: ->
    console.log "assigned module name"
    "someName"

  # CS399
  storeModuleCode: (name, code) ->
    console.log "storing module \"#{name}\", length: #{code.length}"
    @moduleCode[name] = code



#### Literal

