Coder Social home page Coder Social logo

dawn's Introduction

Dawn

Dawn is a compiled language with major similarities to ECMAScript.

Syntax

Dawn alleviates type-errors with a complicated and an in-depth typing system.

import { fraction, string } from "std::types";
import { print, scan } from "std::io";
import { toFrac } from "std::string";

class Point {
  x: fraction;
  y: fraction;
  constructor(point: string) {
    // check if point is (a/b, c/d)
    let arr = point.replace(['(', ')'], '').split(',');
    // array size is fixed
    if (arr.length() == 2) {
      // zero-cost spreading
      print("({s}, {s})", arr[0], arr[1]);
      // fraction-ize
      this.x = toFrac(arr[0]);
      this.y = toFrac(arr[1]);
    };
  }
};

Dawn also has support for structs:

struct MyDawn {
  a: int;
  b: string;
};

Pointers:

const arr = &myVar;
// dereference
*arr;

Node.js-style STL:

import { readFile, FileData } from "std::fs"; // with fs-extra features, too.
import { print } from "std::io";
import { Error } from "std::error";
readFile("./someFile.js", (err: Error, dat: FileData) => {
  if (err) {
    yeet err; // or: "throw err"
  } else {
    print("{}", dat.toString());
  }
})

Compilation Passes

Passes are different steps which modify the source code. Dawn follows an expand-resolve scheme. This means that Dawn will first desugar your source code and then compile it.

Pass 1: Explicit Typing

Dawn will explicitly type all your source code. Example

const x = 10;

Becomes:

const x: int = 10;

Pass 2: Glorious Anonymous Functions (arrow-functions)

const x = (a: int, b: int) => {
  return a*b;
}
x(2,10);

Becomes:

// namespace
const x = {
  function call(a: int, b: int) {
    return a*b;
  };
};
x::call(2,10);

Pass 3: Code-splitting

Self-explanatory. Imports code and tree-shakes it.

Pass 4: Anonymous Function Resolution

When passing an anonymous function as an argument, it needs to be resolved.

Pass 5: LLVM-IR Gen

Generate LLVM-IR.

Pass 6: Optimization

Optimize the IR code.

Pass 7: Compilation

Compile the code

dawn's People

Contributors

furrybrackets avatar

Watchers

 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.