Skip to content

mateeeeeee/Ola

Repository files navigation

Ola

Ola is a toy object-oriented programming language with LLVM backend.

Dependencies

Features

  • classes
    • access modifiers: public, private
    • constructors
    • single inheritance: :
    • polymorphism using vtables: virtual, pure, final
    • this and super keywords
  • reference type: ref
  • automatic type deduction: auto
  • operators:
    • additive: +, -, +=, -=, ++, --
    • multiplicative: *, /, %, *=, /=, %=
    • relation: ==, !=, >, >=, <, <=
    • shift: >>, <<, >>=, <<=
    • bitwise: &, |, ^, ~, &=, |=, ^=
    • logic: &&, ||, !
  • control statements: if else, switch, goto, ?:
  • loop statements: for,foreach, while, do while, break, continue
  • enums
  • functions
    • overloading
    • attributes: inline, noinline, nomangling (equivalent to C++'s extern "C")
  • arrays
  • sizeof, length operators
  • alias
  • strings
  • floats
  • implicit casts
  • scopes
  • import statement
  • standard library

Todo

  • Custom backend
    • windows x86-64 (wip)

Structure

Ola consists of three parts:

  1. Ola library - standard library for Ola language implemented in C and built as static library to be used by the compiler. Currently it contains 5 files: olaio.h, olamath.h, olaassert.h, olastring.h, olamemory.h.
  2. Ola compiler - consists of the following parts:
    • Lexer - turns source file into a sequence of tokens
    • Import Processor - receives tokens from previous phase and processes import statements.
    • Parser - recursive descent parser that receives processed tokens and constructs Abstract Syntax Tree (AST) of a translation unit.
    • Sema - does semantic analysis of a translation unit.
    • LLVM Visitor - traverses AST and emits LLVM IR.
    • LLVM Optimizer - applies optimizations to the generated LLVM IR produced by LLVM Visitor based on the optimization level used.
  3. Ola tests
    • UnitTest framework for testing existing Ola features. Uses GoogleTest.

Usage

Command line options

  • -h,--help: Print this help message and exit
  • --astdump: Dump AST to output/log
  • --testdebug: Print debug information during tests
  • --test : used for running g-tests
  • --Od : No optimizations
  • --O0 : Same as --Od
  • --O1 : Optimize
  • --O2 : Optimize more
  • --O3 : Optimize even more
  • -i ... : Input files
  • -o : Output file
  • --directory : Directory of project files
  • --simple : input code in the form of a string

Samples

Currently to see the samples you can check the test folder: OlaTests/Tests/.