Monday, June 27, 2011

Subject symbols

As I mentioned in the very first post in this blog when I started ELENA project I decided that the best plan is no plan. After all it is hard to plan if you have only a vague idea of your future programming language. After ten years of development several distinct languages were developed (just compare 1.0.0, 1.4.6, 1.5.1 and 1.6.2) and the work goes on. So when people (those few who bother to look at) complain that ELENA is a weird or exotic they forget that it is an experimental language and it shouldn't be all shiny (at least until it is in development phase). Its main purpose is to check the proposed concepts. And at the moment it is an open architecture concept.

This model of development may be called evolutional (yes, in the evolution there is no plan as well). Similar to the real evolution some minor tactical decisions may have a great impact. When I came up with an idea of a message subject I tried to solve a practical question: how to write a real program if you have very limited set of message names. Later it appeared that the subject can be used to implement some kind of multiple dispatching in ELENA. And now (starting from 1.6.3) the subject will be used in VM script engine as a message adapter.

Every time a new subject is declared the appropriate implicit symbol is auto-generated as well (actually two symbols). When the symbol is called without an argument it returns an external role (stateless object) used to invoke a message, otherwise the property wrapper.

So let's look at several use cases. The first case is sending a message. Presume we would like to send a qualified message to the object. Usually it looks like this - anObject verb &subject:aParameter. With the help of the subject symbol we could implement the same code without using subject (remember it is not possible to use subjects in ELENA-script): anObject~subject verb:aParameter. In this code our subject symbol translates verb into subject'verb.

Secondly let's extend an object with a subject property: anObject~(subject::Variable), subject symbol returns a wrapper object around Variable which translates subject'get / subject'set into get / set.

Let's look how this concept can be used in vm terminal. Presume we would like to return the literal constant length: nil 'program'output "abc" nil nil std'dictionary'length &get will print 3.

One may ask why not to allow to use subjects in the script? Of course it could be easily done but in this case there is no need in subjects at all. We could allow methods to have any names the programmer wants and in the result we will get ... Smalltalk. The need to formalize the class interface was one of the main reasons I started this project. Only time will tell if this approach is feasible but at the moment you may consider this as a basis assumption on which the language is built.

P.S. The discussed functionality will be implemented in the upcoming weekly release (probably in two week after 1.6.2 release). In the next post I will display how symbol subject can be used to implement bf interpreter.

Sunday, June 26, 2011

ELENA 1.6.2 released

ELENA 1.6.2 is out now

This release includes alpha version of ELENA script engine, changes in the language syntax, new library lib2(only console samples are migrated).

Starting from 1.6.2 the migration to a new library LIB2 began. At the moment all console and rosetta stone ones are migrated to LIB2

The work on GCX (a revised garbage collection) continues. Young and old generations are introduced.

ELENA Script Engine is introduced. At the moment it is very early alpha version.

Other changes

  • it is possible now to switch to another role inside another one
  • run-time multi-dispatching
  • new argument option: nullable
  • obsolete argument option: norecc
  • #continue is no longer supported
  • new statement: #try
  • some basic byte code optimization rules
  • new compiler options: g0, ox
  • some basic byte code optimization rules

Friday, June 10, 2011

ELENA Virtual Machine Script

The last year in the article The Next Big Thing I mentioned the intention to create a special VM script to manipulate with the objects. It took me half a year to come up with the possible solution. And though it is a very early alpha a new tool introduced in the current release (bin\elt.exe) put this idea into practice.

So what is ELENA script? First of all it should not be confused with a traditional script language, it has not its own interpreter, grammar, libraries. It is pure a set of instruction for ELENA VM to load existing symbols into the memory and send them messages. So its prime goal is to assemble objects in VM memory with the help of special rules (if it is done from ELENA program it could be considered as a self assembling, hence its name - DSA (dynamic self assembling) rule). The possibility to work with your own objects directly without need to write a special test program could be useful as well. I hope it will find an application for code generations, open architecture systems (as a way to build complex group objects) and so on.

The actual system consists of VM terminal (elt.exe) and a special script engine (elenasm.dll) working with ELENA Virtual Machine (elenavm.dll). It is designed to be used directly from ELENA program as well (of course if the program is VM client). There are actually two types of script: inline one (which can be used directly with VM without need for the script engine) and grammar driven (where context-free and DSA rules modify the script text to create an inline one, so it could be considered as a additional layer between the client and VM).

Before I will show how it looks to work with VM terminal I would like to notice that at the moment it is very early alpha version and it is still unstable. Secondly direct script requires some knowledge of ELENA stack machine: a symbol reference should be always preceded by a parameter (if there is no parameter, nil constant should be used), the same is true for the message call. Thirdly only generic messages can be used (without a subject qualifier; actually it was designed for such a use from the beginning). Note also, that the current implementation allows to work only with console applications. There should be a special VM client for GUI applications. And finally it is presumed that you works with LIB2 programs (if you need to use LIB, please change libpath in elt.cfg to ..\lib)

So let's start the terminal. Inline script should be executed with an option "-i"

First of all we need to start a virtual machine and load default template

-i @config win32_vm_console2 @start
The canonical hello world sample will be looked like this:

-i &nil 'program'output "Hello World!!" ^write

Let's print the sum of two numbers:

-i &nil 'program'output 2 3 ^add ^write

Now let's do a bit more complex task and call existing application (it should be compiled before). First of all you have to tell VM where your compiled modules are located

-i @use "..\examples\binary"

And now let's execute the program symbol:

-i &nil binary'program &nil ^evaluate

As you see it is not very convenient way to write the expression (but it could be ok for computer programs). So let's try to use some grammar. I would like to note that the script engine support simple context free grammar. There are several restriction: only one terminal symbol (it should be first) and non-terminal (with except of AB type rule) can be used. So only the following type of rules are allowed:

  • S::=aA
  • S::=a
  • S::=A
  • S::=AB
  • S::=$eps

So let's define our simple rule

-g print ::= "?" expression;
-g expression ::= $literal;

(Note $literal is a special terminal mask accepting any literal constant)

DSA rules are used to provide required symbols and operations.

-g print => &nil 'program'output $body ^write;

(Note $body indicates the place where rule content is inserted)

Now let's mark print as a start rule

-g start ::= print

Let's test if our code works

? "hello world!!"

You could load existing scripts as well


And now you may calculate some basic arithmetic expression


You may look how your expression is translated into direct script with the following command -ton


You will see the script listing. To turn the tracing off type the following


To exit the program, type


That's all I would like to show in this tutorial. In near future I will show some more complex samples (for example I will implement bf interpreter)

P.S. Note that in the current implementation several key features are lacking, for example it is not possible to declare variables. I'm going to implement them in the recent releases. Once again it is still unclear if this turns into something more than a nice toy but it is the direction ELENA Program Language Project is moving to.

"Weekly" release

This is a weekly service release.

  • optimization: direct method call for constants and external roles
  • new statement: #try
  • bsort migrated to lib2
  • fixed bug with inline class argument hint
  • vm terminal
  • script engine

You may download it from sourceforge - ELENA