Skip to content

54nd339/Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FunCompiler

FunCompiler is a statically typed, functional programming language which is a subset of C. Whitespace is ignored and there are no required expression delimiters. That's right: no semi-colons and no forced indent!

Dependencies

Build

  1. generate a build tree using CMake.
  cmake -B bld
  1. build an executable from the build tree.
  cmake --build bld

*** To build generated x86_64 ASM

GNU Binutils:

  as code.S -o code.o
  ld code.o -o code

GNU Compiler Collection

  gcc code.S -o code.exe

LLVM/Clang

  clang code.S -o code.exe --target=x86_64

To use external calls, link with appropriate libraries!

Language Reference

The language is statically typed. Variables must be declared and type annotated before use.

Whitespace is ignored and there are no required expression delimiters. That's right: no semi-colons and no forced indent!

Functions are first-class citizens.

A program in this language comes in the form of a file. The file may contain a series of expressions that will be executed in order, from top to bottom. There is no =main= function or other entry point; control flow starts at the very top of the file and makes it's way to the bottom of the file.

Let's take a look at a basic program:

fact : integer (n : integer) = integer (n : integer) {
  if n < 2 {
    1
  } else {
    n * fact(n - 1)
  }
}

fact(5)

This program will return 120 as a status code. The result of the last expression in the file is the return value. The same holds true for function bodies, and if/else bodies.

Variables in a local scope shadow variables in a parent scope, and may share the same symbolic name.

Releases

No releases published

Packages

No packages published