Skip to content

isaacev/cthulhu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cthulhu language

A strongly-typed language that compiles into PHP

Installation

Using a pre-built phar

  1. Download the cthulhu.phar executable from the latest release
  2. chmod 755 cthulhu.phar
  3. mv cthulhu.phar /usr/local/bin/cthulhu

Building from source

  1. Clone this repository
  2. In the repository root folder, run composer dump-autoload
  3. Access the CLI by running php cli/cli.php. Or make the program available system-wide by something like ln -s `pwd`/bin/cthulhu.php /usr/local/bin/cthulhu

Example

A simple program looks like this:

use ::Io;

#[entry]
fn main() -> () {
  Io::println("hello world");
}

And compiles to the following PHP:

<?php

namespace Hello {
  function main() {
    print("hello world\n");
  }
}

namespace {
  \Hello\main();
}

Name capitalization

  • Modules and types use PascalCase
  • Function and variable names use camelCase

These capitalization rules are enforced by the language.

TODO

  • Basic parsing
  • Variable name resolution across module boundaries
  • Generate and output PHP code from IR
  • Pretty error reporting
  • PHP AST rewriter library
  • Basic function inlining optimization
  • Basic dead-code elimination optimization
  • Constant folding optimization
  • Type name resolution
  • Generic functions
  • Pretty multi-line error snippets
  • Module dependency linearized and cycle detection
  • The Maybe type
  • The List type
  • Floating point numbers
  • Pattern matching
  • Recursion
  • Tail call optimization
  • Closures
  • Extensible records
  • Inference of record constraints