about summary refs log tree commit diff stats
path: root/html/040---tests.cc.html
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-01-14 01:48:06 -0800
committerKartik Agaram <vc@akkartik.com>2020-01-14 01:52:54 -0800
commitc504ca566124d1f097e7fe8a2f9f67c1c59e9ccf (patch)
tree9d8cb8eb057c9d4f2f4628b5446d5ff183c8f89f /html/040---tests.cc.html
parent5c368edcb22a4b7c4df7aada998b42ea4833e795 (diff)
downloadmu-c504ca566124d1f097e7fe8a2f9f67c1c59e9ccf.tar.gz
5893
Diffstat (limited to 'html/040---tests.cc.html')
-rw-r--r--html/040---tests.cc.html168
1 files changed, 83 insertions, 85 deletions
diff --git a/html/040---tests.cc.html b/html/040---tests.cc.html
index a0cb8a6f..e2dbd53e 100644
--- a/html/040---tests.cc.html
+++ b/html/040---tests.cc.html
@@ -69,91 +69,89 @@ if ('onhashchange' in window) {
 <span id="L10" class="LineNr">10 </span><span class="Comment">//: We don't rely on any transforms running in previous layers, but this layer</span>
 <span id="L11" class="LineNr">11 </span><span class="Comment">//: knows about labels and will emit labels for previous layers to transform.</span>
 <span id="L12" class="LineNr">12 </span><span class="Delimiter">:(after &quot;Begin Transforms&quot;)</span>
-<span id="L13" class="LineNr">13 </span><span class="Comment">// Begin Level-4 Transforms</span>
-<span id="L14" class="LineNr">14 </span><span class="Special"><a href='011run.cc.html#L252'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='040---tests.cc.html#L36'>create_test_function</a><span class="Delimiter">);</span>
-<span id="L15" class="LineNr">15 </span><span class="Comment">// End Level-4 Transforms</span>
-<span id="L16" class="LineNr">16 </span>
-<span id="L17" class="LineNr">17 </span><span class="Delimiter">:(code)</span>
-<span id="L18" class="LineNr">18 </span><span class="Normal">void</span> <a href='040---tests.cc.html#L18'>test_run_test</a><span class="Delimiter">()</span> <span class="Delimiter">{</span>
-<span id="L19" class="LineNr">19 </span>  <span class="Special"><a href='010---vm.cc.html#L160'>Mem</a></sp
#
#
#           The Nim Compiler
#        (c) Copyright 2015 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

import ast, types, msgs, osproc, streams, options, idents, securehash

proc readOutput(p: Process): string =
  result = ""
  var output = p.outputStream
  while not output.atEnd:
    result.add(output.readLine)
    result.add("\n")
  if result.len > 0:
    result.setLen(result.len - "\n".len)
  discard p.waitForExit

proc opGorge*(cmd, input, cache: string): string =
  if cache.len > 0:# and optForceFullMake notin gGlobalOptions:
    let h = secureHash(cmd & "\t" & input & "\t" & cache)
    let filename = options.toGeneratedFile("gorge_" & $h, "txt")
    var f: File
    if open(f, filename):
      result = f.readAll
      f.close
      return
    var readSuccessful = false
    try:
      var p = startProcess(cmd, options={poEvalCommand, poStderrToStdout})
      if input.len != 0:
        p.inputStream.write(input)
        p.inputStream.close()
      result = p.readOutput
      readSuccessful = true
      writeFile(filename, result)
    except IOError, OSError:
      if not readSuccessful: result = ""
  else:
    try:
      var p = startProcess(cmd, options={poEvalCommand, poStderrToStdout})
      if input.len != 0:
        p.inputStream.write(input)
        p.inputStream.close()
      result = p.readOutput
    except IOError, OSError:
      result = ""

proc opSlurp*(file: string, info: TLineInfo, module: PSym): string =
  try:
    let filename = file.findFile
    result = readFile(filename)
    # we produce a fake include statement for every slurped filename, so that
    # the module dependencies are accurate:
    appendToModule(module, newNode(nkIncludeStmt, info, @[
      newStrNode(nkStrLit, filename)]))
  except IOError:
    localError(info, errCannotOpenFile, file)
    result = ""

proc atomicTypeX(name: string; t: PType; info: TLineInfo): PNode =
  let sym = newSym(skType, getIdent(name), t.owner, info)
  sym.typ = t
  result = newSymNode(sym)
  result.typ = t

proc mapTypeToAst(t: PType, info: TLineInfo; allowRecursion=false): PNode

proc mapTypeToBracket(name: string; t: PType; info: TLineInfo): PNode =
  result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
  result.add atomicTypeX(name, t, info)
  for i in 0 .. < t.len:
    if t.sons[i] == nil:
      let void = atomicTypeX("void", t, info)
      void.typ = newType(tyEmpty, t.owner)
      result.add void
    else:
      result.add mapTypeToAst(t.sons[i], info)

proc mapTypeToAst(t: PType, info: TLineInfo; allowRecursion=false): PNode =
  template atomicType(name): expr = atomicTypeX(name, t, info)

  case t.kind
  of tyNone: result = atomicType("none")
  of tyBool: result = atomicType("bool")
  of tyChar: result = atomicType("char")
  of tyNil: result = atomicType("nil")
  of tyExpr: result = atomicType("expr")
  of tyStmt: result = atomicType("stmt")
  of tyEmpty: result = atomicType"void"
  of tyArrayConstr, tyArray:
    result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
    result.add atomicType("array")
    result.add mapTypeToAst(t.sons[0], info)
    result.add mapTypeToAst(t.sons[1], info)
  of tyTypeDesc:
    if t.base != nil:
      result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
      result.add atomicType("typeDesc")
      result.add mapTypeToAst(t.base, info)
    else:
      result = atomicType"typeDesc"
  of tyGenericInvocation:
    result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
    for i in 0 .. < t.len:
      result.add mapTypeToAst(t.sons[i], info)
  of tyGenericInst, tyGenericBody, tyOrdinal, tyUserTypeClassInst:
    result = mapTypeToAst(t.lastSon, info)
  of tyDistinct:
    if allowRecursion:
      result = mapTypeToBracket("distinct", t, info)
    else:
      result = atomicType(t.sym.name.s)
  of tyGenericParam, tyForward: result = atomicType(t.sym.name.s)
  of tyObject:
    if allowRecursion:
      result = newNodeIT(nkObjectTy, if t.n.isNil: info else: t.n.info, t)
      if t.sons[0] == nil:
        result.add ast.emptyNode
      else:
        result.add mapTypeToAst(t.sons[0], info)
      result.add copyTree(t.n)
    else:
      result = atomicType(t.sym.name.s)
  of tyEnum:
    result = newNodeIT(nkEnumTy, if t.n.isNil: info else: t.n.info, t)
    result.add copyTree(t.n)
  of tyTuple: result = mapTypeToBracket("tuple", t, info)
  of tySet: result = mapTypeToBracket("set", t, info)
  of tyPtr: result = mapTypeToBracket("ptr", t, info)
  of tyRef: result = mapTypeToBracket("ref", t, info)
  of tyVar: result = mapTypeToBracket("var", t, info)
  of tySequence: result = mapTypeToBracket("seq", t, info)
  of tyProc: result = mapTypeToBracket("proc", t, info)
  of tyOpenArray: result = mapTypeToBracket("openArray", t, info)
  of tyRange:
    result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
    result.add atomicType("range")
    result.add t.n.sons[0].copyTree
    result.add t.n.sons[1].copyTree
  of tyPointer: result = atomicType"pointer"
  of tyString: result = atomicType"string"
  of tyCString: result = atomicType"cstring"
  of tyInt: result = atomicType"int"
  of tyInt8: result = atomicType"int8"
  of tyInt16: result = atomicType"int16"
  of tyInt32: result = atomicType"int32"
  of tyInt64: result = atomicType"int64"
  of tyFloat: result = atomicType"float"
  of tyFloat32: result = atomicType"float32"
  of tyFloat64: result = atomicType"float64"
  of tyFloat128: result = atomicType"float128"
  of tyUInt: result = atomicType"uint"
  of tyUInt8: result = atomicType"uint8"
  of tyUInt16: result = atomicType"uint16"
  of tyUInt32: result = atomicType"uint32"
  of tyUInt64: result = atomicType"uint64"
  of tyBigNum: result = atomicType"bignum"
  of tyConst: result = mapTypeToBracket("const", t, info)
  of tyMutable: result = mapTypeToBracket("mutable", t, info)
  of tyVarargs: result = mapTypeToBracket("varargs", t, info)
  of tyIter: result = mapTypeToBracket("iter", t, info)
  of tyProxy: result = atomicType"error"
  of tyBuiltInTypeClass: result = mapTypeToBracket("builtinTypeClass", t, info)
  of tyUserTypeClass:
    result = mapTypeToBracket("concept", t, info)
    result.add t.n.copyTree
  of tyCompositeTypeClass: result = mapTypeToBracket("compositeTypeClass", t, info)
  of tyAnd: result = mapTypeToBracket("and", t, info)
  of tyOr: result = mapTypeToBracket("or", t, info)
  of tyNot: result = mapTypeToBracket("not", t, info)
  of tyAnything: result = atomicType"anything"
  of tyStatic, tyFromExpr, tyFieldAccessor:
    result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
    result.add atomicType("static")
    if t.n != nil:
      result.add t.n.copyTree

proc opMapTypeToAst*(t: PType; info: TLineInfo): PNode =
  result = mapTypeToAst(t, info, true)