Skip to content

Adi-Jayakumar/Language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

707 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language

An implementation of a C-style statically typed language that compiles down to a bytecode which is then interpreted.

Progress

  • Lex basic scripts
  • Parse arithmetic expressions
  • Lex and parse comparison expressions
  • Lex and parse variables
  • Parse statments
  • Type check statements and expressions
  • Compile things so far
  • Compile and run if-else statements
  • Compile and run functions
  • Compile and run native functions
  • Compile and run while loops
  • Use Main function as entry point to program
  • Implement arrays
  • Implement strings
  • Implement multidimensional arrays
  • Implement structs
  • Implement struct inheritance
  • Interfacing with C/C++ libraries
  • Serialise and de-serialise Functions in order to seperate compilation and execution
  • Optimiser
    • Evaluate constant expressions at compile time
    • Propagate constants through program
    • Keep performing optimisation passes until the AST does not change
    • Control flow optimisations
    • Peephole optimisations of bytecode
  • Multiple file programs
  • Verification
    • Lex and parse verification statements
    • Push precondition through bytecode for a subset of the language
    • Verify output

Long-term Goals

  • Improve garbage collector heuristics to minimise loss of program execution time

Known bugs TODO

  • Overloading of functions where the overloaded types are assignable to each other
    • MBE:
      function void Foo(int i){...}
      function void Foo(double d){...}
      
      Foo(3.14); // would have called the int version
                 // not the double version as it appears
                 // first and ints can be assigned to doubles 
  • Put parsed library functions into different container than normal functions
  • Implicit type conversions for elements of braced initialisers are not implemented
    • MBE:
      Array<int> arr = {3.141, 1.618, 1.414};
      // compiled as:
      // LOAD_DOUBLE 0 (value 3.141) should be --> LOAD_INT 0 (value 3)
      // LOAD_DOUBLE 1 (value 1.618) should be --> LOAD_INT 1 (value 1)
      // LOAD_DOUBLE 2 (value 1.414) should be --> LOAD_INT 2 (value 1)
      // etc.

Example Programs

Hello World!

function void Main()
{
    Print("Hello World!");
}

A simple program to calculate the Fibbonacci numbers

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

function void Main()
{
    Print(Fib(10));
}

Verification

Example 1

function int Square(int x)
(|x = x_0|)
{
    return x * x;
    (|x_0 * x_0|)
}

About

An implementation of a C-style statically typed language which compiles down to an interpreted bytecode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages