Skip to content

Commit

Permalink
Merge #306
Browse files Browse the repository at this point in the history
306: add isNimSkull define r=saem a=saem

## Summary

This allows code bases to detect whether they're using the Nim or
NimSkull compiler.

Originally motivated by Nimph's needs, see:
disruptek/nimph#159

## Details

Also added a compilerapi test to avoid regressions. This is hardcoded in
the compiler executable because system import can be circumvented.



Co-authored-by: Saem Ghani <[email protected]>
  • Loading branch information
bors[bot] and saem authored May 11, 2022
2 parents 9a3ded9 + 89ba670 commit 352ae3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ path="$lib/pure"
nimblepath="$home/.nimble/pkgs2/"
nimblepath="$home/.nimble/pkgs/"

# Hardcode `isNimSkull` define so code bases meant to work for both Nim and
# NimSkull can test to see which compiler they're using. Not done in system
# as a program can exclude system. This was done in order to allow
# https://github.com/disruptek/nimph to work across both. See the following
# PR for some clues: https://github.com/disruptek/nimph/pull/159
--define:isNimSkull

# Syncronize with compiler/commands.specialDefine
@if danger or quick:
obj_checks:off
Expand Down
12 changes: 7 additions & 5 deletions tests/compilerapi/tcompilerapi.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
discard """
description: '''Example program that demonstrates how to use the compiler as
an API to embed into your own projects.
'''
cmd: '''nim c --warnings:off --hints:off $file'''
output: '''top level statements are executed!
(ival: 10, fval: 2.0)
Expand All @@ -11,9 +14,6 @@ raising VMQuit
joinable: "false"
"""

## Example program that demonstrates how to use the
## compiler as an API to embed into your own projects.


import
std/[
Expand Down Expand Up @@ -58,8 +58,6 @@ proc vmReport(config: ConfigRef, report: Report): TErrorHandling {.gcsafe.} =
echo report.internalReport.msg




proc main() =
let i = initInterpreter("myscript.nim", vmReport)
i.implementRoutine("*", "exposed", "addFloats", proc (a: VmArgs) =
Expand Down Expand Up @@ -104,3 +102,7 @@ block error_hook:
let i = initInterpreter("invalid.nim", vmReport)
doAssertRaises(VMQuit):
i.evalScript()

block isNimSkull_define:
const isNimSkull {.booldefine.} = false
doAssert isNimSkull, "define 'isNimSkull' is not set"

0 comments on commit 352ae3d

Please sign in to comment.