Skip to content

Complete Compiler and Virtual Machine for Alpha (hy340)

License

Notifications You must be signed in to change notification settings

PhivPap/AlphaLang_hy340

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alpha

Complete Compiler and Virtual Machine for Alpha

Made in 2020 with Labis Anargyrou for Languages & Compilers (hy340) at CSD

alpha2

alpha3

Linux Installation

The Alpha compiler requires GNU Bison & Flex:

sudo apt install bison
sudo apt install flex

Download & build Alpha:

git clone "https://github.com/PhivPap/AlphaLang_hy340.git"
cd AlphaLang_hy340
make

Usage

Compile an Alpha source file with:

./alphac <source.a> -o <bytecode.abc>

Execute an Alpha binary file with:

./alpha <bytecode.abc>

Alternatively, do both in one line:

./alphac <source.a> --run

Print the quads and human readable byte code with:

./alphac <source.a> --quads --instructions

In other news

While the language is sadly not described in this repo, you can try guessing with the provided testfiles. You can, however, know the following:

  • The Alpha compiler has:
    • compile-time expression evaluation
    • dead code elimination
    • temporary variable reuse optimization
    • minimal evaluation
  • The Alpha virtual machine has:
    • the following library functions:
      • print(...) - Variadic print function. Catches direct or indirect object self reference loops
      • input() - Returns line from console. Implicit convertion to other-than-string possible types.
      • objectmemberkeys(t) - Returns a table with the keys of t indexed from 0 and up.
      • objecttotalmembers(t) - Returns the number of entries in t.
      • objectcopy(t) - Returns a shalow copy of t.
      • totalarguments() - Returns argc of the calling function.
      • argument(i) - Returns the ith argument of the function from where this was called in. Can be used with totalarguments() to create an Alpha variadic function.
      • typeof(x) - Returns the type of x as a string.
      • strtonum(s) - Converts string s to num.
      • sqrt(n) -
      • cos(n) -
      • sin(n) -
    • table functors (double dot ".." operator)
    • tables which are implemented as expanding open addressing linearly probed hash tables
    • tables which receive any type as key and value
    • string concat (ikr damn)
    • perfectly hashed library functions (i.e. they are called in O(1))
    • complete garbage collection

About

Complete Compiler and Virtual Machine for Alpha (hy340)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published