diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-01-05 00:11:29 -0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-01-05 09:11:29 +0100 |
commit | 13c08f3ab4db3cc7b162af383a74c4fc09f0c378 (patch) | |
tree | 017f361f1c260fbcacf0e9840f11ae5cc86192ce /compiler/evalffi.nim | |
parent | a1beeb313fee19b4c9720ca68fde534e2ef587fe (diff) | |
download | Nim-13c08f3ab4db3cc7b162af383a74c4fc09f0c378.tar.gz |
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
Diffstat (limited to 'compiler/evalffi.nim')
-rw-r--r-- | compiler/evalffi.nim | 13 |
1 files changed, 3 insertions, 10 deletions
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: "<errno.h>".}: 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 = |