Giter VIP home page Giter VIP logo

compilers-ntua's Introduction

Llama Compiler Project - NTUA

In this course (Compilers - NTUA) we were asked to create a compiler for a given language, llama, which is a functional programming language. The doc of this language can be found in greek here.

Byte Code Size # Lines of Code # Languages Used Top language Last commit

Authors

Llama Compiler Supported Features

  • Basic Data Types: integer, float, character, boolean
  • Reference Types and Arrays of one or more dimensions (cannot create Ref Array, or Array of Array)
  • User Defined Types (can be recursive too)
  • Library Functions
  • Type Inference
  • Function Closures
  • High Order Functions
  • Structural Equality
  • Optimizations

Library

To build the llama library, lib.a was used which was created using this Library. Most of the functions that the compiler supports comes from the lib.a file. Some other functions that were not implemented were created by us with the help of llvm.

Functions Llama Compiler supports

Input and Output

  • print_int : int -> unit
  • print_bool : bool -> unit
  • print_char : char -> unit
  • print_float : float -> unit
  • print_string : array of char -> unit
  • read_int : unit -> int
  • read_bool : unit -> bool
  • read_char : unit -> char
  • read_float : unit -> float
  • read_string : unit -> array of char
Math Functions
  • abs : int -> int
  • fabs : float -> float
  • sqrt : float -> float
  • sin : float -> float
  • cos : float -> float
  • tan : float -> float
  • atan : float -> float
  • exp : float -> float
  • ln : float -> float
  • pi : pi -> float

Increase/Decrease Functions

  • incr : int ref -> unit
  • decr : int ref -> unit

Convert Functions

  • float_of_int : int -> float
  • int_of_float : float -> int
  • round : float -> int
  • int_of_char : char -> int
  • char_of_int : int -> char

How to build

  • Clone the repository
  • Make sure you have nasm
  • ./libs.sh
  • We changed some synonyms using the change_syms file

Dependencies

  • Flex
  • Bison
  • LLVM
  • Clang - Used to create assembly code from ir and executable from assembly code)
  • C++11
  • Library - Requires nasm if you want to build the library yourself

Build

The llama compiler executable used the following versions of the above dependencies:

  • Flex - Version 2.6.4
  • Bison - Version 3.5.1
  • LLVM - Version 10.0.0
  • Clang - Version 10.0.0-4ubuntu

Installation

  • Clone the repository and move to src folder
  • make to create the llama compiler executable

Usage

The compiler can be used with any of the flags (in any combination) described below:

./llama [path/to/llamafile] -h    (* Prints all possible flag options *)
./llama [path/to/llamafile] -O    (* Optimization Flag *)
./llama [path/to/llamafile] -ast  (* Prints Abstract Syntax Tree *)
./llama [path/to/llamafile] -fv   (* Prints Free Variables each Function has *)
./llama [path/to/llamafile] -i    (* Prints Intermediate Code - LLVM IR *)
./llama [path/to/llamafile] -f    (* Prints Assembly Code *)
./llama [path/to/llamafile] -l    (* Enables __LINE__ Macro - Debugging Purposes *)
./llama [path/to/llamafile] -st   (* Prints complete SymbolTable (may have duplicates, because of scopes). *)

compilers-ntua's People

Contributors

christoshadjichristofi avatar panoszvg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.