diff --git a/.gitignore b/.gitignore index 15272385fe..462df4efc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,27 @@ +* +!**/ +!*.* +nimcache/ + *.o +!/icons/*.o *.exe *.so +*.dylib *.zip *.iss -nimcache -lib/nimcache -tools/nimcache -tools/nimweb -tests/nimcache -tests/accept/run/nimcache -tests/accept/compile/nimcache -tests/reject/nimcache -compiler/nimcache -compiler/c2nim/nimcache -compiler/pas2nim/nimcache -misc + +mapping.txt +tags +install.sh +deinstall.sh + doc/*.html doc/*.pdf doc/*.idx /web/upload -koch -compiler/nimrod* -build/[0-9]_[0-9] -bin/nimrod -examples/cross_calculator/nimrod_commandline/nimcalculator -examples/cross_todo/nimrod_backend/*.html -examples/cross_todo/nimrod_backend/backend -examples/cross_todo/nimrod_backend/testbackend -examples/cross_todo/nimrod_backend/todo.sqlite3 -examples/cross_todo/nimrod_commandline/nimtodo -install.sh -deinstall.sh +build/* +bin/* # iOS specific wildcards. *.mode1v3 @@ -42,534 +33,11 @@ deinstall.sh project.xcworkspace/ xcuserdata/ -# iOS specific absolute paths -examples/cross_calculator/ios/resources/ui/*.m -examples/cross_calculator/ios/tags - -# Android specific absolute paths. -examples/cross_calculator/android/bin/ -examples/cross_calculator/android/gen/ -examples/cross_calculator/android/jni/backend-jni.h -examples/cross_calculator/android/libs/ -examples/cross_calculator/android/local.properties -examples/cross_calculator/android/obj/ -examples/cross_calculator/android/tags - # Generated files. /compile.json -/compiler/c2nim/c2nim /compiler/nimrod.dot -/compiler/pas2nim/pas2nim -/compiler/service -/examples/allany -/examples/cairoex -/examples/cgiex -/examples/cgi/cgi_stacktrace -/examples/cgi/example -/examples/curlex -/examples/debugging -/examples/docstrings -/examples/filterex -/examples/fizzbuzz -/examples/gtk/ex1 -/examples/gtk/ex2 -/examples/gtk/ex3 -/examples/gtk/ex4 -/examples/gtk/ex5 -/examples/gtk/ex6 -/examples/gtk/ex7 -/examples/gtk/ex8 -/examples/gtk/ex9 -/examples/hallo -/examples/htmlrefs -/examples/htmltitle -/examples/httpserver2 -/examples/iupex1 -/examples/keyval -/examples/keyval2 -/examples/luaex -/examples/maximum -/examples/parsecfgex -/examples/pythonex -/examples/sdlex -/examples/statcsv -/examples/talk/dsl -/examples/talk/formatoptimizer -/examples/talk/hoisting -/examples/talk/lazyeval -/examples/talk/quasiquote -/examples/talk/tags -/examples/tclex -/examples/transff -/examples/tunit -/examples/wingui -/examples/x11ex -/lib/libnimrtl.dylib -/lib/libserver.dylib -/lib/packages/docutils/highlite -/lib/pure/actors -/lib/pure/algorithm -/lib/pure/asyncio -/lib/pure/base64 -/lib/pure/basic2d -/lib/pure/basic3d -/lib/pure/browsers -/lib/pure/cgi -/lib/pure/collections/sequtils -/lib/pure/collections/tables -/lib/pure/colors -/lib/pure/complex -/lib/pure/cookies -/lib/pure/dynlib -/lib/pure/encodings -/lib/pure/endians -/lib/pure/events -/lib/pure/fsmonitor -/lib/pure/ftpclient -/lib/pure/gentabs -/lib/pure/hashes -/lib/pure/htmlgen -/lib/pure/htmlparser -/lib/pure/httpclient -/lib/pure/httpserver -/lib/pure/irc -/lib/pure/json -/lib/pure/lexbase -/lib/pure/lib/ -/lib/pure/marshal -/lib/pure/matchers -/lib/pure/math -/lib/pure/md5 -/lib/pure/memfiles -/lib/pure/mersenne -/lib/pure/mimetypes -/lib/pure/nimprof -/lib/pure/numeric -/lib/pure/oids -/lib/pure/os -/lib/pure/osproc -/lib/pure/parsecfg -/lib/pure/parsecsv -/lib/pure/parseopt -/lib/pure/parseopt2 -/lib/pure/parsesql -/lib/pure/parseurl -/lib/pure/parseutils -/lib/pure/parsexml -/lib/pure/pegs -/lib/pure/poly -/lib/pure/redis -/lib/pure/romans -/lib/pure/ropes -/lib/pure/scgi -/lib/pure/smtp -/lib/pure/sockets -/lib/pure/streams -/lib/pure/strtabs -/lib/pure/strutils -/lib/pure/subexes -/lib/pure/terminal -/lib/pure/times -/lib/pure/typetraits -/lib/pure/unicode -/lib/pure/unittest -/lib/pure/uri -/lib/pure/xmldom -/lib/pure/xmldomparser -/lib/pure/xmlparser -/lib/pure/xmltree -/lib/system/sysio -/lib/weird -/lib/wrappers/gtk/gtk2 /reject.json /run.json /testresults.html /testresults.json -/tests/caas/absurd_nesting -/tests/caas/completion_dot_syntax_main -/tests/caasdriver -/tests/caas/forward_declarations -/tests/caas/idetools_api -/tests/caas/imported -/tests/caas/issue_416_template_shift -/tests/caas/issue_452_export_shift -/tests/caas/issue_477_dynamic_dispatch -/tests/caas/its_full_of_procs -/tests/caas/main -/tests/caas/SymbolProcRun.*/ -/tests/ccg/tmissingbracket -/tests/compile/talias -/tests/compile/tambsym2 -/tests/compile/tarrindx -/tests/compile/tassign -/tests/compile/tbindoverload -/tests/compile/tcan_alias_generic -/tests/compile/tcan_alias_specialised_generic -/tests/compile/tcan_inherit_generic -/tests/compile/tcan_specialise_generic -/tests/compile/tccgen1 -/tests/compile/tclosure4 -/tests/compile/tclosurebug2 -/tests/compile/tcmdline -/tests/compile/tcodegenbug1 -/tests/compile/tcolonisproc -/tests/compile/tcolors -/tests/compile/tcommontype -/tests/compile/tcompiles -/tests/compile/tcomputedgoto -/tests/compile/tconsteval -/tests/compile/tconstraints -/tests/compile/tconvcolors -/tests/compile/tcputime -/tests/compile/tdefaultprocparam -/tests/compile/tdictdestruct -/tests/compile/tdiscardable -/tests/compile/tdllvar -/tests/compile/tdumpast -/tests/compile/tdumpast2 -/tests/compile/techo -/tests/compile/teffects1 -/tests/compile/temptyecho -/tests/compile/tendian -/tests/compile/tenum -/tests/compile/tenum2 -/tests/compile/tenum3 -/tests/compile/teval1 -/tests/compile/texport -/tests/compile/tfib -/tests/compile/tforwardgeneric -/tests/compile/tforwty -/tests/compile/tforwty2 -/tests/compile/tgeneric -/tests/compile/tgeneric2 -/tests/compile/tgeneric3 -/tests/compile/tgeneric4 -/tests/compile/tgenericmatcher -/tests/compile/tgenericmatcher2 -/tests/compile/tgenericprocvar -/tests/compile/tgenericprop -/tests/compile/tgenericrefs -/tests/compile/tgenerictmpl -/tests/compile/tgenericvariant -/tests/compile/tgensymgeneric -/tests/compile/tgetstartmilsecs -/tests/compile/tglobalforvar -/tests/compile/thallo -/tests/compile/theaproots -/tests/compile/thexrange -/tests/compile/thygienictempl -/tests/compile/tident -/tests/compile/timplicititems -/tests/compile/timplictderef -/tests/compile/tinheritref -/tests/compile/tio -/tests/compile/tircbot -/tests/compile/titer -/tests/compile/titer2 -/tests/compile/titer_no_tuple_unpack -/tests/compile/titerovl -/tests/compile/tlastmod -/tests/compile/tlinearscanend -/tests/compile/tloops -/tests/compile/tmacro1 -/tests/compile/tmacro2 -/tests/compile/tmacroaspragma -/tests/compile/tmacrostmt -/tests/compile/tmandelbrot -/tests/compile/tmarshal -/tests/compile/tmath -/tests/compile/tmatrix1 -/tests/compile/tmatrix2 -/tests/compile/tmongo -/tests/compile/tnamedparamanonproc -/tests/compile/tnamedparams -/tests/compile/tnestedproc -/tests/compile/tnew -/tests/compile/tnewsets -/tests/compile/tnewuns -/tests/compile/tnoargopenarray -/tests/compile/tnoforward -/tests/compile/tobjconstr2 -/tests/compile/tobjcov -/tests/compile/tobject2 -/tests/compile/tobject3 -/tests/compile/tobjects -/tests/compile/toop -/tests/compile/toptions -/tests/compile/tos -/tests/compile/toverprc -/tests/compile/tparedef -/tests/compile/tparscfg -/tests/compile/tparsefloat -/tests/compile/tparsopt -/tests/compile/tposix -/tests/compile/tprep -/tests/compile/tprocvars -/tests/compile/tpush -/tests/compile/tquicksort -/tests/compile/tquit -/tests/compile/tradix -/tests/compile/treadln -/tests/compile/treadx -/tests/compile/trecmod -/tests/compile/trecmod2 -/tests/compile/trectuple -/tests/compile/trectuples -/tests/compile/tredef -/tests/compile/trepr -/tests/compile/tsecondarrayproperty -/tests/compile/tseq2 -/tests/compile/tseqcon2 -/tests/compile/tshadow_magic_type -/tests/compile/tsizeof -/tests/compile/tslurp -/tests/compile/tsockets -/tests/compile/tsortcall -/tests/compile/tspecialised_is_equivalent -/tests/compile/tstrace -/tests/compile/tstrdesc -/tests/compile/tstrdist -/tests/compile/tstreams -/tests/compile/tstrset -/tests/compile/tstrtabs -/tests/compile/ttableconstr -/tests/compile/ttempl -/tests/compile/ttempl3 -/tests/compile/ttempl4 -/tests/compile/ttempl5 -/tests/compile/ttemplreturntype -/tests/compile/tthread_generic -/tests/compile/ttime -/tests/compile/ttuple1 -/tests/compile/ttypeclasses -/tests/compile/ttypeconverter1 -/tests/compile/tuserpragma -/tests/compile/tvoid -/tests/compile/twalker -/tests/compile/typalias -/tests/dll/client -/tests/gc/closureleak -/tests/gc/cycleleak -/tests/gc/gcbench -/tests/gc/gcleak -/tests/gc/gcleak2 -/tests/gc/gcleak3 -/tests/gc/gctest -/tests/gc/weakrefs -/tests/manyloc/argument_parser/ex_wget -/tests/manyloc/nake/nakefile -/tests/manyloc/packages/noconflicts -/tests/manyloc/standalone/barebone -/tests/patterns/targlist -/tests/patterns/tcse -/tests/patterns/thoist -/tests/patterns/tmatrix -/tests/patterns/tnoalias -/tests/patterns/tnoendlessrec -/tests/patterns/tor -/tests/patterns/tpartial -/tests/patterns/tstar -/tests/patterns/tstmtlist -/tests/reject/t99bott -/tests/reject/tcheckedfield1 -/tests/reject/tdeprecated -/tests/reject/tdisallowif -/tests/reject/tuninit1 -/tests/rodfiles/aconv -/tests/rodfiles/bconv -/tests/rodfiles/bmethods -/tests/rodfiles/bmethods2 -/tests/rodfiles/deada -/tests/rodfiles/deada2 -/tests/rodfiles/hallo -/tests/rodfiles/hallo2 -/tests/rodfiles/tgeneric1 -/tests/rodfiles/tgeneric2 -/tests/run/tack -/tests/run/tactiontable -/tests/run/tambsym2 -/tests/run/tambsys -/tests/run/tanontuples -/tests/run/tarray -/tests/run/tarray2 -/tests/run/tarray3 -/tests/run/tarraycons -/tests/run/tassert -/tests/run/tastoverload1 -/tests/run/tasynciossl -/tests/run/tasyncudp -/tests/run/tbind1 -/tests/run/tbind3 -/tests/run/tbintre2 -/tests/run/tbintree -/tests/run/tborrow -/tests/run/tbug499771 -/tests/run/tbug511622 -/tests/run/tcase_setconstr -/tests/run/tcasestm -/tests/run/tcgbug -/tests/run/tclosure2 -/tests/run/tclosure3 -/tests/run/tcnstseq -/tests/run/tcnstseq2 -/tests/run/tcnstseq3 -/tests/run/tconcat -/tests/run/tconstr2 -/tests/run/tcontinue -/tests/run/tcontinuexc -/tests/run/tcopy -/tests/run/tcountup -/tests/run/tcritbits -/tests/run/tcurrncy -/tests/run/tdestructor -/tests/run/tdrdobbs_examples -/tests/run/temit -/tests/run/tenumhole -/tests/run/tenumitems -/tests/run/teventemitter -/tests/run/tevents -/tests/run/texceptions -/tests/run/texcpt1 -/tests/run/texcsub -/tests/run/texplicitgeneric1 -/tests/run/tfieldindex -/tests/run/tfielditerator -/tests/run/tfielditerator2 -/tests/run/tfilter -/tests/run/tfinally -/tests/run/tfinally2 -/tests/run/tfinally3 -/tests/run/tfinalobj -/tests/run/tfloat1 -/tests/run/tfloat2 -/tests/run/tfloat3 -/tests/run/tformat -/tests/run/tfriends -/tests/run/tgenericassign -/tests/run/tgenericassigntuples -/tests/run/tgenericconverter -/tests/run/tgenericprocvar -/tests/run/tgenerics1 -/tests/run/tgensym -/tests/run/tglobal -/tests/run/thashes -/tests/run/thexlit -/tests/run/thintoff -/tests/run/tidgen -/tests/run/tindent1 -/tests/run/tinit -/tests/run/tinterf -/tests/run/tints -/tests/run/tisopr -/tests/run/titer3 -/tests/run/titer5 -/tests/run/titer6 -/tests/run/titer7 -/tests/run/titer8 -/tests/run/titer9 -/tests/run/titerslice -/tests/run/titervaropenarray -/tests/run/tkoeniglookup -/tests/run/tlet -/tests/run/tlists -/tests/run/tlocals -/tests/run/tlowhigh -/tests/run/tmacro2 -/tests/run/tmacro3 -/tests/run/tmacro4 -/tests/run/tmacros1 -/tests/run/tmath -/tests/run/tmatrix -/tests/run/tmemoization -/tests/run/tmethods1 -/tests/run/tmixin -/tests/run/tmoditer -/tests/run/tmultim1 -/tests/run/tmultim2 -/tests/run/tmultim3 -/tests/run/tmultim4 -/tests/run/tmultim6 -/tests/run/tnamedenumfields -/tests/run/tnestif -/tests/run/tnestprc -/tests/run/tnewderef -/tests/run/tnodeadlocks -/tests/run/tobjasgn -/tests/run/tobjconstr -/tests/run/tobject -/tests/run/tofopr -/tests/run/tonraise -/tests/run/toop1 -/tests/run/topenarrayrepr -/tests/run/topenlen -/tests/run/toprprec -/tests/run/toverflw -/tests/run/toverflw2 -/tests/run/toverl2 -/tests/run/toverl3 -/tests/run/toverwr -/tests/run/tovfint -/tests/run/tpatterns -/tests/run/tpegs -/tests/run/tpos -/tests/run/tprecedence -/tests/run/tprintf -/tests/run/tprocvar -/tests/run/tquotewords -/tests/run/tregex -/tests/run/treguse -/tests/run/trepr -/tests/run/treraise -/tests/run/tromans -/tests/run/tseqcon -/tests/run/tseqtuple -/tests/run/tsequtils -/tests/run/tsets -/tests/run/tsets2 -/tests/run/tsidee2 -/tests/run/tsidee3 -/tests/run/tsimmeth -/tests/run/tsimplesort -/tests/run/tslices -/tests/run/tsortdev -/tests/run/tsplit -/tests/run/tstempl -/tests/run/tstmtexprs -/tests/run/tstrange -/tests/run/tstringinterp -/tests/run/tstrlits -/tests/run/tstrutil -/tests/run/tsubrange -/tests/run/tsubrange2 -/tests/run/ttables -/tests/run/ttables2 -/tests/run/ttoseq -/tests/run/ttypedesc1 -/tests/run/tunhandledexc -/tests/run/tunidecode -/tests/run/tunittests -/tests/run/tuserassert -/tests/run/tvarargs_vs_generic -/tests/run/tvardecl -/tests/run/tvariantasgn -/tests/run/tvariantstack -/tests/run/tvarious1 -/tests/run/tvarnums -/tests/run/tvarres1 -/tests/run/tvarres2 -/tests/run/tvartup -/tests/run/tvtable -/tests/run/twrongexc -/tests/run/txmlgen -/tests/run/txmltree -/tests/run/tzeroarray -/tests/system/helpers/readall_echo -/tests/system/io -/tests/system/params -/tests/tester -/tests/threads/tactors -/tests/threads/tactors2 -/tests/threads/tthreadanalysis2 -/tests/threads/tthreadanalysis3 -/tests/threads/tthreadheapviolation1 -/tools/nimgrep +testament.db diff --git a/compiler/commands.nim b/compiler/commands.nim index 8339219edb..366019c190 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -50,11 +50,33 @@ proc writeAdvancedUsage(pass: TCmdLinePass) = CPU[platform.hostCPU].name]) & AdvancedUsage) quit(0) +template bootSwitch(name, expr, userString: expr): expr = + # Helper to build boot constants, for debugging you can 'echo' the else part. + const name = if expr: " " & userString else: "" + +bootSwitch(usedAvoidTimeMachine, noTimeMachine, "-d:avoidTimeMachine") +bootSwitch(usedRelease, defined(release), "-d:release") +bootSwitch(usedTinyC, hasTinyCBackend, "-d:tinyc") +bootSwitch(usedGnuReadline, defined(useGnuReadline), "-d:useGnuReadline") +bootSwitch(usedNativeStacktrace, + defined(nativeStackTrace) and nativeStackTraceSupported, + "-d:nativeStackTrace") +bootSwitch(usedNoCaas, defined(noCaas), "-d:noCaas") +bootSwitch(usedFFI, hasFFI, "-d:useFFI") +bootSwitch(usedBoehm, defined(boehmgc), "--gc:boehm") +bootSwitch(usedMarkAndSweep, defined(gcmarkandsweep), "--gc:markAndSweep") +bootSwitch(usedGenerational, defined(gcgenerational), "--gc:generational") +bootSwitch(usedNoGC, defined(nogc), "--gc:none") + + proc writeVersionInfo(pass: TCmdLinePass) = if pass == passCmd1: msgWriteln(`%`(HelpMessage, [VersionAsString, platform.OS[platform.hostOS].name, CPU[platform.hostCPU].name])) + msgWriteln("active boot switches:" & usedRelease & usedAvoidTimeMachine & + usedTinyC & usedGnuReadline & usedNativeStacktrace & usedNoCaas & + usedFFI & usedBoehm & usedMarkAndSweep & usedGenerational & usedNoGC) quit(0) var diff --git a/compiler/nversion.nim b/compiler/nversion.nim index b996d0b9b4..3c868ed2af 100644 --- a/compiler/nversion.nim +++ b/compiler/nversion.nim @@ -12,10 +12,9 @@ const MaxSetElements* = 1 shl 16 # (2^16) to support unicode character sets? - defaultAsmMarkerSymbol* = '!' VersionMajor* = 0 VersionMinor* = 9 - VersionPatch* = 4 + VersionPatch* = 5 VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch RodFileVersion* = "1215" # modify this if the rod-format changes! diff --git a/compiler/options.nim b/compiler/options.nim index 36d343d1b5..58a340d213 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -16,7 +16,7 @@ const hasFFI* = defined(useFFI) newScopeForIf* = true useCaas* = not defined(noCaas) - noTimeMachine = defined(avoidTimeMachine) and defined(macosx) + noTimeMachine* = defined(avoidTimeMachine) and defined(macosx) type # please make sure we have under 32 options # (improves code efficiency a lot!) diff --git a/doc/manual.txt b/doc/manual.txt index 98af5aebc6..39e2bad2aa 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -5688,7 +5688,7 @@ Spawn Nimrod has a builtin thread pool that can be used for CPU intensive tasks. For IO intensive tasks the upcoming ``async`` and ``await`` features should be -used. `spawn`:idx: is used to pass a task to the thread pool: +used instead. `spawn`:idx: is used to pass a task to the thread pool: .. code-block:: nimrod proc processLine(line: string) = diff --git a/examples/cross_calculator/.gitignore b/examples/cross_calculator/.gitignore new file mode 100644 index 0000000000..e521bf3389 --- /dev/null +++ b/examples/cross_calculator/.gitignore @@ -0,0 +1,12 @@ +# Android specific absolute paths. +android/bin/ +android/gen/ +android/jni/backend-jni.h +android/libs/ +android/local.properties +android/obj/ +android/tags +# iOS specific absolute paths +ios/resources/ui/*.m +ios/tags + diff --git a/koch.nim b/koch.nim index 9d59344f2b..79acc77915 100644 --- a/koch.nim +++ b/koch.nim @@ -299,7 +299,7 @@ of cmdArgument: of "boot": boot(op.cmdLineRest) of "clean": clean(op.cmdLineRest) of "web": web(op.cmdLineRest) - of "csource": csource(op.cmdLineRest) + of "csource", "csources": csource(op.cmdLineRest) of "zip": zip(op.cmdLineRest) of "inno": inno(op.cmdLineRest) of "install": install(op.cmdLineRest) diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index cd28f9af08..33e558aee2 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -10,6 +10,47 @@ ## The ``tables`` module implements an efficient hash table that is ## a mapping from keys to values. ## +## If you are using simple standard types like ``int`` or ``string`` for the +## keys of the table you won't have any problems, but as soon as you try to use +## a more complex object as a key you will be greeted by a strange compiler +## error:: +## +## Error: type mismatch: got (Person) +## but expected one of: +## hashes.hash(x: openarray[A]): THash +## hashes.hash(x: int): THash +## hashes.hash(x: float): THash +## … +## +## What is happening here is that the types used for table keys require to have +## a ``hash()`` proc which will convert them to a `THash `_ +## value, and the compiler is listing all the hash functions it knows. After +## you add such a proc for your custom type everything will work. See this +## example: +## +## .. code-block:: nimrod +## type +## Person = object +## firstName, lastName: string +## +## proc hash(x: Person): THash = +## ## Piggyback on the already available string hash proc. +## ## +## ## Without this proc nothing works! +## result = hash(x.firstName & x.lastName) +## +## var +## salaries = initTable[Person, int]() +## p1, p2: Person +## +## p1.firstName = "Jon" +## p1.lastName = "Ross" +## salaries[p1] = 30_000 +## +## p2.firstName = "소진" +## p2.lastName = "박" +## salaries[p2] = 45_000 +## ## **Note:** The data types declared here have *value semantics*: This means ## that ``=`` performs a copy of the hash table. @@ -526,3 +567,30 @@ proc sort*[A](t: var TCountTable[A]) = if j < h: break if h == 1: break +when isMainModule: + type + Person = object + firstName, lastName: string + + proc hash(x: Person): THash = + ## Piggyback on the already available string hash proc. + ## + ## Without this proc nothing works! + result = hash(x.firstName & x.lastName) + + var + salaries = initTable[Person, int]() + p1, p2: Person + p1.firstName = "Jon" + p1.lastName = "Ross" + salaries[p1] = 30_000 + p2.firstName = "소진" + p2.lastName = "박" + salaries[p2] = 45_000 + var + s2 = initOrderedTable[Person, int]() + s3 = initCountTable[Person]() + s2[p1] = 30_000 + s2[p2] = 45_000 + s3[p1] = 30_000 + s3[p2] = 45_000 diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 00a33db754..e2fc62d773 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -1612,6 +1612,20 @@ when defined(linux) or defined(solaris) or defined(bsd) or defined(aix): len = readlink(procPath, result, len) setLen(result, len) +when not (defined(windows) or defined(macosx)): + proc getApplHeuristic(): string = + when defined(paramStr): + result = string(paramStr(0)) + # POSIX guaranties that this contains the executable + # as it has been executed by the calling process + if len(result) > 0 and result[0] != DirSep: # not an absolute path? + # iterate over any path in the $PATH environment variable + for p in split(string(getEnv("PATH")), {PathSep}): + var x = joinPath(p, result) + if existsFile(x): return x + else: + result = "" + when defined(macosx): type cuint32* {.importc: "unsigned int", nodecl.} = int @@ -1648,10 +1662,13 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [FReadIO].} = setlen(result, int(len)) elif defined(linux) or defined(aix): result = getApplAux("/proc/self/exe") + if result.len == 0: result = getApplHeuristic() elif defined(solaris): result = getApplAux("/proc/" & $getpid() & "/path/a.out") + if result.len == 0: result = getApplHeuristic() elif defined(freebsd): result = getApplAux("/proc/" & $getpid() & "/file") + if result.len == 0: result = getApplHeuristic() elif defined(macosx): var size: cuint32 getExecPath1(nil, size) @@ -1663,15 +1680,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [FReadIO].} = else: # little heuristic that may work on other POSIX-like systems: result = string(getEnv("_")) - if len(result) == 0: - result = string(paramStr(0)) - # POSIX guaranties that this contains the executable - # as it has been executed by the calling process - if len(result) > 0 and result[0] != DirSep: # not an absolute path? - # iterate over any path in the $PATH environment variable - for p in split(string(getEnv("PATH")), {PathSep}): - var x = joinPath(p, result) - if existsFile(x): return x + if result.len == 0: result = getApplHeuristic() proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} = ## Returns the filename of the application's executable. diff --git a/lib/system.nim b/lib/system.nim index 4a5d46a7f6..ecee7dad75 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -234,6 +234,11 @@ template `>` * (x, y: expr): expr {.immediate.} = ## "is greater" operator. This is the same as ``y < x``. y < x +const + appType* {.magic: "AppType"}: string = "" + ## a string that describes the application type. Possible values: + ## "console", "gui", "lib". + include "system/inclrtl" const NoFakeVars* = defined(NimrodVM) ## true if the backend doesn't support \ @@ -940,10 +945,6 @@ const ## a string that describes the host CPU. Possible values: ## "i386", "alpha", "powerpc", "sparc", "amd64", "mips", "arm". - appType* {.magic: "AppType"}: string = "" - ## a string that describes the application type. Possible values: - ## "console", "gui", "lib". - seqShallowFlag = low(int) proc compileOption*(option: string): bool {. diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 2f7c5ed514..2dc134eaf4 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -77,7 +77,7 @@ proc popCurrentException {.compilerRtl, inl.} = # some platforms have native support for stack traces: const - nativeStackTraceSupported = (defined(macosx) or defined(linux)) and + nativeStackTraceSupported* = (defined(macosx) or defined(linux)) and not nimrodStackTrace hasSomeStackTrace = nimrodStackTrace or defined(nativeStackTrace) and nativeStackTraceSupported diff --git a/lib/system/inclrtl.nim b/lib/system/inclrtl.nim index 12eb90162c..5c82db4da3 100644 --- a/lib/system/inclrtl.nim +++ b/lib/system/inclrtl.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2013 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. diff --git a/lib/wrappers/sqlite3.nim b/lib/wrappers/sqlite3.nim index 586f763ae2..7b7f0874e6 100644 --- a/lib/wrappers/sqlite3.nim +++ b/lib/wrappers/sqlite3.nim @@ -106,15 +106,15 @@ type Pstmt* = ptr Tstmt Tvalue{.pure, final.} = object Pvalue* = ptr Tvalue - PPValue* = ptr Pvalue + PValueArg* = array[0..127, Pvalue] Tcallback* = proc (para1: pointer, para2: int32, para3, para4: cstringArray): int32{.cdecl.} Tbind_destructor_func* = proc (para1: pointer){.cdecl.} Tcreate_function_step_func* = proc (para1: Pcontext, para2: int32, - para3: PPValue){.cdecl.} + para3: PValueArg){.cdecl.} Tcreate_function_func_func* = proc (para1: Pcontext, para2: int32, - para3: PPValue){.cdecl.} + para3: PValueArg){.cdecl.} Tcreate_function_final_func* = proc (para1: Pcontext){.cdecl.} Tresult_func* = proc (para1: pointer){.cdecl.} Tcreate_collation_func* = proc (para1: pointer, para2: int32, para3: pointer, diff --git a/tests/system/tsysspawn.nim b/tests/system/tsysspawn.nim new file mode 100644 index 0000000000..0388918aa8 --- /dev/null +++ b/tests/system/tsysspawn.nim @@ -0,0 +1,29 @@ +discard """ + output: '''4 +8''' + cmd: "nimrod $target --threads:on $options $file" +""" + +var + x, y = 0 + +proc p1 = + for i in 0 .. 1_000_000: + discard + + inc x + +proc p2 = + for i in 0 .. 1_000_000: + discard + + inc y, 2 + +for i in 0.. 3: + spawn(p1()) + spawn(p2()) + +sync() + +echo x +echo y diff --git a/tools/website.tmpl b/tools/website.tmpl index bd68bdb062..1d62427362 100644 --- a/tools/website.tmpl +++ b/tools/website.tmpl @@ -71,7 +71,7 @@