bugfix: proper return types for templates

This commit is contained in:
Araq 2011-06-15 12:35:47 +02:00
commit f7884717c1
6 changed files with 35 additions and 26 deletions

View file

@ -69,6 +69,18 @@ proc semAndEvalConstExpr(c: PContext, n: PNode): PNode =
result = evalConstExpr(c.module, e) result = evalConstExpr(c.module, e)
if result == nil or result.kind == nkEmpty: if result == nil or result.kind == nkEmpty:
GlobalError(n.info, errConstExprExpected) 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 = proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
result = n result = n
@ -76,10 +88,14 @@ proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
of tyExpr: of tyExpr:
# BUGFIX: we cannot expect a type here, because module aliases would not # BUGFIX: we cannot expect a type here, because module aliases would not
# work then (see the ``tmodulealias`` test) # 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 tyStmt: result = semStmt(c, result)
of tyTypeDesc: result.typ = semTypeNode(c, result, nil) 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" include "semtempl.nim"
@ -103,19 +119,6 @@ proc semMacroExpr(c: PContext, n: PNode, sym: PSym,
if semCheck: result = semAfterMacroCall(c, result, sym) if semCheck: result = semAfterMacroCall(c, result, sym)
dec(evalTemplateCounter) 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 = proc forceBool(c: PContext, n: PNode): PNode =
result = fitNode(c, getSysType(tyBool), n) result = fitNode(c, getSysType(tyBool), n)
if result == nil: result = n if result == nil: result = n

View file

@ -31,11 +31,12 @@ semstmts contains the semantic checking phase for statements
semtypes contains the semantic checking phase for types semtypes contains the semantic checking phase for types
seminst instantiation of generic procs and types seminst instantiation of generic procs and types
semfold contains code to deal with constant folding semfold contains code to deal with constant folding
semthreads deep program analysis for threads
evals contains an AST interpreter for compile time evaluation evals contains an AST interpreter for compile time evaluation
pragmas semantic checking of pragmas pragmas semantic checking of pragmas
idents implements a general mapping from identifiers to an internal 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 id-comparison suffices to say whether two Nimrod identifiers
are equivalent are equivalent
ropes implements long strings represented as trees for ropes implements long strings represented as trees for

View file

@ -29,8 +29,8 @@ Path Purpose
``dist`` additional packages for the distribution ``dist`` additional packages for the distribution
``doc`` the documentation; it is a bunch of ``doc`` the documentation; it is a bunch of
reStructuredText files reStructuredText files
``lib`` the Nimrod library; ``rod`` depends on it! ``lib`` the Nimrod library
``web`` website of Nimrod; generated by ``koch.py`` ``web`` website of Nimrod; generated by ``nimweb``
from the ``*.txt`` and ``*.tmpl`` files 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. This syntax tree is the interface between the parser and the code generator.
It is essential to understand most of the compiler's code. 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. parsing. Otherwise generics cannot work.
.. include:: filelist.txt .. include:: filelist.txt

View file

@ -0,0 +1,4 @@
template `=~` (a: int, b: int): bool = false
var foo = 2 =~ 3

View file

@ -69,7 +69,9 @@ block countTableTest1:
t.inc("12", 2) t.inc("12", 2)
t.inc("34", 1) t.inc("34", 1)
assert t.largest()[0] == "90" assert t.largest()[0] == "90"
for k, v in t.pairs:
echo k, v
t.sort() t.sort()
var i = 0 var i = 0
for k, v in t.pairs: for k, v in t.pairs:

View file

@ -3,8 +3,11 @@ High priority (version 0.8.12)
* implement message passing built-ins * implement message passing built-ins
* add --deadlock_prevention:on|off switch? timeout for locks? * add --deadlock_prevention:on|off switch? timeout for locks?
* real types for template results
* built-in serialization * 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 version 0.9.0
@ -19,18 +22,15 @@ version 0.9.0
- fix overloading resolution - fix overloading resolution
- wrong co-/contravariance - wrong co-/contravariance
- make ^ available as operator - make ^ available as operator
- implement closures for the C code generator - implement closures; implement proper coroutines
Bugs Bugs
---- ----
- proc (x: int) is passable to proc (x: var int) !? - proc (x: int) is passable to proc (x: var int) !?
- the parser allows empty object case branches - 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 - bug: generic assign still buggy
- Optimization: If we use a temporary for the result anyway the code gen - Optimization: If we use a temporary for the result anyway the code gen
should make use of this fact to generate better code... 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 - bug: forward proc for generic seems broken
- sorting with leads to a strange memory corruption! - sorting with leads to a strange memory corruption!
--> system.swap or genericAssign is broken! And indeed, if reference counts --> system.swap or genericAssign is broken! And indeed, if reference counts
@ -69,7 +69,6 @@ Library
- radix tree for strings; maybe suffix tree - radix tree for strings; maybe suffix tree
- locale support - locale support
- conversion between character sets
- bignums - bignums
- ftp (and other internet protocols) - ftp (and other internet protocols)