Is it possible to sand box Nimscript, so that it does not have access to write files, make http requests etc?
Can you use it as "mod" scripting language for games? So that potentially "unsafe" scripts can be downloaded from the internet and run on player computers?
How fast is it compared to compiled nim?
Can you run it for a set amount of time or number of instructions? Is it possible to detect infinite loops or very high memory use?
You can limit the stdlib shipped to prevent access to any code you dont want. Http in Nim relies on FFI so it would not work.
Yes it should be usable as a mod scripting language, as long as you limit the stdlib to remove anything that is "unsafe"
Slow.
--maxLoopIterationsVM:N means that infinite loops would crash out of the VM. No clue if there is a way to detect infinite loops aside, or memory usage.
I haven't benchmarked various code execution (which is a huge space), but nim e is quite a bit slower than Python for start-up time:
touch j.nims
(repeat 10 utime nim e j.nims) |& min
(repeat 10 utime py2 -c "") |& min
(repeat 10 utime py3 -c "") |& min
yields 0.0989, 0.00544, 0.00817. So, start up time is 18x slower than py2 and 12x slower than py3. Not sure how Nimscripter compares to nim e, and there is obviously much more to run time than start-up time. (Just ask the Julia people, LOL). { utime and min are my own programs. Writing your own is an exercise for any benchmarker. ;-) }I could be wrong, but I believe the start up time in my test above is mostly compiling the system module Araq is always complaining about being bloated. (Also, that repeat thing is a Zsh-ism).
Not sure if the incremental compilation (IC) work will help here, but it might (dramatically even).
Yea, I've tested with an empty file aswell and it was still near the same results. So seems it's a limit of my glue code/ the NimVM interpreter. Below is the code I was using to test with if you want to give it a whirl.
import nimscripter, times
const code = """
proc fibonacci(n: int): int =
if n <= 0:
echo "wrong input"
elif n == 1:
result = 0
elif n == 2:
result = 1
else: result = fibonacci(n - 1) + fibonacci(n - 2)
echo fibonacci(20)"""
let t = cpuTime()
discard loadScript("", false, stdPath = "/home/jason/nimscripter/stdlib") # The stdlib in the repo