timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

misc nimvm #157

Open timotheecour opened 4 years ago

timotheecour commented 4 years ago

when not defined(nimscript): reduces to when true because nimscript always runs in nimvm

Yes but it semantic checks the else branch. We dealt with this already. If you change this to when true you get undeclared identifier nimCmpMem

D20200524T194136

  when notJSnotNims:
    const nimCmpMem = 1
  proc cmp(x, y: string): int =
    when nimvm:
      discard
    else:
      when not defined(nimscript):
        discard nimCmpMem

wondering whether https://github.com/nim-lang/Nim/pull/13038 would help...

links

[Meta] Generics/Static early symbol resolution · Issue #8677 · nim-lang/Nim

example where my previous proposed if nimct: doens't work:

https://github.com/nim-lang/Nim/pull/13038#issuecomment-570976718

whereas this works:

when defined case2:
  proc c_printf(frmt: cstring): cint {.importc: "printf", header: "<stdio.h>", varargs, discardable.}
  proc main() =
    when nimvm: echo "in nimvm"
    else:
      echo "notin nimvm"
      c_printf("hello\n")
  static: main()
  main()
timotheecour commented 4 years ago

see whether we can overload by nimvm vs rt:

proc fn(): int {.nimvm.} = 1
proc fn(): int {.nimvm:off.} = 2
proc main=
    doAssert fn() == 2
    static: doAssert fn() == 1

links