1.0.11-beta • Published 7 years ago

turboscript v1.0.11-beta

Weekly downloads
8
License
MIT
Repository
github
Last release
7 years ago

TurboScript

Build Status AppVeyor Stories in Ready Greenkeeper badge

Super charged JavaScript for parallel programming and WebAssembly

Throughput Graph

TurboScript is an experimental programming language for parallel programming for web which compiles to JavaScript (asm.js) and WebAssembly (targeting post-MVP). The syntax is similar to TypeScript (Hardly trying to fill the gaps) and the compiler is open source and written in TypeScript. TurboScript has zero dependencies.

This is still an experiment and isn't intended for real use yet but we are working towards an MVP release. Please feel free to open issues if it stop working or need a new feature.

Try online

Install

npm install -g turboscript

Types

TypeNative typeDescription
int8i32An 8-bit signed integer.
uint8i32An 8-bit unsigned integer.
int16i32A 16-bit signed integer.
uint16i32A 16-bit unsigned integer.
int32i32A 32-bit signed integer.
uint32i32A 32-bit unsigned integer.
int64i64A 64-bit signed integer.
uint64i64A 64-bit unsigned integer.
booleani32A 1-bit unsigned integer.
float32f32A 32-bit floating point number.
float64f64A 64-bit floating point number.
voidnoneNo return type.
stringi32A utf-8 encoded textual data type.
Array<T>i32A generic array data type.

Syntax

variables

var myGlobal:int32 = 1;
let evaluatedVar:int32 = myGlobal + 1;
// let is same as var.

Number Literals

let integer:int32 = 1234;
let integer64bit:int64 = 1234;
let floatingPoint:float32 = 1.234f;
let floatingPoint64bit:float64 = 1.234; // default floating point number is 64 bit

// You can also omit type since compiler infer type from the literal
let integer = 1234; // default integer is 32 bit, use type :int64 for 64 bit integer 
let floatingPoint = 1.234f;
let floatingPoint64bit = 1.234;

function

// add.tbs
export function add(a:int32, b:int32):int32 {
    return a + b;
}

class

// vector3D.tbs
export class Vector3D {
    x:float32;
    y:float32;
    z:float32;

    constructor(x:float32, y:float32, z:float32){
        this.x = x;
        this.y = y;
        this.z = z;
    }
}

Generic

class Foo<T> {
    value:T;
    constructor(value:T){
        this.value = value;
    }
    getValue():T {
        return this.value;
    }
}

export function testI32(value:int32):int32 {
    let instance = new Foo<int32>(value);
    return instance.getValue();
}

export function testI64(value:int32):int32 {
    let value2 = value as int64;
    let instance = new Foo<int64>(value2);
    return instance.getValue() as int32;
}

export function testF32(value:float32):float32 {
    let instance = new Foo<float32>(value);
    return instance.getValue();
}

export function testF64(value:float64):float64 {
    let instance = new Foo<float64>(value);
    return instance.getValue();
}

Operator overload

class Vector3D {
    x:float32;
    y:float32;
    z:float32;

    constructor(x:float32, y:float32, z:float32){
        this.x = x;
        this.y = y;
        this.z = z;
    }

    operator + (other:Vector3D):Vector3D {
        return new Vector3D(this.x + other.x, this.y + other.y, this.z + other.z);
    }

    operator - (other:Vector3D):Vector3D {
        return new Vector3D(this.x - other.x, this.y - other.y, this.z - other.z);
    }
}
export function test():boolean {
    let a = new Vector3D(1.0f,1.0f,1.0f);
    let b = new Vector3D(1.0f,1.0f,1.0f);
    let c = a + b;
    return c.x == 2.0f && c.y == 2.0f && c.z == 2.0f;
}

Array

// f64-array.tbs
var a: Array<float64> = null;

export function test(num:int32): Array<float64> {
    a = new Array<float64>(num);
    let i:int32 = 0;
    while (i < num) {
        a[i] = 0.0;
        i = i + 1;
    }
    return a;
}

export function getArrayByteLength(value:Array<float64>):int32 {
    return value.bytesLength;
}
export function getArrayElementSize(value:Array<float64>):int32 {
    return value.elementSize;
}

export function getArray(): Array<float64> {
    return a;
}
export function getData(index:int32):float64 {
    return a[index];
}
export function setData(index:int32, value:float64):void {
    a[index] = value;
}

Compile to wasm

tc add.tbs --wasm --out add.wasm

Join Slack

You need an invitation to join slack. open a ticket with your email address. I will make it happen.

Roadmap

  • Parallel JavaScript
  • WebAssembly Emitter
  • Basic malloc and free
  • ASM.JS Emitter
  • Import external functions with namespace
  • Array Data Type
  • Parallel WebAssembly (post-MVP)

Wiki

Documentations can be found at wiki (under construction :construction:)

Useful links

Credit

Lexical analysis, Parsing, Checking codes are borrowed from Evan Wallace's thinscript

Now enjoy - Wow! this snail is fast

1.0.11-beta

7 years ago

1.0.9-beta

7 years ago

1.0.8-beta

7 years ago

1.0.7-beta

7 years ago

1.0.6-beta

7 years ago

1.0.5-beta

7 years ago

1.0.4-beta

7 years ago

1.0.3-beta

7 years ago

1.0.2-beta

7 years ago

1.0.1-beta

7 years ago

1.0.0-beta

7 years ago

1.1.2-alpha

7 years ago

1.1.1-alpha

7 years ago

1.1.0-alpha

7 years ago

1.0.9-alpha

7 years ago

1.0.8-alpha

7 years ago

1.0.7-alpha

7 years ago

1.0.6-alpha

7 years ago

1.0.5-alpha

7 years ago

1.0.4-alpha

7 years ago

1.0.3-alpha

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago