Author Topic: JAIL  (Read 623 times)

Offline Marcus

  • BASIC Developer
  • Posts: 11
    • NaaLaa
JAIL
« on: July 14, 2018, 07:55:29 AM »
I guess this is not basic related, but this is the only fun forum there is for these kind of things so ... :)

I made a quick experiment with writing an interpreter for a new language in naalaa a while ago (http://www.naalaa.com/community/showthread.php?tid=68). This resultet in a language that was way more "powerful" than naalaa itself. So I decided to rewrite it in C, and this is the result so far. At a first glance it may look like Lua but with C-like syntax, but ... it's not.

I'm not quite sure where I'm heading with this, but I've attached the sourcecode, you can build it with the makefile (on Linux). Sorry again about this not really being basic related.

There are some example programs included. Here's one about functions:

Code: [Select]
/*
 * File: functions.txt
 * -------------------
 */

/* Functions are assigned to variables using function. */
helloWorld = function() {
    wln("Hello world!");
};

/* Call helloWorld. */
helloWorld();

/* Create a new function that takes two parameters and returns their sum. */
sum = function(a, b) {
    return a + b;
};
wln(tostring(sum(3, 7)));


/* When calling a function, two reference variables are always created: this
   and self. self can be used for object-based design and is explained in
   another example. this is a reference to the function variable itself. */
countDown = function(n) {
    wln(tostring(n));
    if (n > 1) {
        sleep(1000);
        /* Make a recursive call through this. Actually we couldn't call
           countDown for this purpose here, because functions can't normally
           access variables from the main program. */
        this(n - 1);
    }
};
countDown(5);

/* If the function variable has sub-variables you can access those through
   this. */
name.first = "John";
name.last = "Doe";
name = function() {
    return this.first + " " + this.last;
};
wln(name());


One of the weirdest things with the language, compared to Lua and Javascript, is that a variable can have an intrinsic value and sub-variables at the same time. You can see that in the last part of the code above. The variable 'name' has two sub-variables (first and last), while its intrinsic value is a function that returns the two sub-variables combined.

I called the language prolan earlier, but now it's JAIL (just another interpreted language). I like stupid names.
« Last Edit: July 14, 2018, 07:58:48 AM by Marcus »

Offline John

  • Forum Support / SB Dev
  • Posts: 2186
    • ScriptBasic Open Source Project
Re: JAIL
« Reply #1 on: July 14, 2018, 11:39:00 AM »
Outstanding!

The make worked fine on my Ubuntu 64 bit laptop.

I would of never have imagined creating an interpreter in NaaLaa but I've learned to not to underestimate your creative energy.
« Last Edit: July 16, 2018, 11:25:42 PM by John »

Offline Marcus

  • BASIC Developer
  • Posts: 11
    • NaaLaa
Re: JAIL
« Reply #2 on: August 09, 2018, 08:16:25 AM »
The latest version can be found here:

http://jail.naalaa.com/

The thing I posted earlier was filled with bugs.

Offline AlyssonR

  • Advocate
  • Posts: 125
Re: JAIL
« Reply #3 on: August 10, 2018, 01:25:29 AM »
Hmmmmm .... interesting .... *scratches chin*

I can see this evolving into something quite useful.

Right now, I'm assuming that it is an interpreter only.

How fast is it (running either as naalaa or as C)?
How strongly typed are the variables?
What's it like handling strings (the big problem area with C IMHO)

I like the sub-variables - a good place to put such properties as ~.length, ~.type, and so on (but not to the ridiculous extent as with Python and Java) - subpended functions are a pain!

I look forward to seeing the next stage.

BTW - are you planning on porting SICK to JAIL?  :o

Offline Marcus

  • BASIC Developer
  • Posts: 11
    • NaaLaa
Re: JAIL
« Reply #4 on: August 10, 2018, 02:03:23 AM »
It's a pure interpreter (no bytecode step), so it's slow as hell, haha :)

It's dynamically typed. The variable types are number, string and function. A variable may also reference another variable, but it's more like creating aliases. Strings work ... fine :)

There's no coercion at all.
« Last Edit: August 10, 2018, 02:17:30 AM by Marcus »

Tomaaz

  • Guest
Re: JAIL
« Reply #5 on: August 11, 2018, 09:06:57 AM »
Marcus, have you finally decided to join the dark side of the development?  ;D Like Aurel and Cybermonkey, before you? I mean the "every year we start something new and abandon existing projects" philosophy. Noooooooo!  ;D

Just kidding. I love the name, BTW.  ;)

Offline John

  • Forum Support / SB Dev
  • Posts: 2186
    • ScriptBasic Open Source Project
Re: JAIL
« Reply #6 on: August 11, 2018, 10:41:33 AM »
Welcome Tomaaz!

Glad to have you here as a member.

Offline Marcus

  • BASIC Developer
  • Posts: 11
    • NaaLaa
Re: JAIL
« Reply #7 on: August 12, 2018, 01:49:05 AM »
Marcus, have you finally decided to join the dark side of the development?  ;D Like Aurel and Cybermonkey, before you? I mean the "every year we start something new and abandon existing projects" philosophy. Noooooooo!  ;D

Just kidding. I love the name, BTW.  ;)

Every tenth year or so I go a bit crazy and want to try out new things, like kebab pizza and fubar language design.