Coder Social home page Coder Social logo

y's Introduction

Deprecated!

This version of the y compiler has been superseded by a new version.

Y Language Compiler

Y is a C like language which compiles into Yolol. Y is intended to be a completely zero cost abstraction over Yolol, suitable as a total replacement of the underlying language.

Example

Types

type struct coordinate {
    x: number,
    y: number,
    z: number
}

type enum<string> color {
    r("red"),
    g("green"),
    b("blue")
}

type range<number> negative => negative < 0;

Structs are a collection of fields which can be accessed together. An enum is a set of values taken from another type, in the example above the color enum is a subset of the string type and the string "green" can be expressed as color.g in code. Ranges express a set of values which are valid instances of this type as an expression, in the example above the negative range accepts all numbers which are less than zero.

Procedures And Macros

def proc add(a: number, b: number) {
    return a + b;
}

def macro add(a: number, b: number)
{
    return a + b
}

Procedures are compiled with a goto which jumps into the procedure and then jumps back to the call site, this is slow but keeps code size small for procedures which are used several times. Conversely macros are copied in line to where they are used, this means that a macro used multiple times can bloat code size but is faster to execute (no 400ms delay caused by the 2 goto statements). All arguments are passed by reference.

Importing Files

import "a.y";
import "b.y" in namespace;

Files of Y code can be imported into another file of Y code. This parses the imported file and makes all the items in it (types, procedures, macros etc) available for use. Files can additionally be imported in a namespace, which prepends the namespace name to the name of the imported item. For example if Add is defined in b.y it would be named namespace:add in this file.

Main Block

main {
    line(add_loop) {
        :output = add(:left, :right);
        goto add_loop;
    }
}

A `Y` file is compiled to a single Yolol chip script. The `main` block defines the entry point of the code. It is optional, if not included compilation will result in an empty output.

y's People

Contributors

martindevans avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  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.