├── web ├── links.txt ├── assets │ └── images │ │ ├── bg.png │ │ ├── foot.png │ │ ├── head.png │ │ ├── logo.png │ │ ├── mascot.png │ │ ├── quote.png │ │ ├── quotes.png │ │ ├── tabEnd.png │ │ ├── favicon.ico │ │ ├── sidebar.png │ │ ├── docs-tools.png │ │ ├── glow-arrow.png │ │ ├── glow-line.png │ │ ├── head-link.png │ │ ├── link_aporia.png │ │ ├── link_forum.png │ │ ├── sidebar_h2.png │ │ ├── site_foot.png │ │ ├── site_neck.png │ │ ├── docs-articles.png │ │ ├── docs-examples.png │ │ ├── link_nimbuild.png │ │ ├── sidebar_head.png │ │ ├── slideshow-nav.png │ │ ├── docs-internals.png │ │ ├── docs-libraries.png │ │ ├── docs-tutorials.png │ │ ├── head-link_hover.png │ │ ├── more-links_forum.png │ │ ├── more-links_editors.png │ │ ├── more-links_github.png │ │ ├── more-links_nimbuild.png │ │ └── slideshow-nav_active.png └── snippets │ └── snippet1.nim ├── koch.nim.cfg ├── lib ├── pure │ ├── smtp.nim.cfg │ ├── nimprof.nim.cfg │ ├── concurrency │ │ └── threadpool.nim.cfg │ ├── asyncdispatch.nim.cfg │ └── actors.nim.cfg ├── nimrtl.nim.cfg ├── impure │ ├── nre │ │ └── .gitignore │ ├── osinfo_win.nim │ └── osinfo_posix.nim ├── stdlib.nimble └── packages │ └── docutils │ └── docutils.babel ├── tests ├── parallel │ ├── nim.cfg │ ├── tsysspawnbadarg.nim │ ├── tlet_spawn.nim │ ├── tdont_be_stupid.nim │ └── tdeepcopy.nim ├── threads │ ├── nim.cfg │ ├── tactors.nim │ └── trecursive_actor.nim ├── manyloc │ ├── packages │ │ ├── package1 │ │ │ ├── p1.babel │ │ │ └── strutils.nim │ │ ├── package2 │ │ │ ├── p2.babel │ │ │ └── strutils.nim │ │ ├── noconflicts.nim.cfg │ │ ├── os.nim │ │ └── noconflicts.nim │ ├── nake │ │ └── nakefile.nim.cfg │ ├── standalone │ │ ├── barebone.nim.cfg │ │ └── barebone.nim │ ├── argument_parser │ │ └── ex_wget.nim.cfg │ ├── keineschweine │ │ ├── dependencies │ │ │ └── sfml │ │ │ │ ├── sfml_vector.nim │ │ │ │ └── README.md │ │ ├── server │ │ │ ├── nim.cfg │ │ │ └── dirserver_settings.json │ │ ├── enet_server │ │ │ ├── server_settings.json │ │ │ └── nim.cfg │ │ ├── client_settings.json │ │ ├── keineschweine.nim.cfg │ │ └── lib │ │ │ └── math_helpers.nim │ └── named_argument_bug │ │ ├── main.nim.cfg │ │ └── tri_engine │ │ ├── config.nim │ │ └── math │ │ ├── rect.nim │ │ └── circle.nim ├── misc │ ├── temptyecho.nim │ ├── 99bottles.nim │ ├── tparedef.nim │ ├── tendian.nim │ ├── minit.nim │ ├── mvarious.nim │ ├── tnewderef.nim │ ├── tgetstartmilsecs.nim │ ├── tcharinc.nim │ ├── tnewsets.nim │ ├── tinc.nim │ ├── tnolen.nim │ ├── tfib.nim │ ├── tnoop.nim │ ├── thintoff.nim │ ├── tlocals.nim │ ├── tnoforward.nim │ ├── tnewuns.nim │ ├── tatomic.nim │ ├── tsizeof.nim │ ├── tcolonisproc.nim │ ├── tunsignedinc.nim │ ├── trawstr.nim │ ├── tsimtych.nim │ ├── tinvalidarrayaccess.nim │ ├── tissue710.nim │ ├── tunsignedcmp.nim │ ├── tinout.nim │ ├── tinit.nim │ ├── treadln.nim │ ├── tbug1217bracketquotes.nim │ ├── tcmdline.nim │ ├── tstrace.nim │ ├── temit.nim │ ├── tnoinst.nim │ ├── tmemoization.nim │ ├── tstrdesc.nim │ ├── tbug511622.nim │ ├── treadx.nim │ └── tdllvar.nim ├── dll │ ├── client.nim.cfg │ └── server.nim.cfg ├── modules │ ├── mrecmod.nim │ ├── mnamspc1.nim │ ├── trecmod.nim │ ├── mnamspc2.nim │ ├── mexport2b.nim │ ├── mexport2a.nim │ ├── mexportb.nim │ ├── mopaque.nim │ ├── mexporta.nim │ ├── timportexcept.nim │ ├── texport2.nim │ ├── mrecmod2.nim │ ├── tselfimport.nim │ ├── tnamspc.nim │ ├── trecincb.nim │ ├── trecmod2.nim │ ├── trecinca.nim │ ├── texport.nim │ ├── tmismatchedvisibility.nim │ └── topaque.nim ├── clearmsg │ ├── mb.nim │ ├── mc.nim │ ├── tconsttypemismatch.nim │ └── ta.nim ├── testament │ └── tester.nim.cfg ├── ambsym │ ├── mambsym2.nim │ ├── mambsys2.nim │ ├── mambsys1.nim │ ├── tambsys.nim │ ├── mambsym1.nim │ ├── tambsym.nim │ └── tambsym3.nim ├── implicit │ └── timplicititems.nim ├── rodfiles │ ├── nim.cfg │ ├── deadb.nim │ ├── hallo.nim │ ├── deada.nim │ ├── int2bool.nim │ ├── aconv.nim │ ├── bconv.nim │ ├── deadg.nim │ ├── deada2.nim │ ├── tgeneric1.nim │ ├── tgeneric2.nim │ ├── amethods.nim │ ├── hallo2.nim │ └── gtkex1.nim ├── stdlib │ ├── techo.nim │ ├── ttime.nim │ ├── nre │ │ ├── optional_nonstrict.nim │ │ └── escape.nim │ ├── tsortcall.nim │ ├── tio.nim │ ├── tquit.nim │ ├── tnre.nim │ ├── tstreams.nim │ ├── thashes.nim │ ├── tcputime.nim │ ├── treloop.nim │ ├── txmlgen.nim │ ├── txmltree.nim │ ├── tos.nim │ ├── tposix.nim │ ├── tsplit.nim │ ├── tunidecode.nim │ ├── tformat.nim │ ├── tpermutations.nim │ ├── twalker.nim │ └── tstrtabs.nim ├── assert │ ├── tunittests.nim │ └── tuserassert.nim ├── osproc │ └── ta.nim ├── system │ ├── helpers │ │ └── readall_echo.nim │ ├── tsettostring.nim │ ├── toString.nim │ └── tfloatToString.nim ├── caas │ ├── imported.nim │ ├── main.nim │ ├── compile-suggest.txt │ ├── def-then-compile.txt │ ├── forward_declarations.txt │ ├── issue_477_dynamic_dispatch.txt │ ├── main_dirty.nim │ ├── compile-then-def.txt │ ├── def-def-compile.txt │ ├── issue_452_export_shift.nim │ ├── basic-recompile.txt │ ├── completion_dot_syntax.txt │ ├── forward_declarations.nim │ ├── its_full_of_procs.txt │ └── issue_416_template_shift.nim ├── defaultprocparam │ ├── tdefaultprocparam.nim │ └── mdefaultprocparam.nim ├── converter │ ├── tconvcolors.nim │ └── ttypeconverter1.nim ├── cpp │ ├── trawsockets.nim │ ├── ttypeinfo.nim │ ├── ttypeinfo2.nim │ ├── tthread_createthread.nim │ ├── tcppraise.nim │ ├── tvector_iterator.nim │ └── tstaticvar_via_typedesc.nim ├── realtimeGC │ ├── shared.nim.cfg │ └── main.nim.cfg ├── js │ ├── tfloatround.nim │ ├── tunittests.nim │ ├── tcopying.nim │ ├── testmagic.nim │ └── tobjfieldbyvar.nim ├── rectest.nim ├── global │ ├── globalaux2.nim │ ├── tglobalforvar.nim │ └── globalaux.nim ├── testdata │ ├── data.csv │ ├── csvtest.csv │ └── doc1.xml ├── template │ ├── ttemplreturntype.nim │ ├── mtempl5.nim │ ├── ttempl4.nim │ ├── tcan_access_hidden_field.nim │ ├── tit.nim │ ├── mcan_access_hidden_field.nim │ ├── tissue909.nim │ ├── tsymchoicefield.nim │ ├── tdefault_nil.nim │ ├── tscope.nim │ ├── thygienictempl.nim │ ├── tmodulealias.nim │ └── twrongsymkind.nim ├── enum │ ├── tenum.nim │ ├── tenumitems.nim │ ├── tenummix.nim │ ├── tenumitems2.nim │ ├── tenum3.nim │ └── tenum2.nim ├── exprs │ ├── thighCString.nim │ ├── tresultwarning.nim │ ├── tstmtexp.nim │ ├── texprstmt.nim │ └── tifexpr_typeinference.nim ├── dir with space │ └── tspace.nim ├── pragmas │ ├── tuserpragma.nim │ ├── tsym_as_pragma.nim │ └── tpush.nim ├── typerel │ ├── tnoargopenarray.nim │ ├── ttypedesc_as_genericparam1.nim │ ├── ttypelessemptyset.nim │ ├── tno_int_in_bool_context.nim │ ├── ttypedesc_as_genericparam2.nim │ ├── typredef.nim │ ├── ttypenovalue.nim │ ├── typedescs.nim │ ├── typalias.nim │ ├── tnocontains.nim │ ├── trectuples.nim │ ├── tregionptrs.nim │ ├── trectuple.nim │ ├── tstr_as_openarray.nim │ ├── tsymchoice_for_expr.nim │ ├── tno_gcmem_in_shared.nim │ └── tregionptrs2.nim ├── lexer │ ├── thexrange.nim │ ├── thexlit.nim │ ├── tmissingnl.nim │ └── tunderscores.nim ├── procvar │ ├── tgenericprocvar.nim │ ├── tprocvars.nim │ └── tprocvar.nim ├── closure │ ├── tissue1642.nim │ ├── tnestedproc.nim │ ├── tinvalidclosure2.nim │ ├── tinvalidclosure.nim │ ├── uclosures.nim │ ├── tnamedparamanonproc.nim │ └── ttimeinfo.nim ├── bind │ ├── mbind3.nim │ ├── tbind3.nim │ ├── tinvalidbindtypedesc.nim │ ├── tbindoverload.nim │ ├── tmixin.nim │ └── tbind2.nim ├── concat │ └── tconcat.nim ├── concepts │ ├── tvarconcept.nim │ └── mvarconcept.nim ├── generics │ ├── tdotlookup.nim │ ├── tableref_is_nil.nim │ ├── tbadgenericlambda.nim │ ├── tsigtypeop.nim │ ├── tgeneric4.nim │ ├── tcan_alias_generic.nim │ ├── tcan_specialise_generic.nim │ ├── tgenerictmpl.nim │ ├── tarray_with_somenumber.nim │ ├── tforwardgeneric.nim │ ├── tspecialised_is_equivalent.nim │ ├── tcan_alias_specialised_generic.nim │ ├── tcan_inherit_generic.nim │ ├── t1050.nim │ ├── tgeneric_inheritance.nim │ ├── tlateboundstatic.nim │ ├── tgeneric2.nim │ ├── tconfusing_arrow.nim │ ├── mdotlookup.nim │ ├── tgenericprop.nim │ ├── moverloading_typedesc.nim │ ├── tsubtypeconstraint.nim │ ├── tcannot_pass_empty_seq_to_generic.nim │ ├── tmetafield.nim │ ├── tinferredgenericprocs.nim │ └── tgenericmatcher2.nim ├── iter │ ├── titerslice.nim │ ├── tcountup.nim │ ├── twrongiter.nim │ ├── titer5.nim │ ├── titer4.nim │ ├── titer_no_tuple_unpack.nim │ ├── tobj_iter.nim │ ├── treciter.nim │ ├── titervaropenarray.nim │ ├── titer9.nim │ ├── titerovl.nim │ └── tconcat.nim ├── types │ ├── tforwty.nim │ ├── tinfiniterecursion.nim │ ├── tauto_canbe_void.nim │ ├── tfinalobj.nim │ └── tillrec.nim ├── range │ ├── compilehelpers.nim │ ├── tsubrange2.nim │ ├── tsubrange3.nim │ ├── tsubrange.nim │ └── tbug499771.nim ├── array │ ├── troof3.nim │ ├── troof2.nim │ ├── tarray3.nim │ ├── tarrayplus.nim │ └── tarraycons2.nim ├── objects │ ├── tillegal_recursion.nim │ ├── tobjloop.nim │ ├── toop.nim │ ├── tobject2.nim │ └── tobject.nim ├── namedparams │ ├── tnamedparams2.nim │ ├── tnamedparams3.nim │ └── tnamedparams.nim ├── deprecated │ └── tdeprecated.nim ├── macros │ ├── tsame_name_497.nim │ ├── tmacroaspragma.nim │ ├── tmacro_in_template.nim │ ├── tnimnode_for_runtime.nim │ ├── treturnsempty.nim │ ├── trecmacro.nim │ ├── tmacrotypes.nim │ ├── tprintf.nim │ ├── texprcolonexpr.nim │ ├── tvarnimnode.nim │ ├── tidgen.nim │ ├── tmacro1.nim │ └── tmemit.nim ├── tuples │ ├── tgeneric_tuple.nim │ ├── tuint_tuple.nim │ ├── twrongtupleaccess.nim │ ├── tdifferent_instantiations.nim │ └── tanontuples.nim ├── method │ ├── tmethod.nim │ ├── mmultim3.nim │ ├── tsimmeth.nim │ ├── temptybody.nim │ └── tmultim3.nim ├── metatype │ ├── typedesc_as_value.nim │ ├── ttypebar.nim │ ├── tconstraints.nim │ ├── tstatic_overloading.nim │ ├── tautonotgeneric.nim │ ├── tautoproc.nim │ └── utypeclasses.nim ├── stckovfl.nim ├── friends │ ├── mfriends.nim │ └── tfriends.nim ├── vm │ ├── toverflowopcsubimmint.nim │ ├── twrongconst.nim │ ├── toverflowopcmulint.nim │ ├── toverflowopcaddimmint.nim │ ├── toverflowopcaddint.nim │ ├── toverflowopcsubint.nim │ ├── tconstobj.nim │ ├── twrongwhen.nim │ ├── tldconst.nim │ ├── tslurp.nim │ ├── tconsttable.nim │ └── tquadplus.nim ├── cnstseq │ ├── tcnstseq3.nim │ ├── tcnstseq2.nim │ └── tcnstseq.nim ├── distinct │ └── tborrowdot.nim ├── proc │ ├── tprocredef.nim │ └── tnestprc.nim ├── overload │ ├── tissue966.nim │ ├── toverl.nim │ └── toverwr.nim ├── sets │ └── tsets_lt.nim ├── trmacros │ ├── tnoendlessrec.nim │ ├── targlist.nim │ ├── tnoalias.nim │ ├── tpartial.nim │ ├── thoist.nim │ ├── tcse.nim │ ├── tstmtlist.nim │ ├── tpatterns.nim │ └── tnoalias2.nim ├── discard │ └── tneedsdiscard.nim ├── openarray │ ├── topena1.nim │ └── topenarrayrepr.nim ├── showoff │ ├── thello2.nim │ ├── thtml1.nim │ ├── tquasiquote.nim │ └── tonce.nim ├── varres │ ├── tvarres3.nim │ ├── tvarres2.nim │ ├── tvarres1.nim │ └── tvartup.nim ├── gensym │ └── tgensym.nim ├── seq │ ├── tseqcon2.nim │ ├── ttoseq.nim │ └── tseq2.nim ├── async │ └── tnestedpfuturetypeparam.nim ├── ccgbugs │ ├── tarray_equality.nim │ ├── taddhigh.nim │ ├── trecursive_table.nim │ ├── tpartialcs.nim │ ├── tbug1081.nim │ ├── tconstobj.nim │ ├── trecursive_closure.nim │ └── tmissingvolatile.nim ├── casestmt │ ├── tcaseoverlaprange.nim │ ├── tcase_setconstr.nim │ ├── tcaseoverlaprange2.nim │ └── tcase_arrayconstr.nim ├── parser │ ├── tinvcolonlocation1.nim │ ├── tinvcolonlocation3.nim │ ├── twhen_in_enum.nim │ ├── tprecedence.nim │ ├── tdomulttest.nim │ └── tinvcolonlocation2.nim ├── assign │ ├── moverload_asgn2.nim │ ├── tgenericassigntuples.nim │ └── toverload_asgn2.nim ├── let │ ├── tlet.nim │ └── tlet2.nim ├── overflw │ └── toverflw2.nim ├── controlflow │ ├── tstatret.nim │ └── tblock1.nim ├── varstmt │ ├── tvardecl.nim │ └── tlet.nim ├── exception │ ├── twrongexc.nim │ ├── tfinally3.nim │ ├── texcsub.nim │ ├── tdefer1.nim │ └── tfinally.nim ├── borrow │ └── tinvalidborrow.nim ├── objvariant │ └── temptycaseobj.nim ├── effects │ ├── tsidee2.nim │ ├── teffects5.nim │ ├── tsidee3.nim │ ├── teffects3.nim │ ├── tsidee4.nim │ ├── tgcsafe.nim │ └── tsidee1.nim ├── init │ └── tzeroarray.nim ├── lookups │ └── tkoeniglookup.nim ├── notnil │ ├── tnotnil_in_objconstr.nim │ ├── tnotnil2.nim │ ├── tnotnil.nim │ └── tnotnil4.nim ├── compiles │ └── tevilcompiles.nim ├── fields │ └── tfields_in_template.nim ├── float │ ├── tfloat1.nim │ └── tfloat2.nim ├── collections │ └── ttableconstr.nim ├── constraints │ └── tconstraints.nim └── astoverload │ └── tastoverload1.nim ├── tinyc ├── config.texi ├── win32 │ ├── include │ │ ├── sys │ │ │ ├── time.h │ │ │ ├── fcntl.h │ │ │ ├── unistd.h │ │ │ └── file.h │ │ ├── values.h │ │ ├── mem.h │ │ ├── stdbool.h │ │ ├── unistd.h │ │ ├── memory.h │ │ └── varargs.h │ ├── lib │ │ ├── libtcc1.a │ │ ├── dllmain.c │ │ └── dllcrt1.c │ ├── libtcc │ │ └── libtcc.a │ └── examples │ │ ├── dll.c │ │ └── hello_dll.c ├── arm-gen.c ├── examples │ ├── ex5.c │ └── ex1.c ├── include │ ├── stdbool.h │ └── varargs.h └── stab.h ├── icons ├── koch.rc ├── nim.rc ├── nim.ico ├── nim.res ├── koch.ico ├── koch.res ├── koch_icon.o └── nim_icon.o ├── examples ├── hallo.nim ├── cgi │ ├── cgi_stacktrace.nim │ ├── example.nim │ └── cgi_server.py ├── myfile.txt ├── cross_calculator │ ├── nim_backend │ │ └── backend.nim │ ├── android │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ └── scripts │ │ │ └── tags.sh │ ├── nim_commandline │ │ └── nim.cfg │ ├── ios │ │ ├── src │ │ │ ├── AppDelegate.h │ │ │ ├── cross-calculator-Prefix.pch │ │ │ └── main.m │ │ └── scripts │ │ │ └── tags.sh │ ├── .gitignore │ └── lazarus │ │ ├── nimlaz.rc │ │ └── readme.txt ├── readme.txt ├── talk │ ├── tags.nim │ ├── lazyeval.nim │ └── quasiquote.nim ├── cross_todo │ ├── nim_commandline │ │ └── nim.cfg │ └── readme.txt ├── maximum.nim ├── keyval2.nim ├── keyval.nim ├── transff.nim ├── fizzbuzz.nim ├── curlex.nim └── debugging.nim ├── bin └── empty.txt ├── contributors.txt ├── tools ├── nimgrep.nim.cfg └── detect │ └── timesize.c ├── start.bat ├── config └── rename.rules.cfg ├── compiler ├── testability.nim ├── nodejs.nim ├── readme.txt ├── plugins │ └── active.nim ├── nimfix │ └── nimfix.nim.cfg ├── nimsuggest │ └── nimsuggest.nim └── nim.cfg ├── install.sh.template ├── doc ├── overview.txt ├── manual │ └── compiler_msgs.txt ├── docgen_sample.nim └── readme.txt ├── compiler.nimble └── bootstrap.sh /web/links.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /koch.nim.cfg: -------------------------------------------------------------------------------- 1 | -d:booting -------------------------------------------------------------------------------- /lib/pure/smtp.nim.cfg: -------------------------------------------------------------------------------- 1 | -d:ssl 2 | -------------------------------------------------------------------------------- /tests/parallel/nim.cfg: -------------------------------------------------------------------------------- 1 | threads:on 2 | -------------------------------------------------------------------------------- /tests/threads/nim.cfg: -------------------------------------------------------------------------------- 1 | threads:on 2 | -------------------------------------------------------------------------------- /lib/pure/nimprof.nim.cfg: -------------------------------------------------------------------------------- 1 | --profiler:on 2 | -------------------------------------------------------------------------------- /tests/manyloc/packages/package1/p1.babel: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/manyloc/packages/package2/p2.babel: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/misc/temptyecho.nim: -------------------------------------------------------------------------------- 1 | echo() 2 | 3 | -------------------------------------------------------------------------------- /tinyc/config.texi: -------------------------------------------------------------------------------- 1 | @set VERSION 0.9.25 2 | -------------------------------------------------------------------------------- /tests/dll/client.nim.cfg: -------------------------------------------------------------------------------- 1 | --define:useNimRtl 2 | -------------------------------------------------------------------------------- /tests/modules/mrecmod.nim: -------------------------------------------------------------------------------- 1 | import trecmod 2 | -------------------------------------------------------------------------------- /icons/koch.rc: -------------------------------------------------------------------------------- 1 | kochicon ICON "koch.ico" 2 | 3 | 4 | -------------------------------------------------------------------------------- /icons/nim.rc: -------------------------------------------------------------------------------- 1 | nimicon ICON "nim.ico" 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/modules/mnamspc1.nim: -------------------------------------------------------------------------------- 1 | import mnamspc2 2 | 3 | -------------------------------------------------------------------------------- /lib/pure/concurrency/threadpool.nim.cfg: -------------------------------------------------------------------------------- 1 | --threads:on 2 | -------------------------------------------------------------------------------- /tests/clearmsg/mb.nim: -------------------------------------------------------------------------------- 1 | type 2 | typ* = distinct string 3 | -------------------------------------------------------------------------------- /tests/clearmsg/mc.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | typ* = distinct int 4 | -------------------------------------------------------------------------------- /tests/dll/server.nim.cfg: -------------------------------------------------------------------------------- 1 | --define:useNimRtl 2 | --app:lib 3 | -------------------------------------------------------------------------------- /tinyc/win32/include/sys/time.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | -------------------------------------------------------------------------------- /tests/manyloc/nake/nakefile.nim.cfg: -------------------------------------------------------------------------------- 1 | path = "dependencies/nake" 2 | -------------------------------------------------------------------------------- /examples/hallo.nim: -------------------------------------------------------------------------------- 1 | # Hello world program 2 | 3 | echo "Hello World" 4 | -------------------------------------------------------------------------------- /icons/nim.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/icons/nim.ico -------------------------------------------------------------------------------- /icons/nim.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/icons/nim.res -------------------------------------------------------------------------------- /lib/pure/asyncdispatch.nim.cfg: -------------------------------------------------------------------------------- 1 | @if nimdoc: 2 | --os:linux 3 | @end 4 | -------------------------------------------------------------------------------- /tests/modules/trecmod.nim: -------------------------------------------------------------------------------- 1 | # recursive module 2 | import mrecmod 3 | -------------------------------------------------------------------------------- /tests/testament/tester.nim.cfg: -------------------------------------------------------------------------------- 1 | path = "$nim" # For compiler/nodejs 2 | -------------------------------------------------------------------------------- /icons/koch.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/icons/koch.ico -------------------------------------------------------------------------------- /icons/koch.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/icons/koch.res -------------------------------------------------------------------------------- /lib/pure/actors.nim.cfg: -------------------------------------------------------------------------------- 1 | # to shut up the tester: 2 | --threads:on 3 | 4 | -------------------------------------------------------------------------------- /tests/ambsym/mambsym2.nim: -------------------------------------------------------------------------------- 1 | type 2 | TExport* = enum a, b, c 3 | 4 | -------------------------------------------------------------------------------- /tests/manyloc/packages/noconflicts.nim.cfg: -------------------------------------------------------------------------------- 1 | # Mark noconflicts as project file -------------------------------------------------------------------------------- /tinyc/arm-gen.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/tinyc/arm-gen.c -------------------------------------------------------------------------------- /bin/empty.txt: -------------------------------------------------------------------------------- 1 | This file keeps several tools from deleting this subdirectory. 2 | -------------------------------------------------------------------------------- /contributors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/contributors.txt -------------------------------------------------------------------------------- /icons/koch_icon.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/icons/koch_icon.o -------------------------------------------------------------------------------- /icons/nim_icon.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/icons/nim_icon.o -------------------------------------------------------------------------------- /tests/implicit/timplicititems.nim: -------------------------------------------------------------------------------- 1 | 2 | for x in [1, 2, 3, 4]: 3 | echo x 4 | 5 | -------------------------------------------------------------------------------- /tests/misc/99bottles.nim: -------------------------------------------------------------------------------- 1 | # Test if the compiler detects invalid module names 2 | -------------------------------------------------------------------------------- /tests/rodfiles/nim.cfg: -------------------------------------------------------------------------------- 1 | --nimcache:"$projectPath/nimcache" 2 | --symbolFiles:on 3 | -------------------------------------------------------------------------------- /tests/stdlib/techo.nim: -------------------------------------------------------------------------------- 1 | # Simplest Nim program 2 | 3 | echo "Hello, World!" 4 | -------------------------------------------------------------------------------- /tests/assert/tunittests.nim: -------------------------------------------------------------------------------- 1 | import "../template/utemplates", "../closure/uclosures" 2 | -------------------------------------------------------------------------------- /tests/modules/mnamspc2.nim: -------------------------------------------------------------------------------- 1 | # export an identifier: 2 | var 3 | global*: int 4 | -------------------------------------------------------------------------------- /tests/osproc/ta.nim: -------------------------------------------------------------------------------- 1 | import strutils 2 | let x = stdin.readLine() 3 | echo x.parseInt + 5 -------------------------------------------------------------------------------- /tests/rodfiles/deadb.nim: -------------------------------------------------------------------------------- 1 | 2 | import deadg 3 | 4 | 5 | echo p1(123, 123) 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/system/helpers/readall_echo.nim: -------------------------------------------------------------------------------- 1 | when isMainModule: 2 | echo(stdin.readAll) 3 | -------------------------------------------------------------------------------- /tools/nimgrep.nim.cfg: -------------------------------------------------------------------------------- 1 | # The GC is stable enough now: 2 | 3 | #--gc:none 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/caas/imported.nim: -------------------------------------------------------------------------------- 1 | proc `+++`*(a,b: string): string = 2 | return a & " " & b 3 | 4 | -------------------------------------------------------------------------------- /tests/defaultprocparam/tdefaultprocparam.nim: -------------------------------------------------------------------------------- 1 | 2 | import mdefaultprocparam 3 | 4 | p() 5 | -------------------------------------------------------------------------------- /tests/converter/tconvcolors.nim: -------------------------------------------------------------------------------- 1 | 2 | import colors 3 | 4 | echo int32(colWhite), 'A' 5 | 6 | -------------------------------------------------------------------------------- /tests/manyloc/standalone/barebone.nim.cfg: -------------------------------------------------------------------------------- 1 | --os:standalone 2 | --deadCodeElim:on 3 | --gc:none 4 | -------------------------------------------------------------------------------- /tinyc/win32/lib/libtcc1.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/tinyc/win32/lib/libtcc1.a -------------------------------------------------------------------------------- /web/assets/images/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/bg.png -------------------------------------------------------------------------------- /tests/cpp/trawsockets.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp $file" 3 | """ 4 | 5 | import rawsockets 6 | -------------------------------------------------------------------------------- /tests/cpp/ttypeinfo.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp $file" 3 | """ 4 | 5 | import typeinfo 6 | -------------------------------------------------------------------------------- /tests/misc/tparedef.nim: -------------------------------------------------------------------------------- 1 | # This test is now superfluous: 2 | 3 | proc a(a: int) = 4 | return 5 | -------------------------------------------------------------------------------- /tests/modules/mexport2b.nim: -------------------------------------------------------------------------------- 1 | proc printXyz*() = echo "xyz" 2 | 3 | proc foo*(x: int) = echo "B.foo" 4 | -------------------------------------------------------------------------------- /tests/realtimeGC/shared.nim.cfg: -------------------------------------------------------------------------------- 1 | --app:lib 2 | --threads:on 3 | 4 | -d:release 5 | -d:useRealtimeGC 6 | -------------------------------------------------------------------------------- /tinyc/win32/libtcc/libtcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/tinyc/win32/libtcc/libtcc.a -------------------------------------------------------------------------------- /web/assets/images/foot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/foot.png -------------------------------------------------------------------------------- /web/assets/images/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/head.png -------------------------------------------------------------------------------- /web/assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/logo.png -------------------------------------------------------------------------------- /web/assets/images/mascot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/mascot.png -------------------------------------------------------------------------------- /web/assets/images/quote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/quote.png -------------------------------------------------------------------------------- /web/assets/images/quotes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/quotes.png -------------------------------------------------------------------------------- /web/assets/images/tabEnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/tabEnd.png -------------------------------------------------------------------------------- /tests/js/tfloatround.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: ''' 3 | 3 4 | ''' 5 | """ 6 | 7 | echo int(22 / 7) 8 | -------------------------------------------------------------------------------- /tests/misc/tendian.nim: -------------------------------------------------------------------------------- 1 | # test the new endian magic 2 | 3 | writeLine(stdout, repr(system.cpuEndian)) 4 | -------------------------------------------------------------------------------- /tests/rectest.nim: -------------------------------------------------------------------------------- 1 | # Test the error message 2 | 3 | proc main() = 4 | main() 5 | 6 | main() 7 | -------------------------------------------------------------------------------- /web/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/favicon.ico -------------------------------------------------------------------------------- /web/assets/images/sidebar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/sidebar.png -------------------------------------------------------------------------------- /tests/global/globalaux2.nim: -------------------------------------------------------------------------------- 1 | import globalaux 2 | 3 | echo "in globalaux2: ", globalInstance[int]().val 4 | 5 | -------------------------------------------------------------------------------- /tests/manyloc/argument_parser/ex_wget.nim.cfg: -------------------------------------------------------------------------------- 1 | # This file exists only to mark 'ex_wget' as the project file 2 | -------------------------------------------------------------------------------- /tests/manyloc/packages/os.nim: -------------------------------------------------------------------------------- 1 | 2 | # Overrides lib/pure/os.nim 3 | 4 | proc yay* = echo "new os.nim" 5 | 6 | -------------------------------------------------------------------------------- /tests/misc/minit.nim: -------------------------------------------------------------------------------- 1 | # Test the new initialization for modules 2 | write(stdout, "Hello from module! ") 3 | -------------------------------------------------------------------------------- /tests/realtimeGC/main.nim.cfg: -------------------------------------------------------------------------------- 1 | 2 | --app:console 3 | --threads:on 4 | 5 | -d:release 6 | -d:useRealtimeGC 7 | -------------------------------------------------------------------------------- /tests/rodfiles/hallo.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "Hello World" 3 | """ 4 | 5 | echo "Hello World" 6 | 7 | -------------------------------------------------------------------------------- /tests/testdata/data.csv: -------------------------------------------------------------------------------- 1 | Algo_A; Algo_B; Algo_C 2 | 12; 12; 16 3 | 2; 5; 9 4 | 63; 65.3; 90 5 | 0; 1.2; 3 6 | 7 | -------------------------------------------------------------------------------- /web/assets/images/docs-tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/docs-tools.png -------------------------------------------------------------------------------- /web/assets/images/glow-arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/glow-arrow.png -------------------------------------------------------------------------------- /web/assets/images/glow-line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/glow-line.png -------------------------------------------------------------------------------- /web/assets/images/head-link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/head-link.png -------------------------------------------------------------------------------- /web/assets/images/link_aporia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/link_aporia.png -------------------------------------------------------------------------------- /web/assets/images/link_forum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/link_forum.png -------------------------------------------------------------------------------- /web/assets/images/sidebar_h2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/sidebar_h2.png -------------------------------------------------------------------------------- /web/assets/images/site_foot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/site_foot.png -------------------------------------------------------------------------------- /web/assets/images/site_neck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/site_neck.png -------------------------------------------------------------------------------- /tests/defaultprocparam/mdefaultprocparam.nim: -------------------------------------------------------------------------------- 1 | 2 | 3 | proc p*(f = (proc(): string = "hi")) = 4 | echo f() 5 | 6 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/dependencies/sfml/sfml_vector.nim: -------------------------------------------------------------------------------- 1 | import sfml, math, strutils 2 | {.deadCodeElim: on.} 3 | -------------------------------------------------------------------------------- /tests/manyloc/named_argument_bug/main.nim.cfg: -------------------------------------------------------------------------------- 1 | # this file only exists to mark 'main.nim' as the main file 2 | 3 | -------------------------------------------------------------------------------- /tests/rodfiles/deada.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''246 3 | ''' 4 | """ 5 | 6 | import deadg, deadb 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/template/ttemplreturntype.nim: -------------------------------------------------------------------------------- 1 | 2 | template `=~` (a: int, b: int): bool = false 3 | var foo = 2 =~ 3 4 | 5 | -------------------------------------------------------------------------------- /web/assets/images/docs-articles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/docs-articles.png -------------------------------------------------------------------------------- /web/assets/images/docs-examples.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/docs-examples.png -------------------------------------------------------------------------------- /web/assets/images/link_nimbuild.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/link_nimbuild.png -------------------------------------------------------------------------------- /web/assets/images/sidebar_head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/sidebar_head.png -------------------------------------------------------------------------------- /web/assets/images/slideshow-nav.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/slideshow-nav.png -------------------------------------------------------------------------------- /tests/stdlib/ttime.nim: -------------------------------------------------------------------------------- 1 | # test the new time module 2 | 3 | import 4 | times 5 | 6 | write(stdout, $getTime()) 7 | -------------------------------------------------------------------------------- /web/assets/images/docs-internals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/docs-internals.png -------------------------------------------------------------------------------- /web/assets/images/docs-libraries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/docs-libraries.png -------------------------------------------------------------------------------- /web/assets/images/docs-tutorials.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/docs-tutorials.png -------------------------------------------------------------------------------- /web/assets/images/head-link_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/head-link_hover.png -------------------------------------------------------------------------------- /web/assets/images/more-links_forum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/more-links_forum.png -------------------------------------------------------------------------------- /examples/cgi/cgi_stacktrace.nim: -------------------------------------------------------------------------------- 1 | import cgi 2 | cgi.setStackTraceStdout() 3 | 4 | var a: string = nil 5 | a.add "foobar" 6 | -------------------------------------------------------------------------------- /lib/nimrtl.nim.cfg: -------------------------------------------------------------------------------- 1 | # The RTL.dll needs to be compiled with these options! 2 | 3 | --app:lib 4 | --define:createNimRtl 5 | 6 | -------------------------------------------------------------------------------- /tests/cpp/ttypeinfo2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp $file" 3 | """ 4 | # bug #2841 5 | import typeinfo 6 | var tt: Any 7 | -------------------------------------------------------------------------------- /tests/enum/tenum.nim: -------------------------------------------------------------------------------- 1 | # Test enums 2 | 3 | type 4 | E = enum a, b, c, x, y, z 5 | 6 | var 7 | en: E 8 | en = a 9 | -------------------------------------------------------------------------------- /tests/exprs/thighCString.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "5" 3 | """ 4 | let test = cstring("foobar") 5 | 6 | echo high(test) 7 | -------------------------------------------------------------------------------- /web/assets/images/more-links_editors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/more-links_editors.png -------------------------------------------------------------------------------- /web/assets/images/more-links_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/more-links_github.png -------------------------------------------------------------------------------- /tests/ambsym/mambsys2.nim: -------------------------------------------------------------------------------- 1 | type 2 | TExport* = enum x, y, z # exactly the same type! 3 | 4 | proc foo*(x: int) = discard 5 | -------------------------------------------------------------------------------- /tests/manyloc/packages/package1/strutils.nim: -------------------------------------------------------------------------------- 1 | 2 | # Overrides lib/pure/os.nim 3 | 4 | proc foo* = echo "package1/strutils" 5 | 6 | -------------------------------------------------------------------------------- /tests/manyloc/packages/package2/strutils.nim: -------------------------------------------------------------------------------- 1 | 2 | # Overrides lib/pure/os.nim 3 | 4 | proc foo* = echo "package2/strutils" 5 | 6 | -------------------------------------------------------------------------------- /tests/stdlib/nre/optional_nonstrict.nim: -------------------------------------------------------------------------------- 1 | import options 2 | converter option2val*[T](val: Option[T]): T = 3 | return val.get() 4 | -------------------------------------------------------------------------------- /tests/stdlib/tsortcall.nim: -------------------------------------------------------------------------------- 1 | import algorithm 2 | 3 | proc foosort(ships: var seq[int]) = sort(ships, system.cmp[int]) 4 | 5 | 6 | -------------------------------------------------------------------------------- /web/assets/images/more-links_nimbuild.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/more-links_nimbuild.png -------------------------------------------------------------------------------- /web/assets/images/slideshow-nav_active.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/Nim/devel/web/assets/images/slideshow-nav_active.png -------------------------------------------------------------------------------- /tests/dir with space/tspace.nim: -------------------------------------------------------------------------------- 1 | # Test for the compiler to be able to compile a Nim file with spaces in it. 2 | 3 | echo("Successful") -------------------------------------------------------------------------------- /tests/pragmas/tuserpragma.nim: -------------------------------------------------------------------------------- 1 | 2 | {.pragma: rtl, cdecl, exportc.} 3 | 4 | proc myproc(x, y: int): int {.rtl} = 5 | nil 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/typerel/tnoargopenarray.nim: -------------------------------------------------------------------------------- 1 | 2 | import db_sqlite 3 | 4 | var db: TDbConn 5 | exec(db, sql"create table blabla()") 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib/impure/nre/.gitignore: -------------------------------------------------------------------------------- 1 | # all executables 2 | * 3 | !*/ 4 | !*.* 5 | *.exe 6 | 7 | # Wildcard patterns. 8 | *.swp 9 | nimcache 10 | -------------------------------------------------------------------------------- /tests/lexer/thexrange.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | TArray = array[0x0012..0x0013, int] 4 | 5 | var a: TArray 6 | 7 | echo a[0x0012] #OUT 0 8 | 9 | -------------------------------------------------------------------------------- /tests/testdata/csvtest.csv: -------------------------------------------------------------------------------- 1 | headerField1,headerField2,headerField3 2 | 12,12132,"hallo "" 3 | du" 4 | 1,, 5 | ,2, 6 | ,,3 7 | 1,2,3 8 | 9 | -------------------------------------------------------------------------------- /examples/myfile.txt: -------------------------------------------------------------------------------- 1 | kladsfa 2 | 3 | asdflksadlfasf 4 | 5 | 6 | adsfljksadfl 7 | 8 | 9 | key=/usr/bin/value 10 | key2=/ha/ha 11 | 12 | -------------------------------------------------------------------------------- /start.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM COLOR 0A 3 | SET NIMRODPATH=. 4 | SET PATH=%NIMRODPATH%\bin;%NIMRODPATH%\dist\mingw\bin;%PATH% 5 | cmd 6 | 7 | -------------------------------------------------------------------------------- /tests/caas/main.nim: -------------------------------------------------------------------------------- 1 | import imported, strutils 2 | 3 | proc main = 4 | var t1 = "text" 5 | var t2 = t1.toUpper 6 | echo(t1 +++ t2) 7 | 8 | -------------------------------------------------------------------------------- /tests/misc/mvarious.nim: -------------------------------------------------------------------------------- 1 | # Test a submodule 2 | 3 | #type 4 | # TStringArr = array [0.. *] of string 5 | 6 | proc exportme* = discard 7 | -------------------------------------------------------------------------------- /tests/procvar/tgenericprocvar.nim: -------------------------------------------------------------------------------- 1 | proc foo[T](thing: T) = 2 | discard thing 3 | 4 | var a: proc (thing: int) {.nimcall.} = foo[int] 5 | 6 | -------------------------------------------------------------------------------- /config/rename.rules.cfg: -------------------------------------------------------------------------------- 1 | TSignedInt 2 | TUnsignedInt 3 | TOrdinal 4 | TReal 5 | TNumber 6 | TEnum 7 | TObject 8 | TResult 9 | TOpenArray 10 | -------------------------------------------------------------------------------- /tests/closure/tissue1642.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tissue1642.nim" 3 | disabled: true 4 | """ 5 | block: 6 | var i = 0 7 | proc p() = inc(i) 8 | -------------------------------------------------------------------------------- /tests/misc/tnewderef.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: 3 3 | 4 | """ 5 | 6 | var x: ref int 7 | new(x) 8 | x[] = 3 9 | 10 | echo x[] 11 | 12 | -------------------------------------------------------------------------------- /tests/modules/mexport2a.nim: -------------------------------------------------------------------------------- 1 | 2 | import mexport2b 3 | export mexport2b 4 | proc printAbc*() = echo "abc" 5 | 6 | proc foo*() = echo "A.foo" 7 | 8 | -------------------------------------------------------------------------------- /tinyc/examples/ex5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/ambsym/mambsys1.nim: -------------------------------------------------------------------------------- 1 | import mambsys2 # import TExport 2 | 3 | type 4 | TExport* = enum x, y, z 5 | 6 | proc foo*(x: int) = 7 | discard 8 | -------------------------------------------------------------------------------- /tests/misc/tgetstartmilsecs.nim: -------------------------------------------------------------------------------- 1 | # 2 | import times, os 3 | 4 | var start = epochTime() 5 | os.sleep(1000) 6 | 7 | echo epochTime() - start #OUT 1000 8 | -------------------------------------------------------------------------------- /tinyc/examples/ex1.c: -------------------------------------------------------------------------------- 1 | #! /usr/local/bin/tcc -run 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/rodfiles/int2bool.nim: -------------------------------------------------------------------------------- 1 | 2 | {.overflowchecks: on.} 3 | 4 | converter uglyToBool*(x: int): bool = 5 | {.Breakpoint.} 6 | result = x != 0 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/stdlib/tio.nim: -------------------------------------------------------------------------------- 1 | # test the file-IO 2 | 3 | proc main() = 4 | for line in lines("thello.nim"): 5 | writeLine(stdout, line) 6 | 7 | main() 8 | -------------------------------------------------------------------------------- /tests/template/mtempl5.nim: -------------------------------------------------------------------------------- 1 | 2 | var 3 | gx = 88 4 | gy = 44 5 | 6 | template templ*(): int = 7 | bind gx, gy 8 | gx + gy 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/bind/mbind3.nim: -------------------------------------------------------------------------------- 1 | # Module A 2 | var 3 | lastId = 0 4 | 5 | template genId*: expr = 6 | bind lastId 7 | inc(lastId) 8 | lastId 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/concat/tconcat.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "DabcD" 3 | """ 4 | 5 | const 6 | x = "abc" 7 | 8 | var v = "D" & x & "D" 9 | 10 | echo v 11 | 12 | -------------------------------------------------------------------------------- /tests/manyloc/named_argument_bug/tri_engine/config.nim: -------------------------------------------------------------------------------- 1 | when defined(doublePrecision): 2 | type 3 | TR* = float64 4 | else: 5 | type 6 | TR* = float32 7 | -------------------------------------------------------------------------------- /tests/modules/mexportb.nim: -------------------------------------------------------------------------------- 1 | # module B 2 | type TMyObject* = object 3 | 4 | const xyz* = 13 5 | 6 | proc q*(x: int): int = 6 7 | proc q*(x: string): string = "8" 8 | -------------------------------------------------------------------------------- /tests/system/tsettostring.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "{a, b, c}" 3 | """ 4 | 5 | # bug #2395 6 | 7 | let alphaSet: set[char] = {'a'..'c'} 8 | echo alphaSet 9 | -------------------------------------------------------------------------------- /compiler/testability.nim: -------------------------------------------------------------------------------- 1 | template tests*(body: stmt) {.immediate.} = 2 | when defined(selftest): 3 | when not declared(unittest): import unittest 4 | body 5 | 6 | -------------------------------------------------------------------------------- /install.sh.template: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set -x 4 | 5 | if [ "$1" != "" ]; then 6 | exec ./koch install "$1" 7 | else 8 | exec ./koch install 9 | fi 10 | -------------------------------------------------------------------------------- /tests/concepts/tvarconcept.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "5" 3 | """ 4 | 5 | # bug #2346, bug #2404 6 | 7 | import mvarconcept 8 | 9 | echo randomInt(5) 10 | -------------------------------------------------------------------------------- /tests/generics/tdotlookup.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''5 5 5 3 | false''' 4 | """ 5 | 6 | import mdotlookup 7 | 8 | foo(7) 9 | # bug #1444 10 | fn(4) 11 | -------------------------------------------------------------------------------- /tests/iter/titerslice.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''2 3 | 3 4 | 4''' 5 | """ 6 | 7 | var t1 = @["1", "2", "3", "4"] 8 | for t in t1[1..3]: 9 | echo t 10 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/server/nim.cfg: -------------------------------------------------------------------------------- 1 | debugger = off 2 | deadCodeElim = on 3 | path = ".." 4 | path = "../genpacket" 5 | path = "../helpers" 6 | define = NoSFML 7 | -------------------------------------------------------------------------------- /tests/misc/tcharinc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "1" 3 | """ 4 | 5 | var c = '\0' 6 | while true: 7 | if c == '\xFF': break 8 | inc c 9 | 10 | echo "1" 11 | -------------------------------------------------------------------------------- /tests/misc/tnewsets.nim: -------------------------------------------------------------------------------- 1 | # new test for sets: 2 | 3 | const elem = ' ' 4 | 5 | var s: set[char] = {elem} 6 | assert(elem in s and 'a' not_in s and 'c' not_in s ) 7 | -------------------------------------------------------------------------------- /tests/types/tforwty.nim: -------------------------------------------------------------------------------- 1 | # Test 13: forward types 2 | 3 | type 4 | PSym = ref TSym 5 | 6 | TSym = object 7 | next: PSym 8 | 9 | var s: PSym 10 | -------------------------------------------------------------------------------- /tinyc/win32/include/values.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TODO: Nothing here yet. Should provide UNIX compatibility constants 3 | * comparible to those in limits.h and float.h. 4 | */ 5 | -------------------------------------------------------------------------------- /tests/bind/tbind3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tbind3.nim" 3 | output: "1" 4 | """ 5 | # Module B 6 | import mbind3 7 | 8 | echo genId() #OUT 1 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/server/dirserver_settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "network":"lamenet", 3 | "port":2049, 4 | "zones":[ 5 | {"name":"alphazone","key":"skittles"} 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/modules/mopaque.nim: -------------------------------------------------------------------------------- 1 | type 2 | TLexer* {.final.} = object 3 | line*: int 4 | filename*: string 5 | buffer: cstring 6 | 7 | proc noProcVar*(): int = 18 8 | -------------------------------------------------------------------------------- /tests/range/compilehelpers.nim: -------------------------------------------------------------------------------- 1 | template accept(e: expr) = 2 | static: assert(compiles(e)) 3 | 4 | template reject(e: expr) = 5 | static: assert(not compiles(e)) 6 | 7 | -------------------------------------------------------------------------------- /tests/stdlib/tquit.nim: -------------------------------------------------------------------------------- 1 | # Test the new beforeQuit variable: 2 | 3 | proc myExit() {.noconv.} = 4 | write(stdout, "just exiting...\n") 5 | 6 | addQuitProc(myExit) 7 | -------------------------------------------------------------------------------- /tests/typerel/ttypedesc_as_genericparam1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 6 3 | errormsg: "type mismatch: got (typedesc[int])" 4 | """ 5 | # bug #3079, #1146 6 | echo repr(int) 7 | -------------------------------------------------------------------------------- /tests/array/troof3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "invalid context for '^' as len!=high+1 for 'a'" 3 | line: "8" 4 | """ 5 | 6 | var a: array[1..3, string] 7 | 8 | echo a[^1] 9 | -------------------------------------------------------------------------------- /tests/exprs/tresultwarning.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | nimout: "Special variable 'result' is shadowed. [ResultShadowed]" 3 | """ 4 | 5 | proc test(): string = 6 | var result = "foo" 7 | -------------------------------------------------------------------------------- /tests/js/tunittests.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''[OK] >:)''' 3 | """ 4 | 5 | import unittest 6 | 7 | suite "Bacon": 8 | test ">:)": 9 | check(true == true) 10 | -------------------------------------------------------------------------------- /tests/objects/tillegal_recursion.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "illegal recursion in type 'object'" 3 | line: 7 4 | """ 5 | # bug #1691 6 | type 7 | Foo = ref object of Foo 8 | -------------------------------------------------------------------------------- /tests/template/ttempl4.nim: -------------------------------------------------------------------------------- 1 | 2 | template `:=`(name, val: expr): stmt {.immediate.} = 3 | var name = val 4 | 5 | ha := 1 * 4 6 | hu := "ta-da" == "ta-da" 7 | echo ha, hu 8 | 9 | -------------------------------------------------------------------------------- /tests/typerel/ttypelessemptyset.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "internal error: invalid kind for last(tyEmpty)" 3 | """ 4 | var q = false 5 | discard (if q: {} else: {}) 6 | 7 | -------------------------------------------------------------------------------- /examples/cross_calculator/nim_backend/backend.nim: -------------------------------------------------------------------------------- 1 | # Backend for the different user interfaces. 2 | 3 | proc myAdd*(x, y: int): int {.cdecl, exportc.} = 4 | result = x + y 5 | 6 | -------------------------------------------------------------------------------- /examples/readme.txt: -------------------------------------------------------------------------------- 1 | In this directory you will find several examples for how to use the Nimrod 2 | library. 3 | 4 | Copyright (c) 2004-2012 Andreas Rumpf. 5 | All rights reserved. 6 | -------------------------------------------------------------------------------- /examples/talk/tags.nim: -------------------------------------------------------------------------------- 1 | 2 | template htmlTag(tag: expr) {.immediate.} = 3 | proc tag(): string = "<" & astToStr(tag) & ">" 4 | 5 | htmlTag(br) 6 | htmlTag(html) 7 | 8 | echo br() 9 | -------------------------------------------------------------------------------- /tests/global/tglobalforvar.nim: -------------------------------------------------------------------------------- 1 | 2 | var funcs: seq[proc (): int {.nimcall.}] = @[] 3 | for i in 0..10: 4 | funcs.add((proc (): int = return i * i)) 5 | 6 | echo(funcs[3]()) 7 | 8 | -------------------------------------------------------------------------------- /tests/misc/tinc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tinc.nim" 3 | line: 8 4 | errormsg: "type mismatch: got (int)" 5 | """ 6 | var x = 0 7 | 8 | inc(x+1) 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/namedparams/tnamedparams2.nim: -------------------------------------------------------------------------------- 1 | import pegs 2 | 3 | discard parsePeg( 4 | pattern = "input", 5 | filename = "filename", 6 | line = 1, 7 | col = 23) 8 | 9 | -------------------------------------------------------------------------------- /tests/rodfiles/aconv.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "ugly conversion successful" 3 | """ 4 | 5 | import int2bool 6 | 7 | if 4: 8 | echo "ugly conversion successful" 9 | 10 | -------------------------------------------------------------------------------- /web/snippets/snippet1.nim: -------------------------------------------------------------------------------- 1 | import strutils 2 | echo "Give a list of integers (separated by spaces): ", 3 | stdin.readLine.split.each(parseInt).max, 4 | " is the maximum!" 5 | -------------------------------------------------------------------------------- /examples/cross_calculator/android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | CrossCalculator 4 | 5 | -------------------------------------------------------------------------------- /examples/cross_todo/nim_commandline/nim.cfg: -------------------------------------------------------------------------------- 1 | # Nimrod configuration file. 2 | # The file is used only to add the path of the backend to the compiler options. 3 | 4 | path="../nim_backend" 5 | -------------------------------------------------------------------------------- /tests/deprecated/tdeprecated.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | nimout: "a is deprecated [Deprecated]" 3 | """ 4 | 5 | var 6 | a {.deprecated.}: array[0..11, int] 7 | 8 | a[8] = 1 9 | 10 | -------------------------------------------------------------------------------- /tests/enum/tenumitems.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 7 3 | errormsg: "attempting to call undeclared routine: 'items'" 4 | """ 5 | 6 | type a = enum b,c,d 7 | a.items() 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/generics/tableref_is_nil.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "true" 3 | """ 4 | 5 | # bug #2221 6 | import tables 7 | 8 | var tblo: TableRef[string, int] 9 | echo tblo == nil 10 | -------------------------------------------------------------------------------- /tests/generics/tbadgenericlambda.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "nested proc can have generic parameters only when" 3 | line: 6 4 | """ 5 | 6 | let x = proc (x, y): auto = x + y 7 | 8 | -------------------------------------------------------------------------------- /tests/macros/tsame_name_497.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | disabled: true 3 | """ 4 | 5 | import macro_bug 6 | 7 | type TObj = object 8 | 9 | proc f(o: TObj) {.macro_bug.} = discard 10 | -------------------------------------------------------------------------------- /tests/misc/tnolen.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 8 3 | errormsg: "type mismatch: got (int literal(3))" 4 | """ 5 | 6 | # please finally disallow Len(3) 7 | 8 | echo len(3) 9 | 10 | -------------------------------------------------------------------------------- /tests/modules/mexporta.nim: -------------------------------------------------------------------------------- 1 | # module A 2 | import mexportb 3 | export mexportb.TMyObject, mexportb.xyz 4 | 5 | export mexportb.q 6 | 7 | proc `$`*(x: TMyObject): string = "my object" 8 | 9 | -------------------------------------------------------------------------------- /tests/rodfiles/bconv.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "ugly conversion successful 2" 3 | """ 4 | 5 | import int2bool 6 | 7 | if 4: 8 | echo "ugly conversion successful 2" 9 | 10 | -------------------------------------------------------------------------------- /tests/tuples/tgeneric_tuple.nim: -------------------------------------------------------------------------------- 1 | # bug #2121 2 | 3 | type 4 | Item[K,V] = tuple 5 | key: K 6 | value: V 7 | 8 | var q = newseq[Item[int,int]](0) 9 | let (x,y) = q[0] 10 | -------------------------------------------------------------------------------- /tests/types/tinfiniterecursion.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "illegal recursion in type 'XIM'" 3 | line: 8 4 | """ 5 | 6 | type 7 | XIM* = ptr XIM 8 | XIMProc* = proc (a2: XIM) 9 | -------------------------------------------------------------------------------- /tinyc/win32/include/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * mem.h maps to string.h 5 | */ 6 | #ifndef __STRICT_ANSI__ 7 | #include 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cross_calculator/nim_commandline/nim.cfg: -------------------------------------------------------------------------------- 1 | # Nimrod configuration file. 2 | # The file is used only to add the path of the backend to the compiler options. 3 | 4 | path="../nim_backend" 5 | -------------------------------------------------------------------------------- /lib/stdlib.nimble: -------------------------------------------------------------------------------- 1 | [Package] 2 | name = "stdlib" 3 | version = "0.9.0" 4 | author = "Dominik Picheta" 5 | description = "Nim's standard library." 6 | license = "MIT" 7 | -------------------------------------------------------------------------------- /tests/clearmsg/tconsttypemismatch.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tconsttypemismatch.nim" 3 | line: 7 4 | errormsg: "type mismatch" 5 | """ 6 | # bug #2252 7 | const foo: int = 1000 / 30 8 | 9 | -------------------------------------------------------------------------------- /tests/misc/tfib.nim: -------------------------------------------------------------------------------- 1 | 2 | iterator fibonacci(): int = 3 | var a = 0 4 | var b = 1 5 | while true: 6 | yield a 7 | var c = b 8 | b = a 9 | a = a + c 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/typerel/tno_int_in_bool_context.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 6 3 | errormsg: "type mismatch: got (int literal(1)) but expected 'bool'" 4 | """ 5 | 6 | if 1: 7 | echo "wtf?" 8 | 9 | -------------------------------------------------------------------------------- /tools/detect/timesize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) { 6 | printf("%ld\n", sizeof(time_t)); 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/caas/compile-suggest.txt: -------------------------------------------------------------------------------- 1 | main.nim 2 | > c --verbosity:0 --hints:on 3 | SuccessX 4 | > idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest $SILENT 5 | skField\tx 6 | skField\ty 7 | 8 | -------------------------------------------------------------------------------- /tests/exprs/tstmtexp.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tstmtexp.nim" 3 | line: 8 4 | errormsg: "value of type 'int literal(5)' has to be discarded" 5 | """ 6 | # Test 3 7 | 8 | 1+4 9 | 10 | -------------------------------------------------------------------------------- /tests/macros/tmacroaspragma.nim: -------------------------------------------------------------------------------- 1 | import macros 2 | 3 | macro foo(x: stmt): stmt = 4 | echo treerepr(callsite()) 5 | result = newNimNode(nnkStmtList) 6 | 7 | proc zoo() {.foo.} = echo "hi" 8 | 9 | -------------------------------------------------------------------------------- /tests/misc/tnoop.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tnoop.nim" 3 | line: 11 4 | errormsg: "attempting to call undeclared routine: 'a'" 5 | """ 6 | 7 | 8 | var 9 | a: int 10 | 11 | a() 12 | -------------------------------------------------------------------------------- /tests/rodfiles/deadg.nim: -------------------------------------------------------------------------------- 1 | 2 | {.deadCodeElim: on.} 3 | 4 | proc p1*(x, y: int): int = 5 | result = x + y 6 | 7 | proc p2*(x, y: string): string = 8 | result = x & y 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/template/tcan_access_hidden_field.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: 33 3 | """ 4 | 5 | import mcan_access_hidden_field 6 | 7 | var myfoo = createFoo(33, 44) 8 | 9 | echo myfoo.geta 10 | -------------------------------------------------------------------------------- /tests/types/tauto_canbe_void.nim: -------------------------------------------------------------------------------- 1 | 2 | import future 3 | 4 | template tempo(s: expr) = 5 | s("arg") 6 | 7 | tempo((s: string)->auto => echo(s)) 8 | tempo((s: string) => echo(s)) 9 | 10 | -------------------------------------------------------------------------------- /tests/caas/def-then-compile.txt: -------------------------------------------------------------------------------- 1 | main.nim 2 | > idetools --track:$TESTNIM,5,18 --def --verbosity:0 --hints:on 3 | strutils.toUpper 4 | ! SuccessX 5 | 6 | > c --verbosity:0 --hints:on 7 | SuccessX 8 | 9 | -------------------------------------------------------------------------------- /tests/macros/tmacro_in_template.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #1944 3 | import macros 4 | 5 | template t(e: expr): stmt = 6 | macro m(eNode: expr): stmt = 7 | echo eNode.treeRepr 8 | m e 9 | 10 | t 5 11 | -------------------------------------------------------------------------------- /tests/method/tmethod.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tmethod.nim" 3 | line: 7 4 | errormsg: "\'method\' needs a parameter that has an object type" 5 | """ 6 | 7 | method m(i: int): int = 8 | return 5 9 | -------------------------------------------------------------------------------- /tests/misc/thintoff.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "thintoff.nim" 3 | output: "0" 4 | """ 5 | 6 | {.hint[XDeclaredButNotUsed]: off.} 7 | var 8 | x: int 9 | 10 | echo x #OUT 0 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/metatype/typedesc_as_value.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "'typedesc' metatype is not valid here; typed '=' instead of ':'?" 3 | """ 4 | 5 | 6 | var x = int 7 | 8 | echo x 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/misc/tlocals.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "(x: string here, a: 1)" 3 | """ 4 | 5 | proc simple[T](a: T) = 6 | var 7 | x = "string here" 8 | echo locals() 9 | 10 | simple(1) 11 | 12 | -------------------------------------------------------------------------------- /tests/modules/timportexcept.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 9 3 | errormsg: "undeclared identifier: '%'" 4 | """ 5 | 6 | import strutils except `%` 7 | 8 | # doesn't work 9 | echo "$1" % "abc" 10 | 11 | -------------------------------------------------------------------------------- /tests/stckovfl.nim: -------------------------------------------------------------------------------- 1 | # To test stack overflow message 2 | 3 | proc over(a: int): int = 4 | if a >= 10: 5 | assert false 6 | return 7 | result = over(a+1)+5 8 | 9 | Echo($over(0)) 10 | 11 | -------------------------------------------------------------------------------- /tests/template/tit.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #1337 3 | 4 | template someIt(a, pred: expr): expr = 5 | var it {.inject.} = 0 6 | pred 7 | 8 | proc aProc(n) = 9 | n.someIt(echo(it)) 10 | 11 | aProc(89) 12 | -------------------------------------------------------------------------------- /tinyc/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | /* ISOC99 boolean */ 5 | 6 | #define bool _Bool 7 | #define true 1 8 | #define false 0 9 | 10 | #endif /* _STDBOOL_H */ 11 | -------------------------------------------------------------------------------- /tinyc/win32/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * This fcntl.h maps to the root fcntl.h 5 | */ 6 | #ifndef __STRICT_ANSI__ 7 | #include 8 | #endif 9 | -------------------------------------------------------------------------------- /compiler/nodejs.nim: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | proc findNodeJs*(): string = 4 | result = findExe("nodejs") 5 | if result == "": 6 | result = findExe("node") 7 | if result == "": 8 | result = findExe("iojs") 9 | -------------------------------------------------------------------------------- /examples/cross_calculator/android/scripts/tags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d src ] 4 | then 5 | cd .. 6 | fi 7 | 8 | if [ -d src ] 9 | then 10 | ~/bin/objctags -R \ 11 | jni \ 12 | src 13 | fi 14 | -------------------------------------------------------------------------------- /examples/cross_calculator/ios/src/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDelegate : UIResponder 4 | 5 | @property (strong, nonatomic) UIWindow *window; 6 | 7 | @end 8 | -------------------------------------------------------------------------------- /examples/maximum.nim: -------------------------------------------------------------------------------- 1 | # Test high level features 2 | 3 | import strutils 4 | 5 | echo "Give a list of numbers (separated by spaces): " 6 | stdin.readLine.split.map(parseInt).max.`$`.echo(" is the maximum!") 7 | -------------------------------------------------------------------------------- /examples/talk/lazyeval.nim: -------------------------------------------------------------------------------- 1 | 2 | const 3 | debug = true 4 | 5 | template log(msg: string) = 6 | if debug: 7 | echo msg 8 | var 9 | x = 1 10 | y = 2 11 | 12 | log("x: " & $x & ", y: " & $y) 13 | -------------------------------------------------------------------------------- /tests/friends/mfriends.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | TMyObj = object 4 | x: int 5 | 6 | proc gen*[T](): T = 7 | var d: TMyObj 8 | # access private field here 9 | d.x = 3 10 | result = d.x 11 | 12 | -------------------------------------------------------------------------------- /tests/misc/tnoforward.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | disabled: true 3 | """ 4 | 5 | {. noforward: on .} 6 | 7 | proc foo(x: int) = 8 | bar x 9 | 10 | proc bar(x: int) = 11 | echo x 12 | 13 | foo(10) 14 | 15 | -------------------------------------------------------------------------------- /tests/pragmas/tsym_as_pragma.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #3171 3 | 4 | template newDataWindow(): stmt = 5 | let eventClosure = proc (closure: pointer): bool {.closure, cdecl.} = 6 | discard 7 | 8 | newDataWindow() 9 | -------------------------------------------------------------------------------- /tests/stdlib/tnre.nim: -------------------------------------------------------------------------------- 1 | import nre 2 | import nre.init 3 | import nre.captures 4 | import nre.find 5 | import nre.split 6 | import nre.match 7 | import nre.replace 8 | import nre.escape 9 | import nre.misc 10 | -------------------------------------------------------------------------------- /tests/vm/toverflowopcsubimmint.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "over- or underflow" 3 | """ 4 | 5 | static: 6 | proc p = 7 | var x = int64.low 8 | discard x - 1 9 | assert false 10 | p() 11 | -------------------------------------------------------------------------------- /tinyc/win32/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | /* ISOC99 boolean */ 5 | 6 | #define bool _Bool 7 | #define true 1 8 | #define false 0 9 | 10 | #endif /* _STDBOOL_H */ 11 | -------------------------------------------------------------------------------- /tinyc/win32/include/sys/unistd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * unistd.h maps (roughly) to io.h 5 | */ 6 | #ifndef __STRICT_ANSI__ 7 | #include 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /tinyc/win32/include/unistd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * unistd.h maps (roughly) to io.h 5 | */ 6 | 7 | #ifndef __STRICT_ANSI__ 8 | #include 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /examples/cross_calculator/ios/scripts/tags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d src ] 4 | then 5 | cd .. 6 | fi 7 | 8 | if [ -d src ] 9 | then 10 | ~/bin/objctags -R \ 11 | build/nimcache \ 12 | src 13 | fi 14 | -------------------------------------------------------------------------------- /tests/array/troof2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "invalid context for '^' as 'foo()' has side effects" 3 | line: "9" 4 | """ 5 | 6 | proc foo(): seq[int] = 7 | echo "ha" 8 | 9 | let f = foo()[^1] 10 | 11 | -------------------------------------------------------------------------------- /tests/cnstseq/tcnstseq3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "AngelikaAnneAnnaAnkaAnja" 3 | """ 4 | 5 | for w in items(["Angelika", "Anne", "Anna", "Anka", "Anja"]): 6 | write(stdout, w) #OUT AngelikaAnneAnnaAnkaAnja 7 | 8 | -------------------------------------------------------------------------------- /tests/enum/tenummix.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tenummix.nim" 3 | line: 11 4 | errormsg: "type mismatch" 5 | """ 6 | 7 | type 8 | TE1 = enum eA, eB 9 | TE2 = enum eC, eD 10 | 11 | assert eA != eC 12 | -------------------------------------------------------------------------------- /tests/generics/tsigtypeop.nim: -------------------------------------------------------------------------------- 1 | type 2 | Vec3[T] = array[3, T] 3 | 4 | proc foo(x: Vec3, y: Vec3.T, z: x.T): x.type.T = 5 | return 10 6 | 7 | var y: Vec3[int] = [1, 2, 3] 8 | var z: int = foo(y, 3, 4) 9 | 10 | -------------------------------------------------------------------------------- /tests/macros/tnimnode_for_runtime.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "bla" 3 | """ 4 | 5 | import macros 6 | proc makeMacro: NimNode = 7 | result = nil 8 | 9 | var p = makeMacro() 10 | 11 | echo "bla" 12 | 13 | -------------------------------------------------------------------------------- /tests/misc/tnewuns.nim: -------------------------------------------------------------------------------- 1 | # test the new unsigned operations: 2 | 3 | import 4 | strutils 5 | 6 | var 7 | x, y: int 8 | 9 | x = 1 10 | y = high(int) 11 | 12 | writeLine(stdout, $ ( x +% y ) ) 13 | -------------------------------------------------------------------------------- /tests/procvar/tprocvars.nim: -------------------------------------------------------------------------------- 1 | proc doSomething(v: int, x: proc(v:int):int): int = return x(v) 2 | proc doSomething(v: int, x: proc(v:int)) = x(v) 3 | 4 | 5 | echo doSomething(10, proc(v: int): int = return v div 2) 6 | 7 | -------------------------------------------------------------------------------- /tests/rodfiles/deada2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''246 3 | xyzabc 4 | ''' 5 | """ 6 | 7 | import deadg, deadb 8 | 9 | # now add call to previously unused proc p2: 10 | echo p2("xyz", "abc") 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/rodfiles/tgeneric1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "abcd" 3 | """ 4 | 5 | import tables 6 | 7 | var x = initTable[int, string]() 8 | 9 | x[2] = "ab" 10 | x[5] = "cd" 11 | 12 | echo x[2], x[5] 13 | 14 | -------------------------------------------------------------------------------- /tests/rodfiles/tgeneric2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "abef" 3 | """ 4 | 5 | import tables 6 | 7 | var x = initTable[int, string]() 8 | 9 | x[2] = "ab" 10 | x[5] = "ef" 11 | 12 | echo x[2], x[5] 13 | 14 | -------------------------------------------------------------------------------- /tests/system/toString.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output:'''@[23, 45] 3 | @[, foo, bar]''' 4 | """ 5 | 6 | echo($(@[23, 45])) 7 | echo($(@["", "foo", "bar"])) 8 | #echo($(["", "foo", "bar"])) 9 | #echo($([23, 45])) 10 | -------------------------------------------------------------------------------- /tests/typerel/ttypedesc_as_genericparam2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 9 3 | errormsg: "'repr' doesn't support 'void' type" 4 | """ 5 | 6 | # bug #2879 7 | 8 | var s: seq[int] 9 | echo repr(s.new_seq(3)) 10 | -------------------------------------------------------------------------------- /tests/vm/twrongconst.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "cannot evaluate at compile time: x" 3 | line: 9 4 | """ 5 | 6 | var x: array[100, char] 7 | template foo : expr = x[42] 8 | 9 | const myConst = foo 10 | -------------------------------------------------------------------------------- /doc/overview.txt: -------------------------------------------------------------------------------- 1 | ============================= 2 | Nim Documentation Overview 3 | ============================= 4 | 5 | :Author: Andreas Rumpf 6 | :Version: |nimversion| 7 | 8 | .. include:: ../doc/docs.txt 9 | 10 | -------------------------------------------------------------------------------- /tests/generics/tgeneric4.nim: -------------------------------------------------------------------------------- 1 | type 2 | TIDGen*[A: Ordinal] = object 3 | next: A 4 | free: seq[A] 5 | 6 | proc newIDGen*[A]: TIDGen[A] = 7 | newSeq result.free, 0 8 | 9 | var x = newIDGen[int]() 10 | 11 | -------------------------------------------------------------------------------- /tests/lexer/thexlit.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "thexlit.nim" 3 | output: "equal" 4 | """ 5 | 6 | var t=0x950412DE 7 | 8 | if t==0x950412DE: 9 | echo "equal" 10 | else: 11 | echo "not equal" 12 | 13 | -------------------------------------------------------------------------------- /tests/template/mcan_access_hidden_field.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | Foo* = object 4 | fooa, foob: int 5 | 6 | proc createFoo*(a, b: int): Foo = Foo(fooa: a, foob: b) 7 | 8 | template geta*(f: Foo): expr = f.fooa 9 | 10 | -------------------------------------------------------------------------------- /tests/typerel/typredef.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "typredef.nim" 3 | line: 7 4 | errormsg: "illegal recursion in type \'Uint8\'" 5 | """ 6 | type 7 | Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8' 8 | 9 | -------------------------------------------------------------------------------- /tests/vm/toverflowopcmulint.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "over- or underflow" 3 | """ 4 | 5 | static: 6 | proc p = 7 | var 8 | x = 1 shl 62 9 | discard x * 2 10 | assert false 11 | p() 12 | -------------------------------------------------------------------------------- /lib/packages/docutils/docutils.babel: -------------------------------------------------------------------------------- 1 | [Package] 2 | name = "docutils" 3 | version = "0.9.0" 4 | author = "Andreas Rumpf" 5 | description = "Nimrod's reStructuredText processor." 6 | license = "MIT" 7 | -------------------------------------------------------------------------------- /tests/clearmsg/ta.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch: got (mc.typ)" 3 | line: 12 4 | """ 5 | 6 | import mb, mc 7 | 8 | proc test(testing: mb.typ) = 9 | discard 10 | 11 | var s: mc.typ 12 | test(s) 13 | -------------------------------------------------------------------------------- /tests/distinct/tborrowdot.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | Foo = object 4 | a, b: int 5 | s: string 6 | 7 | Bar {.borrow: `.`.} = distinct Foo 8 | 9 | var bb: ref Bar 10 | new bb 11 | bb.a = 90 12 | bb.s = "abc" 13 | 14 | -------------------------------------------------------------------------------- /tests/generics/tcan_alias_generic.nim: -------------------------------------------------------------------------------- 1 | ## 2 | ## can_alias_generic Nim Module 3 | ## 4 | ## Created by Eric Doughty-Papassideris on 2011-02-16. 5 | 6 | type 7 | TGen[T] = object 8 | TGen2[T] = TGen[T] 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/manyloc/named_argument_bug/tri_engine/math/rect.nim: -------------------------------------------------------------------------------- 1 | import 2 | tri_engine/config, 3 | tri_engine/math/vec 4 | 5 | type 6 | TRect* = tuple[min, size: TV2[TR]] 7 | 8 | proc max*(o: TRect): TV2[TR] = o.min + o.size 9 | -------------------------------------------------------------------------------- /tests/misc/tatomic.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tatomic.nim" 3 | line: 7 4 | errormsg: "identifier expected, but found 'keyword atomic'" 5 | """ 6 | var 7 | atomic: int 8 | 9 | echo atomic 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/misc/tsizeof.nim: -------------------------------------------------------------------------------- 1 | # Test the sizeof proc 2 | 3 | type 4 | TMyRecord {.final.} = object 5 | x, y: int 6 | b: bool 7 | r: float 8 | s: string 9 | 10 | write(stdout, sizeof(TMyRecord)) 11 | -------------------------------------------------------------------------------- /tests/proc/tprocredef.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tprocredef.nim" 3 | line: 8 4 | errormsg: "redefinition of \'foo\'" 5 | """ 6 | 7 | proc foo(a: int, b: string) = nil 8 | proc foo(a: int, b: string) = nil 9 | 10 | -------------------------------------------------------------------------------- /tests/stdlib/tstreams.nim: -------------------------------------------------------------------------------- 1 | import streams 2 | 3 | var outp = newFileStream(stdout) 4 | var inp = newFileStream(stdin) 5 | write(outp, "Hello! What is your name?") 6 | var line = readLine(inp) 7 | write(outp, "Nice name: " & line) 8 | -------------------------------------------------------------------------------- /tests/vm/toverflowopcaddimmint.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "over- or underflow" 3 | """ 4 | 5 | static: 6 | proc p = 7 | var 8 | x = int64.high 9 | discard x + 1 10 | assert false 11 | p() 12 | -------------------------------------------------------------------------------- /tinyc/win32/include/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * memory.h maps to the standard string.h header. 5 | */ 6 | #ifndef __STRICT_ANSI__ 7 | #include 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /tinyc/win32/include/sys/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mingw32 package. 3 | * 4 | * This file.h maps to the root fcntl.h 5 | * TODO? 6 | */ 7 | #ifndef __STRICT_ANSI__ 8 | #include 9 | #endif 10 | -------------------------------------------------------------------------------- /compiler/readme.txt: -------------------------------------------------------------------------------- 1 | This directory contains the Nim compiler written in Nim. Note that this 2 | code has been translated from a bootstrapping version written in Pascal, so 3 | the code is **not** a poster child of good Nim code. 4 | 5 | -------------------------------------------------------------------------------- /examples/keyval2.nim: -------------------------------------------------------------------------------- 1 | # Filter key=value pairs from "myfile.txt" 2 | import pegs 3 | 4 | for x in lines("myfile.txt"): 5 | if x =~ peg"{\ident} \s* '=' \s* {.*}": 6 | echo "Key: ", matches[0], 7 | " Value: ", matches[1] 8 | -------------------------------------------------------------------------------- /tests/lexer/tmissingnl.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tmissingnl.nim" 3 | line: 7 4 | errormsg: "invalid indentation" 5 | """ 6 | 7 | import strutils var s: seq[int] = @[0, 1, 2, 3, 4, 5, 6] 8 | 9 | #s[1..3] = @[] 10 | 11 | -------------------------------------------------------------------------------- /tests/overload/tissue966.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch: got (PTest)" 3 | """ 4 | 5 | type 6 | PTest = ref object 7 | 8 | proc test(x: PTest, y: int) = nil 9 | 10 | var buf: PTest 11 | buf.test() 12 | 13 | -------------------------------------------------------------------------------- /tests/sets/tsets_lt.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''true 3 | true 4 | true''' 5 | """ 6 | 7 | var s, s1: set[char] 8 | s = {'a'..'d'} 9 | s1 = {'a'..'c'} 10 | echo s1 < s 11 | echo s1 * s == {'a'..'c'} 12 | echo s1 <= s 13 | -------------------------------------------------------------------------------- /tests/trmacros/tnoendlessrec.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "4" 3 | """ 4 | 5 | # test that an endless recursion is avoided: 6 | 7 | template optLen{len(x)}(x: expr): expr = len(x) 8 | 9 | var s = "lala" 10 | echo len(s) 11 | -------------------------------------------------------------------------------- /examples/keyval.nim: -------------------------------------------------------------------------------- 1 | # Filter key=value pairs from "myfile.txt" 2 | import re 3 | 4 | for x in lines("myfile.txt"): 5 | if x =~ re"(\w+)=(.*)": 6 | echo "Key: ", matches[0], 7 | " Value: ", matches[1] 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/transff.nim: -------------------------------------------------------------------------------- 1 | # Shows how to transform a file 2 | 3 | import pegs 4 | 5 | transformFile("infile.txt", "outfile.txt", 6 | [(peg"""S <- {typedesc} \s* {\ident} \s* ',' 7 | typedesc <- \ident '*'* """, r"$2: $1")]) 8 | 9 | -------------------------------------------------------------------------------- /tests/ambsym/tambsys.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tambsys.nim" 3 | output: "" 4 | """ 5 | # Test ambiguous symbols 6 | 7 | import mambsys1, mambsys2 8 | 9 | var 10 | v: mambsys1.TExport 11 | mambsys2.foo(3) #OUT 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/discard/tneedsdiscard.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 10 3 | errormsg: "value of type 'bool' has to be discarded" 4 | """ 5 | 6 | proc p = 7 | var f: TFile 8 | echo "hi" 9 | 10 | open(f, "arg.txt") 11 | 12 | p() 13 | -------------------------------------------------------------------------------- /tests/parallel/tsysspawnbadarg.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 9 3 | errormsg: "'spawn' takes a call expression" 4 | cmd: "nim $target --threads:on $options $file" 5 | """ 6 | 7 | import threadpool 8 | 9 | let foo = spawn(1) 10 | -------------------------------------------------------------------------------- /tests/stdlib/nre/escape.nim: -------------------------------------------------------------------------------- 1 | import nre, unittest 2 | 3 | suite "escape strings": 4 | test "escape strings": 5 | check("123".escapeRe() == "123") 6 | check("[]".escapeRe() == r"\[\]") 7 | check("()".escapeRe() == r"\(\)") 8 | -------------------------------------------------------------------------------- /tests/stdlib/thashes.nim: -------------------------------------------------------------------------------- 1 | import unittest 2 | import hashes 3 | 4 | suite "hashes": 5 | suite "hashing": 6 | test "0.0 and -0.0 should have the same hash value": 7 | var dummy = 0.0 8 | check hash(dummy) == hash(-dummy) 9 | -------------------------------------------------------------------------------- /tests/trmacros/targlist.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "12false3ha" 3 | """ 4 | 5 | proc f(x: varargs[string, `$`]) = discard 6 | template optF{f(x)}(x: varargs[expr]) = 7 | writeLine(stdout, x) 8 | 9 | f 1, 2, false, 3, "ha" 10 | -------------------------------------------------------------------------------- /tests/tuples/tuint_tuple.nim: -------------------------------------------------------------------------------- 1 | # bug #1986 found by gdmoore 2 | 3 | proc test(): int64 = 4 | return 0xdeadbeef.int64 5 | 6 | const items = [ 7 | (var1: test(), var2: 100'u32), 8 | (var1: test(), var2: 192'u32) 9 | ] 10 | 11 | -------------------------------------------------------------------------------- /tests/vm/toverflowopcaddint.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "over- or underflow" 3 | """ 4 | 5 | static: 6 | proc p = 7 | var 8 | x = int64.high 9 | y = 1 10 | discard x + y 11 | assert false 12 | p() 13 | -------------------------------------------------------------------------------- /tests/vm/toverflowopcsubint.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "over- or underflow" 3 | """ 4 | 5 | static: 6 | proc p = 7 | var 8 | x = int64.low 9 | y = 1 10 | discard x - y 11 | assert false 12 | p() 13 | -------------------------------------------------------------------------------- /tests/ambsym/mambsym1.nim: -------------------------------------------------------------------------------- 1 | import mambsym2 # import TExport 2 | 3 | type 4 | TExport* = enum x, y, z 5 | TOtherEnum* = enum mDec, mInc, mAssign 6 | 7 | proc ha() = 8 | var 9 | x: TExport # no error 10 | discard 11 | -------------------------------------------------------------------------------- /tests/caas/forward_declarations.txt: -------------------------------------------------------------------------------- 1 | forward_declarations.nim 2 | 3 | > idetools --track:$TESTNIM,9,5 --def $SILENT 4 | skProc 5 | proc \(string\) 6 | 7 | > idetools --track:$TESTNIM,5,9 --def $SILENT 8 | skProc 9 | proc \(string\) 10 | -------------------------------------------------------------------------------- /tests/friends/tfriends.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "3" 3 | """ 4 | 5 | # Tests that a generic instantiation from a different module may access 6 | # private object fields: 7 | 8 | import mfriends 9 | 10 | echo gen[int]() 11 | 12 | -------------------------------------------------------------------------------- /tests/js/tcopying.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''123 3 | ''' 4 | """ 5 | 6 | type MyArray = array[1, int] 7 | 8 | proc changeArray(a: var MyArray) = 9 | a = [123] 10 | 11 | var a : MyArray 12 | changeArray(a) 13 | echo a[0] 14 | -------------------------------------------------------------------------------- /tests/js/testmagic.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''true 3 | 123 4 | ''' 5 | """ 6 | 7 | # This file tests some magic 8 | 9 | var foo = cstring("foo") 10 | var bar = cstring("foo") 11 | echo(foo == bar) 12 | echo "01234"[1 .. ^2] 13 | -------------------------------------------------------------------------------- /tests/method/mmultim3.nim: -------------------------------------------------------------------------------- 1 | type 2 | TObj* = object {.inheritable.} 3 | 4 | var myObj* : ref TObj 5 | 6 | method test123(a : ref TObj) = 7 | echo("Hi base!") 8 | 9 | proc testMyObj*() = 10 | test123(myObj) 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/misc/tcolonisproc.nim: -------------------------------------------------------------------------------- 1 | 2 | proc p(a, b: int, c: proc ()) = 3 | c() 4 | 5 | when false: 6 | # language spec changed: 7 | p(1, 3): 8 | echo 1 9 | echo 3 10 | 11 | p(1, 1, proc() = 12 | echo 1 13 | echo 2) 14 | -------------------------------------------------------------------------------- /tests/openarray/topena1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "topena1.nim" 3 | line: 9 4 | errormsg: "invalid type" 5 | """ 6 | # Tests a special bug 7 | 8 | var 9 | x: ref openarray[string] #ERROR_MSG invalid type 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/showoff/thello2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''(a: 3, b: 4, s: abc)''' 3 | """ 4 | 5 | type 6 | MyObject = object 7 | a, b: int 8 | s: string 9 | 10 | let obj = MyObject(a: 3, b: 4, s: "abc") 11 | echo obj 12 | -------------------------------------------------------------------------------- /tests/showoff/thtml1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "
" 3 | """ 4 | 5 | template htmlTag(tag: expr) {.immediate.} = 6 | proc tag(): string = "<" & astToStr(tag) & ">" 7 | 8 | htmlTag(br) 9 | htmlTag(html) 10 | 11 | echo br() 12 | -------------------------------------------------------------------------------- /tests/stdlib/tcputime.nim: -------------------------------------------------------------------------------- 1 | 2 | import times, os 3 | 4 | var e = epochTime() 5 | var c = cpuTime() 6 | 7 | os.sleep(1500) 8 | 9 | e = epochTime() - e 10 | c = cpuTime() - c 11 | 12 | echo "epochTime: ", e, " cpuTime: ", c 13 | 14 | -------------------------------------------------------------------------------- /tests/varres/tvarres3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "45" 3 | """ 4 | 5 | var 6 | g = 5 7 | 8 | proc p(): var int = 9 | var bla = addr(g) #: array [0..7, int] 10 | result = bla[] 11 | 12 | p() = 45 13 | 14 | echo g 15 | 16 | -------------------------------------------------------------------------------- /tests/vm/tconstobj.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''(name: hello)''' 3 | """ 4 | 5 | # bug #2774 6 | 7 | type Foo = object 8 | name: string 9 | 10 | const fooArray = [ 11 | Foo(name: "hello") 12 | ] 13 | 14 | echo fooArray[0] 15 | -------------------------------------------------------------------------------- /tests/exprs/texprstmt.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 10 3 | errormsg: "value of type 'string' has to be discarded" 4 | """ 5 | 6 | # bug #578 7 | 8 | proc test: string = 9 | result = "blah" 10 | result[1 .. ^1] 11 | 12 | echo test() 13 | -------------------------------------------------------------------------------- /tests/macros/treturnsempty.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch" 3 | line: 11 4 | """ 5 | # bug #2372 6 | macro foo(dummy: int): stmt = 7 | discard 8 | 9 | proc takeStr(s: string) = echo s 10 | 11 | takeStr foo(12) 12 | 13 | -------------------------------------------------------------------------------- /tests/manyloc/named_argument_bug/tri_engine/math/circle.nim: -------------------------------------------------------------------------------- 1 | import 2 | tri_engine/config, 3 | tri_engine/math/vec 4 | 5 | type 6 | TCircle* = tuple[p: TV2[TR], r: TR] 7 | 8 | converter toCircle*(o: TR): TCircle = 9 | (newV2(), o) 10 | -------------------------------------------------------------------------------- /tests/misc/tunsignedinc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''253''' 3 | """ 4 | 5 | # bug #2427 6 | 7 | import unsigned 8 | 9 | var x = 0'u8 10 | dec x # OverflowError 11 | x -= 1 # OverflowError 12 | x = x - 1 # No error 13 | 14 | echo x 15 | -------------------------------------------------------------------------------- /tests/modules/texport2.nim: -------------------------------------------------------------------------------- 1 | # bug #1595, #1612 2 | 3 | import mexport2a 4 | 5 | proc main() = 6 | echo "Import Test, two lines should follow. One with abc and one with xyz." 7 | printAbc() 8 | printXyz() 9 | 10 | main() 11 | foo(3) 12 | -------------------------------------------------------------------------------- /tests/tuples/twrongtupleaccess.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "twrongtupleaccess.nim" 3 | line: 9 4 | errormsg: "attempting to call undeclared routine: \'setBLAH\'" 5 | """ 6 | # Bugfix 7 | 8 | var v = (5.0, 10.0) 9 | v.setBLAH(10) 10 | 11 | -------------------------------------------------------------------------------- /tests/array/tarray3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tarray3.nim" 3 | output: "3" 4 | """ 5 | # simple check for two dimensional arrays 6 | 7 | const 8 | myData = [[1,2,3], [4, 5, 6]] 9 | 10 | echo myData[0][2] #OUT 3 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/bind/tinvalidbindtypedesc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 10 3 | errormsg: "type mismatch: got (typedesc[float], string)" 4 | """ 5 | 6 | proc foo(T: typedesc; some: T) = 7 | echo($some) 8 | 9 | foo int, 4 10 | foo float, "bad" 11 | 12 | -------------------------------------------------------------------------------- /tests/iter/tcountup.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tcountup.nim" 3 | output: "0123456789" 4 | """ 5 | 6 | # Test new countup and unary < 7 | 8 | for i in 0 .. < 10'i64: 9 | stdout.write(i) 10 | 11 | #OUT 0123456789 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/modules/mrecmod2.nim: -------------------------------------------------------------------------------- 1 | # Module B 2 | import trecmod2 3 | 4 | proc p*(x: trecmod2.T1): trecmod2.T1 = 5 | # this works because the compiler has already 6 | # added T1 to trecmod2's interface symbol table 7 | return x + 1 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/tuples/tdifferent_instantiations.nim: -------------------------------------------------------------------------------- 1 | # bug #1910 2 | import tables 3 | 4 | var p: OrderedTable[tuple[a:int], int] 5 | var q: OrderedTable[tuple[x:int], int] 6 | for key in p.keys: 7 | echo key.a 8 | for key in q.keys: 9 | echo key.x 10 | -------------------------------------------------------------------------------- /tinyc/include/varargs.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARARGS_H 2 | #define _VARARGS_H 3 | 4 | #include 5 | 6 | #define va_dcl 7 | #define va_alist __va_alist 8 | #undef va_start 9 | #define va_start(ap) ap = __builtin_varargs_start 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /tests/gensym/tgensym.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "123100" 3 | """ 4 | 5 | template hygienic(val: expr) = 6 | var x = val 7 | stdout.write x 8 | 9 | var x = 100 10 | 11 | hygienic 1 12 | hygienic 2 13 | hygienic 3 14 | 15 | echo x 16 | 17 | -------------------------------------------------------------------------------- /tests/metatype/ttypebar.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #602 3 | 4 | type 5 | TTest = object 6 | TTest2* = object 7 | TFoo = TTest | TTest2 8 | 9 | proc f(src: ptr TFoo, dst: ptr TFoo) = 10 | echo("asd") 11 | 12 | var x: TTest 13 | f(addr x, addr x) 14 | 15 | -------------------------------------------------------------------------------- /tests/seq/tseqcon2.nim: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | proc rec_dir(dir: string): seq[string] = 4 | result = @[] 5 | for kind, path in walk_dir(dir): 6 | if kind == pcDir: 7 | add(result, rec_dir(path)) 8 | else: 9 | add(result, path) 10 | -------------------------------------------------------------------------------- /tests/typerel/ttypenovalue.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "value expected, but got a type" 3 | line: 7 4 | disabled: true 5 | """ 6 | 7 | proc crashAndBurn() = 8 | var stuff = seq[tuple[title, body: string]] 9 | 10 | 11 | crashAndBurn() 12 | -------------------------------------------------------------------------------- /tests/vm/twrongwhen.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "cannot evaluate at compile time: x" 3 | line: 7 4 | """ 5 | 6 | proc bla(x:int) = 7 | when x == 0: 8 | echo "oops" 9 | else: 10 | echo "good" 11 | 12 | bla(2) # echos "oops" 13 | 14 | -------------------------------------------------------------------------------- /tinyc/win32/include/varargs.h: -------------------------------------------------------------------------------- 1 | #ifndef _VARARGS_H 2 | #define _VARARGS_H 3 | 4 | #include 5 | 6 | #define va_dcl 7 | #define va_alist __va_alist 8 | #undef va_start 9 | #define va_start(ap) ap = __builtin_varargs_start 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /tinyc/win32/lib/dllmain.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) 6 | { 7 | return TRUE; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/async/tnestedpfuturetypeparam.nim: -------------------------------------------------------------------------------- 1 | import asyncdispatch, asyncnet 2 | 3 | proc main {.async.} = 4 | proc f: Future[seq[int]] {.async.} = 5 | await newAsyncSocket().connect("www.google.com", Port(80)) 6 | let x = await f() 7 | 8 | asyncCheck main() 9 | -------------------------------------------------------------------------------- /tests/caas/issue_477_dynamic_dispatch.txt: -------------------------------------------------------------------------------- 1 | issue_477_dynamic_dispatch.nim 2 | > c --run 3 | SuccessX 4 | > idetools --track:issue_477_dynamic_dispatch.nim,19,5 --def $SILENT 5 | def\tskMethod\tissue_477_dynamic_dispatch.collide\tproc \(TUnit, TThing\)\{.inline.\} 6 | -------------------------------------------------------------------------------- /tests/ccgbugs/tarray_equality.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''true 3 | true''' 4 | """ 5 | 6 | # bug #2489 7 | 8 | let a = [1] 9 | let b = [1] 10 | echo a == b 11 | 12 | # bug #2498 13 | var x: array[0, int] 14 | var y: array[0, int] 15 | echo x == y 16 | -------------------------------------------------------------------------------- /tests/generics/tcan_specialise_generic.nim: -------------------------------------------------------------------------------- 1 | ## 2 | ## can_specialise_generic Nim Module 3 | ## 4 | ## Created by Eric Doughty-Papassideris on 2011-02-16. 5 | 6 | type 7 | TGen[T] = object {.inheritable.} 8 | TSpef = object of TGen[string] 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/generics/tgenerictmpl.nim: -------------------------------------------------------------------------------- 1 | 2 | template tmp[T](x: var seq[T]) = 3 | #var yz: T # XXX doesn't work yet 4 | x = @[1, 2, 3] 5 | 6 | macro tmp2[T](x: var seq[T]): stmt = 7 | nil 8 | 9 | var y: seq[int] 10 | tmp(y) 11 | tmp(y) 12 | echo y.repr 13 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/enet_server/server_settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Alpha Zone", 3 | "desc": "Beta Testing", 4 | "host": "localhost", 5 | "port": 8024, 6 | "settings": "alphazone.json", 7 | "dirserver":["localhost",2049,"alphazone","skittles"] 8 | } 9 | -------------------------------------------------------------------------------- /tests/misc/trawstr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "trawstr.nim" 3 | line: 10 4 | errormsg: "closing \" expected" 5 | """ 6 | # Test the new raw strings: 7 | 8 | const 9 | xxx = r"This is a raw string!" 10 | yyy = "This not\" #ERROR 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/modules/tselfimport.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tselfimport.nim" 3 | line: 7 4 | errormsg: "A module cannot import itself" 5 | """ 6 | import strutils as su # guard against regression 7 | import tselfimport #ERROR 8 | echo("Hello World") 9 | 10 | -------------------------------------------------------------------------------- /tests/stdlib/treloop.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "@[(, +, 1, 2, )]" 3 | """ 4 | 5 | import re 6 | 7 | let str = "(+ 1 2)" 8 | var tokenRE = re"""[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)""" 9 | echo str.findAll(tokenRE) 10 | -------------------------------------------------------------------------------- /tests/stdlib/txmlgen.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "txmlgen.nim" 3 | output: "

Nim

" 4 | """ 5 | import htmlgen 6 | 7 | var nim = "Nim" 8 | echo h1(a(href="http://force7.de/nim", nim)) 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/types/tfinalobj.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "abc" 3 | """ 4 | 5 | type 6 | TA = object {.pure, final.} 7 | x: string 8 | 9 | var 10 | a: TA 11 | a.x = "abc" 12 | 13 | doAssert TA.sizeof == string.sizeof 14 | 15 | echo a.x 16 | 17 | -------------------------------------------------------------------------------- /tests/varres/tvarres2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tvarres2.nim" 3 | line: 11 4 | errormsg: "expression has no address" 5 | """ 6 | 7 | var 8 | g = 5 9 | 10 | proc p(): var int = 11 | result = 89 12 | 13 | p() = 45 14 | 15 | echo g 16 | 17 | -------------------------------------------------------------------------------- /tests/casestmt/tcaseoverlaprange.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 13 3 | errormsg: "duplicate case label" 4 | """ 5 | 6 | type 7 | TE = enum A, B, C, D 8 | 9 | var 10 | e: TE 11 | 12 | case e 13 | of A..D, B..C: 14 | echo "redundant" 15 | else: nil 16 | -------------------------------------------------------------------------------- /tests/closure/tnestedproc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "11" 3 | """ 4 | 5 | proc p(x, y: int): int = 6 | result = x + y 7 | 8 | echo p((proc (): int = 9 | var x = 7 10 | return x)(), 11 | (proc (): int = return 4)()) 12 | 13 | -------------------------------------------------------------------------------- /tests/iter/twrongiter.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 12 3 | errormsg: "type mismatch" 4 | """ 5 | 6 | proc first(it: iterator(): int): seq[int] = 7 | return @[] 8 | 9 | iterator primes(): int = 10 | yield 1 11 | 12 | for i in first(primes): 13 | break 14 | -------------------------------------------------------------------------------- /tests/manyloc/standalone/barebone.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #2041: Macros need to be available for os:standalone! 3 | import macros 4 | 5 | proc printf(frmt: cstring) {.varargs, header: "", cdecl.} 6 | 7 | var x = 0 8 | inc x 9 | printf("hi %ld\n", x+4777) 10 | -------------------------------------------------------------------------------- /tests/method/tsimmeth.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsimmeth.nim" 3 | output: "HELLO WORLD!" 4 | """ 5 | # Test method simulation 6 | 7 | import strutils 8 | 9 | var x = "hello world!".toLower.toUpper 10 | x.echo() 11 | #OUT HELLO WORLD! 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/misc/tsimtych.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsimtych.nim" 3 | line: 10 4 | errormsg: "type mismatch: got (bool) but expected \'string\'" 5 | """ 6 | # Test 2 7 | # Simple type checking 8 | 9 | var a: string 10 | a = false #ERROR 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/modules/tnamspc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tnamspc.nim" 3 | line: 10 4 | errormsg: "undeclared identifier: \'global\'" 5 | """ 6 | # Test17 - test correct handling of namespaces 7 | 8 | import mnamspc1 9 | 10 | global = 9 #ERROR 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/modules/trecincb.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "trecincb.nim" 3 | line: 9 4 | errormsg: "recursive dependency: 'tests/modules/trecincb.nim'" 5 | """ 6 | # Test recursive includes 7 | 8 | 9 | include trecincb 10 | 11 | echo "trecinb" 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/modules/trecmod2.nim: -------------------------------------------------------------------------------- 1 | type 2 | T1* = int # Module A exports the type ``T1`` 3 | 4 | import mrecmod2 # the compiler starts parsing B 5 | 6 | proc main() = 7 | var i = p(3) # works because B has been parsed completely here 8 | 9 | main() 10 | 11 | -------------------------------------------------------------------------------- /tests/pragmas/tpush.nim: -------------------------------------------------------------------------------- 1 | # test the new pragmas 2 | 3 | {.push warnings: off, hints: off.} 4 | proc noWarning() = 5 | var 6 | x: int 7 | echo(x) 8 | 9 | {.pop.} 10 | 11 | proc WarnMe() = 12 | var 13 | x: int 14 | echo(x) 15 | 16 | -------------------------------------------------------------------------------- /doc/manual/compiler_msgs.txt: -------------------------------------------------------------------------------- 1 | Compiler Messages 2 | ================= 3 | 4 | The Nim compiler emits different kinds of messages: `hint`:idx:, 5 | `warning`:idx:, and `error`:idx: messages. An *error* message is emitted if 6 | the compiler encounters any static error. 7 | 8 | -------------------------------------------------------------------------------- /tests/misc/tinvalidarrayaccess.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "index out of bounds" 3 | line: 11 4 | """ 5 | 6 | 7 | type TTestArr = array[0..1, int16] 8 | var f: TTestArr 9 | f[0] = 30 10 | f[1] = 40 11 | f[2] = 50 12 | f[3] = 60 13 | 14 | echo(repr(f)) 15 | -------------------------------------------------------------------------------- /tests/misc/tissue710.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tissue710.nim" 3 | line: 8 4 | errorMsg: "attempting to call undeclared routine: '||'" 5 | """ 6 | var sum = 0 7 | for x in 3..1000: 8 | if (x mod 3 == 0) || (x mod 5 == 0): 9 | sum += x 10 | echo(sum) 11 | -------------------------------------------------------------------------------- /tests/modules/trecinca.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tests/reject/trecincb.nim" 3 | line: 9 4 | errormsg: "recursive dependency: 'tests/modules/trecincb.nim'" 5 | """ 6 | # Test recursive includes 7 | 8 | include trecincb 9 | 10 | echo "trecina" 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/parser/tinvcolonlocation1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tinvcolonlocation1.nim" 3 | line: 8 4 | column: 3 5 | errormsg: "':' expected" 6 | """ 7 | try #<- missing ':' 8 | echo "try" 9 | except: 10 | echo "except" 11 | finally: 12 | echo "finally" 13 | -------------------------------------------------------------------------------- /tests/parser/tinvcolonlocation3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tinvcolonlocation3.nim" 3 | line: 12 4 | column: 3 5 | errormsg: "':' expected" 6 | """ 7 | try: 8 | echo "try" 9 | except: 10 | echo "except" 11 | finally #<- missing ':' 12 | echo "finally" 13 | -------------------------------------------------------------------------------- /tests/trmacros/tnoalias.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "23" 3 | """ 4 | 5 | template optslice{a = b + c}(a: expr{noalias}, b, c: expr): stmt = 6 | a = b 7 | inc a, c 8 | 9 | var 10 | x = 12 11 | y = 10 12 | z = 13 13 | 14 | x = y+z 15 | 16 | echo x 17 | -------------------------------------------------------------------------------- /examples/fizzbuzz.nim: -------------------------------------------------------------------------------- 1 | # Fizz Buzz program 2 | 3 | const f = "Fizz" 4 | const b = "Buzz" 5 | for i in 1..100: 6 | if i mod 15 == 0: 7 | echo f, b 8 | elif i mod 5 == 0: 9 | echo b 10 | elif i mod 3 == 0: 11 | echo f 12 | else: 13 | echo i 14 | 15 | -------------------------------------------------------------------------------- /tests/assert/tuserassert.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "x == 45ugh" 3 | """ 4 | 5 | template myAssert(cond: expr) = 6 | when 3 <= 3: 7 | let c = cond.astToStr 8 | if not cond: 9 | echo c, "ugh" 10 | 11 | var x = 454 12 | myAssert(x == 45) 13 | 14 | -------------------------------------------------------------------------------- /tests/assign/moverload_asgn2.nim: -------------------------------------------------------------------------------- 1 | type 2 | Concrete* = object 3 | a*, b*: string 4 | rc*: int # refcount 5 | 6 | proc `=`(d: var Concrete; src: Concrete) = 7 | shallowCopy(d.a, src.a) 8 | shallowCopy(d.b, src.b) 9 | dec d.rc 10 | d.rc = src.rc + 1 11 | -------------------------------------------------------------------------------- /tests/caas/main_dirty.nim: -------------------------------------------------------------------------------- 1 | import imported, strutils 2 | 3 | type 4 | TFoo = object 5 | x: int 6 | y: string 7 | 8 | proc main = 9 | var t1 = "text" 10 | var t2 = t1.toUpper 11 | var foo = TFoo(x: 10, y: "test") 12 | foo. 13 | echo(t1 +++ t2) 14 | 15 | -------------------------------------------------------------------------------- /tests/ccgbugs/taddhigh.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''@[5, 5, 5]''' 3 | """ 4 | 5 | # bug #1832 6 | 7 | var s = @[5] 8 | 9 | # Works fine: 10 | let x = s[s.high] 11 | s.add x 12 | 13 | # Causes the 0 to appear: 14 | s.add s[s.high] 15 | 16 | echo s # @[5, 5, 0] 17 | -------------------------------------------------------------------------------- /tests/closure/tinvalidclosure2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 10 3 | errormsg: "illegal capture 'A'" 4 | """ 5 | 6 | proc outer() = 7 | var A: int 8 | 9 | proc ugh[T](x: T) {.cdecl.} = 10 | echo "ugha", A, x 11 | 12 | ugh[int](12) 13 | 14 | outer() 15 | -------------------------------------------------------------------------------- /tests/enum/tenumitems2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "A\nB\nC" 3 | """ 4 | 5 | type TAlphabet = enum 6 | A, B, C 7 | 8 | iterator items(E: typedesc[enum]): E = 9 | for v in low(E)..high(E): 10 | yield v 11 | 12 | for c in TAlphabet: 13 | echo($c) 14 | 15 | -------------------------------------------------------------------------------- /tests/generics/tarray_with_somenumber.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''@[0.9, 0.1]''' 3 | """ 4 | 5 | # bug #2304 6 | 7 | type TV2*[T:SomeNumber] = array[0..1, T] 8 | proc newV2T*[T](x, y: T=0): TV2[T] = [x, y] 9 | 10 | let x = newV2T[float](0.9, 0.1) 11 | echo(@x) 12 | -------------------------------------------------------------------------------- /tests/let/tlet.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: "10" 3 | errormsg: "'name' cannot be assigned to" 4 | """ 5 | 6 | echo("What's your name? ") 7 | let name = readLine(stdin) 8 | while name == "": 9 | echo("Please tell me your name: ") 10 | name = readLine(stdin) 11 | 12 | -------------------------------------------------------------------------------- /tests/modules/texport.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "my object68" 3 | """ 4 | 5 | import mexporta 6 | 7 | # bug #1029: 8 | from rawsockets import accept 9 | 10 | # B.TMyObject has been imported implicitly here: 11 | var x: TMyObject 12 | echo($x, q(0), q"0") 13 | 14 | -------------------------------------------------------------------------------- /tests/overflw/toverflw2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "toverflw2.nim" 3 | outputsub: "Error: unhandled exception: over- or underflow [OverflowError]" 4 | exitcode: "1" 5 | """ 6 | var a : int32 = 2147483647 7 | var b : int32 = 2147483647 8 | var c = a + b 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/threads/tactors.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | outputsub: "150" 3 | """ 4 | 5 | import actors 6 | 7 | var 8 | pool: TActorPool[int, void] 9 | createActorPool(pool) 10 | for i in 0 .. < 300: 11 | pool.spawn(i, proc (x: int) {.thread.} = echo x) 12 | pool.join() 13 | 14 | -------------------------------------------------------------------------------- /tests/typerel/typedescs.nim: -------------------------------------------------------------------------------- 1 | # bug #1774 2 | proc p(T: typedesc) = discard 3 | 4 | p(type((5, 6))) # Compiles 5 | (type((5, 6))).p # Doesn't compile (SIGSEGV: Illegal storage access.) 6 | type T = type((5, 6)) # Doesn't compile (SIGSEGV: Illegal storage access.) 7 | 8 | -------------------------------------------------------------------------------- /doc/docgen_sample.nim: -------------------------------------------------------------------------------- 1 | ## This module is a sample. 2 | 3 | import strutils 4 | 5 | proc helloWorld*(times: int) = 6 | ## Takes an integer and outputs 7 | ## as many "hello world!"s 8 | 9 | for i in 0 .. times-1: 10 | echo "hello world!" 11 | 12 | helloWorld(5) 13 | -------------------------------------------------------------------------------- /examples/talk/quasiquote.nim: -------------------------------------------------------------------------------- 1 | 2 | import macros 3 | 4 | macro check(ex: expr): stmt = 5 | var info = ex.lineinfo 6 | var expString = ex.toStrLit 7 | result = quote do: 8 | if not `ex`: 9 | echo `info`, ": Check failed: ", `expString` 10 | 11 | check 1 < 2 12 | -------------------------------------------------------------------------------- /tests/lexer/tunderscores.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tunderscores.nim" 3 | line: 8 4 | errormsg: "invalid token: _" 5 | """ 6 | # Bug #502670 7 | 8 | var ef_ = 3 #ERROR_MSG invalid token: _ 9 | var a__b = 1 10 | var c___d = 2 11 | echo(ab, cd, ef_) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/enet_server/nim.cfg: -------------------------------------------------------------------------------- 1 | path = ".." 2 | path = "../dependencies/sfml" 3 | path = "../dependencies/enet" 4 | path = "../dependencies/nake" 5 | path = "../dependencies/genpacket" 6 | path = "../lib" 7 | define = "noChipmunk" 8 | define = "noSFML" 9 | 10 | -------------------------------------------------------------------------------- /tests/modules/tmismatchedvisibility.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 8 3 | errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)' has non-public forward declaration in " 4 | """ 5 | 6 | proc foo(a: int): int 7 | 8 | proc foo*(a: int): int = 9 | result = a + a 10 | -------------------------------------------------------------------------------- /tests/stdlib/txmltree.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "txmltree.nim" 3 | output: "true" 4 | """ 5 | 6 | import xmltree, strtabs 7 | 8 | var x = <>a(href="nim.de", newText("www.nim-test.de")) 9 | 10 | echo($x == "www.nim-test.de") 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/curlex.nim: -------------------------------------------------------------------------------- 1 | import 2 | libcurl 3 | 4 | var hCurl = easy_init() 5 | if hCurl != nil: 6 | discard easy_setopt(hCurl, OPT_VERBOSE, true) 7 | discard easy_setopt(hCurl, OPT_URL, "http://nim-lang.org/") 8 | discard easy_perform(hCurl) 9 | easy_cleanup(hCurl) 10 | 11 | -------------------------------------------------------------------------------- /tests/controlflow/tstatret.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tstatret.nim" 3 | line: 9 4 | errormsg: "statement not allowed after" 5 | """ 6 | # no statement after return 7 | proc main() = 8 | return 9 | echo("huch?") #ERROR_MSG statement not allowed after 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/rodfiles/amethods.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | TBaseClass* = object of TObject 4 | 5 | proc newBaseClass*: ref TBaseClass = 6 | new result 7 | 8 | method echoType*(x: ref TBaseClass) = 9 | echo "base class" 10 | 11 | proc echoAlias*(x: ref TBaseClass) = 12 | echoType x 13 | 14 | -------------------------------------------------------------------------------- /tests/varstmt/tvardecl.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tvardecl.nim" 3 | output: "44" 4 | """ 5 | # Test the new variable declaration syntax 6 | 7 | var 8 | x = 0 9 | s = "Hallo" 10 | a, b: int = 4 11 | 12 | write(stdout, a) 13 | write(stdout, b) #OUT 44 14 | 15 | 16 | -------------------------------------------------------------------------------- /compiler.nimble: -------------------------------------------------------------------------------- 1 | [Package] 2 | name = "compiler" 3 | version = "0.11.3" 4 | author = "Andreas Rumpf" 5 | description = "Compiler package providing the compiler sources as a library." 6 | license = "MIT" 7 | 8 | InstallDirs = "doc, compiler" 9 | 10 | [Deps] 11 | Requires: "nim >= 0.11.3" 12 | -------------------------------------------------------------------------------- /tests/ambsym/tambsym.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tambsym.nim" 3 | line: 11 4 | errormsg: "ambiguous identifier" 5 | """ 6 | # Test ambiguous symbols 7 | 8 | import mambsym1, mambsym2 9 | 10 | var 11 | v: TExport #ERROR_MSG ambiguous identifier 12 | 13 | v = y 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/cnstseq/tcnstseq2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "AngelikaAnneAnnaAnkaAnja" 3 | """ 4 | 5 | const 6 | myWords = @["Angelika", "Anne", "Anna", "Anka", "Anja"] 7 | 8 | for i in 0 .. high(myWords): 9 | write(stdout, myWords[i]) #OUT AngelikaAnneAnnaAnkaAnja 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/converter/ttypeconverter1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''foo 3 | true''' 4 | """ 5 | 6 | converter p(i: int): bool = return i != 0 7 | 8 | if 1: 9 | echo if 4: "foo" else: "barr" 10 | while 0: 11 | echo "bar" 12 | 13 | var a: array[3, bool] 14 | a[0] = 3 15 | echo a[0] 16 | -------------------------------------------------------------------------------- /tests/exception/twrongexc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "twrongexc.nim" 3 | outputsub: "Error: unhandled exception: [ValueError]" 4 | exitcode: "1" 5 | """ 6 | try: 7 | raise newException(ValueError, "") 8 | except OverflowError: 9 | echo("Error caught") 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/client_settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "resolution": [800,600,32], 3 | "default-file": "alphazone.json", 4 | "alias": "foo", 5 | "directory-server":{ 6 | "host":"localhost", 7 | "port":8024 8 | }, 9 | "website":"https://github.com/fowlmouth/keineSchweine" 10 | } 11 | -------------------------------------------------------------------------------- /tests/method/temptybody.nim: -------------------------------------------------------------------------------- 1 | # bug #2401 2 | 3 | type MyClass = ref object of RootObj 4 | 5 | method HelloWorld*(obj: MyClass) = 6 | when defined(myPragma): 7 | echo("Hello World") 8 | # discard # with this line enabled it works 9 | 10 | var obj = MyClass() 11 | obj.HelloWorld() 12 | -------------------------------------------------------------------------------- /tests/testdata/doc1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | bla ah absy hsh 7 | hsh 8 | sjj 9 | 10 | bla 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/typerel/typalias.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | TMyObj = TYourObj 4 | TYourObj = object of RootObj 5 | x, y: int 6 | 7 | proc init: TYourObj = 8 | result.x = 0 9 | result.y = -1 10 | 11 | proc f(x: var TYourObj) = 12 | discard 13 | 14 | var m: TMyObj = init() 15 | f(m) 16 | -------------------------------------------------------------------------------- /examples/cgi/example.nim: -------------------------------------------------------------------------------- 1 | import cgi 2 | 3 | write(stdout, "Content-type: text/html\n\n") 4 | write(stdout, "\n") 5 | write(stdout, "Test\n") 6 | write(stdout, "Hello!") 7 | writeLine(stdout, "") 8 | -------------------------------------------------------------------------------- /tests/bind/tbindoverload.nim: -------------------------------------------------------------------------------- 1 | import strtabs 2 | 3 | template t*() = 4 | block: 5 | bind newStringTable 6 | discard {"Content-Type": "text/html"}.newStringTable() 7 | 8 | discard {:}.newStringTable 9 | 10 | #discard {"Content-Type": "text/html"}.newStringTable() 11 | 12 | t() 13 | -------------------------------------------------------------------------------- /tests/borrow/tinvalidborrow.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 11 3 | errormsg: "no symbol to borrow from found" 4 | """ 5 | 6 | # bug #516 7 | 8 | type 9 | TAtom = culong 10 | 11 | proc `==`*(a, b: TAtom): bool {.borrow.} 12 | 13 | var 14 | d, e: TAtom 15 | 16 | echo( $(d == e) ) 17 | 18 | -------------------------------------------------------------------------------- /tests/enum/tenum3.nim: -------------------------------------------------------------------------------- 1 | # Test enum with explicit size 2 | 3 | type 4 | TEnumHole {.size: sizeof(int).} = enum 5 | eA = 0, 6 | eB = 4, 7 | eC = 5 8 | 9 | var 10 | e: TEnumHole = eB 11 | 12 | case e 13 | of eA: echo "A" 14 | of eB: echo "B" 15 | of eC: echo "C" 16 | 17 | -------------------------------------------------------------------------------- /tests/iter/titer5.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "titer5.nim" 3 | output: "abcxyz" 4 | """ 5 | # Test method call syntax for iterators: 6 | import strutils 7 | 8 | const lines = """abc xyz""" 9 | 10 | for x in lines.split(): 11 | stdout.write(x) 12 | 13 | #OUT abcxyz 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/tuples/tanontuples.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''61, 125''' 3 | """ 4 | 5 | proc `^` (a, b: int): int = 6 | result = 1 7 | for i in 1..b: result = result * a 8 | 9 | var m = (0, 5) 10 | var n = (56, 3) 11 | 12 | m = (n[0] + m[1], m[1] ^ n[1]) 13 | 14 | echo m[0], ", ", m[1] 15 | -------------------------------------------------------------------------------- /examples/cross_calculator/.gitignore: -------------------------------------------------------------------------------- 1 | # Android specific absolute paths. 2 | android/bin/ 3 | android/gen/ 4 | android/jni/backend-jni.h 5 | android/libs/ 6 | android/local.properties 7 | android/obj/ 8 | android/tags 9 | # iOS specific absolute paths 10 | ios/resources/ui/*.m 11 | ios/tags 12 | 13 | -------------------------------------------------------------------------------- /tests/ccgbugs/trecursive_table.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #1700 3 | import tables 4 | 5 | type 6 | E* = enum 7 | eX 8 | eY 9 | T* = object 10 | case kind: E 11 | of eX: 12 | xVal: Table[string, T] 13 | of eY: 14 | nil 15 | 16 | proc p*(x: Table[string, T]) = 17 | discard 18 | -------------------------------------------------------------------------------- /tests/misc/tunsignedcmp.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''true 3 | true 4 | true''' 5 | """ 6 | 7 | # bug 1420 8 | import unsigned 9 | 10 | var x = 40'u32 11 | var y = 30'u32 12 | echo x > y # works 13 | 14 | echo((40'i32) > (30'i32)) 15 | echo((40'u32) > (30'u32)) # Error: ordinal type expected 16 | -------------------------------------------------------------------------------- /tests/parser/twhen_in_enum.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "identifier expected, but found 'keyword when'" 3 | """ 4 | 5 | # bug #2123 6 | type num = enum 7 | NUM_NONE = 0 8 | NUM_ALL = 1 9 | when defined(macosx): NUM_OSX = 10 # only this differs for real 10 | NUM_XTRA = 20 11 | 12 | -------------------------------------------------------------------------------- /tests/varres/tvarres1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tvarres1.nim" 3 | line: 12 4 | errormsg: "address of 'bla' may not escape its stack frame" 5 | """ 6 | 7 | var 8 | g = 5 9 | 10 | proc p(): var int = 11 | var bla: int 12 | result = bla 13 | 14 | p() = 45 15 | 16 | echo g 17 | 18 | -------------------------------------------------------------------------------- /examples/cross_calculator/lazarus/nimlaz.rc: -------------------------------------------------------------------------------- 1 | #define RT_MANIFEST 24 2 | #define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 3 | #define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2 4 | #define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3 5 | 6 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "nimlaz.manifest" 7 | -------------------------------------------------------------------------------- /tests/assign/tgenericassigntuples.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''abc232''' 3 | """ 4 | 5 | var t, s: tuple[x: string, c: int] 6 | 7 | proc ugh: seq[tuple[x: string, c: int]] = 8 | result = @[("abc", 232)] 9 | 10 | t = ugh()[0] 11 | s = t 12 | s = ugh()[0] 13 | 14 | echo s[0], t[1] 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/enum/tenum2.nim: -------------------------------------------------------------------------------- 1 | # Test that enum with holes is handled correctly by case statement 2 | 3 | type 4 | TEnumHole = enum 5 | eA = 0, 6 | eB = 4, 7 | eC = 5 8 | 9 | var 10 | e: TEnumHole = eB 11 | 12 | case e 13 | of eA: echo "A" 14 | of eB: echo "B" 15 | of eC: echo "C" 16 | 17 | -------------------------------------------------------------------------------- /tests/generics/tforwardgeneric.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "1.1000000000000001e+00 11" 3 | ccodecheck: "!@'ClEnv'" 4 | disabled: "true" 5 | """ 6 | 7 | proc p[T](a, b: T): T 8 | 9 | echo p(0.9, 0.1), " ", p(9, 1) 10 | 11 | proc p[T](a, b: T): T = 12 | let c = b 13 | result = a + b + c 14 | 15 | -------------------------------------------------------------------------------- /tests/generics/tspecialised_is_equivalent.nim: -------------------------------------------------------------------------------- 1 | ## 2 | ## specialised_is_equivalent Nim Module 3 | ## 4 | ## Created by Eric Doughty-Papassideris on 2011-02-16. 5 | 6 | type 7 | TGen[T] = tuple[a: T] 8 | TSpef = tuple[a: string] 9 | 10 | var 11 | a: TGen[string] 12 | b: TSpef 13 | a = b 14 | 15 | -------------------------------------------------------------------------------- /tests/misc/tinout.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tinout.nim" 3 | line: 12 4 | errormsg: "type mismatch: got (int literal(3))" 5 | """ 6 | # Test in out checking for parameters 7 | 8 | proc abc(x: var int) = 9 | x = 0 10 | 11 | proc b() = 12 | abc(3) #ERROR 13 | 14 | b() 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/range/tsubrange2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsubrange2.nim" 3 | outputsub: "value out of range: 50 [RangeError]" 4 | exitcode: "1" 5 | """ 6 | 7 | type 8 | TRange = range[0..40] 9 | 10 | proc p(r: TRange) = 11 | discard 12 | 13 | var 14 | r: TRange 15 | y = 50 16 | p y 17 | 18 | -------------------------------------------------------------------------------- /tests/stdlib/tos.nim: -------------------------------------------------------------------------------- 1 | # test some things of the os module 2 | 3 | import os 4 | 5 | proc walkDirTree(root: string) = 6 | for k, f in walkDir(root): 7 | case k 8 | of pcFile, pcLinkToFile: echo(f) 9 | of pcDir: walkDirTree(f) 10 | of pcLinkToDir: discard 11 | 12 | walkDirTree(".") 13 | -------------------------------------------------------------------------------- /tests/vm/tldconst.nim: -------------------------------------------------------------------------------- 1 | # Passes if it compiles 2 | # From issue #1946 3 | 4 | type 5 | Part = object 6 | index: int ## array index of argument to be accessed 7 | 8 | proc foobar(): int = 9 | var x: Part 10 | if x.index < high(int): 11 | discard 12 | 0 13 | 14 | const x = foobar() -------------------------------------------------------------------------------- /tests/vm/tslurp.nim: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | template getScriptDir(): string = 4 | parentDir(instantiationInfo(-1, true).filename) 5 | 6 | const 7 | relRes = slurp"../../readme.txt" 8 | absRes = slurp(parentDir(parentDir(getScriptDir())) / "readme.txt") 9 | 10 | echo relRes 11 | echo absRes 12 | 13 | -------------------------------------------------------------------------------- /tests/ambsym/tambsym3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tambsym3.nim" 3 | line: 11 4 | errormsg: "ambiguous identifier" 5 | """ 6 | # Test ambiguous symbols 7 | 8 | import mambsym1, times 9 | 10 | var 11 | v = mDec #ERROR_MSG ambiguous identifier 12 | 13 | writeLine(stdout, ord(v)) 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/caas/compile-then-def.txt: -------------------------------------------------------------------------------- 1 | main.nim 2 | > c --verbosity:0 --hints:on 3 | SuccessX 4 | 5 | > idetools --track:$TESTNIM,5,18 --def --verbosity:0 --hints:on 6 | strutils.toUpper 7 | ! SuccessX 8 | 9 | > idetools --track:$TESTNIM,5,18 --def --verbosity:0 --hints:on 10 | strutils.toUpper 11 | ! SuccessX 12 | -------------------------------------------------------------------------------- /tests/ccgbugs/tpartialcs.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #2551 3 | 4 | type Tup = tuple 5 | A, a: int 6 | 7 | type Obj = object 8 | A, a: int 9 | 10 | var x: Tup # This works. 11 | var y: Obj # This doesn't. 12 | 13 | # bug #2212 14 | 15 | proc f() = 16 | let 17 | p = 1.0 18 | P = 0.25 + 0.5 19 | 20 | f() 21 | -------------------------------------------------------------------------------- /tests/closure/tinvalidclosure.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 12 3 | errormsg: "type mismatch: got (proc (x: int){.closure, gcsafe, locks: 0.})" 4 | """ 5 | 6 | proc ugh[T](x: T) {.closure.} = 7 | echo "ugha" 8 | 9 | 10 | proc takeCdecl(p: proc (x: int) {.cdecl.}) = discard 11 | 12 | takeCDecl(ugh[int]) 13 | -------------------------------------------------------------------------------- /tests/iter/titer4.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "titer4.nim" 3 | line: 7 4 | errormsg: "iterator within for loop context expected" 5 | """ 6 | # implicit items/pairs, but not if we have 3 for loop vars: 7 | for x, y, z in {'a'..'z'}: #ERROR_MSG iterator within for loop context expected 8 | nil 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/namedparams/tnamedparams3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch: got (int literal(5), b: bool)" 3 | line: 10 4 | """ 5 | 6 | # bug #2993 7 | proc test(i: int, a, b: bool) = discard 8 | #test(5, b = false) #Missing param a 9 | 10 | 5.test(b = false) #Missing param a 11 | -------------------------------------------------------------------------------- /tests/overload/toverl.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "toverl.nim" 3 | line: 11 4 | errormsg: "redefinition of \'TNone\'" 5 | """ 6 | # Test for overloading 7 | 8 | type 9 | TNone {.exportc: "_NONE", final.} = object 10 | 11 | proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone' 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/overload/toverwr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "toverwr.nim" 3 | output: "hello" 4 | """ 5 | # Test the overloading resolution in connection with a qualifier 6 | 7 | proc write(t: TFile, s: string) = 8 | discard # a nop 9 | 10 | system.write(stdout, "hello") 11 | #OUT hello 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/typerel/tnocontains.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tnocontains.nim" 3 | line: 10 4 | errormsg: "type mismatch: got (string, string)" 5 | """ 6 | 7 | # shouldn't compile since it doesn't do what you think it does without 8 | # importing strutils: 9 | 10 | let x = "abcdef".contains("abc") 11 | echo x 12 | -------------------------------------------------------------------------------- /doc/readme.txt: -------------------------------------------------------------------------------- 1 | ============================ 2 | Nim's documenation system 3 | ============================ 4 | 5 | This folder contains Nim's documentation. The documentation 6 | is written in a format called *reStructuredText*, a markup language that reads 7 | like ASCII and can be converted to HTML automatically! 8 | -------------------------------------------------------------------------------- /tests/caas/def-def-compile.txt: -------------------------------------------------------------------------------- 1 | main.nim 2 | > idetools --track:$TESTNIM,5,18 --def --verbosity:0 --hints:on 3 | strutils.toUpper 4 | ! SuccessX 5 | 6 | > idetools --track:$TESTNIM,5,18 --def --verbosity:0 --hints:on 7 | strutils.toUpper 8 | ! SuccessX 9 | 10 | > c --verbosity:0 --hints:on 11 | SuccessX 12 | 13 | -------------------------------------------------------------------------------- /tests/caas/issue_452_export_shift.nim: -------------------------------------------------------------------------------- 1 | const 2 | VERSION_STR1* = "0.5.0" ## Idetools shifts this one column. 3 | VERSION_STR2 = "0.5.0" ## This one is ok. 4 | VERSION_STR3* = "0.5.0" ## Bad. 5 | VERSION_STR4 = "0.5.0" ## Ok. 6 | 7 | proc forward1*(): string = result = "" 8 | proc forward2(): string = result = "" 9 | -------------------------------------------------------------------------------- /tests/ccgbugs/tbug1081.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''1 3 | 0 4 | 0 5 | 0''' 6 | """ 7 | 8 | proc `1/1`() = echo(1 div 1) 9 | template `1/2`() = echo(1 div 2) 10 | var `1/3` = 1 div 4 11 | `1/3` = 1 div 3 # oops, 1/3!=1/4 12 | let `1/4` = 1 div 4 13 | 14 | `1/1`() 15 | `1/2`() 16 | echo `1/3` 17 | echo `1/4` 18 | -------------------------------------------------------------------------------- /tests/closure/uclosures.nim: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | test "loop variables are captured by copy": 4 | var funcs: seq[proc (): int {.closure.}] = @[] 5 | 6 | for i in 0..10: 7 | let ii = i 8 | funcs.add do -> int: return ii * ii 9 | 10 | check funcs[0]() == 0 11 | check funcs[3]() == 9 12 | 13 | -------------------------------------------------------------------------------- /tests/iter/titer_no_tuple_unpack.nim: -------------------------------------------------------------------------------- 1 | 2 | iterator xrange(fromm, to: int, step = 1): tuple[x, y: int] = 3 | var a = fromm 4 | while a <= to: 5 | yield (a, a+1) 6 | inc(a, step) 7 | 8 | for a, b in xrange(3, 7): 9 | echo a, " ", b 10 | 11 | for tup in xrange(3, 7): 12 | echo tup 13 | 14 | -------------------------------------------------------------------------------- /tests/js/tobjfieldbyvar.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''5 3 | ''' 4 | """ 5 | 6 | # bug #2798 7 | 8 | type Inner = object 9 | value: int 10 | 11 | type Outer = object 12 | i: Inner 13 | 14 | proc test(i: var Inner) = 15 | i.value += 5 16 | 17 | var o: Outer 18 | test(o.i) 19 | 20 | echo o.i.value 21 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/keineschweine.nim.cfg: -------------------------------------------------------------------------------- 1 | path = "lib" 2 | path = "dependencies/sfml" 3 | path = "dependencies/chipmunk" 4 | path = "dependencies/nake" 5 | path = "dependencies/enet" 6 | path = "dependencies/genpacket" 7 | path = "enet_server" 8 | debugger = off 9 | warning[SmallLshouldNotBeUsed] = off 10 | -------------------------------------------------------------------------------- /tests/metatype/tconstraints.nim: -------------------------------------------------------------------------------- 1 | 2 | 3 | proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string = 4 | result = $x 5 | 6 | type 7 | TMyObj = tuple[x, y: int] 8 | 9 | var 10 | x: TMyObj 11 | 12 | assert myGenericProc(232) == "232" 13 | assert myGenericProc(x) == "(x: 0, y: 0)" 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/misc/tinit.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tinit.nim" 3 | output: "Hello from module! Hello from main module!" 4 | """ 5 | # Test the new init section in modules 6 | 7 | import minit 8 | 9 | write(stdout, "Hello from main module!\n") 10 | #OUT Hello from module! Hello from main module! 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/objects/tobjloop.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "is Nil false" 3 | """ 4 | # bug #1658 5 | 6 | type 7 | Loop* = ref object 8 | onBeforeSelect*: proc (L: Loop) 9 | 10 | var L: Loop 11 | new L 12 | L.onBeforeSelect = proc (bar: Loop) = 13 | echo "is Nil ", bar.isNil 14 | 15 | L.onBeforeSelect(L) 16 | -------------------------------------------------------------------------------- /tests/objvariant/temptycaseobj.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 11 3 | errormsg: "identifier expected, but found 'keyword of'" 4 | """ 5 | 6 | type 7 | TMyEnum = enum enA, enU, enO 8 | TMyCase = object 9 | case e: TMyEnum 10 | of enA: 11 | of enU: x, y: int 12 | of enO: a, b: string 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/parallel/tlet_spawn.nim: -------------------------------------------------------------------------------- 1 | 2 | import threadpool 3 | 4 | proc foo(): int = 999 5 | 6 | # test that the disjoint checker deals with 'a = spawn f(); g = spawn f()': 7 | 8 | proc main = 9 | parallel: 10 | let f = spawn foo() 11 | let b = spawn foo() 12 | echo "done", f, " ", b 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /tests/procvar/tprocvar.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch" 3 | line: 17 4 | file: "tprocvar.nim" 5 | """ 6 | 7 | type 8 | TCallback = proc (a, b: int) 9 | 10 | proc huh(x, y: var int) = 11 | x = 0 12 | y = x+1 13 | 14 | proc so(c: TCallback) = 15 | c(2, 4) 16 | 17 | so(huh) 18 | 19 | -------------------------------------------------------------------------------- /tests/range/tsubrange3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsubrange.nim" 3 | outputsub: "value out of range: 50 [RangeError]" 4 | exitcode: "1" 5 | """ 6 | 7 | type 8 | TRange = range[0..40] 9 | 10 | proc p(r: TRange) = 11 | discard 12 | 13 | var 14 | r: TRange 15 | y = 50 16 | r = y 17 | 18 | #p y 19 | -------------------------------------------------------------------------------- /tests/trmacros/tpartial.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''-2''' 3 | """ 4 | 5 | proc p(x, y: int; cond: bool): int = 6 | result = if cond: x + y else: x - y 7 | 8 | template optP{p(x, y, true)}(x, y: expr): expr = x - y 9 | template optP{p(x, y, false)}(x, y: expr): expr = x + y 10 | 11 | echo p(2, 4, true) 12 | -------------------------------------------------------------------------------- /examples/cross_calculator/ios/src/cross-calculator-Prefix.pch: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #ifndef __IPHONE_3_0 4 | #warning "This project uses features only available in iOS SDK 3.0 and later." 5 | #endif 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #import 10 | #endif 11 | -------------------------------------------------------------------------------- /tests/manyloc/packages/noconflicts.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''package1/strutils 3 | package2/strutils 4 | noconflicts 5 | new os.nim''' 6 | """ 7 | 8 | import package1/strutils as su1 9 | import package2.strutils as su2 10 | 11 | import os 12 | 13 | su1.foo() 14 | su2.foo() 15 | echo "noconflicts" 16 | yay() 17 | -------------------------------------------------------------------------------- /tests/range/tsubrange.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 20 3 | errormsg: "cannot convert 60 to TRange" 4 | """ 5 | 6 | type 7 | TRange = range[0..40] 8 | 9 | proc p(r: TRange) = 10 | nil 11 | 12 | var 13 | r: TRange 14 | y = 50 15 | r = y 16 | 17 | p y 18 | 19 | const 20 | myConst: TRange = 60 21 | 22 | -------------------------------------------------------------------------------- /tests/seq/ttoseq.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "2345623456" 3 | """ 4 | 5 | import sequtils 6 | 7 | for x in toSeq(countup(2, 6)): 8 | stdout.write(x) 9 | for x in items(toSeq(countup(2, 6))): 10 | stdout.write(x) 11 | 12 | import strutils 13 | 14 | var y: type("a b c".split) 15 | y = "xzy" 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/trmacros/thoist.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''true 3 | true''' 4 | """ 5 | 6 | import pegs 7 | 8 | template optPeg{peg(pattern)}(pattern: string{lit}): TPeg = 9 | var gl {.global, gensym.} = peg(pattern) 10 | gl 11 | 12 | echo match("(a b c)", peg"'(' @ ')'") 13 | echo match("W_HI_Le", peg"\y 'while'") 14 | -------------------------------------------------------------------------------- /examples/cross_calculator/ios/src/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | #import "backend.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | @autoreleasepool { 9 | NimMain(); 10 | return UIApplicationMain(argc, argv, nil, 11 | NSStringFromClass([AppDelegate class])); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/impure/osinfo_win.nim: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Nim's Runtime Library 4 | # (c) Copyright 2015 Dominik Picheta 5 | # 6 | # See the file "copying.txt", included in this 7 | # distribution, for details about the copyright. 8 | # 9 | 10 | {.error: "This module has been moved to the 'osinfo' nimble package.".} 11 | -------------------------------------------------------------------------------- /tests/cpp/tthread_createthread.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp --hints:on --threads:on $options $file" 3 | """ 4 | 5 | proc threadMain(a: int) {.thread.} = 6 | discard 7 | 8 | proc main() = 9 | var thread: TThread[int] 10 | 11 | thread.createThread(threadMain, 0) 12 | thread.joinThreads() 13 | 14 | main() -------------------------------------------------------------------------------- /tests/exception/tfinally3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tfinally3.nim" 3 | output: "false" 4 | """ 5 | # Test break in try statement: 6 | 7 | proc main: bool = 8 | while true: 9 | try: 10 | return true 11 | finally: 12 | break 13 | return false 14 | 15 | echo main() #OUT false 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/generics/tcan_alias_specialised_generic.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | disabled: false 3 | """ 4 | 5 | ## 6 | ## can_alias_specialised_generic Nim Module 7 | ## 8 | ## Created by Eric Doughty-Papassideris on 2011-02-16. 9 | 10 | type 11 | TGen[T] = object 12 | TSpef = TGen[string] 13 | 14 | var 15 | s: TSpef 16 | 17 | -------------------------------------------------------------------------------- /tests/generics/tcan_inherit_generic.nim: -------------------------------------------------------------------------------- 1 | ## 2 | ## can_inherit_generic Nim Module 3 | ## 4 | ## Created by Eric Doughty-Papassideris on 2011-02-16. 5 | 6 | type 7 | TGen[T] = object of TObject 8 | x, y: T 9 | 10 | TSpef[T] = object of TGen[T] 11 | 12 | 13 | var s: TSpef[float] 14 | s.x = 0.4 15 | s.y = 0.6 16 | 17 | -------------------------------------------------------------------------------- /tests/macros/trecmacro.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "trecmacro.nim" 3 | line: 8 4 | errormsg: "recursive dependency: 'dump'" 5 | """ 6 | 7 | macro dump(n: stmt): stmt = 8 | dump(n) 9 | if kind(n) == nnkNone: 10 | nil 11 | else: 12 | hint($kind(n)) 13 | for i in countUp(0, len(n)-1): 14 | nil 15 | -------------------------------------------------------------------------------- /tests/proc/tnestprc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tnestprc.nim" 3 | output: "10" 4 | """ 5 | # Test nested procs without closures 6 | 7 | proc Add3(x: int): int = 8 | proc add(x, y: int): int {.noconv.} = 9 | result = x + y 10 | 11 | result = add(x, 3) 12 | 13 | echo Add3(7) #OUT 10 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/impure/osinfo_posix.nim: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Nim's Runtime Library 4 | # (c) Copyright 2015 Dominik Picheta 5 | # 6 | # See the file "copying.txt", included in this 7 | # distribution, for details about the copyright. 8 | # 9 | 10 | {.error: "This module has been moved to the 'osinfo' nimble package.".} 11 | -------------------------------------------------------------------------------- /tests/closure/tnamedparamanonproc.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | PButton = ref object 4 | TButtonClicked = proc(button: PButton) {.nimcall.} 5 | 6 | proc newButton*(onClick: TButtonClicked) = 7 | discard 8 | 9 | proc main() = 10 | newButton(onClick = proc(b: PButton) = 11 | var requestomat = 12 12 | ) 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /tests/exception/texcsub.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "texcsub.nim" 3 | output: "caught!" 4 | """ 5 | # Test inheritance for exception matching: 6 | 7 | try: 8 | raise newException(OSError, "dummy message") 9 | except Exception: 10 | echo "caught!" 11 | except: 12 | echo "wtf!?" 13 | 14 | #OUT caught! 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/generics/t1050.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | msg: "int" 3 | output: "4" 4 | """ 5 | 6 | import typetraits 7 | 8 | type ArrayType[T] = distinct T 9 | 10 | proc arrayItem(a: ArrayType): auto = 11 | static: echo(name(type(a).T)) 12 | result = (type(a).T)(4) 13 | 14 | var arr: ArrayType[int] 15 | echo arrayItem(arr) 16 | 17 | -------------------------------------------------------------------------------- /tests/generics/tgeneric_inheritance.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "0.0" 3 | """ 4 | 5 | # bug #1919 6 | 7 | type 8 | Base[M] = object of RootObj 9 | a : M 10 | 11 | Sub1[M] = object of Base[M] 12 | b : int 13 | 14 | Sub2[M] = object of Sub1[M] 15 | c : int 16 | 17 | var x: Sub2[float] 18 | 19 | echo x.a 20 | -------------------------------------------------------------------------------- /tests/generics/tlateboundstatic.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | msg: "array[0..3, int]" 3 | """ 4 | 5 | type 6 | KK[I: static[int]] = object 7 | x: array[I, int] 8 | 9 | proc foo(a: static[string]): KK[a.len] = 10 | result.x[0] = 12 11 | 12 | var x = foo "test" 13 | 14 | import typetraits 15 | static: echo x.x.type.name 16 | 17 | -------------------------------------------------------------------------------- /tests/metatype/tstatic_overloading.nim: -------------------------------------------------------------------------------- 1 | # bug #2266 2 | 3 | import macros 4 | 5 | proc impl(op: static[int]) = echo "impl 1 called" 6 | proc impl(op: static[int], init: int) = echo "impl 2 called" 7 | 8 | macro wrapper2: stmt = newCall(bindSym"impl", newLit(0), newLit(0)) 9 | 10 | wrapper2() # Code generation for this fails. 11 | -------------------------------------------------------------------------------- /tests/stdlib/tposix.nim: -------------------------------------------------------------------------------- 1 | # Test Posix interface 2 | 3 | when not defined(windows): 4 | 5 | import posix 6 | 7 | var 8 | u: Tutsname 9 | 10 | discard uname(u) 11 | 12 | writeLine(stdout, u.sysname) 13 | writeLine(stdout, u.nodename) 14 | writeLine(stdout, u.release) 15 | writeLine(stdout, u.machine) 16 | 17 | -------------------------------------------------------------------------------- /tests/stdlib/tsplit.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsplit.nim" 3 | output: "true" 4 | """ 5 | import strutils 6 | 7 | var s = "" 8 | for w in split("|abc|xy|z", {'|'}): 9 | s.add("#") 10 | s.add(w) 11 | 12 | if s == "#abc#xy#z": 13 | echo "true" 14 | else: 15 | echo "false" 16 | 17 | #OUT true 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/template/tissue909.nim: -------------------------------------------------------------------------------- 1 | import macros 2 | 3 | template baz() = 4 | proc bar() = 5 | var x = 5 6 | iterator foo(): int {.closure.} = 7 | echo x 8 | var y = foo 9 | discard y() 10 | 11 | macro test(): stmt = 12 | result = getAst(baz()) 13 | echo(treeRepr(result)) 14 | 15 | test() 16 | bar() 17 | -------------------------------------------------------------------------------- /tests/typerel/trectuples.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "illegal recursion in type 'Node'" 3 | line: 6 4 | """ 5 | 6 | type Node = tuple[left: ref Node] 7 | 8 | proc traverse(root: ref Node) = 9 | if root.left != nil: traverse(root.left) 10 | 11 | type A = tuple[B: ptr A] 12 | proc C(D: ptr A) = C(D.B) 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/typerel/tregionptrs.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 16 3 | errormsg: "type mismatch: got (BPtr) but expected 'APtr'" 4 | """ 5 | 6 | type 7 | RegionA = object 8 | APtr = RegionA ptr int 9 | RegionB = object 10 | BPtr = RegionB ptr int 11 | 12 | var x,xx: APtr 13 | var y: BPtr 14 | x = nil 15 | x = xx 16 | x = y 17 | -------------------------------------------------------------------------------- /tests/effects/tsidee2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsidee2.nim" 3 | output: "5" 4 | """ 5 | 6 | var 7 | global: int 8 | 9 | proc dontcare(x: int): int = return x 10 | 11 | proc SideEffectLyer(x, y: int): int {.noSideEffect.} = 12 | return x + y + dontcare(x) 13 | 14 | echo SideEffectLyer(1, 3) #OUT 5 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/exception/tdefer1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''hi 3 | hi''' 4 | """ 5 | 6 | # bug #1742 7 | 8 | template test(): expr = 9 | let a = 0 10 | defer: echo "hi" 11 | a 12 | 13 | let i = test() 14 | 15 | import strutils 16 | let x = try: parseInt("133a") 17 | except: -1 18 | finally: echo "hi" 19 | -------------------------------------------------------------------------------- /tests/method/tmultim3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tmultim3.nim" 3 | output: "Hi derived!" 4 | """ 5 | import mmultim3 6 | 7 | type 8 | TBObj* = object of TObj 9 | 10 | 11 | method test123(a : ref TBObj) = 12 | echo("Hi derived!") 13 | 14 | var a : ref TBObj 15 | new(a) 16 | myObj = a 17 | testMyObj() 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/misc/treadln.nim: -------------------------------------------------------------------------------- 1 | # test the improved readline handling that does not care whether its 2 | # Macintosh, Unix or Windows text format. 3 | 4 | var 5 | inp: File 6 | line: string 7 | 8 | if open(inp, "readme.txt"): 9 | while not endOfFile(inp): 10 | line = readLine(inp) 11 | echo("#" & line & "#") 12 | close(inp) 13 | -------------------------------------------------------------------------------- /tests/parallel/tdont_be_stupid.nim: -------------------------------------------------------------------------------- 1 | 2 | import threadpool, os 3 | 4 | proc single(time: int) = 5 | sleep time 6 | echo time 7 | 8 | proc sleepsort(nums: openArray[int]) = 9 | parallel: 10 | var i = 0 11 | while i <= len(nums) + -1: 12 | spawn single(nums[i]) 13 | i += 1 14 | 15 | sleepsort([50,3,40,25]) 16 | -------------------------------------------------------------------------------- /tests/trmacros/tcse.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "4" 3 | """ 4 | 5 | template cse{f(a, a, x)}(a: expr{(nkDotExpr|call|nkBracketExpr)&noSideEffect}, 6 | f: expr, x: varargs[expr]): expr = 7 | let aa = a 8 | f(aa, aa, x)+4 9 | 10 | var 11 | a: array[0..10, int] 12 | i = 3 13 | echo a[i] + a[i] 14 | -------------------------------------------------------------------------------- /tests/effects/teffects5.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch" 3 | line: 7 4 | """ 5 | 6 | proc p(q: proc() ): proc() {.tags: [], raises: [], closure.} = 7 | return proc () = 8 | q() 9 | 10 | let yay = p(proc () = raise newException(EIO, "IO")) 11 | 12 | proc main() {.raises: [], tags: [].} = yay() 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /tests/init/tzeroarray.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: done 3 | """ 4 | 5 | for i in 0 .. 1: 6 | var a: array[0..4, int] 7 | if a[0] != 0: quit "bug" 8 | a[0] = 6 9 | 10 | proc main = 11 | for i in 0 .. 1: 12 | var a: array[0..4, int] 13 | if a[0] != 0: quit "bug" 14 | a[0] = 6 15 | 16 | main() 17 | echo "done" 18 | 19 | -------------------------------------------------------------------------------- /tests/lookups/tkoeniglookup.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''x: 0 y: 0''' 3 | """ 4 | 5 | proc toString*[T](x: T): string = return $x 6 | 7 | 8 | type 9 | TMyObj = object 10 | x, y: int 11 | 12 | proc `$`*(a: TMyObj): string = 13 | result = "x: " & $a.x & " y: " & $a.y 14 | 15 | var a: TMyObj 16 | echo toString(a) 17 | 18 | -------------------------------------------------------------------------------- /tests/misc/tbug1217bracketquotes.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "13{(.{}}{*4&*$**()&*@1235" 3 | """ 4 | 5 | type 6 | Test = enum 7 | `1`, `3`, `{`, `(.`, `{}}{`, `*4&*$**()&*@` 8 | 9 | let `.}` = 1 10 | let `(}` = 2 11 | let `[` = 3 12 | let `]` = 5 13 | 14 | echo `1`, `3`, `{`, `(.`, `{}}{`, `*4&*$**()&*@`, `.}`, `(}`, `[`, `]` 15 | -------------------------------------------------------------------------------- /tests/stdlib/tunidecode.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim $target --hints:on -d:embedUnidecodeTable $options $file" 3 | output: "Ausserst" 4 | """ 5 | 6 | import unidecode 7 | 8 | loadUnidecodeTable("lib/pure/unidecode/unidecode.dat") 9 | 10 | #assert unidecode("\x53\x17\x4E\xB0") == "Bei Jing" 11 | echo unidecode("Äußerst") 12 | 13 | -------------------------------------------------------------------------------- /tests/template/tsymchoicefield.nim: -------------------------------------------------------------------------------- 1 | type Foo = object 2 | len: int 3 | 4 | var f = Foo(len: 40) 5 | 6 | template getLen(f: Foo): expr = f.len 7 | 8 | echo f.getLen 9 | # This fails, because `len` gets the nkOpenSymChoice 10 | # treatment inside the template early pass and then 11 | # it can't be recognized as a field anymore 12 | 13 | -------------------------------------------------------------------------------- /compiler/plugins/active.nim: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # The Nim Compiler 4 | # (c) Copyright 2015 Andreas Rumpf 5 | # 6 | # See the file "copying.txt", included in this 7 | # distribution, for details about the copyright. 8 | # 9 | 10 | ## Include file that imports all plugins that are active. 11 | 12 | import 13 | locals.locals 14 | -------------------------------------------------------------------------------- /tests/misc/tcmdline.nim: -------------------------------------------------------------------------------- 1 | # Test the command line 2 | 3 | import 4 | os, strutils 5 | 6 | var 7 | i: int 8 | params = paramCount() 9 | i = 0 10 | writeLine(stdout, "This exe: " & getAppFilename()) 11 | writeLine(stdout, "Number of parameters: " & $params) 12 | while i <= params: 13 | writeLine(stdout, paramStr(i)) 14 | i = i + 1 15 | -------------------------------------------------------------------------------- /tests/typerel/trectuple.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "illegal recursion in type 'TNode'" 3 | line: 8 4 | disabled: true 5 | """ 6 | 7 | type 8 | PNode = ref TNode 9 | TNode = tuple # comment 10 | self: PNode # comment 11 | a, b: int # comment 12 | 13 | var node: PNode 14 | new(node) 15 | node.self = node 16 | 17 | -------------------------------------------------------------------------------- /tinyc/stab.h: -------------------------------------------------------------------------------- 1 | #ifndef __GNU_STAB__ 2 | 3 | /* Indicate the GNU stab.h is in use. */ 4 | 5 | #define __GNU_STAB__ 6 | 7 | #define __define_stab(NAME, CODE, STRING) NAME=CODE, 8 | 9 | enum __stab_debug_code 10 | { 11 | #include "stab.def" 12 | LAST_UNUSED_STAB_CODE 13 | }; 14 | 15 | #undef __define_stab 16 | 17 | #endif /* __GNU_STAB_ */ 18 | -------------------------------------------------------------------------------- /examples/cgi/cgi_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import BaseHTTPServer 3 | import CGIHTTPServer 4 | 5 | server = BaseHTTPServer.HTTPServer 6 | handler = CGIHTTPServer.CGIHTTPRequestHandler 7 | server_address = ('localhost', 8008) 8 | handler.cgi_directories = ['/'] 9 | 10 | httpd = server(server_address, handler) 11 | httpd.serve_forever() 12 | -------------------------------------------------------------------------------- /tests/exprs/tifexpr_typeinference.nim: -------------------------------------------------------------------------------- 1 | #bug #712 2 | 3 | import tables 4 | 5 | proc test(): TTable[string, string] = 6 | discard 7 | 8 | proc test2(): TTable[string, string] = 9 | discard 10 | 11 | var x = 5 12 | let blah = 13 | case x 14 | of 5: 15 | test2() 16 | of 2: 17 | test() 18 | else: test() 19 | 20 | echo blah.len 21 | -------------------------------------------------------------------------------- /tests/global/globalaux.nim: -------------------------------------------------------------------------------- 1 | type 2 | TObj*[T] = object 3 | val*: T 4 | 5 | var 6 | totalGlobals* = 0 7 | 8 | proc makeObj[T](x: T): TObj[T] = 9 | totalGlobals += 1 10 | result.val = x 11 | 12 | proc globalInstance*[T]: var TObj[T] = 13 | var g {.global.} = when T is int: makeObj(10) else: makeObj("hello") 14 | result = g 15 | 16 | -------------------------------------------------------------------------------- /tests/misc/tstrace.nim: -------------------------------------------------------------------------------- 1 | # Test the new stacktraces (great for debugging!) 2 | 3 | {.push stack_trace: on.} 4 | 5 | proc recTest(i: int) = 6 | # enter 7 | if i < 10: 8 | recTest(i+1) 9 | else: # should printStackTrace() 10 | var p: ptr int = nil 11 | p[] = 12 12 | # leave 13 | 14 | {.pop.} 15 | 16 | recTest(0) 17 | -------------------------------------------------------------------------------- /tests/modules/topaque.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "topaque.nim" 3 | line: 16 4 | errormsg: "undeclared field: \'buffer\'" 5 | """ 6 | # Test the new opaque types 7 | 8 | import 9 | mopaque 10 | 11 | var 12 | L: TLexer 13 | 14 | L.filename = "ha" 15 | L.line = 34 16 | L.buffer[0] = '\0' #ERROR_MSG undeclared field: 'buffer' 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/objects/toop.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "b" 3 | """ 4 | 5 | type 6 | TA = object of TObject 7 | x, y: int 8 | 9 | TB = object of TA 10 | z: int 11 | 12 | TC = object of TB 13 | whatever: string 14 | 15 | proc p(a: var TA) = echo "a" 16 | proc p(b: var TB) = echo "b" 17 | 18 | var c: TC 19 | 20 | p(c) 21 | 22 | -------------------------------------------------------------------------------- /tests/parser/tprecedence.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''holla 3 | true''' 4 | """ 5 | 6 | # Test top level semicolon works properly: 7 | import os; echo "holla" 8 | 9 | # Test the new predence rules 10 | 11 | proc `\+` (x, y: int): int = result = x + y 12 | proc `\*` (x, y: int): int = result = x * y 13 | 14 | echo 5 \+ 1 \* 9 == 6*9 15 | 16 | -------------------------------------------------------------------------------- /tests/stdlib/tformat.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tformat.nim" 3 | output: "Hi Andreas! How do you feel, Rumpf?" 4 | """ 5 | # Tests the new format proc (including the & and &= operators) 6 | 7 | import strutils 8 | 9 | echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"]) 10 | #OUT Hi Andreas! How do you feel, Rumpf? 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/varres/tvartup.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tvartup.nim" 3 | output: "2 3" 4 | """ 5 | # Test the new tuple unpacking 6 | 7 | proc divmod(a, b: int): tuple[di, mo: int] = 8 | return (a div b, a mod b) 9 | 10 | var (x, y) = divmod(15, 6) 11 | stdout.write(x) 12 | stdout.write(" ") 13 | stdout.write(y) 14 | 15 | #OUT 2 3 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/closure/ttimeinfo.nim: -------------------------------------------------------------------------------- 1 | # bug #2073 2 | 3 | import sequtils 4 | import times 5 | 6 | # 1 7 | proc f(n: int): TimeInfo = 8 | TimeInfo(year: n, month: mJan, monthday: 1) 9 | 10 | echo toSeq(2000 || 2015).map(f) 11 | 12 | # 2 13 | echo toSeq(2000 || 2015).map(proc (n: int): TimeInfo = 14 | TimeInfo(year: n, month: mJan, monthday: 1) 15 | ) 16 | -------------------------------------------------------------------------------- /tests/misc/temit.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "temit.nim" 3 | output: "509" 4 | """ 5 | # Test the new ``emit`` pragma: 6 | 7 | {.emit: """ 8 | static int cvariable = 420; 9 | 10 | """.} 11 | 12 | proc embedsC() = 13 | var nimVar = 89 14 | {.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".} 15 | 16 | embedsC() 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/misc/tnoinst.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 12 3 | errormsg: "instantiate 'notConcrete' explicitly" 4 | disabled: "true" 5 | """ 6 | 7 | proc wrap[T]() = 8 | proc notConcrete[T](x, y: int): int = 9 | var dummy: T 10 | result = x - y 11 | 12 | var x: proc (x, y: T): int 13 | x = notConcrete 14 | 15 | 16 | wrap[int]() 17 | 18 | -------------------------------------------------------------------------------- /tests/notnil/tnotnil_in_objconstr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "field not initialized: bar" 3 | line: "13" 4 | """ 5 | 6 | # bug #2355 7 | type 8 | Foo = object 9 | foo: string not nil 10 | bar: string not nil 11 | 12 | # Create instance without initializaing the `bar` field 13 | var f = Foo(foo: "foo") 14 | echo f.bar.isNil # true 15 | -------------------------------------------------------------------------------- /tests/seq/tseq2.nim: -------------------------------------------------------------------------------- 1 | proc `*` *(a, b: seq[int]): seq[int] = 2 | # allocate a new sequence: 3 | newSeq(result, len(a)) 4 | # multiply two int sequences: 5 | for i in 0..len(a)-1: result[i] = a[i] * b[i] 6 | 7 | when isMainModule: 8 | # test the new ``*`` operator for sequences: 9 | assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/cross_calculator/lazarus/readme.txt: -------------------------------------------------------------------------------- 1 | This example demonstrates how to use Nim with Lazarus. The GUI is generated 2 | with Lazarus, while the "backend" is written in Nim. To compile the example, 3 | use this command: 4 | 5 | nim c --app:gui --no_main --no_linking backend.nim 6 | 7 | Open the ``nimlaz.lpi`` file in Lazarus and run the program. 8 | 9 | -------------------------------------------------------------------------------- /tests/generics/tgeneric2.nim: -------------------------------------------------------------------------------- 1 | import tables 2 | 3 | type 4 | TX = Table[string, int] 5 | 6 | proc foo(models: seq[TX]): seq[int] = 7 | result = @[] 8 | for model in models.items: 9 | result.add model["foobar"] 10 | 11 | type 12 | Obj = object 13 | field: Table[string, string] 14 | var t: Obj 15 | discard initTable[type(t.field), string]() 16 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/lib/math_helpers.nim: -------------------------------------------------------------------------------- 1 | import strutils, math 2 | 3 | proc degrees*(rad: float): float = 4 | return rad * 180.0 / PI 5 | proc radians*(deg: float): float = 6 | return deg * PI / 180.0 7 | 8 | ## V not math, sue me 9 | proc ff*(f: float, precision = 2): string {.inline.} = 10 | return formatFloat(f, ffDecimal, precision) 11 | -------------------------------------------------------------------------------- /tests/misc/tmemoization.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | msg: "test 1\ntest 2\ntest 3" 3 | output: "TEST 1\nTEST 2\nTEST 3" 4 | """ 5 | 6 | import strutils 7 | 8 | proc foo(s: static[string]): string = 9 | static: echo s 10 | 11 | const R = s.toUpper 12 | return R 13 | 14 | echo foo("test 1") 15 | echo foo("test 2") 16 | echo foo("test " & $3) 17 | 18 | -------------------------------------------------------------------------------- /tests/rodfiles/hallo2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "Hello World" 3 | """ 4 | 5 | # Test incremental type information 6 | 7 | type 8 | TNode = object {.pure.} 9 | le, ri: ref TNode 10 | data: string 11 | 12 | proc newNode(data: string): ref TNode = 13 | new(result) 14 | result.data = data 15 | 16 | echo newNode("Hello World").data 17 | 18 | -------------------------------------------------------------------------------- /tests/casestmt/tcase_setconstr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "an identifier" 3 | """ 4 | 5 | const 6 | SymChars: set[char] = {'a'..'z', 'A'..'Z', '\x80'..'\xFF'} 7 | 8 | proc classify(s: string) = 9 | case s[0] 10 | of SymChars, '_': echo "an identifier" 11 | of {'0'..'9'}: echo "a number" 12 | else: echo "other" 13 | 14 | classify("Hurra") 15 | 16 | -------------------------------------------------------------------------------- /tests/casestmt/tcaseoverlaprange2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 13 3 | errormsg: "duplicate case label" 4 | """ 5 | 6 | 7 | 8 | 9 | proc checkDuplicates(myval: int32): bool = 10 | case myval 11 | of 0x7B: 12 | echo "this should not compile" 13 | of 0x78 .. 0x7D: 14 | result = true 15 | else: 16 | nil 17 | 18 | echo checkDuplicates(0x7B) 19 | -------------------------------------------------------------------------------- /tests/ccgbugs/tconstobj.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''(FirstName: James, LastName: Franco)''' 3 | """ 4 | 5 | # bug #1547 6 | import tables 7 | 8 | type Person* = object 9 | FirstName*: string 10 | LastName*: string 11 | 12 | let people = { 13 | "001": Person(FirstName: "James", LastName: "Franco") 14 | }.toTable() 15 | 16 | echo people["001"] 17 | -------------------------------------------------------------------------------- /tests/iter/tobj_iter.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "7" 3 | """ 4 | 5 | # bug #2023 6 | 7 | {.deadCodeElim:on.} 8 | 9 | type 10 | Obj = object 11 | iter: iterator (): int8 {.closure.} 12 | 13 | iterator test(): int8 {.closure.} = 14 | yield 7 15 | 16 | proc init():Obj= 17 | result.iter = test 18 | 19 | var o = init() 20 | echo(o.iter()) 21 | -------------------------------------------------------------------------------- /tests/manyloc/keineschweine/dependencies/sfml/README.md: -------------------------------------------------------------------------------- 1 | sfml-nimrod 2 | =========== 3 | 4 | Nimrod binding of SFML 2.0 5 | 6 | This is only tested for Linux at the moment 7 | 8 | ### What is needed for Windows / OS X? 9 | 10 | * The library names need filling in 11 | * TWindowHandle is handled differently on those platforms 12 | 13 | I believe that is it 14 | -------------------------------------------------------------------------------- /tests/stdlib/tpermutations.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''@[0, 2, 1] 3 | @[1, 0, 2] 4 | @[1, 2, 0] 5 | @[2, 0, 1] 6 | @[2, 1, 0] 7 | @[2, 0, 1] 8 | @[1, 2, 0] 9 | @[1, 0, 2] 10 | @[0, 2, 1] 11 | @[0, 1, 2]''' 12 | """ 13 | import algorithm 14 | 15 | var v = @[0, 1, 2] 16 | while v.nextPermutation(): 17 | echo v 18 | while v.prevPermutation(): 19 | echo v 20 | -------------------------------------------------------------------------------- /tests/template/tdefault_nil.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #2629 3 | import sequtils, os 4 | 5 | template glob_rst(basedir: string = nil): expr = 6 | if baseDir.isNil: 7 | to_seq(walk_files("*.rst")) 8 | else: 9 | to_seq(walk_files(basedir/"*.rst")) 10 | 11 | let 12 | rst_files = concat(glob_rst(), glob_rst("docs")) 13 | 14 | when isMainModule: echo rst_files 15 | -------------------------------------------------------------------------------- /tests/template/tscope.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "redefinition of 'x'" 3 | """ 4 | 5 | var x = 1 6 | template quantity(): stmt {.immediate.} = 7 | # Causes internal error in compiler/sem.nim 8 | proc unit*(x = 1.0): float = 12 9 | # Throws the correct error: redefinition of 'x' 10 | #proc unit*(y = 1.0): float = 12 11 | quantity() 12 | var x = 2 13 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set -x 4 | 5 | if [ ! -e csources/.git ]; then 6 | git clone --depth 1 git://github.com/nim-lang/csources.git csources 7 | fi 8 | 9 | cd "csources" 10 | sh build.sh 11 | cd ".." 12 | 13 | ./bin/nim c koch 14 | ./koch boot -d:release 15 | 16 | cp -f install.sh.template install.sh 17 | chmod +x install.sh 18 | 19 | exit 0 20 | -------------------------------------------------------------------------------- /examples/debugging.nim: -------------------------------------------------------------------------------- 1 | # Simple program to test the debugger 2 | # compile with --debugger:on 3 | 4 | proc someComp(x, y: int): int = 5 | let a = x+y 6 | if a > 7: 7 | let b = a*90 8 | {.breakpoint.} 9 | result = b 10 | {.breakpoint.} 11 | 12 | proc pp() = 13 | var aa = 45 14 | var bb = "abcdef" 15 | echo someComp(23, 45) 16 | 17 | pp() 18 | -------------------------------------------------------------------------------- /tests/ccgbugs/trecursive_closure.nim: -------------------------------------------------------------------------------- 1 | # bug #2233 2 | type MalType = object 3 | fun: proc: MalType 4 | 5 | proc f(x: proc: MalType) = 6 | discard x() 7 | 8 | f(nil) 9 | 10 | # bug #2823 11 | 12 | type A = object #of RootObj <-- Uncomment this to get no errors 13 | test: proc(i: A): bool 14 | var a: proc(i: A): bool # Or comment this line to get no errors 15 | -------------------------------------------------------------------------------- /tests/metatype/tautonotgeneric.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "wof!" 3 | """ 4 | 5 | # bug #1659 6 | type Animal = ref object {.inheritable.} 7 | type Dog = ref object of Animal 8 | 9 | method say(a: Animal): auto = "wat!" 10 | method say(a: Dog): auto = "wof!" 11 | 12 | proc saySomething(a: Animal): auto = a.say() 13 | 14 | var a = Dog() 15 | echo saySomething(a) 16 | -------------------------------------------------------------------------------- /tests/misc/tstrdesc.nim: -------------------------------------------------------------------------------- 1 | var 2 | x: array [0..2, int] 3 | 4 | x = [0, 1, 2] 5 | 6 | type 7 | TStringDesc {.final.} = object 8 | len, space: int # len and space without counting the terminating zero 9 | data: array [0..0, char] # for the '\0' character 10 | 11 | var 12 | emptyString {.exportc: "emptyString".}: TStringDesc 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/showoff/tquasiquote.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | outputsub: '''tquasiquote.nim(14,8): Check failed: 1 > 2''' 3 | """ 4 | 5 | import macros 6 | 7 | macro check(ex: expr): stmt = 8 | var info = ex.lineInfo 9 | var expString = ex.toStrLit 10 | result = quote do: 11 | if not `ex`: 12 | echo `info`, ": Check failed: ", `expString` 13 | 14 | check 1 > 2 15 | -------------------------------------------------------------------------------- /tests/vm/tconsttable.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''is 3 | finally 4 | nice!''' 5 | """ 6 | 7 | import tables 8 | 9 | const 10 | foo = {"ah": "finally", "this": "is", "possible.": "nice!"}.toTable() 11 | 12 | # protect against overly smart compiler: 13 | var x = "this" 14 | 15 | echo foo[x] 16 | x = "ah" 17 | echo foo[x] 18 | x = "possible." 19 | echo foo[x] 20 | -------------------------------------------------------------------------------- /tests/cpp/tcppraise.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp $file" 3 | output: '''foo 4 | bar 5 | Need odd and >= 3 digits## 6 | baz''' 7 | """ 8 | 9 | # bug #1888 10 | echo "foo" 11 | try: 12 | echo "bar" 13 | raise newException(ValueError, "Need odd and >= 3 digits") 14 | # echo "baz" 15 | except ValueError: 16 | echo getCurrentExceptionMsg(), "##" 17 | echo "baz" 18 | -------------------------------------------------------------------------------- /tests/generics/tconfusing_arrow.nim: -------------------------------------------------------------------------------- 1 | import algorithm, future 2 | 3 | type Deck = object 4 | value: int 5 | 6 | proc sort(h: var seq[Deck]) = 7 | # works: 8 | h.sort(proc (x, y: Deck): auto = 9 | cmp(x.value, y.value)) 10 | # fails: 11 | h.sort((x, y: Deck) => cmp(ord(x.value), ord(y.value))) 12 | 13 | var player: seq[Deck] = @[] 14 | 15 | player.sort() 16 | -------------------------------------------------------------------------------- /tests/iter/treciter.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "treciter.nim" 3 | line: 9 4 | errormsg: "recursive dependency: \'myrec\'" 5 | """ 6 | # Test that an error message occurs for a recursive iterator 7 | 8 | iterator myrec(n: int): int = 9 | for x in myrec(n-1): #ERROR_MSG recursive dependency: 'myrec' 10 | yield x 11 | 12 | for x in myrec(10): echo x 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/macros/tmacrotypes.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | nimout: '''void 3 | int''' 4 | """ 5 | 6 | import macros 7 | 8 | macro checkType(ex: stmt; expected: expr): stmt = 9 | var t = ex.getType() 10 | echo t 11 | 12 | proc voidProc = echo "hello" 13 | proc intProc(a: int, b: float): int = 10 14 | 15 | checkType(voidProc(), "void") 16 | checkType(intProc(10, 20.0), "int") 17 | -------------------------------------------------------------------------------- /tests/macros/tprintf.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tprintf.nim" 3 | output: "Andreas Rumpf" 4 | """ 5 | # Test a printf proc 6 | 7 | proc printf(file: TFile, args: openarray[string]) = 8 | var i = 0 9 | while i < args.len: 10 | write(file, args[i]) 11 | inc(i) 12 | 13 | printf(stdout, ["Andreas ", "Rumpf\n"]) 14 | #OUT Andreas Rumpf 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/system/tfloatToString.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output:'''2.3242 3 | 2.982 4 | 123912.1 5 | 123912.1823 6 | 5.0 7 | 1e+100 8 | inf 9 | -inf 10 | nan 11 | ''' 12 | """ 13 | 14 | echo($(2.3242)) 15 | echo($(2.982)) 16 | echo($(123912.1)) 17 | echo($(123912.1823)) 18 | echo($(5.0)) 19 | echo($(1e100)) 20 | echo($(1e1000000)) 21 | echo($(-1e1000000)) 22 | echo($(0.0/0.0)) 23 | -------------------------------------------------------------------------------- /tests/trmacros/tstmtlist.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''0 3 | |12| 4 | 34 5 | ''' 6 | """ 7 | 8 | template optWrite{ 9 | write(f, x) 10 | ((write|writeLine){w})(f, y) 11 | }(x, y: varargs[expr], f, w: expr) = 12 | w(f, "|", x, y, "|") 13 | 14 | if true: 15 | echo "0" 16 | write stdout, "1" 17 | writeLine stdout, "2" 18 | write stdout, "3" 19 | echo "4" 20 | -------------------------------------------------------------------------------- /tests/exception/tfinally.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tfinally.nim" 3 | output: "came\nhere\n3" 4 | """ 5 | # Test return in try statement: 6 | 7 | proc main: int = 8 | try: 9 | try: 10 | return 1 11 | finally: 12 | echo("came") 13 | return 2 14 | finally: 15 | echo("here") 16 | return 3 17 | 18 | echo main() #OUT came here 3 19 | 20 | -------------------------------------------------------------------------------- /tests/generics/mdotlookup.nim: -------------------------------------------------------------------------------- 1 | proc baz(o: any): int = 5 # if bar is exported, it works 2 | 3 | type MyObj = object 4 | x: int 5 | 6 | proc foo*(b: any) = 7 | var o: MyObj 8 | echo b.baz, " ", o.x.baz, " ", b.baz() 9 | 10 | import sets 11 | 12 | var intset = initSet[int]() 13 | 14 | proc fn*[T](a: T) = 15 | if a in intset: echo("true") 16 | else: echo("false") 17 | -------------------------------------------------------------------------------- /tests/macros/texprcolonexpr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | msg: ''' 3 | Infix 4 | Ident !"=>" 5 | Call 6 | Ident !"name" 7 | Ident !"a" 8 | ExprColonExpr 9 | Ident !"b" 10 | Ident !"cint" 11 | NilLit nil 12 | ''' 13 | """ 14 | import macros 15 | 16 | macro def(x: stmt): stmt {.immediate.} = 17 | echo treeRepr(x) 18 | 19 | def name(a, b:cint) => nil 20 | -------------------------------------------------------------------------------- /tests/misc/tbug511622.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tbug511622.nim" 3 | output: "3" 4 | """ 5 | import StrUtils, Math 6 | 7 | proc FibonacciA(n: int): int64 = 8 | var fn = float64(n) 9 | var p: float64 = (1.0 + sqrt(5.0)) / 2.0 10 | var q: float64 = 1.0 / p 11 | return int64((pow(p, fn) + pow(q, fn)) / sqrt(5.0)) 12 | 13 | echo FibonacciA(4) #OUT 3 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/stdlib/twalker.nim: -------------------------------------------------------------------------------- 1 | # iterate over all files with a given filter: 2 | 3 | import 4 | "../../lib/pure/os.nim", ../../ lib / pure / times 5 | 6 | proc main(filter: string) = 7 | for filename in walkFiles(filter): 8 | writeLine(stdout, filename) 9 | 10 | for key, val in envPairs(): 11 | writeLine(stdout, key & '=' & val) 12 | 13 | main("*.nim") 14 | -------------------------------------------------------------------------------- /tests/threads/trecursive_actor.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | outputsub: "0" 3 | """ 4 | 5 | import actors 6 | 7 | var 8 | a: TActorPool[int, void] 9 | createActorPool(a) 10 | 11 | proc task(i: int) {.thread.} = 12 | echo i 13 | if i != 0: a.spawn (i-1, task) 14 | 15 | # count from 9 till 0 and check 0 is somewhere in the output 16 | a.spawn(9, task) 17 | a.join() 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/compiles/tevilcompiles.nim: -------------------------------------------------------------------------------- 1 | # bug #1055 2 | import unittest 3 | type TMatrix*[N,M: static[int], T] = object 4 | data*: array[0..N*M-1, T] 5 | proc `==`*(a: distinct TMatrix; b: distinct TMatrix): bool = 6 | result = a.data == b.data 7 | 8 | test "c": 9 | var a = TMatrix[2,2,int](data: [1,2,3,4]) 10 | var b = TMatrix[2,2,int](data: [1,2,3,4]) 11 | check(a == b) 12 | 13 | -------------------------------------------------------------------------------- /tests/cpp/tvector_iterator.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp $file" 3 | """ 4 | 5 | {.emit: """ 6 | 7 | template 8 | struct Vector { 9 | struct Iterator {}; 10 | }; 11 | 12 | """.} 13 | 14 | type 15 | Vector {.importcpp: "Vector".} [T] = object 16 | VectorIterator {.importcpp: "Vector<'0>::Iterator".} [T] = object 17 | 18 | var x: VectorIterator[void] 19 | 20 | -------------------------------------------------------------------------------- /tests/fields/tfields_in_template.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''n 3 | n''' 4 | """ 5 | 6 | # bug #1902 7 | # This works. 8 | for name, value in (n: "v").fieldPairs: 9 | echo name 10 | 11 | # This doesn't compile - "expression 'name' has no type (or is ambiguous)". 12 | template wrapper: stmt = 13 | for name, value in (n: "v").fieldPairs: 14 | echo name 15 | wrapper() 16 | -------------------------------------------------------------------------------- /tests/metatype/tautoproc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "empty" 3 | """ 4 | 5 | # bug #898 6 | 7 | import typetraits 8 | 9 | proc measureTime(e: auto) = 10 | echo e.type.name 11 | 12 | proc generate(a: int): void = 13 | discard 14 | 15 | proc runExample = 16 | var builder: int = 0 17 | 18 | measureTime: 19 | builder.generate() 20 | 21 | measureTime: 22 | discard 23 | -------------------------------------------------------------------------------- /tests/namedparams/tnamedparams.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tnamedparams.nim" 3 | line: 8 4 | errormsg: "type mismatch: got (input: string, filename: string, line: int literal(1), col: int literal(23))" 5 | """ 6 | import pegs 7 | 8 | discard parsePeg( 9 | input = "input", 10 | filename = "filename", 11 | line = 1, 12 | col = 23) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/openarray/topenarrayrepr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "topenarrayrepr.nim" 3 | output: "5 - [1]" 4 | """ 5 | type 6 | TProc = proc (n: int, m: openarray[int64]) {.nimcall.} 7 | 8 | proc Foo(x: int, P: TProc) = 9 | P(x, [ 1'i64 ]) 10 | 11 | proc Bar(n: int, m: openarray[int64]) = 12 | echo($n & " - " & repr(m)) 13 | 14 | Foo(5, Bar) #OUT 5 - [1] 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/template/thygienictempl.nim: -------------------------------------------------------------------------------- 1 | 2 | var 3 | e = "abc" 4 | 5 | raise newException(EIO, e & "ha!") 6 | 7 | template t() = echo(foo) 8 | 9 | var foo = 12 10 | t() 11 | 12 | 13 | template test_in(a, b, c: expr): bool {.immediate, dirty.} = 14 | var result {.gensym.}: bool = false 15 | false 16 | 17 | when isMainModule: 18 | assert test_in(ret2, "test", str_val) 19 | -------------------------------------------------------------------------------- /tests/typerel/tstr_as_openarray.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''success''' 3 | """ 4 | var s = "HI" 5 | 6 | proc x (zz: openarray[char]) = 7 | discard 8 | 9 | x s 10 | 11 | proc z [T] (zz: openarray[T]) = 12 | discard 13 | 14 | z s 15 | z([s,s,s]) 16 | 17 | proc y [T] (arg: var openarray[T]) = 18 | arg[0] = 'X' 19 | y s 20 | doAssert s == "XI" 21 | 22 | echo "success" 23 | -------------------------------------------------------------------------------- /tests/array/tarrayplus.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch: got (array[0..2, float], array[0..1, float])" 3 | """ 4 | 5 | proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] = 6 | for i in low(v1)..high(v1): 7 | result[i] = v1[i] + v2[i] 8 | 9 | var 10 | v1: array[0..2, float] = [3.0, 1.2, 3.0] 11 | v2: array[0..1, float] = [2.0, 1.0] 12 | v3 = v1 + v2 13 | 14 | -------------------------------------------------------------------------------- /tests/controlflow/tblock1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tblock1.nim" 3 | line: 14 4 | errormsg: "undeclared identifier: \'ha\'" 5 | """ 6 | # check for forward label and 7 | # for failure when label is not declared 8 | 9 | proc main = 10 | block endLess: 11 | write(stdout, "Muaahh!\N") 12 | break endLess 13 | 14 | break ha #ERROR 15 | 16 | main() 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/generics/tgenericprop.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | TProperty[T] = object of TObject 4 | getProc: proc(property: TProperty[T]): T {.nimcall.} 5 | setProc: proc(property: TProperty[T], value: T) {.nimcall.} 6 | value: T 7 | 8 | proc newProperty[T](value: TObject): TProperty[T] = 9 | result.getProc = proc (property: TProperty[T]) = 10 | return property.value 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/iter/titervaropenarray.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "titer2.nim" 3 | output: "123" 4 | """ 5 | # Try to break the transformation pass: 6 | iterator iterAndZero(a: var openArray[int]): int = 7 | for i in 0..len(a)-1: 8 | yield a[i] 9 | a[i] = 0 10 | 11 | var x = [[1, 2, 3], [4, 5, 6]] 12 | for y in iterAndZero(x[0]): write(stdout, $y) 13 | #OUT 123 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/macros/tvarnimnode.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: 10 3 | """ 4 | 5 | #bug #926 6 | 7 | import macros 8 | 9 | proc test(f: var NimNode) {.compileTime.} = 10 | f = newNimNode(nnkStmtList) 11 | f.add newCall(newIdentNode("echo"), newLit(10)) 12 | 13 | macro blah(prc: stmt): stmt = 14 | result = prc 15 | 16 | test(result) 17 | 18 | proc test() {.blah.} = 19 | echo 5 20 | -------------------------------------------------------------------------------- /tests/misc/treadx.nim: -------------------------------------------------------------------------------- 1 | 2 | when not defined(windows): 3 | import posix 4 | 5 | var inp = "" 6 | var buf: array[0..10, char] 7 | while true: 8 | var r = read(0, addr(buf), sizeof(buf)-1) 9 | add inp, $buf 10 | if r != sizeof(buf)-1: break 11 | 12 | echo inp 13 | #dafkladskölklödsaf ölksdakölfölksfklwe4iojr389wr 89uweokf sdlkf jweklr jweflksdj fioewjfsdlfsd 14 | 15 | -------------------------------------------------------------------------------- /compiler/nimfix/nimfix.nim.cfg: -------------------------------------------------------------------------------- 1 | # Special configuration file for the Nim project 2 | # gc:markAndSweep 3 | 4 | hint[XDeclaredButNotUsed]:off 5 | path:"$projectPath/.." 6 | 7 | path:"$lib/packages/docutils" 8 | path:"../../compiler" 9 | 10 | define:useStdoutAsStdmsg 11 | symbol:nimfix 12 | define:nimfix 13 | 14 | cs:partial 15 | #define:useNodeIds 16 | define:booting 17 | define:noDocgen 18 | -------------------------------------------------------------------------------- /tests/notnil/tnotnil2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "cannot prove 'y' is not nil" 3 | line:20 4 | """ 5 | 6 | import strutils 7 | 8 | 9 | type 10 | TObj = object 11 | x, y: int 12 | 13 | proc q(x: pointer not nil) = 14 | nil 15 | 16 | proc p() = 17 | var x: pointer 18 | let y = x 19 | if not y.isNil or y != x: 20 | q(y) 21 | else: 22 | q(y) 23 | 24 | p() 25 | -------------------------------------------------------------------------------- /tests/rodfiles/gtkex1.nim: -------------------------------------------------------------------------------- 1 | import 2 | cairo, glib2, gtk2 3 | 4 | proc destroy(widget: pWidget, data: pgpointer) {.cdecl.} = 5 | main_quit() 6 | 7 | var 8 | window: pWidget 9 | nimrod_init() 10 | window = window_new(WINDOW_TOPLEVEL) 11 | discard signal_connect(window, "destroy", 12 | SIGNAL_FUNC(gtkex1.destroy), nil) 13 | show(window) 14 | main() 15 | -------------------------------------------------------------------------------- /tests/vm/tquadplus.nim: -------------------------------------------------------------------------------- 1 | # bug #1023 2 | 3 | discard """ 4 | output: "1 == 1" 5 | """ 6 | 7 | type Quadruple = tuple[a, b, c, d: int] 8 | 9 | proc `+`(s, t: Quadruple): Quadruple = 10 | (a: s.a + t.a, b: s.b + t.b, c: s.c + t.c, d: s.d + t.d) 11 | 12 | const 13 | A = (a: 0, b: -1, c: 0, d: 1) 14 | B = (a: 0, b: -2, c: 1, d: 0) 15 | C = A + B 16 | 17 | echo C.d, " == ", (A+B).d 18 | -------------------------------------------------------------------------------- /tests/caas/basic-recompile.txt: -------------------------------------------------------------------------------- 1 | main.nim 2 | > c --verbosity:0 --hints:on 3 | SuccessX 4 | # The "Processing" string will be found always in proc mode since each 5 | # compilation command will generate it. We need to test it only in Caas mode to 6 | # verify the server is not recompiling again the file. 7 | CaasRun > c --verbosity:0 --hints:on 8 | CaasRun ! Processing 9 | CaasRun SuccessX 10 | 11 | -------------------------------------------------------------------------------- /tests/effects/tsidee3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsidee3.nim" 3 | output: "5" 4 | """ 5 | 6 | var 7 | global: int 8 | 9 | proc dontcare(x: int): int {.noSideEffect.} = return x 10 | 11 | proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = 12 | return x + y + dontcare(x) 13 | 14 | echo noSideEffect(1, 3, dontcare) #OUT 5 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/float/tfloat1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tfloat1.nim" 3 | outputsub: "Error: unhandled exception: FPU operation caused an overflow [FloatOverflowError]" 4 | exitcode: "1" 5 | """ 6 | # Test new floating point exceptions 7 | 8 | {.floatChecks: on.} 9 | 10 | var x = 0.8 11 | var y = 0.0 12 | 13 | echo x / y #OUT Error: unhandled exception: FPU operation caused an overflow 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/generics/moverloading_typedesc.nim: -------------------------------------------------------------------------------- 1 | import tables 2 | 3 | type 4 | FFoo* = object 5 | FBar* = object 6 | 7 | proc new*(_: typedesc[FFoo]): int = 2 8 | proc new*[T](_: typedesc[T]): int = 3 9 | proc new*(_: typedesc): int = 4 10 | proc new*(_: typedesc[seq[Table[int, seq[Table[int, string]]]]]): int = 5 11 | proc new*(_: typedesc[seq[Table[int, seq[Table[int, typedesc]]]]]): int = 6 12 | -------------------------------------------------------------------------------- /tests/generics/tsubtypeconstraint.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #1684 3 | type 4 | BaseType {.inheritable pure.} = object 5 | idx: int 6 | 7 | DerivedType* {.final pure.} = object of BaseType 8 | 9 | proc index*[Toohoo: BaseType](h: Toohoo): int {.inline.} = h.idx 10 | proc newDerived(idx: int): DerivedType {.inline.} = DerivedType(idx: idx) 11 | 12 | let d = newDerived(2) 13 | assert(d.index == 2) 14 | -------------------------------------------------------------------------------- /tests/parallel/tdeepcopy.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''13 abc''' 3 | """ 4 | 5 | type 6 | PBinaryTree = ref object 7 | le, ri: PBinaryTree 8 | value: int 9 | 10 | 11 | proc main = 12 | var x: PBinaryTree 13 | deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13)))) 14 | var y: string 15 | deepCopy y, "abc" 16 | echo x.ri.le.value, " ", y 17 | 18 | main() 19 | -------------------------------------------------------------------------------- /tests/parser/tdomulttest.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tdomulttest.nim" 3 | output: "555\ntest\nmulti lines\n99999999\nend" 4 | disabled: true 5 | """ 6 | proc foo(bar, baz: proc (x: int): int) = 7 | echo bar(555) 8 | echo baz(99999999) 9 | 10 | foo do (x: int) -> int: 11 | return x 12 | do (x: int) -> int: 13 | echo("test") 14 | echo("multi lines") 15 | return x 16 | 17 | echo("end") -------------------------------------------------------------------------------- /tinyc/win32/lib/dllcrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved); 6 | 7 | BOOL WINAPI _dllstart(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) 8 | { 9 | BOOL bRet; 10 | bRet = DllMain (hDll, dwReason, lpReserved); 11 | return bRet; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/ccgbugs/tmissingvolatile.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "1" 3 | cmd: r"nim c --hints:on $options -d:release $file" 4 | ccodecheck: "'NI volatile state;'" 5 | """ 6 | 7 | # bug #1539 8 | 9 | proc err() = 10 | raise newException(Exception, "test") 11 | 12 | proc main() = 13 | var state: int 14 | try: 15 | state = 1 16 | err() 17 | except: 18 | echo state 19 | 20 | main() 21 | -------------------------------------------------------------------------------- /tests/float/tfloat2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tfloat2.nim" 3 | outputsub: "Error: unhandled exception: FPU operation caused a NaN result [FloatInvalidOpError]" 4 | exitcode: "1" 5 | """ 6 | # Test new floating point exceptions 7 | 8 | {.floatChecks: on.} 9 | 10 | var x = 0.0 11 | var y = 0.0 12 | 13 | echo x / y #OUT Error: unhandled exception: FPU operation caused a NaN result 14 | 15 | 16 | -------------------------------------------------------------------------------- /tinyc/win32/examples/dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // dll.c - Windows DLL example - dynamically linked part 4 | // 5 | 6 | #include 7 | 8 | #define DLL_EXPORT __declspec(dllexport) 9 | 10 | 11 | DLL_EXPORT void HelloWorld (void) 12 | { 13 | MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/caas/completion_dot_syntax.txt: -------------------------------------------------------------------------------- 1 | completion_dot_syntax_main.nim 2 | > idetools --track:$TESTNIM,24,15 --def 3 | def\tskProc\t$MODULE.echoRemainingDollars 4 | > idetools --trackDirty:completion_dot_syntax_dirty.nim,$TESTNIM,25,12 --suggest 5 | sug\tskProc\techoRemainingDollars 6 | # The suggestion should not mention the other echoRemaining* variants. 7 | !echoRemainingEuros 8 | !echoRemainingBugs 9 | 10 | -------------------------------------------------------------------------------- /tests/collections/ttableconstr.nim: -------------------------------------------------------------------------------- 1 | # Test if the new table constructor syntax works: 2 | 3 | template ignoreExpr(e: expr): stmt {.immediate.} = 4 | discard 5 | 6 | # test first class '..' syntactical citizen: 7 | ignoreExpr x <> 2..4 8 | # test table constructor: 9 | ignoreExpr({:}) 10 | ignoreExpr({2: 3, "key": "value"}) 11 | 12 | # NEW: 13 | assert 56 in 50..100 14 | 15 | assert 56 in ..60 16 | 17 | -------------------------------------------------------------------------------- /tests/constraints/tconstraints.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 16 3 | errormsg: "type mismatch: got (int literal(232))" 4 | """ 5 | 6 | proc myGenericProc[T: object|tuple|ptr|ref|distinct](x: T): string = 7 | result = $x 8 | 9 | type 10 | TMyObj = tuple[x, y: int] 11 | 12 | var 13 | x: TMyObj 14 | 15 | assert myGenericProc(x) == "(x: 0, y: 0)" 16 | assert myGenericProc(232) == "232" 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/generics/tcannot_pass_empty_seq_to_generic.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "type mismatch: got (seq[empty])" 3 | line: 16 4 | """ 5 | 6 | # bug #836 7 | 8 | type 9 | TOption*[T] = object 10 | case FIsSome: bool 11 | of false: nil 12 | of true: FData: T 13 | 14 | proc some*[T](value: T): TOption[T] = TOption[T](FIsSome: true, FData: value) 15 | 16 | echo some(@[]).FIsSome 17 | 18 | -------------------------------------------------------------------------------- /tests/notnil/tnotnil.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 22 3 | errormsg: "type mismatch" 4 | """ 5 | 6 | type 7 | PObj = ref TObj not nil 8 | TObj = object 9 | x: int 10 | 11 | MyString = string not nil 12 | 13 | #var x: PObj = nil 14 | 15 | proc p(x: string not nil): int = 16 | result = 45 17 | 18 | proc q(x: MyString) = nil 19 | proc q2(x: string) = nil 20 | 21 | q2(nil) 22 | q(nil) 23 | 24 | -------------------------------------------------------------------------------- /tests/trmacros/tpatterns.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''48 3 | hel''' 4 | """ 5 | 6 | template optZero{x+x}(x: int): int = x*3 7 | template andthen{`*`(x,3)}(x: int): int = x*4 8 | template optSubstr1{x = substr(x, a, b)}(x: string, a, b: int) = setlen(x, b+1) 9 | 10 | var y = 12 11 | echo y+y 12 | 13 | var s: array[0..2, string] 14 | s[0] = "hello" 15 | s[0] = substr(s[0], 0, 2) 16 | 17 | echo s[0] 18 | -------------------------------------------------------------------------------- /tests/typerel/tsymchoice_for_expr.nim: -------------------------------------------------------------------------------- 1 | # bug #1988 2 | 3 | template t(e: expr) = discard 4 | 5 | proc positive(x: int): int = +x 6 | proc negative(x: int): int = -x 7 | proc negative(x: float): float = -x 8 | 9 | proc p1 = t(negative) 10 | proc p2[X] = t(positive) 11 | proc p3[X] = t(negative) 12 | 13 | p1() # This compiles. 14 | p2[int]() # This compiles. 15 | p3[int]() # This raises an error. 16 | -------------------------------------------------------------------------------- /tests/bind/tmixin.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "1\n2" 3 | """ 4 | 5 | type 6 | TFoo1 = object of TObject 7 | v: int 8 | TFoo2 = object of TFoo1 9 | v2: int 10 | 11 | proc test(f: TFoo1) = 12 | echo "1" 13 | 14 | proc Foo[T](f: T) = 15 | mixin test 16 | test(f) 17 | 18 | var 19 | a: TFoo1 20 | b: TFoo2 21 | 22 | 23 | proc test(f: TFoo2) = 24 | echo "2" 25 | 26 | Foo(a) 27 | Foo(b) 28 | -------------------------------------------------------------------------------- /tests/let/tlet2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: "13" 3 | errormsg: "type mismatch: got (int literal(8), int literal(5), int, int)" 4 | """ 5 | 6 | proc divmod(a, b: int, res, remainder: var int) = 7 | res = a div b # integer division 8 | remainder = a mod b # integer modulo operation 9 | 10 | let 11 | x = 9 12 | y = 3 13 | divmod(8, 5, x, y) # modifies x and y 14 | echo(x) 15 | echo(y) 16 | 17 | -------------------------------------------------------------------------------- /tests/macros/tidgen.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: "3 4" 3 | """ 4 | 5 | import macros 6 | 7 | # Test compile-time state in same module 8 | 9 | var gid {.compileTime.} = 3 10 | 11 | macro genId(): expr = 12 | result = newIntLitNode(gid) 13 | inc gid 14 | 15 | proc Id1(): int {.compileTime.} = return genId() 16 | proc Id2(): int {.compileTime.} = return genId() 17 | 18 | echo Id1(), " ", Id2() 19 | 20 | -------------------------------------------------------------------------------- /tests/types/tillrec.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tillrec.nim" 3 | line: 13 4 | errormsg: "illegal recursion in type \'TIllegal\'" 5 | """ 6 | # test illegal recursive types 7 | 8 | type 9 | TLegal {.final.} = object 10 | x: int 11 | kids: seq[TLegal] 12 | 13 | TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal' 14 | y: int 15 | x: array[0..3, TIllegal] 16 | 17 | -------------------------------------------------------------------------------- /tests/cnstseq/tcnstseq.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tcnstseq.nim" 3 | output: "AngelikaAnneAnnaAnkaAnja" 4 | """ 5 | # Test the new implicit conversion from sequences to arrays in a constant 6 | # context. 7 | 8 | import strutils 9 | 10 | const 11 | myWords = "Angelika Anne Anna Anka Anja".split() 12 | 13 | for x in items(myWords): 14 | write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/concepts/mvarconcept.nim: -------------------------------------------------------------------------------- 1 | type RNG* = concept var rng 2 | rng.randomUint32() is uint32 3 | 4 | type MersenneTwister* = object 5 | 6 | proc randomUint32*(self: var MersenneTwister): uint32 = 5 7 | 8 | proc randomInt*(rng: var RNG; max: Positive): Natural = 5 9 | 10 | var mersenneTwisterInst = MersenneTwister() 11 | 12 | proc randomInt*(max: Positive): Natural = 13 | mersenneTwisterInst.randomInt(max) 14 | -------------------------------------------------------------------------------- /tests/objects/tobject2.nim: -------------------------------------------------------------------------------- 1 | # Tests the object implementation 2 | 3 | type 4 | TPoint2d {.inheritable.} = object 5 | x, y: int 6 | 7 | TPoint3d = object of TPoint2d 8 | z: int # added a field 9 | 10 | proc getPoint( p: var TPoint2d) = 11 | {.breakpoint.} 12 | writeLine(stdout, p.x) 13 | 14 | var 15 | p: TPoint3d 16 | 17 | TPoint2d(p).x = 34 18 | p.y = 98 19 | p.z = 343 20 | 21 | getPoint(p) 22 | -------------------------------------------------------------------------------- /tests/parser/tinvcolonlocation2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tinvcolonlocation2.nim" 3 | line: 11 4 | column: 1 5 | errormsg: "':' expected" 6 | """ 7 | try: 8 | echo "try" 9 | except #<- missing ':' 10 | echo "except" 11 | finally: 12 | #<-- error will be here above, at the beginning of finally, 13 | # since compiler tries to consome echo and part of except 14 | # expression 15 | echo "finally" 16 | -------------------------------------------------------------------------------- /tests/showoff/tonce.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''first call of p 3 | some call of p 4 | new instantiation 5 | some call of p''' 6 | """ 7 | 8 | template once(body: stmt) = 9 | var x {.global.} = false 10 | if not x: 11 | x = true 12 | body 13 | 14 | proc p() = 15 | once: 16 | echo "first call of p" 17 | echo "some call of p" 18 | 19 | p() 20 | once: 21 | echo "new instantiation" 22 | p() 23 | -------------------------------------------------------------------------------- /tests/array/tarraycons2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tarraycons.nim" 3 | output: "6" 4 | """ 5 | 6 | type 7 | TEnum = enum 8 | eA, eB, eC, eD, eE, eF 9 | 10 | const 11 | myMapping: array[TEnum, array[0..1, int]] = [ 12 | eA: [1, 2], 13 | eB: [3, 4], 14 | [5, 6], 15 | eD: [0: 8, 1: 9], 16 | eE: [0: 8, 9], 17 | eF: [2, 1: 9] 18 | ] 19 | 20 | echo myMapping[eC][1] 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/astoverload/tastoverload1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''string literal 3 | no string literal 4 | no string literal''' 5 | """ 6 | 7 | proc optLit(a: string{lit}) = 8 | echo "string literal" 9 | 10 | proc optLit(a: string) = 11 | echo "no string literal" 12 | 13 | const 14 | constant = "abc" 15 | 16 | var 17 | variable = "xyz" 18 | 19 | optLit("literal") 20 | optLit(constant) 21 | optLit(variable) 22 | -------------------------------------------------------------------------------- /tests/bind/tbind2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tbind2.nim" 3 | line: 14 4 | errormsg: "ambiguous call" 5 | """ 6 | # Test the new ``bind`` keyword for templates 7 | 8 | proc p1(x: int8, y: int): int = return x + y 9 | proc p1(x: int, y: int8): int = return x - y 10 | 11 | template tempBind(x, y: expr): expr = 12 | (bind p1(x, y)) #ERROR_MSG ambiguous call 13 | 14 | echo tempBind(1'i8, 2'i8) 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/casestmt/tcase_arrayconstr.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''Not found! 3 | Found!''' 4 | """ 5 | 6 | const 7 | md_extension = [".md", ".markdown"] 8 | 9 | proc test(ext: string) = 10 | case ext 11 | of ".txt", md_extension: 12 | echo "Found!" 13 | else: 14 | echo "Not found!" 15 | 16 | test(".something") 17 | # ensure it's not evaluated at compile-time: 18 | var foo = ".markdown" 19 | test(foo) 20 | -------------------------------------------------------------------------------- /tests/effects/teffects3.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 18 3 | errormsg: "type mismatch" 4 | """ 5 | 6 | type 7 | TObj = object {.pure, inheritable.} 8 | TObjB = object of TObj 9 | a, b, c: string 10 | fn: proc (): int {.tags: [].} 11 | 12 | EIO2 = ref object of EIO 13 | 14 | proc raiser(): int {.tags: [TObj, FWriteIO].} = 15 | writeLine stdout, "arg" 16 | 17 | var o: TObjB 18 | o.fn = raiser 19 | 20 | -------------------------------------------------------------------------------- /tests/effects/tsidee4.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsidee4.nim" 3 | line: 15 4 | errormsg: "type mismatch" 5 | """ 6 | 7 | var 8 | global: int 9 | 10 | proc dontcare(x: int): int = return x 11 | 12 | proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = 13 | return x + y + dontcare(x) 14 | 15 | echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/iter/titer9.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''5 3 | 14 4 | 0''' 5 | """ 6 | 7 | iterator count[T](x: T, skip: bool): int {.closure.} = 8 | if skip: return x+10 9 | else: yield x+1 10 | 11 | if skip: return x+10 12 | else: yield x+2 13 | 14 | proc takeProc[T](x: iterator (x: T, skip: bool): int) = 15 | echo x(4, false) 16 | echo x(4, true) 17 | echo x(4, false) 18 | 19 | takeProc(count[int]) 20 | 21 | -------------------------------------------------------------------------------- /tests/iter/titerovl.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''9 3 | 1 4 | 2 5 | 3 6 | ''' 7 | """ 8 | 9 | # Test the new overloading rules for iterators: 10 | 11 | # test that iterator 'p' is preferred: 12 | proc p(): seq[int] = @[1, 2, 3] 13 | iterator p(): int = yield 9 14 | 15 | for x in p(): echo x 16 | 17 | # test that 'q' works in this position: 18 | proc q(): seq[int] = @[1, 2, 3] 19 | 20 | for x in q(): echo x 21 | 22 | -------------------------------------------------------------------------------- /tests/range/tbug499771.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tbug499771.nim" 3 | output: '''TSubRange: 5 from 1 to 10 4 | true true true''' 5 | """ 6 | type 7 | TSubRange = range[1 .. 10] 8 | TEnum = enum A, B, C 9 | var sr: TSubRange = 5 10 | echo("TSubRange: " & $sr & " from " & $low(TSubRange) & " to " & 11 | $high(TSubRange)) 12 | 13 | const cset = {A} + {B} 14 | echo A in cset, " ", B in cset, " ", C notin cset 15 | -------------------------------------------------------------------------------- /tests/template/tmodulealias.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | disabled: true 3 | """ 4 | 5 | when defined(windows): 6 | import winlean 7 | else: 8 | import posix 9 | 10 | when defined(Windows): 11 | template orig: expr = 12 | winlean 13 | else: 14 | template orig: expr = 15 | posix 16 | 17 | proc socket(domain, typ, protocol: int): int = 18 | result = orig.socket(ord(domain), ord(typ), ord(protocol))) 19 | 20 | -------------------------------------------------------------------------------- /tests/assign/toverload_asgn2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''i value 88 3 | 2aa''' 4 | """ 5 | 6 | import moverload_asgn2 7 | 8 | proc passAround(i: int): Concrete = 9 | echo "i value ", i 10 | result = Concrete(a: "aa", b: "bb", rc: 0) 11 | 12 | proc main = 13 | let 14 | i = 88 15 | v = passAround(i) 16 | z = v.a 17 | var 18 | x: Concrete 19 | x = v 20 | echo x.rc, z # 2aa 21 | 22 | main() 23 | -------------------------------------------------------------------------------- /tests/effects/tgcsafe.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | line: 17 3 | errormsg: "'mainUnsafe' is not GC-safe" 4 | cmd: "nim $target --hints:on --threads:on $options $file" 5 | """ 6 | 7 | proc mymap(x: proc ()) = 8 | x() 9 | 10 | var 11 | myglob: string 12 | 13 | proc mainSafe() {.gcsafe.} = 14 | mymap(proc () = echo "foo") 15 | 16 | proc mainUnsafe() {.gcsafe.} = 17 | mymap(proc () = myglob = "bar"; echo "foo", myglob) 18 | -------------------------------------------------------------------------------- /tests/generics/tmetafield.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim check $options $file" 3 | errormsg: "'proc' is not a concrete type" 4 | errormsg: "'Foo' is not a concrete type." 5 | errormsg: "invalid type: 'proc' in this context: 'TBaseMed'" 6 | """ 7 | 8 | type 9 | Foo[T] = object 10 | x: T 11 | 12 | TBaseMed = object 13 | doSmth: proc 14 | data: seq[Foo] 15 | 16 | var a: TBaseMed 17 | 18 | # issue 188 19 | -------------------------------------------------------------------------------- /tests/varstmt/tlet.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''Very funny, your name is name. 3 | nameabc''' 4 | """ 5 | 6 | proc main = 7 | let name = "name" 8 | if name == "": 9 | echo("Poor soul, you lost your name?") 10 | elif name == "name": 11 | echo("Very funny, your name is name.") 12 | else: 13 | echo("Hi, ", name, "!") 14 | 15 | let (x, y) = ("abc", name) 16 | echo y, x 17 | 18 | main() 19 | 20 | -------------------------------------------------------------------------------- /compiler/nimsuggest/nimsuggest.nim: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # The Nim Compiler 4 | # (c) Copyright 2015 Andreas Rumpf 5 | # 6 | # See the file "copying.txt", included in this 7 | # distribution, for details about the copyright. 8 | # 9 | 10 | ## Nimsuggest has been moved to https://github.com/nim-lang/nimsuggest 11 | 12 | {.error: "This project has moved to the following repo: https://github.com/nim-lang/nimsuggest".} 13 | -------------------------------------------------------------------------------- /tests/macros/tmacro1.nim: -------------------------------------------------------------------------------- 1 | import macros 2 | 3 | from uri import `/` 4 | 5 | macro test*(a: stmt): stmt {.immediate.} = 6 | var nodes: tuple[a, b: int] 7 | nodes.a = 4 8 | nodes[1] = 45 9 | 10 | type 11 | TTypeEx = object 12 | x, y: int 13 | case b: bool 14 | of false: nil 15 | of true: z: float 16 | 17 | var t: TTypeEx 18 | t.b = true 19 | t.z = 4.5 20 | 21 | test: 22 | "hi" 23 | 24 | -------------------------------------------------------------------------------- /tests/stdlib/tstrtabs.nim: -------------------------------------------------------------------------------- 1 | import strtabs 2 | 3 | var tab = newStringTable({"key1": "val1", "key2": "val2"}, 4 | modeStyleInsensitive) 5 | for i in 0..80: 6 | tab["key_" & $i] = "value" & $i 7 | 8 | for key, val in pairs(tab): 9 | writeLine(stdout, key, ": ", val) 10 | writeLine(stdout, "length of table ", $tab.len) 11 | 12 | writeLine(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment})) 13 | -------------------------------------------------------------------------------- /compiler/nim.cfg: -------------------------------------------------------------------------------- 1 | # Special configuration file for the Nim project 2 | 3 | hint[XDeclaredButNotUsed]:off 4 | path:"llvm" 5 | path:"$projectPath/.." 6 | 7 | path:"$lib/packages/docutils" 8 | 9 | define:booting 10 | import:testability 11 | 12 | @if windows: 13 | cincludes: "$lib/wrappers/libffi/common" 14 | @end 15 | 16 | define:useStdoutAsStdmsg 17 | 18 | cs:partial 19 | #define:useNodeIds 20 | symbol:nimfix 21 | #gc:markAndSweep 22 | -------------------------------------------------------------------------------- /tests/cpp/tstaticvar_via_typedesc.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | cmd: "nim cpp $file" 3 | output: "42" 4 | """ 5 | 6 | # bug #2324 7 | 8 | static: assert defined(cpp), "compile in cpp mode" 9 | 10 | {.emit: """ 11 | class Foo { 12 | public: 13 | static int x; 14 | }; 15 | int Foo::x = 42; 16 | """.} 17 | 18 | type Foo {.importcpp:"Foo".} = object 19 | proc x* (this: typedesc[Foo]): int {.importcpp:"Foo::x@", nodecl.} 20 | echo Foo.x 21 | -------------------------------------------------------------------------------- /tests/generics/tinferredgenericprocs.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''123 3 | 1 4 | 2 5 | 3''' 6 | """ 7 | 8 | # https://github.com/Araq/Nim/issues/797 9 | proc foo[T](s:T):string = $s 10 | 11 | type IntStringProc = proc(x: int): string 12 | 13 | var f1 = IntStringProc(foo) 14 | var f2: proc(x: int): string = foo 15 | var f3: IntStringProc = foo 16 | 17 | echo f1(1), f2(2), f3(3) 18 | 19 | for x in map([1,2,3], foo): echo x 20 | 21 | -------------------------------------------------------------------------------- /tests/trmacros/tnoalias2.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''0''' 3 | """ 4 | 5 | # bug #206 6 | template optimizeOut{testFunc(a, b)}(a: int, b: int{alias}) : expr = 0 7 | 8 | proc testFunc(a, b: int): int = result = a + b 9 | var testVar = 1 10 | echo testFunc(testVar, testVar) 11 | 12 | 13 | template ex{a = b + c}(a : int{noalias}, b, c : int) = 14 | a = b 15 | inc a, b 16 | echo "came here" 17 | 18 | var x = 5 19 | x = x + x 20 | -------------------------------------------------------------------------------- /examples/cross_todo/readme.txt: -------------------------------------------------------------------------------- 1 | The cross platform todo illustrates how to use Nim to create a backend 2 | called by different native user interfaces. 3 | 4 | This example builds on the knowledge learned from the cross_calculator example. 5 | Check it out first to learn how to set up Nim on different platforms. 6 | Additional implementations are provided at the external 7 | https://github.com/gradha/nimrod-crossplatform-todo github repository. 8 | -------------------------------------------------------------------------------- /tests/caas/forward_declarations.nim: -------------------------------------------------------------------------------- 1 | # This example shows that idetools returns an empty signature for a forward 2 | # declared proc in proc/symproc runs, but correctly returns the full signature 3 | # in caas mode. 4 | 5 | proc echoHello(text: string) 6 | 7 | proc testForward() = 8 | echo "T" 9 | echoHello("T") 10 | 11 | proc echoHello(text: string) = 12 | echo "Hello Mr." & text 13 | 14 | when isMainModule: 15 | testForward() 16 | -------------------------------------------------------------------------------- /tests/caas/its_full_of_procs.txt: -------------------------------------------------------------------------------- 1 | its_full_of_procs.nim 2 | 3 | > idetools --track:$TESTNIM,26,15 --def $SILENT 4 | skProc 5 | proc \( 6 | 7 | > idetools --track:$TESTNIM,27,21 --def $SILENT 8 | skIterator 9 | iterator \( 10 | !proc \( 11 | 12 | > idetools --track:$TESTNIM,29,0 --def $SILENT 13 | skMethod 14 | method \( 15 | !proc \( 16 | 17 | > idetools --track:$TESTNIM,27,15 --def $SILENT 18 | skTemplate 19 | template \( 20 | !proc \( 21 | -------------------------------------------------------------------------------- /tests/effects/tsidee1.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | file: "tsidee1.nim" 3 | line: 12 4 | errormsg: "\'SideEffectLyer\' can have side effects" 5 | """ 6 | 7 | var 8 | global: int 9 | 10 | proc dontcare(x: int): int = return x + global 11 | 12 | proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects 13 | return x + y + dontcare(x) 14 | 15 | echo SideEffectLyer(1, 3) 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/generics/tgenericmatcher2.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | TMatcherKind = enum 4 | mkTerminal, mkSequence, mkAlternation, mkRepeat 5 | TMatcher[T] = object 6 | case kind: TMatcherKind 7 | of mkTerminal: 8 | value: T 9 | of mkSequence, mkAlternation: 10 | matchers: seq[TMatcher[T]] 11 | of mkRepeat: 12 | matcher: ref TMatcher[T] 13 | min, max: int 14 | 15 | var 16 | m: ref TMatcher[int] 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/notnil/tnotnil4.nim: -------------------------------------------------------------------------------- 1 | discard "" 2 | type 3 | TObj = ref object 4 | 5 | proc check(a: TObj not nil) = 6 | echo repr(a) 7 | 8 | proc doit() = 9 | var x : array[0..1, TObj] 10 | 11 | if x[0] != nil: 12 | check(x[0]) 13 | 14 | doit() 15 | 16 | # bug #2352 17 | 18 | proc p(x: proc() {.noconv.} not nil) = discard 19 | p(proc() {.noconv.} = discard) 20 | # Error: cannot prove 'proc () {.noconv.} = discard ' is not nil 21 | -------------------------------------------------------------------------------- /tests/caas/issue_416_template_shift.nim: -------------------------------------------------------------------------------- 1 | import unicode, sequtils 2 | 3 | proc test() = 4 | let input = readFile("weird.nim") 5 | for letter in runes(string(input)): 6 | echo int(letter) 7 | 8 | when 1 > 0: 9 | proc failtest() = 10 | let 11 | input = readFile("weird.nim") 12 | letters = toSeq(runes(string(input))) 13 | for letter in letters: 14 | echo int(letter) 15 | 16 | when isMainModule: 17 | test() 18 | -------------------------------------------------------------------------------- /tests/iter/tconcat.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''1 3 | 2 4 | 3 5 | 4 6 | 20 7 | 21 8 | 22 9 | 23''' 10 | """ 11 | 12 | proc toIter*[T](s: Slice[T]): iterator: T = 13 | iterator it: T {.closure.} = 14 | for x in s.a..s.b: 15 | yield x 16 | return it 17 | 18 | iterator concat*[T](its: varargs[T, toIter]): auto = 19 | for i in its: 20 | for x in i(): 21 | yield x 22 | 23 | for i in concat(1..4, 20..23): 24 | echo i 25 | -------------------------------------------------------------------------------- /tests/macros/tmemit.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | output: '''HELLO WORLD 3 | c_func''' 4 | """ 5 | 6 | import macros, strutils 7 | 8 | emit("echo " & '"' & "hello world".toUpper & '"') 9 | 10 | # bug #1025 11 | 12 | macro foo(icname): stmt = 13 | let ic = newStrLitNode($icname) 14 | result = quote do: 15 | proc x* = 16 | proc private {.exportc: `ic`.} = discard 17 | echo `ic` 18 | private() 19 | 20 | foo(c_func) 21 | x() 22 | -------------------------------------------------------------------------------- /tests/metatype/utypeclasses.nim: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | proc concat(a, b): string = 4 | result = $a & $b 5 | 6 | test "if proc param types are not supplied, the params are assumed to be generic": 7 | check concat(1, "test") == "1test" 8 | check concat(1, 20) == "120" 9 | check concat("foo", "bar") == "foobar" 10 | 11 | test "explicit param types can still be specified": 12 | check concat[cstring, cstring]("x", "y") == "xy" 13 | 14 | -------------------------------------------------------------------------------- /tests/misc/tdllvar.nim: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | proc getDllName: string = 4 | result = "mylib.dll" 5 | if fileExists(result): return 6 | result = "mylib2.dll" 7 | if fileExists(result): return 8 | quit("could not load dynamic library") 9 | 10 | proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().} 11 | proc myImport2(s: int) {.cdecl, importc, dynlib: getDllName().} 12 | 13 | myImport("test2") 14 | myImport2(12) 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/objects/tobject.nim: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | type Obj = object 4 | foo: int 5 | 6 | proc makeObj(x: int): Obj = 7 | result.foo = x 8 | 9 | suite "object basic methods": 10 | test "it should convert an object to a string": 11 | var obj = makeObj(1) 12 | # Should be "obj: (foo: 1)" or similar. 13 | check($obj == "(foo: 1)") 14 | test "it should test equality based on fields": 15 | check(makeObj(1) == makeObj(1)) 16 | -------------------------------------------------------------------------------- /tests/template/twrongsymkind.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "cannot use symbol of kind 'var' as a 'param'" 3 | line: 20 4 | """ 5 | 6 | # bug #3158 7 | 8 | type 9 | MyData = object 10 | x: int 11 | 12 | template newDataWindow(data: ref MyData): stmt = 13 | proc testProc(data: ref MyData) = 14 | echo "Hello, ", data.x 15 | testProc(data) 16 | 17 | var d: ref MyData 18 | new(d) 19 | d.x = 10 20 | newDataWindow(d) 21 | -------------------------------------------------------------------------------- /tests/typerel/tno_gcmem_in_shared.nim: -------------------------------------------------------------------------------- 1 | discard """ 2 | errormsg: "shared memory may not refer to GC'ed thread local memory" 3 | line: 14 4 | disabled: true 5 | """ 6 | 7 | type 8 | Region = object 9 | Foo = Region ptr int 10 | 11 | MyObject = object 12 | a, b: string 13 | 14 | Bar[T] = shared ptr T 15 | Bzar = Bar[MyObject] 16 | 17 | proc bar(x: Region ptr int) = 18 | discard 19 | 20 | var 21 | s: Foo 22 | 23 | bar s 24 | -------------------------------------------------------------------------------- /tests/typerel/tregionptrs2.nim: -------------------------------------------------------------------------------- 1 | 2 | # bug #2039 3 | 4 | type 5 | RegionTy = object 6 | ThingyPtr = RegionTy ptr Thingy 7 | Thingy = object 8 | next: ThingyPtr 9 | name: string 10 | 11 | proc iname(t: ThingyPtr) = 12 | var x = t 13 | 14 | while not x.isNil: 15 | echo x.name 16 | x = x.next 17 | 18 | proc go() = 19 | var athing : ThingyPtr 20 | 21 | iname(athing) 22 | 23 | go() 24 | -------------------------------------------------------------------------------- /tinyc/win32/examples/hello_dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // HELLO_DLL.C - Windows DLL example - main application part 4 | // 5 | 6 | #include 7 | 8 | void HelloWorld (void); 9 | 10 | int WINAPI WinMain( 11 | HINSTANCE hInstance, 12 | HINSTANCE hPrevInstance, 13 | LPSTR lpCmdLine, 14 | int nCmdShow) 15 | { 16 | HelloWorld(); 17 | return 0; 18 | } 19 | 20 | --------------------------------------------------------------------------------