-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[superseded] VM: allow importc var in some cases #12840
[superseded] VM: allow importc var in some cases #12840
Conversation
Well, I am totally on your side, fprintf, stdout and stderr should just work at compile time. But saying that Regarding your future plans with let and const, am totally on your side with |
right, on further inspection, importcSymbol hardcodes some symbols; this PR makes it work for those, so i've updated a bit the description; |
So only allow it for |
AFAIK that's already the case, the check is done inside |
13037ef
to
aa881f8
Compare
/cc @Araq
before PR:
importc var variables doesn't work at CT (
Error: cannot evaluate at compile time:
), requiring user to compile a separate library to expose getters/setters instead of directly using importc var, which has its own issues (more complex, can't be inlined, etc). Eg: see example 2 in #12825getStdout
; ditto withgetErrno / setErrno
to get/set errno;after PR:
importc var now works at CT for stdin/stdout/stderr
example 1
print to stderr at CT: (requires building nim with -d:nimHasLibFFI and compiling with --experimental:compiletimeFFI for importc at CT)
example 2
illustrates why
if s.importcCondVar: return
is also needed in the PRnote 1
pre-existing BUG that can be fixed in future PR: as shown in snippet above, var variables at CT work for ptr types (eg cstderr) but for integral types (eg errno), they currently return the address instead of the value; help welcome to fix that; probably a bug inside
compiler/evalffi.nim
note 2
(related to #12824 but different)
in future PR, it would be nice also to allow importc
let
andconst
at CT:these can be worked around using an intermediate library exactly as shown in example2 in #12825:
but ideally would work directly, making interop simpler