about summary refs log tree commit diff stats
path: root/html/factorial.mu.html
Commit message (Expand)AuthorAgeFilesLines
* 2423 - describe shape-shifting in html docsKartik K. Agaram2015-11-101-1/+1
* 2177Kartik K. Agaram2015-09-071-21/+24
* 2175Kartik K. Agaram2015-09-061-24/+21
* 2062Kartik K. Agaram2015-08-231-3/+3
* 1949Kartik K. Agaram2015-08-061-2/+2
* 1925Kartik K. Agaram2015-08-031-2/+2
* 1885Kartik K. Agaram2015-07-291-13/+13
* 1853Kartik K. Agaram2015-07-251-2/+2
* 1818Kartik K. Agaram2015-07-181-2/+2
* 1778Kartik K. Agaram2015-07-131-4/+4
* 1690Kartik K. Agaram2015-07-011-1/+1
* 1631 - update html versionsKartik K. Agaram2015-06-231-5/+5
* 1556Kartik K. Agaram2015-06-121-9/+9
* 1549Kartik K. Agaram2015-06-091-2/+2
* 1517Kartik K. Agaram2015-05-301-4/+4
* 1470Kartik K. Agaram2015-05-261-3/+3
* 1459Kartik K. Agaram2015-05-251-0/+71
Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
#
#           The Nimrod Compiler
#        (c) Copyright 2011 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# This module implements the searching for procs and iterators.
# This is needed for proper handling of forward declarations.

import 
  ast, astalgo, msgs, semdata, types, trees

proc SearchForProc*(c: PContext, fn: PSym, tos: int): PSym
  # Searchs for the fn in the symbol table. If the parameter lists are exactly
  # the same the sym in the symbol table is returned, else nil.
proc SearchForBorrowProc*(c: PContext, fn: PSym, tos: int): PSym
  # Searchs for the fn in the symbol table. If the parameter lists are suitable
  # for borrowing the sym in the symbol table is returned, else nil.
# implementation

proc equalGenericParams(procA, procB: PNode): bool = 
  var a, b: PSym
  result = procA == procB
  if result: return 
  if (procA == nil) or (procB == nil): return 
  if sonsLen(procA) != sonsLen(procB): return 
  for i in countup(0, sonsLen(procA) - 1): 
    if procA.sons[i].kind != nkSym: 
      InternalError(procA.info, "equalGenericParams")
    if procB.sons[i].kind != nkSym: 
      InternalError(procB.info, "equalGenericParams")
    a = procA.sons[i].sym
    b = procB.sons[i].sym
    if (a.name.id != b.name.id) or not sameTypeOrNil(a.typ, b.typ): return 
    if (a.ast != nil) and (b.ast != nil): 
      if not ExprStructuralEquivalent(a.ast, b.ast): return 
  result = true

proc SearchForProc(c: PContext, fn: PSym, tos: int): PSym = 
  var it: TIdentIter
  result = initIdentIter(it, c.tab.stack[tos], fn.Name)
  while result != nil: 
    if (result.Kind == fn.kind): 
      if equalGenericParams(result.ast.sons[genericParamsPos], 
                            fn.ast.sons[genericParamsPos]): 
        case equalParams(result.typ.n, fn.typ.n)
        of paramsEqual: 
          return 
        of paramsIncompatible: 
          LocalError(fn.info, errNotOverloadable, fn.name.s)
          return 
        of paramsNotEqual: 
          nil
    result = NextIdentIter(it, c.tab.stack[tos])

proc paramsFitBorrow(a, b: PNode): bool = 
  var length = sonsLen(a)
  result = false
  if length == sonsLen(b): 
    for i in countup(1, length - 1): 
      var m = a.sons[i].sym
      var n = b.sons[i].sym
      assert((m.kind == skParam) and (n.kind == skParam))
      if not equalOrDistinctOf(m.typ, n.typ): return 
    if not equalOrDistinctOf(a.sons[0].typ, b.sons[0].typ): return 
    result = true

proc SearchForBorrowProc(c: PContext, fn: PSym, tos: int): PSym = 
  # Searchs for the fn in the symbol table. If the parameter lists are suitable
  # for borrowing the sym in the symbol table is returned, else nil.
  var it: TIdentIter
  for scope in countdown(tos, 0): 
    result = initIdentIter(it, c.tab.stack[scope], fn.Name)
    while result != nil: 
      # watchout! result must not be the same as fn!
      if (result.Kind == fn.kind) and (result.id != fn.id): 
        if equalGenericParams(result.ast.sons[genericParamsPos], 
                              fn.ast.sons[genericParamsPos]): 
          if paramsFitBorrow(fn.typ.n, result.typ.n): return 
      result = NextIdentIter(it, c.tab.stack[scope])