Table of Contents

MI-NUR Runtime systems - NULOG - Non-Useful Language Of Gods

Team members:

The goal of the work

The goals of our work are:

  1. design programming language,
  2. design compiler to a bytecode,
  3. design stack-based bytecode virtual machine.

NULOG - language

The programming language's syntax is defined by a grammar.

We have used the ANTLRWorks(http://www.antlr.org/works/index.html) software for creating a grammar for our language and for generating the AST. This tool is able to create a Lexer and Parser classes in your preferred language based on the specified grammar. As our favourite programming language is C#, we have used the CSharp3 extension for this tool.

Our language supports basic elements needed for implementing algorithmic problems such as the Knapsack problem.

That is:

List of reserved key words

Compiler

Our compiler consists of three base parts.

Class loader

Class loader scans the work directory for files with .nulog extension and for classes inside of those files. It checks whether there is any Main function in all the classes and whether there are no more than one Main functions in each one of the classes.

It also gathers vital information about each class:

ScopeTracker

Instances of this object represent a scope in the program. We have three levels of scope in our language. Those are global scope, class scope and function scope. Each scope tracks declared functions, local variables and objects in order to provide the compiler information needed to perform some compile-time checks such as:

The ScopeTracker also stores the compiled bytecode.

Compiler itself

The compiler first runs the ClassLoader in order to obtain information about classes that are going to be compiled. Than it runs Lexer for tokenization of the input and Parser for creating the Abstract Syntaxt Tree. When the AST is created without errors, the compiler starts processing the tree for each class found.

The result of the compiler run is a list of bytecode instructions, that can be processed by the NULOG Virtual Machine.

Exceptions

The compiler throws two types of exception:

Virtual machine

Stack

        ___________ __________
        |   PBP   |1
        |   SP    |1 HEAD
        |   FS    |1__      FRAME
        |  LOCALS |?  
        |  STACK  |?  
        ----------------------
        |         |
            ... 

Heap

        ______________ __________
        |   MARKER   |1
        |   TYPE     |1  HEAD
        |   LENGTH   |4   10   OBJECT
        |   CLASS    |4__  
        |   Data     |?   
        -------------------------
        |            |
             ...

Integers caching

Class table

Function lookup

Object table

Integer caching

Garbage collector

Native functions

Literature

Source code

Use of the program

run.bat

NULOGVirtualMachine.exe FinalKnapsack\ Main -args FinalKnapsack\knap_15.in knap_15.out
NULOGVirtualMachine.exe

List of all parameters:

Mandatory:
ClassPath - path to directory with classes to run.
MainClass - Name of the class containing the entrypoint function Main.

Optional:
-hs iteger value in range from 1 to 2147483647  - The size of the heap in MB.
-ss iteger value in range from 1 to 2147483647 - The size of the stack size in kB.
-ics iteger value in range from 1 to 2147483647 - The maximum size of integers to cache.
-args Arguments to be passed to the program. This switch must be last of the parameters!

Example using only mandatory parameters: NULOGVirtualMachine.exe C:\MyClasses\ MyMainClass

Example using optional parameters : NULOGVirtualMachine.exe C:\MyClasses\ MyMainClass -hs 100000 -ss 10000

Example pasing arguments to the program: NULOGVirtualMachine.exe C:\MyClasses\ MyMainClass -args myParam1 myParam2 -mySwitch value