summary refs log tree commit diff stats
path: root/copying.txt
blob: a7ba3143f2027559d79f18722d91120bd6c0eb5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
=====================================================
Nim -- a Compiler for Nim. https://nim-lang.org/

Copyright (C) 2006-2020 Andreas Rumpf. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

[ MIT license: http://www.opensource.org/licenses/mit-license.php ]
} /* 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 Nim Compiler
#        (c) Copyright 2018 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module implements helpers for the macro cache.

import lineinfos, ast, modulegraphs, vmdef, magicsys

proc recordInc*(c: PCtx; info: TLineInfo; key: string; by: BiggestInt) =
  var recorded = newNodeI(nkCommentStmt, info)
  recorded.add newStrNode("inc", info)
  recorded.add newStrNode(key, info)
  recorded.add newIntNode(nkIntLit, by)
  c.graph.recordStmt(c.graph, c.module, recorded)

proc recordPut*(c: PCtx; info: TLineInfo; key: string; k: string; val: PNode) =
  var recorded = newNodeI(nkCommentStmt, info)
  recorded.add newStrNode("put", info)
  recorded.add newStrNode(key, info)
  recorded.add newStrNode(k, info)
  recorded.add copyTree(val)
  c.graph.recordStmt(c.graph, c.module, recorded)

proc recordAdd*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
  var recorded = newNodeI(nkCommentStmt, info)
  recorded.add newStrNode("add", info)
  recorded.add newStrNode(key, info)
  recorded.add copyTree(val)
  c.graph.recordStmt(c.graph, c.module, recorded)

proc recordIncl*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
  var recorded = newNodeI(nkCommentStmt, info)
  recorded.add newStrNode("incl", info)
  recorded.add newStrNode(key, info)
  recorded.add copyTree(val)
  c.graph.recordStmt(c.graph, c.module, recorded)

when false:
  proc genCall3(g: ModuleGraph; m: TMagic; s: string; a, b, c: PNode): PNode =
    newTree(nkStaticStmt, newTree(nkCall, createMagic(g, s, m).newSymNode, a, b, c))

  proc genCall2(g: ModuleGraph; m: TMagic; s: string; a, b: PNode): PNode =
    newTree(nkStaticStmt, newTree(nkCall, createMagic(g, s, m).newSymNode, a, b))

  template nodeFrom(s: string): PNode =
    var res = newStrNode(s, info)
    res.typ = getSysType(g, info, tyString)
    res

  template nodeFrom(i: BiggestInt): PNode =
    var res = newIntNode(i, info)
    res.typ = getSysType(g, info, tyInt)
    res

  template nodeFrom(n: PNode): PNode = copyTree(n)

  template record(call) =
    g.recordStmt(g, c.module, call)

  proc recordInc*(c: PCtx; info: TLineInfo; key: string; by: BiggestInt) =
    let g = c.graph
    record genCall2(mNccInc, "inc", nodeFrom key, nodeFrom by)

  proc recordPut*(c: PCtx; info: TLineInfo; key: string; k: string; val: PNode) =
    let g = c.graph
    record genCall3(mNctPut, "[]=", nodeFrom key, nodeFrom k, nodeFrom val)

  proc recordAdd*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
    let g = c.graph
    record genCall2(mNcsAdd, "add", nodeFrom key, nodeFrom val)

  proc recordIncl*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
    let g = c.graph
    record genCall2(mNcsIncl, "incl", nodeFrom key, nodeFrom val)