 
 exports.compileTopLevel = compileTopLevel
 exports.compileExpression = compileExpression
+exports.findMatchingDefinitions = findMatchingDefinitions
 exports.astizeList = astizeList
 exports.astizeExpression = astizeExpression
 exports.astizeExpressionWithWrapper = astizeExpressionWithWrapper

compiledModules = newMap()
moduleGraph = newMap()

compileTopLevel = (source, moduleName = '@unnamed') ->
  required = newSetWith 'Prelude' # TODO: Hardcoded prelude dependency
  if (not lookupInMap compiledModules, 'Prelude') and moduleName isnt 'Prelude'
    request: 'Prelude'
  else
    directRequires = subtractSets required, (newSetWith moduleName)

      (subtractSets requires, acc)
    concatSets collected, acc


findMatchingDefinitions = (moduleName, reference) ->
  {declared: {savedScopes}} = lookupCompiledModule moduleName
  {ctx} = contextWithDependencies moduleName
  {scope, type} = reference
  return [] unless scope
  definitions = concatMaps (while scope isnt 0
    found = savedScopes[scope]
    scope = found.parent
    found.definitions)..., ctx._scope()
  findMatchingDefinitionsOnType type, definitions

findMatchingDefinitionsOnType = (type, definitions) ->
  setToArray definitions

# API


