Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the nim compiler version programmatically ?

Tags:

nim-lang

Is there any constant variable or proc that allows to access the compiler version as a string or number?

like image 920
Jundiaius Avatar asked Oct 09 '18 18:10

Jundiaius


People also ask

What does Nim compile to?

Nim source code can also be compiled into Objective C and JavaScript. The Objective C language is mainly used for iOS software development; by compiling to it, you can write iOS applications natively in Nim. You can also use Nim to develop Android applications by using the C++ compilation backend.

Does Nim compile to C?

The Nim compiler supports mainly two backend families: the C, C++ and Objective-C targets and the JavaScript target. The C like targets creates source files that can be compiled into a library or a final executable. The JavaScript target can generate a .

How do I run a NIM code?

To see all compiler options, type nim --help in your terminal. If you're using VSCode with the Code Runner extension mentioned before, you'll just have to press Ctrl+Alt+N and your file will be compiled and run.

Does Nim use LLVM?

Introduction. nlvm (the nim-level virtual machine?) is an LLVM-based compiler for the Nim language. From Nim's point of view, it's a backend just like C or JavaScript - from LLVM's point of view, it's a language frontend that emits IR.


1 Answers

The version can be obtained as a string via system.NimVersion (remember that system is implicitly imported):

echo NimVersion # 0.18.0

You can also access its component parts (MAJOR.MINOR.PATCH) as numbers like so:

echo NimMajor # 0
echo NimMinor # 18
echo NimPatch # 0

This makes checking versions for compatibility very easy when combined with tuples:

when (NimMajor, NimMinor, NimPatch) >= (0, 19, 0):
  echo "we're on at least Nim v0.19.0"
like image 170
Jundiaius Avatar answered Nov 15 '22 09:11

Jundiaius