Coder Social home page Coder Social logo

nim-lang / nim Goto Github PK

View Code? Open in Web Editor NEW
16.1K 303.0 1.5K 124.96 MB

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).

Home Page: https://nim-lang.org

License: Other

Nim 96.38% Python 0.51% C 0.44% Shell 0.07% Assembly 0.03% C++ 0.18% HTML 1.86% CSS 0.42% Batchfile 0.02% NSIS 0.08% GDB 0.01%
language compiler metaprogramming macros efficient procedural nim hacktoberfest

nim's Issues

CreateThread doesn't accept functions with generics

My code -> https://gist.github.com/1110749 (although, the code was altered for issue #42)
When you try to pass a function to createThread, if it depends on generics for one of its arguments, the compiler will not accept it.

parallel.nim(24, 17) Error: type mismatch: got (TThread[TThreadFuncArgs[int]], proc(TThreadFuncArgs[int]), TThreadFuncArgs[int])
but expected one of:
createThread(t: var TThread[TMsg], tp: proc (TMsg){.thread.}, param: TMsg)
createThread(t: var TThread[TMsg], tp: proc (){.thread.})

Variant object with variable object size hurts the compiler

type
  TEnum = enum
    has_value, empty
  TA = object
    case discriminator: TEnum
    of has_value:
      x : char
    of empty:
proc n(x : char): ref TA =
  new(result)
  result.discriminator = has_value
  result.x = x
var a = n('j')
echo repr(a)

Makes:
Hint: used config file '/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Error: internal error: computeRecSizeAux()
Traceback (most recent call last)
nimrod.nim(86)(?):           nimrod
nimrod.nim(69)(?):           HandleCmdLine
main.nim(201)(?):            MainCommand
main.nim(121)(?):            CommandCompileToC
main.nim(95)(?):             CompileProject
main.nim(90)(?):             CompileModule
passes.nim(139)(?):          processModule
passes.nim(104)(?):          processTopLevelStmt
sem.nim(202)(?):             myProcess
sem.nim(188)(?):             SemStmtAndGenerateGenerics
semstmts.nim(828)(?):        semStmt
semstmts.nim(563)(?):        SemTypeSection
semstmts.nim(558)(?):        typeSectionFinalPass
semtypinst.nim(15)(?):       checkConstructedType
types.nim(969)(?):           computeSize
types.nim(955)(?):           computeSizeAux
types.nim(850)(?):           computeRecSizeAux
types.nim(837)(?):           computeRecSizeAux
types.nim(861)(?):           computeRecSizeAux
msgs.nim(577)(?):            InternalError
msgs.nim(524)(?):            rawMessage
msgs.nim(521)(?):            rawMessage
msgs.nim(478)(?):            handleError
Error: unhandled exception: [Assertion failure] file: rod/msgs.nim line: 478
 [EAssertionFailed]

Macros and string

import macros
proc testProc: string {.compileTime.} =
  result = ""
  result = result & ""
macro test(n : stmt): stmt =
  result = newNimNode(nnkStmtList)
  echo testProc()
test:
  "hi"

Produces (NB: line numbers in eval are probably wrong, I played around with it):
Hint: used config file '/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: macros [Processing]
Error: command line(0)(?): internal error: getStrValue
Traceback (most recent call last)
nimrod.nim(86)(?):           nimrod
nimrod.nim(69)(?):           HandleCmdLine
main.nim(201)(?):            MainCommand
main.nim(121)(?):            CommandCompileToC
main.nim(95)(?):             CompileProject
main.nim(90)(?):             CompileModule
passes.nim(139)(?):          processModule
passes.nim(104)(?):          processTopLevelStmt
sem.nim(202)(?):             myProcess
sem.nim(188)(?):             SemStmtAndGenerateGenerics
semstmts.nim(813)(?):        semStmt
semstmts.nim(32)(?):         semCommand
semstmts.nim(24)(?):         semExprNoType
semexprs.nim(1021)(?):       semExpr
semexprs.nim(934)(?):        semMacroStmt
sem.nim(109)(?):             semMacroExpr
evals.nim(1104)(?):          eval
evals.nim(1085)(?):          evalAux
evals.nim(1043)(?):          evalAux
evals.nim(776)(?):           evalMagicOrCall
evals.nim(450)(?):           evalEcho
evals.nim(443)(?):           getStrValue
msgs.nim(573)(?):            InternalError
msgs.nim(552)(?):            liMessage
msgs.nim(478)(?):            handleError
Error: unhandled exception: [Assertion failure] file: rod/msgs.nim line: 478
 [EAssertionFailed]
Works if you invert and use result = "" & result though.

methods cause compiler to segfault

Code:
method m(i: int): int =
return 5

Result:
Mike-Benfields-MacBook:Code mike$ nimrod compile --run sample.nim
Hint: used config file '/Users/mike/Applications/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: sample [Processing]
No stack traceback available
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Nimrod 0.8.10.
Mac OS 10.6.3.

Macro error adding nodes to another node

The code:

import
  macros, strutils

macro test_macro*(n: stmt): stmt =
  result = newNimNode(nnkStmtList)
  var ass : PNimrodNode = newNimNode(nnkAsgn)
  add(ass, newIdentNode("str"))
  add(ass, newStrLitNode("after"))
  add(result, ass)
when isMainModule:
  var str: string = "before"
  test_macro(str):
    var i : integer = 123
  echo str

Doesn't compile with:
Hint: system [Processing]
Hint: macro_gen [Processing]
Hint: macros [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Traceback (most recent call last)
nimrod.nim(86)(?): nimrod
nimrod.nim(69)(?): HandleCmdLine
main.nim(201)(?): MainCommand
main.nim(121)(?): CommandCompileToC
main.nim(95)(?): CompileProject
main.nim(90)(?): CompileModule
passes.nim(139)(?): processModule
passes.nim(104)(?): processTopLevelStmt
sem.nim(182)(?): myProcess
sem.nim(168)(?): SemStmtAndGenerateGenerics
semstmts.nim(825)(?): semStmt
semstmts.nim(45)(?): semWhen
semstmts.nim(814)(?): semStmt
semstmts.nim(808)(?): semStmt
semstmts.nim(32)(?): semCommand
semstmts.nim(24)(?): semExprNoType
semexprs.nim(1022)(?): semExpr
semexprs.nim(935)(?): semMacroStmt
sem.nim(109)(?): semMacroExpr
evals.nim(1084)(?): eval
evals.nim(1065)(?): evalAux
evals.nim(1023)(?): evalAux
evals.nim(806)(?): evalMagicOrCall
evals.nim(1023)(?): evalAux
evals.nim(745)(?): evalMagicOrCall
evals.nim(284)(?): evalCall
evals.nim(1065)(?): evalAux
evals.nim(1045)(?): evalAux
evals.nim(364)(?): evalAsgn
assign.nim(171)(?): FieldDiscriminantCheck
Error: unhandled exception: assignment to discriminant changes object branch [EInvalidField]

'index out of bounds' in httpserver.nim

When running the example at http://force7.de/nimrod/httpserver.html , and accessing localhost from Chromium (specifically), I get an

Error: unhandled exception: index out of bounds [EInvalidIndex]

at the line in httpserver.nim in next() that reads

if cmpIgnoreCase(data[0], "GET") == 0 or cmpIgnoreCase(data[0], "POST") == 0:

This is due to data having no elements, due to buf being the null string. It seems that, rather than sending a request with "GET / HTTP/1.1" as the first line, Chromium is sending a zero-length line. I don't know if this is proper behaviour, but in any case my program should not crash. So I propose changing this to something like

if data.len() == 0 or cmpIgnoreCase(data[0], "GET") == 0 or cmpIgnoreCase(data[0], "POST") == 0:

bootstrapping

after cloning the git, I've tried to do bootstrapping as shown in the wiki but got the following error:

c:\Users\root\Nimrod\lib\pure\osproc.nim(323, 67) Error: type mismatch: got (seq
[string], openarray[string])
but expected one of:
&(x: string, y: char): string
&(x: char, y: char): string
&(x: string, y: string): string
&(x: char, y: string): string
&(x: T, y: seq[T]): seq[T]
&(x: seq[T], y: seq[T]): seq[T]
&(x: seq[T], y: T): seq[T]

FAILURE

after looking into the file I've do the following, changed:
if false: # poUseShell in options:
cmdl = buildCommandLine(getEnv("COMSPEC"), @["/c", command] & args)
else:
cmdl = buildCommandLine(command, args)
into:
#if false: # poUseShell in options:
# cmdl = buildCommandLine(getEnv("COMSPEC"), @["/c", command] & args)
#else:
cmdl = buildCommandLine(command, args)

because it produce the same effect, but now compiles.

now when I try again I get the following error (after rod/nimrod.exe is done - iteration 1):
Hint: operation successful (41491 lines compiled; 72 sec total) [SuccessX]
iteration: 2
Traceback (most recent call last)
koch.nim(195) koch
koch.nim(138) boot
koch.nim(123) bootIteration
os.nim(653) moveFile
os.nim(167) OSError
Error: unhandled exception: Access is denied.
[EOS]

P.S:
I've tested the newly compiled rod/nimrod.exe and it seems to work.

Parameter names in procedural types

In the tutorial there's the example "procedural type":

type
  TCallback = proc(x: int)

proc echoItem(x: int) =
  echo(x)

proc forEach(callback: TCallback) =
  const
    data = [2, 3, 5, 7, 11]
  for d in items(data):
    callback(d)

forEach(echoItem)

Why is it necessary to give parameters names when only declaring a type?
I feel like I should be able to do:

type
  TCallback = proc(int)

Is this in the works?

Mac OS Support broken with thread-local storage

Mac can not bootstrap since 974a143 :
$ sh build.sh
gcc -w -O3 -fno-strict-aliasing -Ibuild -c build/3_2/nim__dat.c -o build/3_2/nim__dat.o
gcc -w -O3 -fno-strict-aliasing -Ibuild -c build/3_2/system.c -o build/3_2/system.o
build/3_2/system.c:379: error: thread-local storage not supported for this target
build/3_2/system.c:386: error: thread-local storage not supported for this target
build/3_2/system.c:387: error: thread-local storage not supported for this target

See http://lists.apple.com/archives/xcode-users/2006/Jun/msg00550.html

(edit: fixed sha-1)

GC leak

EDIT: The issue is still present with a bit more complicated scenario

type
  TTestObj = object of TObject
    x: string

proc MakeObj(): TTestObj =
  result.x = "Hello"

var global = MakeObj()

var count = 0
proc raiseRandomly =
  inc count
  if count mod 2 == 0:
    raise newException(ESystem, "")

proc foo =
  while true:
    raiseRandomly()
    global = MakeObj()

while true:
  try:
    foo()
  except:
    nil

Special 'of' macro syntax doesn't parse

From the manual:
import macros
macro case_token(n: stmt): stmt =
# creates a lexical analyzer from regular expressions
# ... (implementation is an exercise for the reader :-)
nil

case_token: # this colon tells the parser it is a macro statement
of r"[A-Za-z_]+[A-Za-z_0-9]*":
  return tkIdentifier
of r"0-9+":
  return tkInteger
of r"[\+\-\*\?]+":
  return tkOperator
else:
  return tkUnknown

Doesn't parse with:
Hint: used config file '/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: macros [Processing]
Error: test.nim(8): expression expected, but found '[same indentation]'

koch fails to boot with Error: system module needs 'pushFrame'

According to git bisect, the bad commit is 1986469582280ae0eda91f1d337e9dc0759f8b77. I booted with the revision before and rebuilt koch there too, but that doesn't help.

➜  Nimrod  ./koch boot                                          
iteration: 1
compiler/nimrod0 cc   compiler/nimrod.nim
Hint: used config file '/home/tass/dev/nimrod/Nimrod/config/nimrod.cfg' [Conf]
Hint: used config file 'compiler/nimrod.cfg' [Conf]
Hint: system [Processing]
Error: system module needs 'pushFrame'
FAILURE

is empty.txt in Nimrod/build no longer needed?

Nimrod/build dir contents are now

csources.zip
cycle.h
empty.txt
nimbase.h

there are some files and empty.txt seems no longer needed.

and other projects often use to commit empty dir by addnig `.gitignore'.

thank you. :-)

Compiler crashes when compiling the mandelbrot benchmark

When compiling the mandelbrot benchmark: https://bitbucket.org/jmb/shootout/src/741575f6602f/programs/mandelbrot/mandelbrot.nimrod the compiler crashes with the following backtrace:

Hint: used config file '/home/jerome/prog/nimrod/hg/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: mandelbrot [Processing]
Hint: math [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Traceback (most recent call last)
nimrod.nim(88)           nimrod
nimrod.nim(69)           HandleCmdLine
main.nim(201)            MainCommand
main.nim(121)            CommandCompileToC
main.nim(95)             CompileProject
main.nim(90)             CompileModule
passes.nim(139)          processModule
passes.nim(104)          processTopLevelStmt
cgen.nim(935)            myProcess
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(753)        genStmts
ccgstmts.nim(183)        genWhileStmt
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(753)        genStmts
ccgstmts.nim(183)        genWhileStmt
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(751)        genStmts
ccgstmts.nim(202)        genBlock
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(753)        genStmts
ccgstmts.nim(183)        genWhileStmt
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(750)        genStmts
ccgstmts.nim(764)        genStmts
ccgstmts.nim(738)        genAsgn
ccgexprs.nim(1680)       expr
ccgexprs.nim(783)        genCall
ccgexprs.nim(269)        initLocExpr
ccgexprs.nim(1637)       expr
cgen.nim(691)            genProc
cgen.nim(685)            genProcNoForward
cgen.nim(616)            genProcAux
ccgstmts.nim(750)        genStmts
ccgstmts.nim(758)        genStmts
ccgstmts.nim(159)        genReturnStmt
ccgstmts.nim(764)        genStmts
ccgstmts.nim(738)        genAsgn
ccgexprs.nim(1687)       expr
ccgexprs.nim(1538)       genTupleConstr
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Internal error on preinitialised PNimrodNode variable declaration in recursive macro

import  macros

macro test*(a: stmt): stmt =
  proc testproc(recurse: int) =
    echo "Thats weird"
    var o : PNimrodNode = nil
    echo "  no its not!"
    o = newNimNode(nnkNone)
    if recurse > 0:
      testproc(recurse - 1)
  testproc(5)

test:
  "hi"

If you remove the = nil, or replace it with newNimNode(nnkNone) it works...

Fails with
Error: test_case_of.nim(6): internal error: evalAux: nkNone

Invalid C code generation.

gcc.exe -c -w -IC:\Users\alex\Downloads\Araq-Nimrod-ffa6519\Araq-Nimrod-ffa6519\
lib -o C:\Users\Alex\Desktop\vlc\nimcache\irc.o C:\Users\Alex\Desktop\vlc\nimcac
he\irc.c
C:\Users\Alex\Desktop\vlc\nimcache\nim__dat.c:182: error: field `Data' has incom
plete type
C:\Users\Alex\Desktop\vlc\nimcache\irc.c:88: error: field `Data' has incomplete
type
Error: execution of an external program failed

GIST -> https://gist.github.com/1140601

Actor pool "join" returns too early

If one of the actions already running tries to send a new action to the pool after the main thread has called join, then the new actions may not get called.

import actors

var
  a: TActorPool[int, void]
createActorPool(a)

proc task (i: int) {.thread.} =
  echo i
  if i != 0: a.spawn (i-1, task)

a.spawn (10, task)
a.join()

This code should print all numbers between 0 and 10 in no particular order, instead it only prints "10".

Use a proper build system

The current build system for the nimrod compiler looks rather improvised. How about using a build system like CMake? This would enable easy cross-compiling and user familiarity.

const and compile time evaluation

The documentation of 'const' is not up to date: It is possible that it is evaluated at runtime; 'const' means 'readonly' then. Unfortunately, what is and what will be compile time evaluable heavily depends on the implementation.

high, len function with sequences

Hi.

Following code:

var q: seq[int]
q = @[1,2,3,4,5]
q[high(q)+1] = 10
q[high(q)+2] = 666

echo($high(q))
echo($len(q))
echo($q[5])

C:\nimrod>nimrod c -d:release --opt:size hello
4
5
10

It means that high and len functions are based on static information about sequences?
Maybe echo($high(q)) should print 6 and echo($len(q)) should 7 ?

And if I compile without -d:release and --opt:size (just pure nimrod c hello.nim), I get the following error:

Traceback (most recent call last)
hello.nim(10) hello
Error: unhandled exception: index out of bounds [EInvalidIndex]

Where I'm wrong?

It should not be Redefined Error in REPL.

example:

>>> proc echo_int(a,b:int,x,y:var int) =
...     x = a 
stdin(14, 0) Error: tabulators are not allowed
>>> proc echo_int(a,b:int,x,y:var int) =
...     x = a
stdin(15, 0) Error: tabulators are not allowed
stdin(14, 4) Error: redefinition of 'echo_int'

In example, "echo_int" proc is Error.then, "echo-int" should be un-defined,and could redefine.

2 Xml Parsing errors

  1. Having an xml comment on the same line as an xml node causes the parser to fail to parse the next node correctly.
  2. PXmlNode.text seems to be broken.

Possible Compiler Bugs

When trying to call a func like:

for func in items(emitter.events[event]):
        func(args) #call function with args.

I get func is not callable.

Also, when I try to pass a List to a table, it doesn't behave correctly.

append(emitter.events[event], func)

events is a Table and what its returning is a DoublyLinkedList which I try to append the proc to.

Gist -> https://gist.github.com/1101726

Compiler freeze linked to macro and strutils.replace (or at least strings)

import macros, strutils
macro mac(n: expr): expr =
  expectKind(n, nnkCall)
  expectLen(n, 2)
  expectKind(n[1], nnkStrLit)
  var s : string = n[1].strVal
  s = s.replace("l", "!!") # <--- Offending line right here people
  result = newStrLitNode("Your value sir: '$#'" % [s])

const s = mac("HEllo World")
echo s

Fail to compile c2nim

Using current HEAD (3d36182)

iota github/Araq/Nimrod % ./bin/nimrod c rod/c2nim/c2nim.nim
Hint: used config file '/home/manveru/github/Araq/Nimrod/config/nimrod.cfg' [Conf]
Hint: used config file 'rod/c2nim/c2nim.cfg' [Conf]
Hint: system [Processing]
Hint: c2nim [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: os [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Hint: parseopt [Processing]
Hint: llstream [Processing]
Hint: ast [Processing]
Hint: msgs [Processing]
Hint: options [Processing]
Hint: lists [Processing]
Hint: nstrtabs [Processing]
Hint: nhashes [Processing]
Hint: nversion [Processing]
Hint: crc [Processing]
Hint: ropes [Processing]
Hint: platform [Processing]
/home/manveru/github/Araq/Nimrod/rod/ropes.nim(215, 18) Hint: 'RopeSeqInsert(rs: var TRopeSeq, r: PRope, at: Natural)' is declared but not used [XDeclaredButNotUsed]
Hint: idents [Processing]
Hint: rnimsyn [Processing]
Hint: scanner [Processing]
Hint: lexbase [Processing]
Hint: wordrecg [Processing]
/home/manveru/github/Araq/Nimrod/rod/scanner.nim(174, 14) Hint: 'findIdent(L: TLexer, indent: int): bool' is declared but not used [XDeclaredButNotUsed]
/home/manveru/github/Araq/Nimrod/rod/rnimsyn.nim(414, 26) Hint: 'rfNoIndent' is declared but not used [XDeclaredButNotUsed]
/home/manveru/github/Araq/Nimrod/rod/rnimsyn.nim(238, 11) Hint: 'popCom(g: var TSrcGen)' is declared but not used [XDeclaredButNotUsed]
/home/manveru/github/Araq/Nimrod/rod/rnimsyn.nim(111, 12) Hint: 'putLong(g: var TSrcGen, kind: TTokType, s: string, lineLen: int)' is declared but not used [XDeclaredButNotUsed]
Hint: clex [Processing]
Hint: cparse [Processing]
Hint: pegs [Processing]
Hint: unicode [Processing]
Hint: astalgo [Processing]
Hint: rodutils [Processing]
/home/manveru/github/Araq/Nimrod/rod/astalgo.nim(234, 19) Hint: 'strTableToYaml(n: TStrTable, marker: var TIntSet, indent: int, maxRecDepth: int): PRope' is declared but not used [XDeclaredButNotUsed]
Hint: strtabs [Processing]
Hint: hashes [Processing]
rod/c2nim/cpp.nim(281, 22) Error: type mismatch: got (string, string, int, int)
but expected one of: 
parsePeg(pattern: string, filename: string, line: int, col: int): TPeg

Wrong information on library and base package license.

End of Copyright year should be 2011.

diff --git a/lib/copying.txt b/lib/copying.txt
index 6fcdca1..ab2de06 100755
--- a/lib/copying.txt
+++ b/lib/copying.txt
@@ -1,6 +1,6 @@
 =======================================================
                   The Nimrod Runtime Library
-             Copyright (C) 2004-2010  Andreas Rumpf
+             Copyright (C) 2004-2011  Andreas Rumpf
 =======================================================

 This is the file copying.txt, it applies to the Nimrod Run-Time Library

Cannot Use Arrow Key in REPL.

Env: Ubuntu 11.01.

I use Arrow Key in Nimrod REPL,I don't expected the behavior.

>>> ^[[A^[[D^[[D^[[D

I think UP or Down Key is "History",And Right or Left Key is "Move Cursor".

Reference object initialisation fails in macro

This code:
import macros

type 
    TA = tuple[a : int]
    PA = ref TA

macro test*(a: stmt): stmt =
  var val : PA
  new(val)
  val.a = 4

test:
  "hi"

Produces upon compilation:
Hint: used config file '/yadayada/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: macros [Processing]
stack trace: (most recent call last)
test.nim(12): file: test.nim, line: 12
Error: test.nim(10): attempt to access a nil address

repr does not like sets of enums

type
  TEnum = enum
    a, b
var val = {a, b}
echo repr(val)

results in:
Traceback (most recent call last)
test.nim(5):              test
repr.nim(102)(?):            reprSet
repr.nim(81)(?):             reprSetAux
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Hint: used config file '/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: test.nim(2): 'TEnum' is declared but not used [XDeclaredButNotUsed]
gcc -c -w -fasm-blocks -O1 -I/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/lib -o nimcache/nim__dat.o nimcache/nim__dat.c
gcc -c -w -fasm-blocks -O1 -I/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/lib -o nimcache/test.o nimcache/test.c
gcc  -ldl   -o test  nimcache/test.o nimcache/nim__dat.o nimcache/lib/system.o
Hint: operation successful (5559 lines compiled; 1 sec total) [SuccessX]
./test
Error: execution of an external program failed

Compiler segfaults

Experimenting with Nimrod today, I was able to make the compiler segfault by attempting to compile:

type Node = tuple[left: ref Node]

proc traverse(root: ref Node) =
  if root.left != nil: traverse(root.left)

This code is nonsense, but on the principle that the compiler should never segfault, I'm suggesting this is a bug. I'm not certain what in the code is causing it, but it seems to at least require: the tuple (the equivalent object does not cause a segfault), the recursive reference in the tuple, and the recursive proc.

Nimrod was compiled on Ubuntu 10.04, on an AMD-64 architecture. I'm compiling the above code like so:

james@bast:~/nim_hw$ nimrod c hw.nim
Hint: used config file '/home/james/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: hw [Processing]
Segmentation fault

illegal recursion in type 'TThread'

I get the mentioned error with the following code:

proc `||->`* [T] (func: proc(): T, callback: proc(val: T)): TThread[TThreadFuncArgs[T]] =

The error is related to generics because when I change T to int in the return value (T is suppose to be int anyway), it'll work.

The full code can be found here: https://gist.github.com/1110749

Missing error messages for usage of PNimrodNode in non-compiletime code

This compiles:
import macros
proc makeMacro: PObject =
result = nil
var p = makeMacro
This doesn't:
import macros
proc makeMacro: PNimrodNode =
result = nil
var p = makeMacro

Dump:
Hint: used config file '/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: macros [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Error: internal error: mapType
Traceback (most recent call last)
nimrod.nim(85)(?): nimrod
nimrod.nim(69)(?): HandleCmdLine
main.nim(194)(?): MainCommand
main.nim(120)(?): CommandCompileToC
main.nim(95)(?): CompileProject
main.nim(90)(?): CompileModule
passes.nim(134)(?): processModule
passes.nim(98)(?): processTopLevelStmt
cgen.nim(917)(?): myProcess
ccgstmts.nim(719)(?): genStmts
cgen.nim(677)(?): genProc
cgen.nim(659)(?): genProcNoForward
cgen.nim(654)(?): genProcPrototype
ccgtypes.nim(523)(?): genProcHeader
ccgtypes.nim(181)(?): genProcParams
ccgtypes.nim(122)(?): isInvalidReturnType
ccgtypes.nim(105)(?): mapType
msgs.nim(487)(?): InternalError
msgs.nim(457)(?): rawMessage
msgs.nim(454)(?): rawMessage
msgs.nim(410)(?): handleError
Error: unhandled exception: [Assertion failure] file: rod/msgs.nim line: 410
[EAssertionFailed]

cant use w/ #!shebang

Many script programming languages are commonly able to comment out w/ '#'.
Nimrod is also able to do it.

And many script programming languages are able to use w/ #!shebang.

!shebang is i.e.

#!/usr/bin/env gosh

(define (fib n)
  (if (< n 2) 1
    (+ (fib (- n 2)) (fib (- n 1)))))

(print (fib 30))

But Nimrod cant kick w/ #!shebang.

Methods using objects cause SIGSEGV

To reproduce, compile (eg with nimrod c test.nim) following source:
method somethin(obj: TObject) =
echo "do nothing"
Generates
Hint: used config file '/Users/eric/Documents/Private/Code/nimrod/Compiler/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Traceback (most recent call last)
nimrod.nim(85) nimrod
nimrod.nim(69) HandleCmdLine
main.nim(194) MainCommand
main.nim(120) CommandCompileToC
main.nim(95) CompileProject
main.nim(90) CompileModule
passes.nim(137) processModule
passes.nim(91) closePasses
cgen.nim(965) myClose
cgen.nim(604) genProcAux
ccgstmts.nim(679) genStmts
ccgstmts.nim(120) genIfStmt
ccgexprs.nim(257) initLocExpr
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

doc/altsyn.txt missing

Using install.sh, I get the following error:

cp: doc/altsyn.txt: No such file or directory

Error compiling nimrtl on mac os x

Error when linking nimrtl on mac os x:

Undefined symbols:
  "_environ", referenced from:
      _Getenvvarsc_40240 in os.o
      _Getenvvarsc_40240 in os.o
ld: symbol(s) not found

It seems from the man:

Shared libraries and bundles don't have direct access to environ, which is only available to the loader ld(1) when a complete program is being linked.
The environment routines can still be used, but if direct access to environ is needed, the _NSGetEnviron() routine, defined in <crt_externs.h>, can be used to retrieve the address of environ at runtime.

I'm willing to fix, but would need some pointers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.