Typescript to C compiler
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
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
For loops does not work:
for (let entry of someArray) {
console.log(entry); // 1, "string", false
}
Comments does not work:
// this is a comment
/* this is also a comment */
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 are currently not supported
interface LabeledValue {
label: string;
value: number;
}
Exports and imports are currently not supported:
export * from "./ZipCodeValidator"; // exports class 'ZipCodeValidator
...
import { ZipCodeValidator } from "./ZipCodeValidator";
The output basically looks like this right now:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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.
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
.