Compiler for actsl, a minimal low-level action-based programming language, sources

tkorrovi@mail.com
17 Oct 2007 17:39:10 -0700

          From comp.compilers

Related articles
Compiler for actsl, a minimal low-level action-based programming langu tkorrovi@mail.com (2007-10-17)
| List of all articles for this month |

From: tkorrovi@mail.com
Newsgroups: comp.compilers
Date: 17 Oct 2007 17:39:10 -0700
Organization: Compilers Central
Keywords: available, comment
Posted-Date: 18 Oct 2007 00:43:24 EDT

Summary: compiler, low-level action-based programming language actsl


Compiler for actsl, a minimal low-level action-based programming
language


Cross-posted to alt.sources.


This is the source code for the compiler of the programming language
called actsl, both in C and in actsl. The compiler is extremely small,
its source code in C is less than 300 lines of normal (not obfuscated)
code. The code written in actsl is approximately 1.5 times longer than
a code written in C, that is because of longer language constructs,
but the code is as well-structured as the C code, and there are much
less, or more exactly, a minimal possible number of syntax rules.


In spite that the language is the most minimal for a programming
language, it has pointers, with both references and dereferences, and
therefore it enables to do everything which can be done with
C. Arguments can be passed to external functions, and both C library
and POSIX functions can be called from the actsl program, which can be
done without including any header files. Arguments cannot be passed
the same way to the functions written in actsl, and there are no local
variables, this is because local variables cannot be implemented in a
compiler without a symbol table. But it is possible to pass arguments
to the actsl functions, using the data stack.


The following is how to use the compiler in Linux, using gcc. It must
be possible to compile it using MinGW in Windows, and also by using
several other compilers, but one should find out how to do that with
these compilers. Copy the code of the compiler in C and actsl
language, from here to files which are named, say, actsl.c and
actsl.acl.


Compile
the stage 1 compiler:


gcc actsl.c -o actsl_


Then compile the stage 2 compiler, using the stage 1 compiler:


echo -e 'actsl.acl\nactsl.s\n' | ./actsl_
gcc actsl.s -o actsl


Now you have stage 2 compiler, which you can use in the following way:


echo -e 'something.acl\nsomething.s\n' | ./actsl
gcc something.s -o something


You can also write a simple shell script, makefile, or a small program
which uses system calls to run these command lines, to make compiling
easier, or to create self-running scripts in actsl, which might be
useful because the compiler is very fast, and the language is easy
to learn and remember, and enables to write scripts which can access
POSIX functions. In order to make sure that everything went properly,
you can compile the stage 3 compiler the same way. Then compare the
assembly outputs of the stage 1 and stage 2 compilers (the *.s files)
using diff. If these are identical, then the bootstrap was successful.


The error-checking which the compiler has, was enough for me to write
the code of the compiler in actsl, which didn't take more time than
writing the compiler in C. But this certainly needs some knowledge
about debugging the programs written in languages which give a lot of
freedom to the programmer, like C (e.g. how and what debug statements
to add), but it is good to use such debugging methods for programs
written in more strict programming languages as well.


As it is the custom, this description should also include the Hello
World program written in actsl language. Here it is:


int nul


fun main
                "Hello World!\n" arg call printf ref nul =
                0 return
endfun


It should be easy to port the compiler to another processor, I
couldn't make the porting easier though, as the compiler is so small
that it mostly consists of assembly instructions. The compiler should
fit well for using in small devices, as it is very small, and it can
also be possible to access hardware directly from actsl program, when
the ports are in the main address space, and this can be done with the
language word length for that particular processor.


The compiler can compile itself (bootstrap), and the outputs of the
stage 2 and stage 3 compilers are identical. The stage 2 compiler has
been tested using many different tests, including using all operators
and nested if and while statements.


[ Source code in the archive at ftp://ftp.iecc.com/pub/file/actsl.txt.gz -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.