From 1deb9820f5473afc1469064488f4ed45a2aabb55 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 19 Aug 2014 20:28:51 +0200 Subject: [PATCH 1/4] fixes #1420 --- compiler/types.nim | 2 +- tests/misc/tunsignedcmp.nim | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/misc/tunsignedcmp.nim diff --git a/compiler/types.nim b/compiler/types.nim index 7559f4d2d..b25e3f697 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -99,7 +99,7 @@ proc isPureObject(typ: PType): bool = proc getOrdValue(n: PNode): BiggestInt = case n.kind - of nkCharLit..nkInt64Lit: result = n.intVal + of nkCharLit..nkUInt64Lit: result = n.intVal of nkNilLit: result = 0 of nkHiddenStdConv: result = getOrdValue(n.sons[1]) else: diff --git a/tests/misc/tunsignedcmp.nim b/tests/misc/tunsignedcmp.nim new file mode 100644 index 000000000..a66fbaae1 --- /dev/null +++ b/tests/misc/tunsignedcmp.nim @@ -0,0 +1,15 @@ +discard """ + output: '''true +true +true''' +""" + +# bug 1420 +import unsigned + +var x = 40'u32 +var y = 30'u32 +echo x > y # works + +echo((40'i32) > (30'i32)) +echo((40'u32) > (30'u32)) # Error: ordinal type expected From e935a35bcf97aaf34d9ef0edb016a9dd3c0894a1 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 19 Aug 2014 20:42:48 +0200 Subject: [PATCH 2/4] fixes #1380 --- compiler/semexprs.nim | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index aadcdb2f4..da12ec08c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1374,20 +1374,19 @@ proc lookUpForDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PSym = if onlyCurrentScope: return checkSonsLen(n, 2) var m = lookUpForDefined(c, n.sons[0], onlyCurrentScope) - if (m != nil) and (m.kind == skModule): - if (n.sons[1].kind == nkIdent): - var ident = n.sons[1].ident - if m == c.module: - result = strTableGet(c.topLevelScope.symbols, ident) - else: - result = strTableGet(m.tab, ident) + if m != nil and m.kind == skModule: + let ident = considerQuotedIdent(n[1]) + if m == c.module: + result = strTableGet(c.topLevelScope.symbols, ident) else: - localError(n.sons[1].info, errIdentifierExpected, "") + result = strTableGet(m.tab, ident) of nkAccQuoted: result = lookUpForDefined(c, considerQuotedIdent(n), onlyCurrentScope) of nkSym: result = n.sym - else: + of nkOpenSymChoice, nkClosedSymChoice: + result = n.sons[0].sym + else: localError(n.info, errIdentifierExpected, renderTree(n)) result = nil From ebe313e627d0184596cc7af6d49fa0814ec407d0 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 19 Aug 2014 22:35:16 +0200 Subject: [PATCH 3/4] fixes #1334 --- compiler/astalgo.nim | 12 ------------ compiler/types.nim | 32 ++++++++++++++++++++++++++++++++ tests/misc/tvarious1.nim | 9 ++++++++- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 16efbb172..eb7ffc63e 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -116,14 +116,6 @@ proc iiTablePut*(t: var TIITable, key, val: int) # implementation -proc skipConv*(n: PNode): PNode = - case n.kind - of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64: - result = n.sons[0] - of nkHiddenStdConv, nkHiddenSubConv, nkConv: - result = n.sons[1] - else: result = n - proc skipConvAndClosure*(n: PNode): PNode = result = n while true: @@ -135,10 +127,6 @@ proc skipConvAndClosure*(n: PNode): PNode = result = result.sons[1] else: break -proc skipConvTakeType*(n: PNode): PNode = - result = n.skipConv - result.typ = n.typ - proc sameValue*(a, b: PNode): bool = result = false case a.kind diff --git a/compiler/types.nim b/compiler/types.nim index b25e3f697..824ca47d0 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1369,3 +1369,35 @@ proc containsCompileTimeOnly*(t: PType): bool = if t.sons[i] != nil and isCompileTimeOnly(t.sons[i]): return true return false + +type + OrdinalType* = enum + NoneLike, IntLike, FloatLike + +proc classify*(t: PType): OrdinalType = + ## for convenient type checking: + if t == nil: + result = NoneLike + else: + case skipTypes(t, abstractVarRange).kind + of tyFloat..tyFloat128: result = FloatLike + of tyInt..tyInt64, tyUInt..tyUInt64, tyBool, tyChar, tyEnum: + result = IntLike + else: result = NoneLike + +proc skipConv*(n: PNode): PNode = + result = n + case n.kind + of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64: + # only skip the conversion if it doesn't lose too important information + # (see bug # + if n.sons[0].typ.classify == n.typ.classify: + result = n.sons[0] + of nkHiddenStdConv, nkHiddenSubConv, nkConv: + if n.sons[1].typ.classify == n.typ.classify: + result = n.sons[1] + else: discard + +proc skipConvTakeType*(n: PNode): PNode = + result = n.skipConv + result.typ = n.typ diff --git a/tests/misc/tvarious1.nim b/tests/misc/tvarious1.nim index 6e4612ae3..1f2da2ae5 100644 --- a/tests/misc/tvarious1.nim +++ b/tests/misc/tvarious1.nim @@ -3,7 +3,8 @@ discard """ output: '''1 0 Whopie -12''' +12 +1.7''' """ echo len([1_000_000]) #OUT 1 @@ -39,3 +40,9 @@ var val12 = TSomeRange(hour: 12) value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour) echo value + +# bug #1334 + +var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] +#var x = int(ys.high / 2) #echo ys[x] # Works +echo ys[int(ys.high / 2)] # Doesn't work From 9ee59da4121ea43a646c373c83844d44c4a574c4 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 19 Aug 2014 22:57:49 +0200 Subject: [PATCH 4/4] minor improvements for the FAQ --- web/question.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web/question.txt b/web/question.txt index 89e242e35..be90cc67a 100644 --- a/web/question.txt +++ b/web/question.txt @@ -28,6 +28,14 @@ one of the even fewer that produces native binaries that require no runtime or interpreter. +What have been the major influences in the language's design? +------------------------------------------------------------- + +The language borrows heavily from: Modula 3, Delphi, Ada, C++, Python, Lisp, +Oberon. As far as possible the list is sorted by the impact of influence. + + + What is Nimrod's take on concurrency? ------------------------------------- @@ -89,8 +97,8 @@ Why is it named ``proc``? *Procedure* used to be the common term as opposed to a *function* which is a mathematical entity that has no side effects. It was planned to have ``func`` -as syntactic sugar for ``proc {.noSideEffect.}`` but the more fine-grained -effect system makes that unimportant. +as syntactic sugar for ``proc {.noSideEffect.}`` but with the more fine-grained +effect system it is not yet clear what ``func`` should be a shortcut for. Compilation @@ -117,15 +125,16 @@ Change the value of the ``cc`` variable to one of the following: ============== ============================================ Abbreviation C/C++ Compiler ============== ============================================ -``dmc`` Digital Mars C++ ``vcc`` Microsoft's Visual C++ ``gcc`` Gnu C -``tcc`` Tiny C ``llvm_gcc`` LLVM-GCC compiler ``icc`` Intel C++ compiler +``clang`` Clang compiler ``ucc`` Generic UNIX C compiler ============== ============================================ +Other C compilers are not officially supported, but might work too. + If your C compiler is not in the above list, try using the *generic UNIX C compiler* (``ucc``). If the C compiler needs different command line arguments try the ``--passc`` and ``--passl`` switches.