fixes #2600
This commit is contained in:
parent
ecc0090939
commit
2c91e999e2
3 changed files with 50 additions and 20 deletions
|
|
@ -147,6 +147,7 @@ proc copyCandidate(a: var TCandidate, b: TCandidate) =
|
||||||
|
|
||||||
proc sumGeneric(t: PType): int =
|
proc sumGeneric(t: PType): int =
|
||||||
var t = t
|
var t = t
|
||||||
|
var isvar = 1
|
||||||
while true:
|
while true:
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyGenericInst, tyArray, tyRef, tyPtr, tyDistinct, tyArrayConstr,
|
of tyGenericInst, tyArray, tyRef, tyPtr, tyDistinct, tyArrayConstr,
|
||||||
|
|
@ -154,8 +155,9 @@ proc sumGeneric(t: PType): int =
|
||||||
t = t.lastSon
|
t = t.lastSon
|
||||||
inc result
|
inc result
|
||||||
of tyVar:
|
of tyVar:
|
||||||
# but do not make 'var T' more specific than 'T'!
|
|
||||||
t = t.sons[0]
|
t = t.sons[0]
|
||||||
|
inc result
|
||||||
|
inc isvar
|
||||||
of tyGenericInvocation, tyTuple:
|
of tyGenericInvocation, tyTuple:
|
||||||
result = ord(t.kind == tyGenericInvocation)
|
result = ord(t.kind == tyGenericInvocation)
|
||||||
for i in 0 .. <t.len: result += t.sons[i].sumGeneric
|
for i in 0 .. <t.len: result += t.sons[i].sumGeneric
|
||||||
|
|
@ -164,7 +166,7 @@ proc sumGeneric(t: PType): int =
|
||||||
of tyBool, tyChar, tyEnum, tyObject, tyProc, tyPointer,
|
of tyBool, tyChar, tyEnum, tyObject, tyProc, tyPointer,
|
||||||
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
|
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||||
tyUInt..tyUInt64:
|
tyUInt..tyUInt64:
|
||||||
return 1
|
return isvar
|
||||||
else: return 0
|
else: return 0
|
||||||
|
|
||||||
#var ggDebug: bool
|
#var ggDebug: bool
|
||||||
|
|
@ -1470,9 +1472,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
return
|
return
|
||||||
if formal.typ.kind == tyVar:
|
if formal.typ.kind == tyVar:
|
||||||
if n.isLValue:
|
if not n.isLValue:
|
||||||
inc(m.genericMatches, 100)
|
|
||||||
else:
|
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ ref T
|
||||||
123
|
123
|
||||||
2
|
2
|
||||||
1
|
1
|
||||||
@[123, 2, 1]'''
|
@[123, 2, 1]
|
||||||
|
Called!'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Things that's even in the spec now!
|
# Things that's even in the spec now!
|
||||||
|
|
@ -79,3 +80,31 @@ proc takeV[T](a: varargs[T]) =
|
||||||
|
|
||||||
takeV([123, 2, 1]) # takeV's T is "int", not "array of int"
|
takeV([123, 2, 1]) # takeV's T is "int", not "array of int"
|
||||||
echo(@[123, 2, 1])
|
echo(@[123, 2, 1])
|
||||||
|
|
||||||
|
# bug #2600
|
||||||
|
|
||||||
|
type
|
||||||
|
FutureBase* = ref object of RootObj ## Untyped future.
|
||||||
|
|
||||||
|
Future*[T] = ref object of FutureBase ## Typed future.
|
||||||
|
value: T ## Stored value
|
||||||
|
|
||||||
|
FutureVar*[T] = distinct Future[T]
|
||||||
|
|
||||||
|
proc newFuture*[T](): Future[T] =
|
||||||
|
new(result)
|
||||||
|
|
||||||
|
proc newFutureVar*[T](): FutureVar[T] =
|
||||||
|
result = FutureVar[T](newFuture[T]())
|
||||||
|
|
||||||
|
proc mget*[T](future: FutureVar[T]): var T =
|
||||||
|
Future[T](future).value
|
||||||
|
|
||||||
|
proc reset*[T](future: FutureVar[T]) =
|
||||||
|
echo "Called!"
|
||||||
|
|
||||||
|
when true:
|
||||||
|
var foo = newFutureVar[string]()
|
||||||
|
foo.mget() = ""
|
||||||
|
foo.mget.add("Foobar")
|
||||||
|
foo.reset()
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ General FAQ
|
||||||
language that tries to give the programmer ultimate power without compromises
|
language that tries to give the programmer ultimate power without compromises
|
||||||
on runtime efficiency.
|
on runtime efficiency.
|
||||||
This means it focuses on compile-time mechanisms in all their
|
This means it focuses on compile-time mechanisms in all their
|
||||||
various forms. Beneath a nice infix/indentation based syntax with a
|
various forms. Beneath a nice infix/indentation based syntax with a
|
||||||
powerful (AST based, hygienic) macro system lies a semantic model that supports
|
powerful (AST based, hygienic) macro system lies a semantic model that supports
|
||||||
a soft realtime GC on thread local heaps. Asynchronous message passing is used
|
a soft realtime GC on thread local heaps. Asynchronous message passing is used
|
||||||
between threads, so no "stop the world" mechanism is necessary. An unsafe
|
between threads, so no "stop the world" mechanism is necessary. An unsafe
|
||||||
shared memory heap is also provided for the increased efficiency that results
|
shared memory heap is also provided for the increased efficiency that results
|
||||||
from that model.
|
from that model.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -29,8 +29,8 @@ General FAQ
|
||||||
Why yet another programming language?
|
Why yet another programming language?
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
Nim is one of the very few *programmable* statically typed languages, and
|
Nim is one of the very few *programmable* statically typed languages, and
|
||||||
one of the even fewer that produces native binaries that require no
|
one of the even fewer that produces native binaries that require no
|
||||||
runtime or interpreter.
|
runtime or interpreter.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,12 +48,12 @@ General FAQ
|
||||||
What is Nim's take on concurrency?
|
What is Nim's take on concurrency?
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
Nim primarily focusses on thread local (and garbage collected) heaps and
|
Nim primarily focusses on thread local (and garbage collected) heaps and
|
||||||
message passing between threads. Each thread has its own GC, so no
|
message passing between threads. Each thread has its own GC, so no
|
||||||
"stop the world" mechanism is necessary. An unsafe shared memory heap is also
|
"stop the world" mechanism is necessary. An unsafe shared memory heap is also
|
||||||
provided.
|
provided.
|
||||||
|
|
||||||
Future versions will additionally include a GC "per thread group"
|
Future versions will additionally include a GC "per thread group"
|
||||||
and Nim's type system will be enhanced to accurately model this shared
|
and Nim's type system will be enhanced to accurately model this shared
|
||||||
memory heap.
|
memory heap.
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ General FAQ
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The compiler is in development and some important features are still missing.
|
The compiler is in development and some important features are still missing.
|
||||||
However, the compiler is quite stable already: It is able to compile itself
|
However, the compiler is quite stable already: It is able to compile itself
|
||||||
and a substantial body of other code. Until version 1.0.0 is released,
|
and a substantial body of other code. Until version 1.0.0 is released,
|
||||||
minor incompatibilities with older versions of the compiler will be introduced.
|
minor incompatibilities with older versions of the compiler will be introduced.
|
||||||
|
|
||||||
|
|
@ -83,9 +83,9 @@ General FAQ
|
||||||
|
|
||||||
How fast is Nim?
|
How fast is Nim?
|
||||||
----------------
|
----------------
|
||||||
Benchmarks show it to be comparable to C. Some language features (methods,
|
Benchmarks show it to be comparable to C. Some language features (methods,
|
||||||
closures, message passing) are not yet as optimized as they could and will be.
|
closures, message passing) are not yet as optimized as they could and will be.
|
||||||
The only overhead Nim has over C is the GC which has been tuned
|
The only overhead Nim has over C is the GC which has been tuned
|
||||||
for years but still needs some work.
|
for years but still needs some work.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ General FAQ
|
||||||
|
|
||||||
A JVM backend is almost impossible. The JVM is not expressive enough. It has
|
A JVM backend is almost impossible. The JVM is not expressive enough. It has
|
||||||
never been designed as a general purpose VM anyway. A CLR backend is possible
|
never been designed as a general purpose VM anyway. A CLR backend is possible
|
||||||
but would require much work.
|
but would require much work.
|
||||||
|
|
||||||
|
|
||||||
.. container:: standout
|
.. container:: standout
|
||||||
|
|
@ -112,6 +112,7 @@ General FAQ
|
||||||
- jEdit: https://github.com/exhu/nimrod-misc/tree/master/jedit
|
- jEdit: https://github.com/exhu/nimrod-misc/tree/master/jedit
|
||||||
- TextMate: Available in bundle installer (`Repository <https://github.com/textmate/nim.tmbundle>`_)
|
- TextMate: Available in bundle installer (`Repository <https://github.com/textmate/nim.tmbundle>`_)
|
||||||
- Sublime Text: Available via Package Control (`Repository <https://github.com/Varriount/NimLime>`_)
|
- Sublime Text: Available via Package Control (`Repository <https://github.com/Varriount/NimLime>`_)
|
||||||
|
- LiClipse: http://www.liclipse.com/ (Eclipse based plugin)
|
||||||
|
|
||||||
|
|
||||||
.. container:: standout
|
.. container:: standout
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue