Skip to content
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

vmhook : user defined vmops: proc fn(): int {.vmhook.} = impl to JIT-compile and dlopen fn at CT (using regular backend, not VM) #598

Open
timotheecour opened this issue Feb 18, 2021 · 0 comments

Comments

@timotheecour
Copy link
Owner

timotheecour commented Feb 18, 2021

goal

  • compile a proc at CT using its own compilation context/defines etc, in much same way as nimscript is a separate compilation context than subsequent compilation.

motivation

example

when not defined js:
  import posix

proc fn(a: int): int {.vmhook.} = # {.vmhook: "-d:bar".} is also possible
  doAssert not defined(js)
  doAssert int.sizeof == 8
  doAssert declared(posix)

doAssert no declared(posix)
doAssert defined(js)
doAssert int.sizeof == 8

doAssert defined(js)
doAssert int.sizeof == 4
const a = fn(3)
doAssert a == 8

implementation

  • a vmhook proc is compiled at CT (in its own separate compilation context using regular backend)
  • reuse similar logic as --compiletimeFFI for conversion to/from PNode to value
  • see also vmops, vmconv, vmhooks
  • I've already implemented this a while back in a private branch

bikeshedding

import or importc could also be used by importc is ambiguous because a proc with no body could mean either a regular importc proc, or a ctfe proc with empty body
another option is vmhost or vmhook or ctfe, jit

proc fn(): int {.vmhook.} =
  result = 12

links

@timotheecour timotheecour changed the title user defined vmops: proc fn(): int {.vmhook.} to compile fn at CT (using regular backend, not VM!) user defined vmops: proc fn(): int {.vmhook.} = impl to compile fn at CT (using regular backend, not VM!) Feb 18, 2021
@timotheecour timotheecour changed the title user defined vmops: proc fn(): int {.vmhook.} = impl to compile fn at CT (using regular backend, not VM!) user defined vmops: proc fn(): int {.vmhook.} = impl to jit compile and dlopen fn at CT (using regular backend, not VM!) Feb 18, 2021
@timotheecour timotheecour changed the title user defined vmops: proc fn(): int {.vmhook.} = impl to jit compile and dlopen fn at CT (using regular backend, not VM!) vmhook : user defined vmops: proc fn(): int {.vmhook.} = impl to jit compile and dlopen fn at CT (using regular backend, not VM!) Feb 18, 2021
@timotheecour timotheecour changed the title vmhook : user defined vmops: proc fn(): int {.vmhook.} = impl to jit compile and dlopen fn at CT (using regular backend, not VM!) vmhook : user defined vmops: proc fn(): int {.vmhook.} = impl to JIT-compile and dlopen fn at CT (using regular backend, not VM) Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant