typenative 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +42 -9
- package/bin/index.js +11 -5
- package/bin/transpiler.js +89 -13
- package/package.json +11 -8
- package/types/typenative.d.ts +1 -3
- package/bin/tcc/doc/tcc-doc.html +0 -2418
- package/bin/tcc/doc/tcc-win32.txt +0 -156
- package/bin/tcc/examples/dll.c +0 -12
- package/bin/tcc/examples/fib.c +0 -23
- package/bin/tcc/examples/hello_dll.c +0 -19
- package/bin/tcc/examples/hello_win.c +0 -163
- package/bin/tcc/examples/libtcc_test.c +0 -76
- package/bin/tcc/include/_mingw.h +0 -139
- package/bin/tcc/include/assert.h +0 -54
- package/bin/tcc/include/conio.h +0 -409
- package/bin/tcc/include/ctype.h +0 -281
- package/bin/tcc/include/dir.h +0 -31
- package/bin/tcc/include/direct.h +0 -68
- package/bin/tcc/include/dirent.h +0 -135
- package/bin/tcc/include/dos.h +0 -55
- package/bin/tcc/include/errno.h +0 -75
- package/bin/tcc/include/excpt.h +0 -123
- package/bin/tcc/include/fcntl.h +0 -52
- package/bin/tcc/include/fenv.h +0 -108
- package/bin/tcc/include/float.h +0 -57
- package/bin/tcc/include/inttypes.h +0 -297
- package/bin/tcc/include/io.h +0 -418
- package/bin/tcc/include/limits.h +0 -111
- package/bin/tcc/include/locale.h +0 -91
- package/bin/tcc/include/malloc.h +0 -175
- package/bin/tcc/include/math.h +0 -777
- package/bin/tcc/include/mem.h +0 -13
- package/bin/tcc/include/memory.h +0 -40
- package/bin/tcc/include/process.h +0 -176
- package/bin/tcc/include/sec_api/conio_s.h +0 -42
- package/bin/tcc/include/sec_api/crtdbg_s.h +0 -19
- package/bin/tcc/include/sec_api/io_s.h +0 -33
- package/bin/tcc/include/sec_api/mbstring_s.h +0 -52
- package/bin/tcc/include/sec_api/search_s.h +0 -25
- package/bin/tcc/include/sec_api/stdio_s.h +0 -145
- package/bin/tcc/include/sec_api/stdlib_s.h +0 -67
- package/bin/tcc/include/sec_api/stralign_s.h +0 -30
- package/bin/tcc/include/sec_api/string_s.h +0 -41
- package/bin/tcc/include/sec_api/sys/timeb_s.h +0 -34
- package/bin/tcc/include/sec_api/tchar_s.h +0 -266
- package/bin/tcc/include/sec_api/time_s.h +0 -61
- package/bin/tcc/include/sec_api/wchar_s.h +0 -128
- package/bin/tcc/include/setjmp.h +0 -160
- package/bin/tcc/include/share.h +0 -28
- package/bin/tcc/include/signal.h +0 -63
- package/bin/tcc/include/stdarg.h +0 -41
- package/bin/tcc/include/stdbool.h +0 -10
- package/bin/tcc/include/stddef.h +0 -28
- package/bin/tcc/include/stdint.h +0 -209
- package/bin/tcc/include/stdio.h +0 -429
- package/bin/tcc/include/stdlib.h +0 -580
- package/bin/tcc/include/string.h +0 -164
- package/bin/tcc/include/sys/fcntl.h +0 -13
- package/bin/tcc/include/sys/file.h +0 -14
- package/bin/tcc/include/sys/locking.h +0 -30
- package/bin/tcc/include/sys/stat.h +0 -290
- package/bin/tcc/include/sys/time.h +0 -69
- package/bin/tcc/include/sys/timeb.h +0 -133
- package/bin/tcc/include/sys/types.h +0 -118
- package/bin/tcc/include/sys/unistd.h +0 -14
- package/bin/tcc/include/sys/utime.h +0 -146
- package/bin/tcc/include/tcclib.h +0 -78
- package/bin/tcc/include/tchar.h +0 -1102
- package/bin/tcc/include/time.h +0 -287
- package/bin/tcc/include/vadefs.h +0 -11
- package/bin/tcc/include/values.h +0 -4
- package/bin/tcc/include/varargs.h +0 -12
- package/bin/tcc/include/wchar.h +0 -871
- package/bin/tcc/include/wctype.h +0 -172
- package/bin/tcc/include/winapi/basetsd.h +0 -149
- package/bin/tcc/include/winapi/basetyps.h +0 -85
- package/bin/tcc/include/winapi/guiddef.h +0 -151
- package/bin/tcc/include/winapi/intrin.h +0 -11
- package/bin/tcc/include/winapi/poppack.h +0 -8
- package/bin/tcc/include/winapi/pshpack1.h +0 -8
- package/bin/tcc/include/winapi/pshpack2.h +0 -8
- package/bin/tcc/include/winapi/pshpack4.h +0 -8
- package/bin/tcc/include/winapi/pshpack8.h +0 -8
- package/bin/tcc/include/winapi/reason.h +0 -80
- package/bin/tcc/include/winapi/specstrings.h +0 -7
- package/bin/tcc/include/winapi/stralign.h +0 -154
- package/bin/tcc/include/winapi/tvout.h +0 -79
- package/bin/tcc/include/winapi/winbase.h +0 -2951
- package/bin/tcc/include/winapi/wincon.h +0 -301
- package/bin/tcc/include/winapi/windef.h +0 -293
- package/bin/tcc/include/winapi/windows.h +0 -123
- package/bin/tcc/include/winapi/winerror.h +0 -3166
- package/bin/tcc/include/winapi/wingdi.h +0 -4080
- package/bin/tcc/include/winapi/winnetwk.h +0 -476
- package/bin/tcc/include/winapi/winnls.h +0 -765
- package/bin/tcc/include/winapi/winnt.h +0 -5770
- package/bin/tcc/include/winapi/winreg.h +0 -272
- package/bin/tcc/include/winapi/winuser.h +0 -5651
- package/bin/tcc/include/winapi/winver.h +0 -160
- package/bin/tcc/lib/gdi32.def +0 -337
- package/bin/tcc/lib/kernel32.def +0 -765
- package/bin/tcc/lib/libtcc1.a +0 -0
- package/bin/tcc/lib/msvcrt.def +0 -1399
- package/bin/tcc/lib/user32.def +0 -654
- package/bin/tcc/libtcc/libtcc.def +0 -38
- package/bin/tcc/libtcc/libtcc.h +0 -100
- package/bin/tcc/libtcc.dll +0 -0
- package/bin/tcc/tcc.exe +0 -0
- package/bin/tcc/tiny_impdef.exe +0 -0
- package/bin/tcc/tiny_libmaker.exe +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -2,18 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
Build native applications using Typescript.
|
|
4
4
|
|
|
5
|
+
## PreRequisites
|
|
6
|
+
|
|
7
|
+
- Go 1.21 or newer.
|
|
8
|
+
|
|
5
9
|
## Get Started
|
|
6
10
|
|
|
7
11
|
- Write a file `test.ts` with content `console.log('Hello World!');` or any other message
|
|
8
|
-
- Run `npx typenative --source test.ts`
|
|
9
|
-
-
|
|
12
|
+
- Run `npx typenative --source test.ts --script`
|
|
13
|
+
- See your message in the terminal
|
|
14
|
+
|
|
15
|
+
## Typescript Syntax Support
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
TypeNative currently supports a subset of TypeScript syntax elements that are transpiled to Go code:
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
| Feature | Supported | Notes |
|
|
20
|
+
|---------|:---------:|-------|
|
|
21
|
+
| **Basic Types** | | |
|
|
22
|
+
| number | ✅ | Transpiled to `float64` |
|
|
23
|
+
| boolean | ✅ | Transpiled to `bool` |
|
|
24
|
+
| string | ✅ | |
|
|
25
|
+
| null | ✅ | |
|
|
26
|
+
| any | ✅ | Used for type inference |
|
|
27
|
+
| **Variables** | | |
|
|
28
|
+
| Variable declarations | ✅ | `let` and `const` |
|
|
29
|
+
| **Operators** | | |
|
|
30
|
+
| Arithmetic operators | ✅ | `+`, `-`, etc. |
|
|
31
|
+
| Comparison operators | ✅ | `==`, `!=`, etc. |
|
|
32
|
+
| Logical operators | ✅ | `&&`, `\|\|` |
|
|
33
|
+
| Increment/Decrement | ✅ | `++`, `--` |
|
|
34
|
+
| **Control Flow** | | |
|
|
35
|
+
| For loops | ✅ | Standard `for` loops |
|
|
36
|
+
| **Data Structures** | | |
|
|
37
|
+
| Arrays | ✅ | Basic array operations |
|
|
38
|
+
| **Functions** | | |
|
|
39
|
+
| console.log | ✅ | Mapped to `fmt.Println` |
|
|
40
|
+
| **Unsupported Features** | | |
|
|
41
|
+
| Classes | ❌ | Not implemented |
|
|
42
|
+
| Interfaces | ❌ | Not implemented |
|
|
43
|
+
| Functions | ❌ | Custom function definitions not supported |
|
|
44
|
+
| Arrow Functions | ❌ | Not implemented |
|
|
45
|
+
| If/Else statements | ❌ | Not implemented |
|
|
46
|
+
| While/Do loops | ❌ | Not implemented |
|
|
47
|
+
| Switch statements | ❌ | Not implemented |
|
|
48
|
+
| Async/Await | ❌ | Not implemented |
|
|
49
|
+
| Modules/Imports | ❌ | Not implemented |
|
|
50
|
+
| Generics | ❌ | Not implemented |
|
|
15
51
|
|
|
16
|
-
|
|
17
|
-
- Database (using sqlite)
|
|
18
|
-
- Web Server (using libmicrohttpd)
|
|
19
|
-
- UI App (using webview)
|
|
52
|
+
TypeNative is currently in early development and new features are being added regularly.
|
package/bin/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import inquirer from 'inquirer';
|
|
|
3
3
|
import shell from 'shelljs';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import {
|
|
6
|
+
import { transpileToNative } from './transpiler.js';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
@@ -34,14 +34,20 @@ const __dirname = path.dirname(__filename);
|
|
|
34
34
|
const tsCode = answers.tsCode
|
|
35
35
|
? answers.tsCode
|
|
36
36
|
: await fs.readFile(target ?? answers.path, { encoding: 'utf-8' });
|
|
37
|
-
const
|
|
37
|
+
const nativeCode = transpileToNative(tsCode);
|
|
38
38
|
await fs.ensureDir('dist');
|
|
39
|
-
await fs.writeFile('dist/code.
|
|
40
|
-
shell.exec(
|
|
39
|
+
await fs.writeFile('dist/code.go', nativeCode, { encoding: 'utf-8' });
|
|
40
|
+
shell.exec('go build -o dist/native.exe dist/code.go');
|
|
41
|
+
// await fs.remove('dist/code.go');
|
|
41
42
|
if (answers.output) {
|
|
42
43
|
await fs.copy('dist/native.exe', answers.output, { overwrite: true });
|
|
44
|
+
await fs.remove('dist/native.exe');
|
|
43
45
|
}
|
|
44
|
-
if (
|
|
46
|
+
if (scriptMode) {
|
|
47
|
+
shell.exec(path.join('dist', 'native.exe'));
|
|
48
|
+
await fs.remove('dist/native.exe');
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
45
51
|
console.log('DONE');
|
|
46
52
|
}
|
|
47
53
|
})();
|
package/bin/transpiler.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
|
|
2
|
+
let TypeCheker;
|
|
3
|
+
export function transpileToNative(code) {
|
|
3
4
|
const sourceFile = ts.createSourceFile('main.ts', code, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS);
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
TypeCheker = ts.createProgram(['main.ts'], {}).getTypeChecker();
|
|
6
|
+
return `package main
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
import "fmt"
|
|
9
|
+
|
|
10
|
+
func main() {
|
|
8
11
|
${visit(sourceFile)}
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
+
}`;
|
|
12
13
|
}
|
|
13
|
-
export function visit(node) {
|
|
14
|
+
export function visit(node, inline = false) {
|
|
14
15
|
let code = '';
|
|
15
16
|
if (ts.isIdentifier(node)) {
|
|
16
17
|
return node.text;
|
|
@@ -18,18 +19,93 @@ export function visit(node) {
|
|
|
18
19
|
else if (ts.isStringLiteral(node)) {
|
|
19
20
|
return `"${node.text}"`;
|
|
20
21
|
}
|
|
22
|
+
else if (ts.isNumericLiteral(node)) {
|
|
23
|
+
return `float64(${node.text})`;
|
|
24
|
+
}
|
|
25
|
+
else if (ts.isToken(node) && node.kind === ts.SyntaxKind.TrueKeyword) {
|
|
26
|
+
return `true`;
|
|
27
|
+
}
|
|
28
|
+
else if (ts.isToken(node) && node.kind === ts.SyntaxKind.FalseKeyword) {
|
|
29
|
+
return `false`;
|
|
30
|
+
}
|
|
31
|
+
else if (ts.isBlock(node)) {
|
|
32
|
+
return `{\n\t\t${node.statements.map((n) => visit(n)).join('\t')}}\n\t`;
|
|
33
|
+
}
|
|
21
34
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
22
35
|
return `${visit(node.expression)}.${visit(node.name)}`;
|
|
23
36
|
}
|
|
37
|
+
else if (ts.isVariableDeclaration(node)) {
|
|
38
|
+
const type = getType(node.type);
|
|
39
|
+
const initializer = node.initializer ? `= ${visit(node.initializer)}` : '';
|
|
40
|
+
return `${type === ':' ? '' : 'var'} ${visit(node.name)} ${type}${type === ':' ? '' : ' '}${initializer}`;
|
|
41
|
+
}
|
|
24
42
|
else if (ts.isCallExpression(node)) {
|
|
25
43
|
const expr = visit(node.expression);
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
return `${getFunction(expr)}(${node.arguments.map((a) => visit(a)).join(',')})`;
|
|
45
|
+
}
|
|
46
|
+
else if (ts.isPrefixUnaryExpression(node)) {
|
|
47
|
+
return `${getOperatorText(node.operator)}${visit(node.operand)}`;
|
|
48
|
+
}
|
|
49
|
+
else if (ts.isPostfixUnaryExpression(node)) {
|
|
50
|
+
return `${visit(node.operand, true)}${getOperatorText(node.operator)}`;
|
|
51
|
+
}
|
|
52
|
+
else if (ts.isBinaryExpression(node)) {
|
|
53
|
+
return `${visit(node.left)} ${node.operatorToken.getText()} ${visit(node.right)}`;
|
|
54
|
+
}
|
|
55
|
+
else if (ts.isParenthesizedExpression(node)) {
|
|
56
|
+
return `(${visit(node.expression)})`;
|
|
57
|
+
}
|
|
58
|
+
else if (ts.isVariableDeclarationList(node)) {
|
|
59
|
+
return (node.declarations.map((n) => visit(n)).join(inline ? ';' : ';\n\t') + (inline ? ';' : ';\n\t'));
|
|
28
60
|
}
|
|
29
61
|
else if (ts.isExpressionStatement(node)) {
|
|
30
|
-
return visit(node.expression) + ';\n';
|
|
62
|
+
return visit(node.expression) + (inline ? ';' : ';\n\t');
|
|
63
|
+
}
|
|
64
|
+
else if (ts.isForStatement(node)) {
|
|
65
|
+
return `for${visit(node.initializer, true)} ${visit(node.condition, true)}; ${visit(node.incrementor, true)}${visit(node.statement)}`;
|
|
31
66
|
}
|
|
32
|
-
|
|
33
|
-
ts.forEachChild(node, (subNode) =>
|
|
67
|
+
console.log(ts.SyntaxKind[node.kind], node.getText());
|
|
68
|
+
ts.forEachChild(node, (subNode) => {
|
|
69
|
+
code += visit(subNode);
|
|
70
|
+
return null;
|
|
71
|
+
});
|
|
34
72
|
return code;
|
|
35
73
|
}
|
|
74
|
+
function getType(typeNode) {
|
|
75
|
+
const type = TypeCheker.getTypeFromTypeNode(typeNode);
|
|
76
|
+
const typeName = TypeCheker.typeToString(type);
|
|
77
|
+
switch (typeName) {
|
|
78
|
+
case 'number':
|
|
79
|
+
return 'float64';
|
|
80
|
+
case 'boolean':
|
|
81
|
+
return 'bool';
|
|
82
|
+
case 'any':
|
|
83
|
+
return ':';
|
|
84
|
+
default:
|
|
85
|
+
return typeName;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function getFunction(expr) {
|
|
89
|
+
switch (expr) {
|
|
90
|
+
case 'console.log':
|
|
91
|
+
return 'fmt.Println';
|
|
92
|
+
default:
|
|
93
|
+
return expr;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function getOperatorText(operator) {
|
|
97
|
+
switch (operator) {
|
|
98
|
+
case ts.SyntaxKind.PlusToken:
|
|
99
|
+
return '+';
|
|
100
|
+
case ts.SyntaxKind.MinusToken:
|
|
101
|
+
return '-';
|
|
102
|
+
case ts.SyntaxKind.TildeToken:
|
|
103
|
+
return '~';
|
|
104
|
+
case ts.SyntaxKind.ExclamationToken:
|
|
105
|
+
return '!';
|
|
106
|
+
case ts.SyntaxKind.PlusPlusToken:
|
|
107
|
+
return '++';
|
|
108
|
+
case ts.SyntaxKind.MinusMinusToken:
|
|
109
|
+
return '--';
|
|
110
|
+
}
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typenative",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Build native applications using Typescript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"start:compiler": "node ./bin/index",
|
|
13
13
|
"start:script": "node ./bin/index --script",
|
|
14
14
|
"test": "node ./bin/index --source test/test.ts --script",
|
|
15
|
+
"test2": "node ./bin/index --source test/test2.ts --script",
|
|
16
|
+
"test3": "node ./bin/index --source test/test3.ts --script",
|
|
17
|
+
"test4": "node ./bin/index --source test/test4.ts --script",
|
|
15
18
|
"release": "npm publish"
|
|
16
19
|
},
|
|
17
20
|
"repository": {
|
|
@@ -26,14 +29,14 @@
|
|
|
26
29
|
"homepage": "https://github.com/danisss9/typenative#readme",
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"@types/fs-extra": "^11.0.4",
|
|
29
|
-
"@types/inquirer": "^9.0.
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"@types/shelljs": "^0.8.
|
|
32
|
+
"@types/inquirer": "^9.0.8",
|
|
33
|
+
"@types/node": "^22.15.21",
|
|
34
|
+
"@types/shelljs": "^0.8.16"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"fs-extra": "^11.
|
|
35
|
-
"inquirer": "^
|
|
36
|
-
"shelljs": "^0.
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"fs-extra": "^11.3.0",
|
|
38
|
+
"inquirer": "^12.6.1",
|
|
39
|
+
"shelljs": "^0.10.0",
|
|
40
|
+
"typescript": "^5.8.3"
|
|
38
41
|
}
|
|
39
42
|
}
|
package/types/typenative.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface Array<T> {
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns a string representation of an array.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
push(element: T): void;
|
|
10
10
|
|
|
11
11
|
[n: number]: T;
|
|
12
12
|
}
|
|
@@ -15,5 +15,3 @@ interface Console {
|
|
|
15
15
|
log(...data: any[]): void;
|
|
16
16
|
}
|
|
17
17
|
declare var console: Console;
|
|
18
|
-
|
|
19
|
-
declare var getchar: () => void;
|