Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
Note: Now this Kinx is a little pending the development. A near future this could be freezed, but I am still sitting on the fence. As a successor, Kilite is available but it's under construction so far. You can see the new product of Kilite here, and check it out.
Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
Ruby is a major scripting language. Also Python is. However, either of these syntax is NOT familiar to C programmers. This Kinx is a script language for people who want C-like syntax.
The concept is, "Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers."
"C programmers" in this context means "almost all programmers." Because I think almost all programmers have used or known C language at least. And "Providing C Like Syntax" as well also means "friendly for almost all programmers."
Mainly there are features below.
--debug
and you can run a script with debugger.The script language is a platform as a glue between libraries. This means a language itself is not a main purpose, it should be just a backend or supporter due to use a library you want to use.
Therefore another design goal for this language is to be extendable, lightweight, and easy to use for user's own purpose. Kinx will be able to be the best platform for any libraries which you want to use or your own library.
Kinx is including useful libraries below in the standard package as All-In-One.
Parsek
like Parsec
.Making libraries improvement and extension is one of the main purpose of this language.
There is Quick Reference Guide. Please see Quick Reference Guide for your understanding.
For the detail of Kinx specification, see Kinx Specification. This document is also including Test Codes. I named this system as SpecTest. See SpecTest for detail.
And you can try it on the REPL. See REPL for detail.
I guess almost all programmers want a lightweight scripting language with C style syntax because it is simple, easy, and familiar to them. C style syntax is the most fitting in the programmer's hand, I guess.
Any other languages are also all good solution, but for me...
end
.self
.Sharing the definition of C Style Syntax, it is below.
{
and }
switch-when
is now supported without fallthrough by default.
break
statement.There are a lot of pros and cons about switch-case
.
Therefore now the followings are supported instead of switch-case
.
You can use it as it depends on your situation.
break
, you can use switch-when instead for that purpose.As C style Syntax family there are C, C++, Java, JavaScript, C#, and so on. If you agree, or if you don't agree, anyway push the star.
Currently this project supports x86-64 Windows and Linux only. I really want someone to support any other platforms if possible because I do not have any other platform environment. Please see detail here
IMPORTANT
If you faced a crash of thekinx
executable, please trymake clean all
to re-build everything. Sometimes changing a structure in common header will cause a crash because dependencies in Makefile are imcomplete.
On Windows, tested with Visual Studio 2017 Express Edition with x64. To build, see below.
$ make.cmd
Note that on Windows, compiling ir_exec.c
takes long time around 15 minutes, so please wait for it.
It is no problem on Linux because it is around 2 or 3 minutes.
On Linux, tested with gcc 7.4.0 with x64. To build, see below.
$ make
If anyone wants to support some other platform, the followings have to be done.
utliity/kmyacc
is prepared only for x86-64 Windows and Linux.
src/extlib
, and the other libraries which is provided as a binary is managed on this repository. That repository is registered as a submodule under src/extlib
.
You can download an installer from Releases page.
Or you also can install by scoop. Type the below:
scoop bucket add kinx https://github.com/Kray-G/kinx # only needed the first time
scoop install kinx
# For Windows
$ kinx.exe [options] [<script-file>]
# For Linux
$ ./kinx [options] [<script-file>]
Here is current available options.
Option | Description |
---|---|
-h |
Display help. |
-v , --version |
Display version number. |
-d |
Dump compiled code. |
-D |
Display AST. |
-i |
Input source code from stdin. |
-c |
Check the syntax only without any executions. |
-q |
Do quiet mode without displaying warning & error, and exit code 0 means successful. |
--debug |
Debugger mode and run with a debugger. |
--dot |
Output the dump by .dot format. |
--with-native |
Dump compiled code of a native function. Use with -d . |
--native-call-max-depth |
Specify the max depth to call a native function. 1024 by default. |
--case-threshold |
Specify the max interval between case's integer value. 16 by default. |
--exec:repl |
Run the Repl. |
--exec:spectest |
Run the SpecTest. |
You will think it is like JavaScript.
function fib(n) {
if (n < 3) return n;
return fib(n-2) + fib(n-1);
}
System.println("fib(34) = ", fib(34));
function fact(n) {
if (n < 1) return 1;
return n * fact(n-1);
}
System.println(fact(5000));
class Example(i) {
public get() { return i; }
}
System.println(new Example(100).get());
Remember the fibonacci function above. That is a simple fibonacci function and execute it with time measurement like below.
$ time ./kinx examples/fib.kx
fib(34) = 9227465
real 0m0.718s
user 0m0.609s
sys 0m0.000s
Replace function
to native
.
That's all.
native fib(n) {
if (n < 3) return n;
return fib(n-2) + fib(n-1);
}
System.println("fib(34) = ", fib(34));
Let's execute it and measure it!
$ time ./kinx examples/native_fib.kx
fib(34) = 9227465
real 0m0.167s
user 0m0.063s
sys 0m0.016s
How nice it is around 10x faster.
But you have to know the limitations with native function. See Native Functions for details.
You can use REPL (Read-Eval-Print-Loop) with the option of --exec:repl
as below.
$ ./kinx --exec:repl
Here is a demo animation. REPL has an autocomplete by [TAB]
key.
See REPL for details.
Have fun with it!
Debugger is now available. Run with the --debug
option.
$ ./kinx --debug script.kx
Here is a sample screen shot. See Kinx Debugger for details.
This project is licensed under the MIT License. See the LICENSE file for details. About the licenses of internal used libraries, follow the licenses of each library. See docs/licenses folder for details.