       js: ''
     }
   else
-    module = lookupInMap compiledModules, moduleName
-    toInject = concatSets (collectRequiresFor moduleName), (newSetWith moduleName)
-    ctx = injectedContext toInject
+    module = lookupCompiledModule moduleName
+    {modules, ctx} = contextWithDependencies moduleName
     [expression] = _terms ast
     {js} = compileCtxAstToJs topLevelExpression, ctx, expression
     (finalizeTypes ctx, expression)
-    js: library + immutable + (listOfLines map lookupJs, setToArray toInject) + js
+    js: library + immutable + (listOfLines map lookupJs, modules) + js
     ast: ast
     errors: checkTypes ctx
+
+contextWithDependencies = (moduleName) ->
+  toInject = concatSets (collectRequiresFor moduleName), (newSetWith moduleName)
+  ctx: injectedContext toInject
+  modules: setToArray toInject
 
 # Primitive type checking for now
 checkTypes = (ctx) ->

ms = {}
ms.fn = ms_fn = (ctx, call) ->
    # For now expect the curried constructor call
    args = _validArguments call
    [paramList, defs...] = args
    params = paramTupleIn call, paramList
    defs ?= []

    failed

lookupJs = (moduleName) ->
  js = (lookupCompiledModule moduleName)?.js
  if not js
    console.error "#{moduleName} not found"
  else
