mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 07:21:19 +00:00
bugfix: proper return types for templates
This commit is contained in:
@@ -69,6 +69,18 @@ proc semAndEvalConstExpr(c: PContext, n: PNode): PNode =
|
||||
result = evalConstExpr(c.module, e)
|
||||
if result == nil or result.kind == nkEmpty:
|
||||
GlobalError(n.info, errConstExprExpected)
|
||||
|
||||
include seminst, semcall
|
||||
|
||||
proc typeMismatch(n: PNode, formal, actual: PType) =
|
||||
GlobalError(n.Info, errGenerated, msgKindToString(errTypeMismatch) &
|
||||
typeToString(actual) & ") " &
|
||||
`%`(msgKindToString(errButExpectedX), [typeToString(formal)]))
|
||||
|
||||
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
|
||||
result = IndexTypesMatch(c, formal, arg.typ, arg)
|
||||
if result == nil:
|
||||
typeMismatch(arg, formal, arg.typ)
|
||||
|
||||
proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
||||
result = n
|
||||
@@ -76,10 +88,14 @@ proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
||||
of tyExpr:
|
||||
# BUGFIX: we cannot expect a type here, because module aliases would not
|
||||
# work then (see the ``tmodulealias`` test)
|
||||
result = semExpr(c, result) # semExprWithType(c, result)
|
||||
# semExprWithType(c, result)
|
||||
result = semExpr(c, result)
|
||||
of tyStmt: result = semStmt(c, result)
|
||||
of tyTypeDesc: result.typ = semTypeNode(c, result, nil)
|
||||
else: GlobalError(s.info, errInvalidParamKindX, typeToString(s.typ.sons[0]))
|
||||
else:
|
||||
result = semExpr(c, result)
|
||||
result = fitNode(c, s.typ.sons[0], result)
|
||||
#GlobalError(s.info, errInvalidParamKindX, typeToString(s.typ.sons[0]))
|
||||
|
||||
include "semtempl.nim"
|
||||
|
||||
@@ -103,19 +119,6 @@ proc semMacroExpr(c: PContext, n: PNode, sym: PSym,
|
||||
if semCheck: result = semAfterMacroCall(c, result, sym)
|
||||
dec(evalTemplateCounter)
|
||||
|
||||
include seminst, semcall
|
||||
|
||||
proc typeMismatch(n: PNode, formal, actual: PType) =
|
||||
GlobalError(n.Info, errGenerated, msgKindToString(errTypeMismatch) &
|
||||
typeToString(actual) & ") " &
|
||||
`%`(msgKindToString(errButExpectedX), [typeToString(formal)]))
|
||||
|
||||
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
|
||||
result = IndexTypesMatch(c, formal, arg.typ, arg)
|
||||
if result == nil:
|
||||
#debug(arg)
|
||||
typeMismatch(arg, formal, arg.typ)
|
||||
|
||||
proc forceBool(c: PContext, n: PNode): PNode =
|
||||
result = fitNode(c, getSysType(tyBool), n)
|
||||
if result == nil: result = n
|
||||
|
||||
@@ -31,11 +31,12 @@ semstmts contains the semantic checking phase for statements
|
||||
semtypes contains the semantic checking phase for types
|
||||
seminst instantiation of generic procs and types
|
||||
semfold contains code to deal with constant folding
|
||||
semthreads deep program analysis for threads
|
||||
evals contains an AST interpreter for compile time evaluation
|
||||
pragmas semantic checking of pragmas
|
||||
|
||||
idents implements a general mapping from identifiers to an internal
|
||||
representation (``PIdent``) that is used, so that a simple
|
||||
representation (``PIdent``) that is used so that a simple
|
||||
id-comparison suffices to say whether two Nimrod identifiers
|
||||
are equivalent
|
||||
ropes implements long strings represented as trees for
|
||||
|
||||
@@ -29,8 +29,8 @@ Path Purpose
|
||||
``dist`` additional packages for the distribution
|
||||
``doc`` the documentation; it is a bunch of
|
||||
reStructuredText files
|
||||
``lib`` the Nimrod library; ``rod`` depends on it!
|
||||
``web`` website of Nimrod; generated by ``koch.py``
|
||||
``lib`` the Nimrod library
|
||||
``web`` website of Nimrod; generated by ``nimweb``
|
||||
from the ``*.txt`` and ``*.tmpl`` files
|
||||
============ ==============================================
|
||||
|
||||
@@ -117,7 +117,7 @@ parser. The parser builds a syntax tree that is used by the code generator.
|
||||
This syntax tree is the interface between the parser and the code generator.
|
||||
It is essential to understand most of the compiler's code.
|
||||
|
||||
In order to compile Nimrod correctly, type-checking has to be seperated from
|
||||
In order to compile Nimrod correctly, type-checking has to be separated from
|
||||
parsing. Otherwise generics cannot work.
|
||||
|
||||
.. include:: filelist.txt
|
||||
|
||||
4
tests/accept/compile/ttemplreturntype.nim
Normal file
4
tests/accept/compile/ttemplreturntype.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
template `=~` (a: int, b: int): bool = false
|
||||
var foo = 2 =~ 3
|
||||
|
||||
@@ -69,7 +69,9 @@ block countTableTest1:
|
||||
t.inc("12", 2)
|
||||
t.inc("34", 1)
|
||||
assert t.largest()[0] == "90"
|
||||
|
||||
|
||||
for k, v in t.pairs:
|
||||
echo k, v
|
||||
t.sort()
|
||||
var i = 0
|
||||
for k, v in t.pairs:
|
||||
|
||||
11
todo.txt
11
todo.txt
@@ -3,8 +3,11 @@ High priority (version 0.8.12)
|
||||
* implement message passing built-ins
|
||||
|
||||
* add --deadlock_prevention:on|off switch? timeout for locks?
|
||||
* real types for template results
|
||||
* built-in serialization
|
||||
- bug: invoking a generic iterator twice triggers a code gen bug
|
||||
- pegs: the anchor '^' does not work because many procs use a linear search
|
||||
and matchLen()
|
||||
- conversion between character sets
|
||||
|
||||
|
||||
version 0.9.0
|
||||
@@ -19,18 +22,15 @@ version 0.9.0
|
||||
- fix overloading resolution
|
||||
- wrong co-/contravariance
|
||||
- make ^ available as operator
|
||||
- implement closures for the C code generator
|
||||
- implement closures; implement proper coroutines
|
||||
|
||||
Bugs
|
||||
----
|
||||
- proc (x: int) is passable to proc (x: var int) !?
|
||||
- the parser allows empty object case branches
|
||||
- pegs: the anchor '^' does not work because many procs use a linear search
|
||||
and matchLen()
|
||||
- bug: generic assign still buggy
|
||||
- Optimization: If we use a temporary for the result anyway the code gen
|
||||
should make use of this fact to generate better code...
|
||||
- bug: invoking a generic iterator twice triggers a code gen bug
|
||||
- bug: forward proc for generic seems broken
|
||||
- sorting with leads to a strange memory corruption!
|
||||
--> system.swap or genericAssign is broken! And indeed, if reference counts
|
||||
@@ -69,7 +69,6 @@ Library
|
||||
|
||||
- radix tree for strings; maybe suffix tree
|
||||
- locale support
|
||||
- conversion between character sets
|
||||
- bignums
|
||||
- ftp (and other internet protocols)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user