From ee74706c3b1e040dded3baf2ee3c05ae111c968a Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 22 Feb 2014 01:09:43 +0100 Subject: fixed opcConv --- compiler/astalgo.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'compiler/astalgo.nim') diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 64c1b717c..cce2cc215 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -337,7 +337,10 @@ proc treeToYamlAux(n: PNode, marker: var TIntSet, indent: int, appf(result, ",$N$1\"floatVal\": $2", [istr, toRope(n.floatVal.toStrMaxPrecision)]) of nkStrLit..nkTripleStrLit: - appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) + if n.strVal.isNil: + appf(result, ",$N$1\"strVal\": null", [istr]) + else: + appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: appf(result, ",$N$1\"sym\": $2", [istr, symToYamlAux(n.sym, marker, indent + 2, maxRecDepth)]) @@ -407,7 +410,10 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope = appf(result, ",$N$1\"floatVal\": $2", [istr, toRope(n.floatVal.toStrMaxPrecision)]) of nkStrLit..nkTripleStrLit: - appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) + if n.strVal.isNil: + appf(result, ",$N$1\"strVal\": null", [istr]) + else: + appf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: appf(result, ",$N$1\"sym\": $2_$3", [istr, toRope(n.sym.name.s), toRope(n.sym.id)]) -- cgit 1.4.1-2-gfad0 From 45a345e93da9d80d5a7f2aaa5903e9f75c0bf2d6 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 9 Mar 2014 23:38:17 +0200 Subject: fix #866; generic static params --- compiler/ast.nim | 4 ++++ compiler/astalgo.nim | 8 +++++++- compiler/guards.nim | 4 ---- compiler/semtypes.nim | 35 ++++++++++++++++++++++------------- doc/manual.txt | 4 ++-- 5 files changed, 35 insertions(+), 20 deletions(-) (limited to 'compiler/astalgo.nim') diff --git a/compiler/ast.nim b/compiler/ast.nim index 9c9dfce9a..f9cab0d88 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -818,6 +818,9 @@ type counter*: int data*: TObjectSeq + TImplication* = enum + impUnknown, impNo, impYes + # BUGFIX: a module is overloadable so that a proc can have the # same name as an imported module. This is necessary because of # the poor naming choices in the standard library. @@ -865,6 +868,7 @@ const nkCallKinds* = {nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit, nkHiddenCallConv} + nkLiterals* = {nkCharLit..nkTripleStrLit} nkLambdaKinds* = {nkLambda, nkDo} declarativeDefs* = {nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef} procDefs* = nkLambdaKinds + declarativeDefs diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index cce2cc215..36dd7f562 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -50,7 +50,7 @@ proc strTableGet*(t: TStrTable, name: PIdent): PSym type TTabIter*{.final.} = object # consider all fields here private h*: THash # current hash - + proc initTabIter*(ti: var TTabIter, tab: TStrTable): PSym proc nextIter*(ti: var TTabIter, tab: TStrTable): PSym # usage: @@ -157,6 +157,12 @@ proc leValue*(a, b: PNode): bool = #InternalError(a.info, "leValue") discard +proc weakLeValue*(a, b: PNode): TImplication = + if a.kind notin nkLiterals or b.kind notin nkLiterals: + result = impUnknown + else: + result = if leValue(a, b): impYes else: impNo + proc lookupInRecord(n: PNode, field: PIdent): PSym = result = nil case n.kind diff --git a/compiler/guards.nim b/compiler/guards.nim index fe868054f..f475f5068 100644 --- a/compiler/guards.nim +++ b/compiler/guards.nim @@ -274,10 +274,6 @@ proc pred(n: PNode): PNode = else: result = n -type - TImplication* = enum - impUnknown, impNo, impYes - proc impliesEq(fact, eq: PNode): TImplication = let (loc, val) = if isLocation(eq.sons[1]): (1, 2) else: (2, 1) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 299a3a9b9..c441c3c44 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -147,26 +147,35 @@ proc semDistinct(c: PContext, n: PNode, prev: PType): PType = else: result = newConstraint(c, tyDistinct) -proc semRangeAux(c: PContext, n: PNode, prev: PType): PType = +proc semRangeAux(c: PContext, n: PNode, prev: PType): PType = assert isRange(n) checkSonsLen(n, 3) result = newOrPrevType(tyRange, prev, c) result.n = newNodeI(nkRange, n.info) - if (n[1].kind == nkEmpty) or (n[2].kind == nkEmpty): + if (n[1].kind == nkEmpty) or (n[2].kind == nkEmpty): localError(n.info, errRangeIsEmpty) - var a = semConstExpr(c, n[1]) - var b = semConstExpr(c, n[2]) - if not sameType(a.typ, b.typ): + + var imm: array[2, PNode] + imm[0] = semExprWithType(c, n[1], {efDetermineType}) + imm[1] = semExprWithType(c, n[2], {efDetermineType}) + + if not sameType(imm[0].typ, imm[1].typ): localError(n.info, errPureTypeMismatch) - elif a.typ.kind notin {tyInt..tyInt64,tyEnum,tyBool,tyChar, - tyFloat..tyFloat128,tyUInt8..tyUInt32}: + elif not imm[0].typ.isOrdinalType: localError(n.info, errOrdinalTypeExpected) - elif enumHasHoles(a.typ): - localError(n.info, errEnumXHasHoles, a.typ.sym.name.s) - elif not leValue(a, b): localError(n.info, errRangeIsEmpty) - addSon(result.n, a) - addSon(result.n, b) - addSonSkipIntLit(result, b.typ) + elif enumHasHoles(imm[0].typ): + localError(n.info, errEnumXHasHoles, imm[0].typ.sym.name.s) + + for i in 0..1: + if hasGenericArguments(imm[i]): + result.n.addSon makeStaticExpr(c, imm[i]) + else: + result.n.addSon semConstExpr(c, imm[i]) + + if weakLeValue(result.n[0], result.n[1]) == impNo: + localError(n.info, errRangeIsEmpty) + + addSonSkipIntLit(result, imm[0].typ) proc semRange(c: PContext, n: PNode, prev: PType): PType = result = nil diff --git a/doc/manual.txt b/doc/manual.txt index 748d41d4b..c85998741 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -4062,8 +4062,8 @@ Static params can also appear in the signatures of generic types: AffineTransform2D[T] = Matrix[3, 3, T] AffineTransform3D[T] = Matrix[4, 4, T] - AffineTransform3D[float] # OK - AffineTransform2D[string] # Error, `string` is not a `Number` + var m1: AffineTransform3D[float] # OK + var m2: AffineTransform2D[string] # Error, `string` is not a `Number` typedesc -- cgit 1.4.1-2-gfad0