Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.

sebbekarlsson/tscc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tscc

Typescript to C compiler

Support

The compiler currently supports:

  • Function definitions
  • Data types (string, number, null, void, undefined)
  • Arrays (sort of)
  • Function calls
  • If
  • Else
  • While loops
  • Static string concatenation ("hello " + "world")
  • Automatically detect requirements and inject #include tags
  • == - comparison
  • != - comparison
  • < - comparison
  • > - comparison
  • Null values
  • Undefined values
  • Classes with methods
  • Classes with member variables
  • console.log

Installation & Usage

To install tscc, first simply compile it:

    make

Then you can move it to /usr/local/bin:

    sudo mv ./tscc.out /usr/local/bin/tscc

Now you can use it like this:

    tscc <filename>.ts

Known issues

For loops

For loops does not work:

    for (let entry of someArray) {
        console.log(entry); // 1, "string", false
    }

Comments

Comments does not work:

    // this is a comment

    /* this is also a comment */

Floating point numbers

Floating point numbers are malformed when compiled, the following code:

    let age:number = 33.5;

Becomes this when compiled (int):

    int age = 33.5f;

Interfaces

Interfaces are currently not supported

    interface LabeledValue {
        label: string;
        value: number;
    }

Exports & Imports

Exports and imports are currently not supported:

    export * from "./ZipCodeValidator";  // exports class 'ZipCodeValidator

    ...

    import { ZipCodeValidator } from "./ZipCodeValidator";

Too many semi colons

The output basically looks like this right now:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Solutions

If you find any solution for any of these issues, feel free to create a pull-request... Also if you find any other issues, please report them.

Notes

Machine code

The compiler does not turn the typescript input to machine code, you should use a C compiler to do that. I would suggest using gcc.