Skip to content

maierfelix/hevia-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hevia Compiler

Swift-like strongly typed language that compiles to JavaScript.

Features

  • Custom operators
  • Type inference
  • Enums
  • Inout (pass by reference)
  • Classes

Todo:

  • Arrays
  • Structs
  • Bootstrapping
  • Operator overloading
  • Optimizations (Tree shaking, variable folding..)
  • Restrict inout possibilities ewww

Examples

Swap two variables with a custom operator

let a = 7
let b = 42

infix operator swap {
  associativity left
  precedence 120
  constructor(lhs: inout Int, rhs: inout Int) {
    const tmp = lhs
    lhs = rhs
    rhs = tmp
  }
}

a swap b;

Compare two vectors

class Vector {
  let x = 0
  let y = 0
  constructor(x:Int, y:Int) {
    this.x = x
    this.y = y
  }
}

infix operator equals {
  associativity left
  precedence 90
  constructor(left:Vector, right:Vector)->Boolean {
    return (
      left.x == right.x &&
      left.y == right.y
    )
  }
}

let vecA = Vector(2, 2)
let vecB = Vector(4, 4)

vecA equals vecB // false

Fibonacci

func fibonacci(n:Int) {
  if n == 0 || n == 1 {
    return n;
  }
  return fibonacci(n - 1) + fibonacci(n - 2);
}

About

Strongly typed language that compiles to JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published