summary refs log tree commit diff stats
path: root/tests/effects/tgcsafe.nim
blob: 363624f19566b5fb31524e87df688bac539a2bf7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
discard """
  errormsg: "'mainUnsafe' is not GC-safe"
  line: 26
  cmd: "nim $target --hints:on --threads:on $options $file"
"""

# bug #6955
var global_proc: proc(a: string): int {.nimcall.} = nil

proc myproc(i: int) {.gcsafe.} =
  if global_proc != nil:
    echo "a"
  if isNil(global_proc):
    return

proc mymap(x: proc ()) =
  x()

var
  myglob: string

proc mainSafe() {.gcsafe.} =
  mymap(proc () = echo "foo")

proc mainUnsafe() {.gcsafe.} =
  mymap(proc () = myglob = "bar"; echo "foo", myglob)
n class="p">: int TC = object of TB c: int proc test(p: TA) = if p of TB: echo "tbObj of TC ", p of TC var v = TC() v.a = 1 v.b = 2 v.c = 3 test(v) block t924: type MyObject = object of RootObj x: int var asd: MyObject proc isMyObject(obj: RootObj) = echo obj of MyObject if obj of MyObject: let a = MyObject(obj) echo a.x asd.x = 5 isMyObject(asd) block t4673: type BaseObj[T] = ref object of RootObj SomeObj = ref object of BaseObj[int] proc doSomething[T](o: BaseObj[T]) = echo "true" var o = new(SomeObj) o.doSomething() # Error: cannot instantiate: 'T' block t1658: type Loop = ref object onBeforeSelect: proc (L: Loop) var L: Loop new L L.onBeforeSelect = proc (bar: Loop) = echo "is Nil ", bar.isNil L.onBeforeSelect(L) block t2508: type GenericNodeObj[T] = ref object obj: T Node = ref object children: seq[Node] parent: Node nodeObj: GenericNodeObj[int] proc newNode(nodeObj: GenericNodeObj): Node = result = Node(nodeObj: nodeObj) newSeq(result.children, 10) var genericObj = GenericNodeObj[int]() var myNode = newNode(genericObj) block t2540: type BaseSceneNode[T] = ref object of RootObj children: seq[BaseSceneNode[T]] parent: BaseSceneNode[T] SceneNode[T] = ref object of BaseSceneNode[T] SomeObj = ref object proc newSceneNode[T](): SceneNode[T] = new result result.children = @[] var aNode = newSceneNode[SomeObj]() block t3038: type Data[T] = ref object of RootObj data: T Type = ref object of RootObj SubType[T] = ref object of Type data: Data[T] SubSubType = ref object of SubType SubSubSubType = ref object of SubSubType ul class="simple"><li>Linux: i386, AMD64</li> <li>Mac OS X: i386</li> <li>FreeBSD: i386</li> </ul> <h1 id="installation">Installation</h1><h2 id="installation-on-linux-unix">Installation on Linux/UNIX</h2><dl class="docutils"><dt>Note:</dt> <dd>A C compiler is required - knowledge of C is not!</dd> </dl> <p>The GNU C Compiler is fully supported, other compilers may work. The C compiler should be in your <tt class="docutils literal"><span class="pre">$PATH</span></tt> (most likely the case). Note that some few Linux distributions do not ship with a GCC compiler preinstalled - then you have to install it.</p> <p>Install Nimrod by downloading the appropriate <tt class="docutils literal"><span class="pre">.zip</span></tt> file and extracting it to a directory of your choice. The Nimrod Compiler will stay in this directory (unless you copy it somewhere else). The compiler does not need write access to its directory anymore, so copying the nimrod folder to <tt class="docutils literal"><span class="pre">/opt</span></tt> does work.</p> <p>Then run the following command:<pre> sh build.sh</pre> </p> <p>Unlike other software, Nimrod does not distribute its files over the whole file hierarchy. This has the advantage that you can deinstall it by just deleting its folder. The disadvantage is that you have to add it to your <tt class="docutils literal"><span class="pre">PATH</span></tt> manually. An alternative is to create a symbolic link in <tt class="docutils literal"><span class="pre">/usr/bin</span></tt>:<pre> [sudo] ln -s $your_install_dir/bin/nimrod /usr/bin/nimrod</pre> </p> <h2 id="installation-on-the-macintosh">Installation on the Macintosh</h2><p>Only MacOS X is supported. Since MacOS X is UNIX based too, it works like the installation on Linux. You need to install Apple's developer's tools for the GNU Compiler Collection though.</p> <h2 id="installation-on-windows">Installation on Windows</h2><p>Install Nimrod by downloading and running the <tt class="docutils literal"><span class="pre">nimrod_$version.exe</span></tt> file. As default, the <tt class="docutils literal"><span class="pre">LLVM-GCC</span></tt> compiler is used that is bundled with this installer. You can change the configuration file to use another C compiler.</p> <p>Currently, the following C compilers are supported under Windows:</p> <ul class="simple"><li><p>Microsoft's Visual C++<br /><a class="reference external" href="http://msdn.microsoft.com/visualc">http://msdn.microsoft.com/visualc</a><br />(You need the SDK too - but not the full one: Essential are only the win32api header files and import libraries.)<br /></p></li> <li><p>Gnu C Compiler (the mingw version; the cygwin version has not been tested!)<br /><a class="reference external" href="http://www.mingw.org/download.shtml">http://www.mingw.org/download.shtml</a><br /></p></li> <li><p>LLVM with GNU C/C++ frontend<br /><a class="reference external" href="http://llvm.org/releases/download.html#2.2">http://llvm.org/releases/download.html#2.2</a><br /></p></li> <li><p>Digital Mars C++<br /><a class="reference external" href="http://www.digitalmars.com/download/freecompiler.html">http://www.digitalmars.com/download/freecompiler.html</a><br /></p></li> </ul> <p>For better compile times I recommend Digital Mars C++ -- it is easy to install and a small package.</p> <pre> x < 0 && y >= 0 </pre> </div> </div> <div id="footer"> copyright &copy; 2009 Andreas Rumpf | Last update: 2009-02-10 | <a class="reference" href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a> | <a class="reference" href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> | <a class="reference" href="http://www.dcarter.co.uk">design by dcarter</a> </div> </div> </body> <bugtest att="value" /> </html>