bugfix: proper return types for templates

This commit is contained in:
Araq
2011-06-15 12:35:47 +02:00
parent a15475f582
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)
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

View File

@@ -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

View File

@@ -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

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("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:

View File

@@ -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)