From 13c08f3ab4db3cc7b162af383a74c4fc09f0c378 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sun, 5 Jan 2020 00:11:29 -0800 Subject: VM: support importc var, ptr/pointer types, cast int <=> ptr/pointer (#12877) * VM: allow certain hardcoded special var variables at CT * VM: allow all importc var, cast[int](ptr) * fix tests tests/vm/tstaticprintseq.nim, tests/cpp/t8241.nim * VM: == works for ptr/pointer nodes * bugfix: ==, cast now also works for pointer, not just ptr * VM supports cast PtrLikeKinds <=> PtrLikeKinds / int * improve cname handling * fixup + bug fix * VM: support cast from ref to int * address comment: opcLdGlobalDeref => opcLdGlobalDerefFFI * defensive check against typ == nil --- compiler/evalffi.nim | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'compiler/evalffi.nim') diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim index 543810886..cb383a393 100644 --- a/compiler/evalffi.nim +++ b/compiler/evalffi.nim @@ -46,19 +46,12 @@ proc getDll(conf: ConfigRef, cache: var TDllCache; dll: string; info: TLineInfo) const nkPtrLit = nkIntLit # hopefully we can get rid of this hack soon -var myerrno {.importc: "errno", header: "".}: cint ## error variable - proc importcSymbol*(conf: ConfigRef, sym: PSym): PNode = - let name = $sym.loc.r + let name = sym.cname # $sym.loc.r would point to internal name # the AST does not support untyped pointers directly, so we use an nkIntLit # that contains the address instead: result = newNodeIT(nkPtrLit, sym.info, sym.typ) - case name - of "stdin": result.intVal = cast[ByteAddress](system.stdin) - of "stdout": result.intVal = cast[ByteAddress](system.stdout) - of "stderr": result.intVal = cast[ByteAddress](system.stderr) - of "vmErrnoWrapper": result.intVal = cast[ByteAddress](myerrno) - else: + when true: let lib = sym.annex if lib != nil and lib.path.kind notin {nkStrLit..nkTripleStrLit}: globalError(conf, sym.info, "dynlib needs to be a string lit") @@ -74,7 +67,7 @@ proc importcSymbol*(conf: ConfigRef, sym: PSym): PNode = let dll = if lib.kind == libHeader: libcDll else: lib.path.strVal let dllhandle = getDll(conf, gDllCache, dll, sym.info) theAddr = dllhandle.symAddr(name) - if theAddr.isNil: globalError(conf, sym.info, "cannot import: " & sym.name.s) + if theAddr.isNil: globalError(conf, sym.info, "cannot import: " & name) result.intVal = cast[ByteAddress](theAddr) proc mapType(conf: ConfigRef, t: ast.PType): ptr libffi.TType = -- cgit 1.4.1-2-gfad0 =devel&id=07d5a8085bbcc21a1d9d06a2976ecc00e9c8d55b'>copying.txt
blob: 2657a09dfcd85a825e99ab13906b90500fb45c08 (plain) (tree)




























                                                                                
=======================================================
                  The Nimrod Runtime Library
             Copyright (C) 2004-2007  Andreas Rumpf
=======================================================

This is the file copying.txt, it applies to the Nimrod Run-Time Library
(lib) and base packages (base) distributed by members of the Nimrod
Development Team.

The source code of the Nimrod Runtime Libraries and packages are
distributed under the Library GNU General Public License
(see the file lgpl.txt) with the following modification:

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,
and to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a module
which is not derived from or based on this library. If you modify this
library, you may extend this exception to your version of the library, but
you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.

If you didn't receive a copy of the file lgpl.txt, contact:
      Free Software Foundation
      675 Mass Ave
      Cambridge, MA  02139
      USA