fixes binding of overloaded procs
This commit is contained in:
parent
28b68d914e
commit
a41bf611a0
6 changed files with 51 additions and 26 deletions
|
|
@ -118,6 +118,8 @@ const
|
||||||
":shock:": "icon_eek",
|
":shock:": "icon_eek",
|
||||||
":?": "icon_e_confused",
|
":?": "icon_e_confused",
|
||||||
":-?": "icon_e_confused",
|
":-?": "icon_e_confused",
|
||||||
|
":-/": "icon_e_confused",
|
||||||
|
|
||||||
"8-)": "icon_cool",
|
"8-)": "icon_cool",
|
||||||
|
|
||||||
":lol:": "icon_lol",
|
":lol:": "icon_lol",
|
||||||
|
|
@ -430,8 +432,10 @@ proc setRef(p: var TRstParser, key: string, value: PRstNode) =
|
||||||
var length = len(p.s.refs)
|
var length = len(p.s.refs)
|
||||||
for i in countup(0, length - 1):
|
for i in countup(0, length - 1):
|
||||||
if key == p.s.refs[i].key:
|
if key == p.s.refs[i].key:
|
||||||
p.s.refs[i].value = value
|
if p.s.refs[i].value.addNodes != value.addNodes:
|
||||||
rstMessage(p, warnRedefinitionOfLabel, key)
|
rstMessage(p, warnRedefinitionOfLabel, key)
|
||||||
|
|
||||||
|
p.s.refs[i].value = value
|
||||||
return
|
return
|
||||||
setlen(p.s.refs, length + 1)
|
setlen(p.s.refs, length + 1)
|
||||||
p.s.refs[length].key = key
|
p.s.refs[length].key = key
|
||||||
|
|
|
||||||
|
|
@ -749,11 +749,14 @@ proc makeDeref(n: PNode): PNode =
|
||||||
|
|
||||||
proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
## returns nil if it's not a built-in field access
|
## returns nil if it's not a built-in field access
|
||||||
|
checkSonsLen(n, 2)
|
||||||
|
# early exit for this; see tests/compile/tbindoverload.nim:
|
||||||
|
if n.sons[1].kind == nkSymChoice: return
|
||||||
|
|
||||||
var s = qualifiedLookup(c, n, {checkAmbiguity, checkUndeclared})
|
var s = qualifiedLookup(c, n, {checkAmbiguity, checkUndeclared})
|
||||||
if s != nil:
|
if s != nil:
|
||||||
return semSym(c, n, s, flags)
|
return semSym(c, n, s, flags)
|
||||||
|
|
||||||
checkSonsLen(n, 2)
|
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0], flags)
|
n.sons[0] = semExprWithType(c, n.sons[0], flags)
|
||||||
restoreOldStyleType(n.sons[0])
|
restoreOldStyleType(n.sons[0])
|
||||||
var i = considerAcc(n.sons[1])
|
var i = considerAcc(n.sons[1])
|
||||||
|
|
@ -830,6 +833,11 @@ proc semFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# in Nimrod. We first allow types in the semantic checking.
|
# in Nimrod. We first allow types in the semantic checking.
|
||||||
result = builtinFieldAccess(c, n, flags)
|
result = builtinFieldAccess(c, n, flags)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
|
if n.sons[1].kind == nkSymChoice:
|
||||||
|
result = newNodeI(nkDotCall, n.info)
|
||||||
|
addSon(result, n.sons[1])
|
||||||
|
addSon(result, copyTree(n[0]))
|
||||||
|
else:
|
||||||
var i = considerAcc(n.sons[1])
|
var i = considerAcc(n.sons[1])
|
||||||
var f = SymTabGet(c.tab, i)
|
var f = SymTabGet(c.tab, i)
|
||||||
# if f != nil and f.kind == skStub: loadStub(f)
|
# if f != nil and f.kind == skStub: loadStub(f)
|
||||||
|
|
|
||||||
12
tests/compile/tbindoverload.nim
Normal file
12
tests/compile/tbindoverload.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import strtabs
|
||||||
|
|
||||||
|
template t*() =
|
||||||
|
block:
|
||||||
|
bind newStringTable
|
||||||
|
discard {"Content-Type": "text/html"}.newStringTable()
|
||||||
|
|
||||||
|
discard {:}.newStringTable
|
||||||
|
|
||||||
|
#discard {"Content-Type": "text/html"}.newStringTable()
|
||||||
|
|
||||||
|
t()
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
Discuss Nimrod in our `forum <http://force7.de/heimdall>`_.
|
Discuss Nimrod in our `forum <http://forum.nimrod-code.org/>`_.
|
||||||
|
|
||||||
Visit our project page at GitHub: http://github.com/Araq/Nimrod.
|
Visit our project page at GitHub: http://github.com/Araq/Nimrod.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,6 @@ power with Python's readability and C's performance.**
|
||||||
Welcome to Nimrod
|
Welcome to Nimrod
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
.. container:: snippet
|
|
||||||
*Nimrod looks like this:*
|
|
||||||
|
|
||||||
.. code-block:: nimrod
|
|
||||||
import strutils
|
|
||||||
|
|
||||||
echo "List of ints (separate by whitespace): "
|
|
||||||
echo stdin.readLine.split.each(parseInt).max,
|
|
||||||
" is the maximum"
|
|
||||||
|
|
||||||
**Nimrod** is a new statically typed, imperative
|
**Nimrod** is a new statically typed, imperative
|
||||||
programming language, that supports procedural, object oriented, functional
|
programming language, that supports procedural, object oriented, functional
|
||||||
and generic programming styles while remaining simple and efficient.
|
and generic programming styles while remaining simple and efficient.
|
||||||
|
|
@ -37,6 +27,17 @@ focuses on the 3E: efficiency, expressiveness, elegance (in the order of
|
||||||
priority).
|
priority).
|
||||||
|
|
||||||
|
|
||||||
|
.. container:: snippet
|
||||||
|
*Nimrod looks like this:*
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
echo "Type in a list of ints of ints (separate by whitespace): "
|
||||||
|
let tokens = stdin.readLine.split
|
||||||
|
echo tokens.each(parseInt).max, " is the maximum."
|
||||||
|
|
||||||
|
|
||||||
Nimrod is efficient
|
Nimrod is efficient
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
|
@ -67,7 +68,7 @@ Nimrod is expressive
|
||||||
* Modern type system with local type inference, tuples, variants,
|
* Modern type system with local type inference, tuples, variants,
|
||||||
generics, etc.
|
generics, etc.
|
||||||
* User-defineable operators; code with new operators is often easier to read
|
* User-defineable operators; code with new operators is often easier to read
|
||||||
than code which overloads built-in operators. In the code snippet, the
|
than code which overloads built-in operators. For example, a
|
||||||
``=~`` operator is defined in the ``re`` module.
|
``=~`` operator is defined in the ``re`` module.
|
||||||
* Macros can modify the abstract syntax tree at compile time.
|
* Macros can modify the abstract syntax tree at compile time.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue