Home

Awesome

<p align="right"> <img src="http://img.shields.io/badge/License-MIT-blue.svg?style=flat"/> </p> <p align="center"><img src="docs/kilite.png" height="128px" /></p> <p align="center"> Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers. </p>

Kilite

This is like a lightweight Kinx but more flexible, portable, and faster. Mainly, we will provide the following features for your help.

Motivation

Kinx is very useful for me. It's a really important project for me and actually I love it. However, unfortunately I feel now I have some difficulities to improve it more at least as long as it is. This means I'd need to remake it from its architecture if I wanted to make it improve more.

That's why I decided to try to making a new design of a programming language that I really wanted with a new architecture, athough I am going to keep using Kinx as well also in future.

Usecases

There are some usecases that I want to try. It would be roughly 4 patterns as below.

  1. To run the script as it is on the fly.
  2. To output C source code to make an executable.
  3. To generate the executable from your script directly by calling another compiler intrnally.
  4. To compile the script separatedly and to run the code with those precompiled codes.

Running the Script

This will work with the current version.

$ ./kilite file.klt

Outputting C Code and Making the Executable

$ ./kilite --cfull file.klt > file.c
(file.c)
$ gcc -o file file.c -L. -lkilite -lm
(file)
$ cl /Fefile.exe file.c kilite.lib
(file.exe)
$ ./file

Note that you need the actual compiler like gcc on Linux, cl.exe on Windows, or something to make an actual executable. Instead, you can use the compiler you want.

Generating the Executable Directly

$ ./kilite -X file.klt
(file or file.exe)
$ ./file

Note that, also in this case, you need the actual compiler like gcc on Linux, cl.exe on Windows. It's cl.exe on Windows and gcc on Linux by default, and you could also use the MinGW gcc with the option --cc=gcc on Windows environment.

Compiling the Script Separatedly

Note that this is not implemented yet.

$ ./kilite -c file1.klt
(file1.kc)
$ ./kilite -c file2.klt
(file2.kc)
$ ./kilite file1.kc file2.kc

Benchmark

Now, I did benchmark with some script languages because even the current version of kilite can run the code like a fibonacci. That's why I'll show it below. The target program is the 38th result of a fibonacci as usual.

On Windows

VersionTimeResultRemark
C (-O3)gcc 8.1.00.14s39088169Simple C code.
Kilite(C compiled)(beta/gcc MinGW 8.1.0)0.17s39088169Compiled the output from Kilite.
C (-O2)VS20190.18s39088169Simple C code.
C (-O2)tcc 0.9.270.22s39088169Simple C code.
Kilite(C compiled)(beta/cl VS2019)0.22s39088169Compiled the output from Kilite.
luajit2.1.0-beta30.35s39088169-
PyPy7.3.90.40s39088169-
Kilite(C compiled)(beta/tcc 0.9.27)0.53s39088169Compiled the output from Kilite.
Kinx(native)1.1.10.57s39088169-
Kilite(beta)0.68s39088169-
Lua5.4.42.59s39088169-
Ruby3.1.2p204.02s39088169-
Kinx1.1.15.18s39088169-
Python3.11.05.94s39088169-

On Linux

VersionTimeResultRemark
C (-O3)gcc 11.2.00.062s39088169Simple C code.
Kilite(C compiled)(beta/gcc 11.2.0)0.110s39088169Compiled the output from Kilite.
luajit2.1.0-beta30.318s39088169-
PyPy7.3.90.330s39088169-
Kinx(native)1.1.10.389s39088169-
Kilite(beta)0.622s39088169-
Lua5.4.42.526s39088169-
Ruby3.0.2p1072.576s39088169-
Kinx1.1.14.657s39088169-
Python3.10.67.461s39088169-

Result

There is some differences between on Windows and on Linux, but luajit and PyPy was very fast and amazing. That's exactly JIT as expected. As for Kilite, this is almost the result that I wanted, but it could be slower by increasing the code in the future. I will try to keep the perfrmance even if the code would be more complex.

Source Code

The source codes for each language are shown below.

Kinx/Kilite

Kilite is now already supported the System.println method as well as Kinx. And when I outputted the C source code and compiled it, that was super fast.

function fib(n) {
    if (n < 2) return n;
    return fib(n - 2) + fib(n - 1);
}
System.println(fib(38));

Kinx(native)

Kinx native was super fast, but we have to specify the native everytime.

native fib(n) {
    if (n < 2) return n;
    return fib(n - 2) + fib(n - 1);
}
System.println(fib(38));

C

This is just a simple C code.

#include <stdio.h>

int fib(int n) {
    if (n < 2) return n;
    return fib(n - 2) + fib(n - 1);
}

int main()
{
    printf("%d\n", fib(38));
}

Ruby

Ruby is now much faster than before.

def fib(n)
    return n if n < 2
    fib(n - 2) + fib(n - 1)
end
puts fib(38)

Lua/luajit

Lua is almost same as Ruby about the performance, but luajit is amazing and super fast.

function fib(n)
    if n < 2 then return n end
    return fib(n - 2) + fib(n - 1)
end
print(fib(38))

Python/PyPy

Python was slow, but PyPy was very fast.

def fib(n):
    if n < 2:
        return n
    return fib(n-2) + fib(n-1)
print(fib(38))

TODO

I will note the followings as I don't forget it.

There could be something I've forgotten. I'll add it when I remember it.

In addition, the followings are the task list for the current implementation.

Others

Goal

Below is the goal I wanted to achive. Some of them has been already done by Kinx, but some hasn't.

Design Concept

To meet the goal, I will try with followings.

native

Note that native keyword will be no longer supported because Kilite will work automatically with a similar way thought it's a little different. For example, as you looked at above, the Kilite(beta-x) is working with a specialized method for 64bit integers and it has been already optimized. It's like native in Kinx, but we don't have to use some keywords like native and it will work automatilly as we write it naturally.