Hacker News new | ask | show | jobs
Knit – A Scripting Language (github.com)
7 points by nilput 2169 days ago
3 comments

This is a scripting language i've written in C.

It has a surprisingly decent performance compared to other interpreted languages.

This could be partly attributable to the fact that the whole language is written in headers, so everything is available to the compiler where it can inline and do all kinds of optimizations, additionally the language is small and doesn't require much during initialization (the benchmark is ran 100 times with perf).

There's a benchmark in examples/bench/ where it beats PHP7, Python, Perl, and PUC Lua

I hope you keep working on this. I think there is a definite need for something very small and simple that can be embedded into other tools, to squeeze out extra performance in critical spots without resorting to the nitroglycerin of C/C++.
Looks great, but why would I prefer this over say Lua or Wren? Yes, the benchmarks look nice, but not extraordinary. What is the killer argument/advantage here? What is the use-case?
There isn't a killer argument, the project is in its infancy and i created it for experimentation, there are many directions that could be taken, if i were to go with a scripting language for something like a game engine or a similar C or C++ project that needs scripting i'd definitely go with Lua because of how popular and mature it is.

in terms of benchmarks alone languages with JIT compilers will definitely beat this, that's one possible direction to go with (there are great projects out there that make adding this capability potentially easier, MIR for example), another feature would be a C FFI rather than just a C API.

Can these scripts be compiled into executables?
Yes, You'd need a small wrapper in C that just includes the language's header and calls two functions to initialize it and provide the script code to be executed.

i added a tool that does that: https://github.com/nilput/knit/blob/master/scripts/knc

a slightly better way of doing this would be implementing a way of exporting the scripts' bytecode and executing it as that is currently being done only in memory, this would avoid the need to reparse it and hides the script's source code.