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

add --experimental:vmopsDanger; add generic conversion for vmops #13813

Merged
merged 5 commits into from
Apr 20, 2020

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Mar 31, 2020

  • this PR adds compiler/vmconv.nim with generic proc toLit*[T](a: T): PNode to convert a concrete type to a PNode (it works recursively). fromLit is also added for reverse direction. I only implemented the branches that were needed to support the vmops introduced, but it's easy to make it more complete in future PRs as needed. This avoids tedious manual conversion.

  • it PR also adds --experimental:vmopsDanger to enable certain operations in VM that I and others need.
    Since this is hidden behind a flag, only code that needs this feature will be able to use it.

  • can close staticExec removes trailing LF which interferes with binary output that happens to end with 0xA #13786 by providing a more flexible alternative

often requested

This was also requested in several occasions, eg:

What I'm asking is, could there ever be a staticTime proc analog to times.getTime

We talked about adding getCurrentDir for bump's use-case. I would use this in nimph and testutils and golden and openapi, too. I guess I'm just a bad person.

I think you have to concede that if this isn't provided, a work-around will be developed, and that's clearly a worse option. Can you really champion NimScript as the right tool for writing build scripts when one cannot even find the current working directory in NimScript?

  • nimterop also needs a lot of functions at CT (by design) and currently to resort to using staticExec which, I've argued in several places (eg https://forum.nim-lang.org/t/6058#37491) is often not the right tool (error prone / os specific shell commands, requires manual serialization/deserialization, inefficient, and many other drawbacks you encounter once you start using it more)

  • staticExec is too limited (eg, no flags, and other issues), this PR provides a workaround that should close staticExec removes trailing LF which interferes with binary output that happens to end with 0xA #13786; IMO it's better to reuse stdlib's osproc API's than re-invent another proc with different semantics that keep tripping users; caching (as done in staticExec) can always be done via a separate / orthogonal API eg cache(execCmdEx(...), ... ) usable at both RT and CT

example after PR:

nim c -r --experimental:vmopsDanger t10460.nim works

import osproc, os, times
proc main()=
  {.push experimental: "vmopsDanger".} # not yet meaningful in localized context
  echo getCurrentDir()
  let t = getTime()
  echo t.toUnixFloat
  echo cpuTime()
  let (outp, errC) = execCmdEx("echo ok1 && echo ok2 && nonexistant", {poEchoCmd,poStdErrToStdOut})
  # let (outp, errC) = gorgeEx("echo ok1 && echo ok2")
    # removes LF and has other "surprising" behavior that differs from
    # `execCmdEx`; `execCmdEx` gives you more control when needed.
  echo (outp, errC)
  {.pop.}

static: main()
main()

links

@timotheecour
Copy link
Member Author

ping @Araq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

staticExec removes trailing LF which interferes with binary output that happens to end with 0xA
2 participants