fixes #1809; implements overloading based on 'var T'
This commit is contained in:
parent
1592067566
commit
d4bca58b7d
4 changed files with 149 additions and 154 deletions
|
|
@ -211,7 +211,7 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult =
|
||||||
elif compareTypes(n.typ, n.sons[1].typ, dcEqIgnoreDistinct):
|
elif compareTypes(n.typ, n.sons[1].typ, dcEqIgnoreDistinct):
|
||||||
# types that are equal modulo distinction preserve l-value:
|
# types that are equal modulo distinction preserve l-value:
|
||||||
result = isAssignable(owner, n.sons[1])
|
result = isAssignable(owner, n.sons[1])
|
||||||
of nkHiddenDeref, nkDerefExpr:
|
of nkHiddenDeref, nkDerefExpr, nkHiddenAddr:
|
||||||
result = arLValue
|
result = arLValue
|
||||||
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
|
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
|
||||||
result = isAssignable(owner, n.sons[0])
|
result = isAssignable(owner, n.sons[0])
|
||||||
|
|
@ -221,6 +221,9 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult =
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc isLValue*(n: PNode): bool =
|
||||||
|
isAssignable(nil, n) in {arLValue, arLocalLValue}
|
||||||
|
|
||||||
proc matchNodeKinds*(p, n: PNode): bool =
|
proc matchNodeKinds*(p, n: PNode): bool =
|
||||||
# matches the parameter constraint 'p' against the concrete AST 'n'.
|
# matches the parameter constraint 'p' against the concrete AST 'n'.
|
||||||
# Efficiency matters here.
|
# Efficiency matters here.
|
||||||
|
|
|
||||||
|
|
@ -191,21 +191,6 @@ proc complexDisambiguation(a, b: PType): int =
|
||||||
for i in 1 .. <a.len: x += a.sons[i].sumGeneric
|
for i in 1 .. <a.len: x += a.sons[i].sumGeneric
|
||||||
for i in 1 .. <b.len: y += b.sons[i].sumGeneric
|
for i in 1 .. <b.len: y += b.sons[i].sumGeneric
|
||||||
result = x - y
|
result = x - y
|
||||||
when false:
|
|
||||||
proc betterThan(a, b: PType): bool {.inline.} = a.sumGeneric > b.sumGeneric
|
|
||||||
|
|
||||||
if a.len > 1 and b.len > 1:
|
|
||||||
let aa = a.sons[1].sumGeneric
|
|
||||||
let bb = b.sons[1].sumGeneric
|
|
||||||
var a = a
|
|
||||||
var b = b
|
|
||||||
|
|
||||||
if aa < bb: swap(a, b)
|
|
||||||
# all must be better
|
|
||||||
for i in 2 .. <min(a.len, b.len):
|
|
||||||
if not a.sons[i].betterThan(b.sons[i]): return 0
|
|
||||||
# a must be longer or of the same length as b:
|
|
||||||
result = a.len - b.len
|
|
||||||
|
|
||||||
proc cmpCandidates*(a, b: TCandidate): int =
|
proc cmpCandidates*(a, b: TCandidate): int =
|
||||||
result = a.exactMatches - b.exactMatches
|
result = a.exactMatches - b.exactMatches
|
||||||
|
|
@ -1463,6 +1448,12 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
else:
|
else:
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
return
|
return
|
||||||
|
if formal.typ.kind == tyVar:
|
||||||
|
if n.isLValue:
|
||||||
|
inc(m.genericMatches, 100)
|
||||||
|
else:
|
||||||
|
m.state = csNoMatch
|
||||||
|
return
|
||||||
|
|
||||||
var
|
var
|
||||||
# iterates over formal parameters
|
# iterates over formal parameters
|
||||||
|
|
|
||||||
4
todo.txt
4
todo.txt
|
|
@ -3,7 +3,6 @@ version 0.10.4
|
||||||
|
|
||||||
- improve GC-unsafety warnings
|
- improve GC-unsafety warnings
|
||||||
- make 'nil' work for 'add' and 'len'
|
- make 'nil' work for 'add' and 'len'
|
||||||
- get rid of 'mget'; aka priority of 'var' needs to be 'var{lvalue}'
|
|
||||||
- disallow negative indexing
|
- disallow negative indexing
|
||||||
- improve the parser; deal with echo $foo gotcha
|
- improve the parser; deal with echo $foo gotcha
|
||||||
|
|
||||||
|
|
@ -59,9 +58,9 @@ Bugs
|
||||||
version 0.9.x
|
version 0.9.x
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
- pragmas need 'bindSym' support
|
||||||
- allow simple read accesses to global variables --> difficult to ensure that
|
- allow simple read accesses to global variables --> difficult to ensure that
|
||||||
no data races happen
|
no data races happen
|
||||||
- pragmas need 'bindSym' support
|
|
||||||
- pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work
|
- pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work
|
||||||
reliably with user-defined pragmas
|
reliably with user-defined pragmas
|
||||||
- memory manager: add a measure of fragmentation
|
- memory manager: add a measure of fragmentation
|
||||||
|
|
@ -76,7 +75,6 @@ version 0.9.X
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- macros as type pragmas
|
- macros as type pragmas
|
||||||
- document how lazy overloading resolution works
|
|
||||||
- document NimMain and check whether it works for threading
|
- document NimMain and check whether it works for threading
|
||||||
|
|
||||||
GC
|
GC
|
||||||
|
|
|
||||||
41
web/news.txt
41
web/news.txt
|
|
@ -4,7 +4,7 @@ News
|
||||||
|
|
||||||
..
|
..
|
||||||
2015-03-01 Version 0.10.4 released
|
2015-03-01 Version 0.10.4 released
|
||||||
=================================
|
==================================
|
||||||
|
|
||||||
|
|
||||||
Changes affecting backwards compatibility
|
Changes affecting backwards compatibility
|
||||||
|
|
@ -54,6 +54,17 @@ News
|
||||||
takesBlock 1, 2, "some", 0.90, "random stuff":
|
takesBlock 1, 2, "some", 0.90, "random stuff":
|
||||||
echo "yay"
|
echo "yay"
|
||||||
|
|
||||||
|
- Overloading by 'var T' is now finally possible:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
proc varOrConst(x: var int) = echo "var"
|
||||||
|
proc varOrConst(x: int) = echo "const"
|
||||||
|
|
||||||
|
var x: int
|
||||||
|
varOrConst(x) # "var"
|
||||||
|
varOrConst(45) # "const"
|
||||||
|
|
||||||
|
|
||||||
Library additions
|
Library additions
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|
@ -61,8 +72,8 @@ News
|
||||||
- Added multipart param to httpclient's ``post`` and ``postContent`` together
|
- Added multipart param to httpclient's ``post`` and ``postContent`` together
|
||||||
with a ``newMultipartData`` proc.
|
with a ``newMultipartData`` proc.
|
||||||
- Added `%*` operator for JSON.
|
- Added `%*` operator for JSON.
|
||||||
- The compiler is now a Nimble package.
|
- The compiler is now available as Nimble package for c2nim.
|
||||||
-
|
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
--------
|
--------
|
||||||
|
|
@ -103,8 +114,7 @@ News
|
||||||
(`#1866 <https://github.com/Araq/Nim/issues/1866>`_).
|
(`#1866 <https://github.com/Araq/Nim/issues/1866>`_).
|
||||||
- Fixed "Incorrect assembler generated"
|
- Fixed "Incorrect assembler generated"
|
||||||
(`#1907 <https://github.com/Araq/Nim/issues/1907>`_)
|
(`#1907 <https://github.com/Araq/Nim/issues/1907>`_)
|
||||||
- Fixed "Expression templates that define macros are unusable in some contexts
|
- Fixed "Expression templates that define macros are unusable in some contexts"
|
||||||
"
|
|
||||||
(`#1903 <https://github.com/Araq/Nim/issues/1903>`_)
|
(`#1903 <https://github.com/Araq/Nim/issues/1903>`_)
|
||||||
- Fixed "a second level generic subclass causes the compiler to crash"
|
- Fixed "a second level generic subclass causes the compiler to crash"
|
||||||
(`#1919 <https://github.com/Araq/Nim/issues/1919>`_)
|
(`#1919 <https://github.com/Araq/Nim/issues/1919>`_)
|
||||||
|
|
@ -116,8 +126,7 @@ News
|
||||||
(`#1838 <https://github.com/Araq/Nim/issues/1838>`_)
|
(`#1838 <https://github.com/Araq/Nim/issues/1838>`_)
|
||||||
- Fixed "ICE with template"
|
- Fixed "ICE with template"
|
||||||
(`#1915 <https://github.com/Araq/Nim/issues/1915>`_)
|
(`#1915 <https://github.com/Araq/Nim/issues/1915>`_)
|
||||||
- Fixed "include the tool directory in the installer as it is required by koch
|
- Fixed "include the tool directory in the installer as it is required by koch"
|
||||||
"
|
|
||||||
(`#1947 <https://github.com/Araq/Nim/issues/1947>`_)
|
(`#1947 <https://github.com/Araq/Nim/issues/1947>`_)
|
||||||
- Fixed "Can't compile if file location contains spaces on Windows"
|
- Fixed "Can't compile if file location contains spaces on Windows"
|
||||||
(`#1955 <https://github.com/Araq/Nim/issues/1955>`_)
|
(`#1955 <https://github.com/Araq/Nim/issues/1955>`_)
|
||||||
|
|
@ -151,14 +160,11 @@ News
|
||||||
(`#2039 <https://github.com/Araq/Nim/issues/2039>`_)
|
(`#2039 <https://github.com/Araq/Nim/issues/2039>`_)
|
||||||
- Fixed "Macros fail to compile when compiled with --os:standalone"
|
- Fixed "Macros fail to compile when compiled with --os:standalone"
|
||||||
(`#2041 <https://github.com/Araq/Nim/issues/2041>`_)
|
(`#2041 <https://github.com/Araq/Nim/issues/2041>`_)
|
||||||
- Fixed "Reading from {.compileTime.} variables can cause code generation to f
|
- Fixed "Reading from {.compileTime.} variables can cause code generation to fail"
|
||||||
ail"
|
|
||||||
(`#2022 <https://github.com/Araq/Nim/issues/2022>`_)
|
(`#2022 <https://github.com/Araq/Nim/issues/2022>`_)
|
||||||
- Fixed "Passing overloaded symbols to templates fails inside generic procedur
|
- Fixed "Passing overloaded symbols to templates fails inside generic procedures"
|
||||||
es"
|
|
||||||
(`#1988 <https://github.com/Araq/Nim/issues/1988>`_)
|
(`#1988 <https://github.com/Araq/Nim/issues/1988>`_)
|
||||||
- Fixed "Compiling iterator with object assignment in release mode causes "var
|
- Fixed "Compiling iterator with object assignment in release mode causes "var not init""
|
||||||
not init""
|
|
||||||
(`#2023 <https://github.com/Araq/Nim/issues/2023>`_)
|
(`#2023 <https://github.com/Araq/Nim/issues/2023>`_)
|
||||||
- Fixed "calling a large number of macros doing some computation fails"
|
- Fixed "calling a large number of macros doing some computation fails"
|
||||||
(`#1989 <https://github.com/Araq/Nim/issues/1989>`_)
|
(`#1989 <https://github.com/Araq/Nim/issues/1989>`_)
|
||||||
|
|
@ -196,8 +202,7 @@ es"
|
||||||
(`#2102 <https://github.com/Araq/Nim/issues/2102>`_)
|
(`#2102 <https://github.com/Araq/Nim/issues/2102>`_)
|
||||||
- Fixed "hint[path] = off not working in nim.cfg"
|
- Fixed "hint[path] = off not working in nim.cfg"
|
||||||
(`#2103 <https://github.com/Araq/Nim/issues/2103>`_)
|
(`#2103 <https://github.com/Araq/Nim/issues/2103>`_)
|
||||||
- Fixed "compiler crashes when getting a tuple from a sequence of generic tupl
|
- Fixed "compiler crashes when getting a tuple from a sequence of generic tuples"
|
||||||
es"
|
|
||||||
(`#2121 <https://github.com/Araq/Nim/issues/2121>`_)
|
(`#2121 <https://github.com/Araq/Nim/issues/2121>`_)
|
||||||
- Fixed "nim check hangs with when"
|
- Fixed "nim check hangs with when"
|
||||||
(`#2123 <https://github.com/Araq/Nim/issues/2123>`_)
|
(`#2123 <https://github.com/Araq/Nim/issues/2123>`_)
|
||||||
|
|
@ -225,13 +230,11 @@ es"
|
||||||
(`#2216 <https://github.com/Araq/Nim/issues/2216>`_)
|
(`#2216 <https://github.com/Araq/Nim/issues/2216>`_)
|
||||||
- Fixed "--threads:on breaks async"
|
- Fixed "--threads:on breaks async"
|
||||||
(`#2074 <https://github.com/Araq/Nim/issues/2074>`_)
|
(`#2074 <https://github.com/Araq/Nim/issues/2074>`_)
|
||||||
- Fixed "Type mismatch not always caught, can generate bad code for C backend.
|
- Fixed "Type mismatch not always caught, can generate bad code for C backend."
|
||||||
"
|
|
||||||
(`#2169 <https://github.com/Araq/Nim/issues/2169>`_)
|
(`#2169 <https://github.com/Araq/Nim/issues/2169>`_)
|
||||||
- Fixed "Failed C compilation when storing proc to own type in object"
|
- Fixed "Failed C compilation when storing proc to own type in object"
|
||||||
(`#2233 <https://github.com/Araq/Nim/issues/2233>`_)
|
(`#2233 <https://github.com/Araq/Nim/issues/2233>`_)
|
||||||
- Fixed "Unknown line/column number in constant declaration type conversion er
|
- Fixed "Unknown line/column number in constant declaration type conversion error"
|
||||||
ror"
|
|
||||||
(`#2252 <https://github.com/Araq/Nim/issues/2252>`_)
|
(`#2252 <https://github.com/Araq/Nim/issues/2252>`_)
|
||||||
- Fixed "Adding {.compile.} fails if nimcache already exists."
|
- Fixed "Adding {.compile.} fails if nimcache already exists."
|
||||||
(`#2247 <https://github.com/Araq/Nim/issues/2247>`_)
|
(`#2247 <https://github.com/Araq/Nim/issues/2247>`_)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue