thyscript 1.0.0 → 2.0.0
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/DOKUMEN.md +525 -0
- package/README.md +204 -0
- package/bin/thy-node.js +1 -1
- package/bin/thy.js +32 -21
- package/dist/calculator.thy.js +624 -0
- package/dist/thy-build.json +7 -0
- package/examples/calculator.thy +1 -0
- package/package.json +2 -2
- package/public/home.html +19 -0
- package/src/compiler/CodeGenerator.js +44 -6
- package/src/index.js +1 -1
- package/src/parser/Parser.js +41 -3
- package/src/server/ControlPanel.js +2 -2
- package/src/server/ServerEngine.js +13 -12
- package/tests/run-tests.js +40 -0
- package/tests/test_v2_features.thy +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# ⚡ ThyScript v2.0.0
|
|
2
|
+
|
|
3
|
+
> **A blazing-fast, next-generation programming language built on Node.js.**
|
|
4
|
+
> Engineered for high-speed machine learning, physics simulations, complex algorithms, and modern full-stack web architectures.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/thyscript)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🌟 Why ThyScript?
|
|
13
|
+
|
|
14
|
+
- ⚡ **12x Faster Math & Numeric Operations**: Built-in JIT compilation with TypedArrays (`Float64Array`, `Int32Array`) and V8 TurboFan inline cache triggers.
|
|
15
|
+
- 📦 **Seamless npm Library Integration**: Import any npm library directly with `import "library_name"` or `import lib from "library_name"`.
|
|
16
|
+
- 🌐 **First-Class Web & Full-Stack Servers**: Built-in Express and native HTTP servers via `server(port): ... end()` and `route get "/": ... end()`. No boilerplate needed!
|
|
17
|
+
- 🎨 **External & Inline HTML**: Serve external HTML templates with `classHtml(Page) from "public/home.html"` or use `res.renderHtml("page.html", data)` with dynamic interpolation.
|
|
18
|
+
- 🖥️ **Live Web Control Panel**: Turn your host computer into a remote ThyScript server with `thy panel`. Run scripts in memory with **zero compilation to disk**, accessible from any device on your local WiFi/LAN network.
|
|
19
|
+
- 🛡️ **Built-in Security & Database Engines**: Native JWT, bcrypt/scrypt hashing, AES-256 encryption, XSS sanitization, SQLi detection, and multi-database support (MySQL, PostgreSQL, MongoDB, Redis, SQLite).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
Install globally via npm:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g thyscript
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or install locally in your project:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install thyscript
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Once installed, you have access to three universal CLI commands:
|
|
38
|
+
- `thy` — Universal CLI tool
|
|
39
|
+
- `thys` — Control Panel and server launcher
|
|
40
|
+
- `thy-node` — High-speed direct script runner with ASCII dashboard
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 🚀 Quick Start
|
|
45
|
+
|
|
46
|
+
### 1. Create a script (`hello.thy`)
|
|
47
|
+
|
|
48
|
+
```thy
|
|
49
|
+
// hello.thy - Welcome to ThyScript v2
|
|
50
|
+
import "chalk"
|
|
51
|
+
|
|
52
|
+
const table name = "ThyScript v2"
|
|
53
|
+
print(chalk.cyan("⚡ Hello from " + name + "!"))
|
|
54
|
+
|
|
55
|
+
// Fast numeric calculation
|
|
56
|
+
const table result = calculate((100 + 37) * 2 - 10)
|
|
57
|
+
print("Calculation result: " + result)
|
|
58
|
+
|
|
59
|
+
// OOP Class Example
|
|
60
|
+
public class(Player):
|
|
61
|
+
const table username = "Guest"
|
|
62
|
+
const table score = 0
|
|
63
|
+
|
|
64
|
+
func levelUp(pts):
|
|
65
|
+
add pts in score
|
|
66
|
+
print(username + " earned " + pts + " points! Total: " + score)
|
|
67
|
+
end()
|
|
68
|
+
end()
|
|
69
|
+
|
|
70
|
+
const table p1 = new Player()
|
|
71
|
+
change(p1.username to("Alice"))
|
|
72
|
+
p1.levelUp(100)
|
|
73
|
+
p1.levelUp(50)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Run the script
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
thy run hello.thy
|
|
80
|
+
# or directly:
|
|
81
|
+
thy-node hello.thy
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 🌐 Web Server & REST API Example
|
|
87
|
+
|
|
88
|
+
ThyScript makes backend web development effortless:
|
|
89
|
+
|
|
90
|
+
```thy
|
|
91
|
+
// server.thy
|
|
92
|
+
import "chalk"
|
|
93
|
+
|
|
94
|
+
// External HTML page for the home route
|
|
95
|
+
classHtml(Home) from "public/home.html"
|
|
96
|
+
|
|
97
|
+
// Start server on port 5000 (accessible across LAN on 0.0.0.0)
|
|
98
|
+
server(5000):
|
|
99
|
+
print(chalk.green("🚀 Server running on port 5000"))
|
|
100
|
+
end()
|
|
101
|
+
|
|
102
|
+
const table items = []
|
|
103
|
+
|
|
104
|
+
// REST Endpoints
|
|
105
|
+
route get "/api/items":
|
|
106
|
+
res.json({ success: true, count: items.length, items: items })
|
|
107
|
+
end()
|
|
108
|
+
|
|
109
|
+
route post "/api/items":
|
|
110
|
+
const table newItem = {
|
|
111
|
+
id: items.length + 1,
|
|
112
|
+
name: req.body.name || "Untitled Item",
|
|
113
|
+
createdAt: Date.now()
|
|
114
|
+
}
|
|
115
|
+
add newItem in items
|
|
116
|
+
res.json({ success: true, item: newItem })
|
|
117
|
+
end()
|
|
118
|
+
|
|
119
|
+
// Dynamic external HTML rendering with template interpolation
|
|
120
|
+
route get "/dashboard":
|
|
121
|
+
res.renderHtml("public/home.html", {
|
|
122
|
+
title: "ThyScript Live Dashboard",
|
|
123
|
+
user: "Admin"
|
|
124
|
+
})
|
|
125
|
+
end()
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Run the server:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
thy serve server.thy --port 5000
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 🖥️ ThyScript Control Panel (Remote Server)
|
|
137
|
+
|
|
138
|
+
Transform your main PC/laptop into a live, remote-accessible ThyScript server without writing a single line of server setup:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
thy panel --port 7777
|
|
142
|
+
# or
|
|
143
|
+
thys panel
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Features:
|
|
147
|
+
- **Zero-Compile In-Memory Runner**: Write ThyScript code in the web browser and click **RUN** — it executes instantly in host memory without creating `.js` files on disk.
|
|
148
|
+
- **Remote Network Access**: Automatically detects your WiFi/LAN IP addresses (`http://192.168.1.x:7777`) so you can access the IDE from your smartphone, tablet, or secondary laptop.
|
|
149
|
+
- **Live Hardware Monitor**: Real-time CPU usage, RAM utilization, V8 Heap metrics, and network adapters.
|
|
150
|
+
- **File Explorer**: Browse, view, edit, and save `.thy` files directly on the host computer.
|
|
151
|
+
- **Terminal Logs**: Bidirectional live console output capturing stdout, stderr, execution timers, and memory deltas.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 📦 What's New in v2.0.0
|
|
156
|
+
|
|
157
|
+
1. **Direct npm Library Imports**:
|
|
158
|
+
```thy
|
|
159
|
+
import "chalk"
|
|
160
|
+
import "lodash" as _
|
|
161
|
+
import "axios"
|
|
162
|
+
import express from "express"
|
|
163
|
+
import { readFileSync } from "fs"
|
|
164
|
+
```
|
|
165
|
+
2. **External HTML Support**:
|
|
166
|
+
- `classHtml(Name) from "path/to/file.html"`
|
|
167
|
+
- `classHtml(Name): "path/to/file.html" end()`
|
|
168
|
+
- `res.renderHtml("file.html", { key: "value" })` with Mustache-style `{{key}}` interpolation
|
|
169
|
+
- `res.sendFile("file.html")`
|
|
170
|
+
3. **Automatic Server Initialization**:
|
|
171
|
+
- `ServerEngine` and `server(port):` automatically initialize routing, CORS, JSON body-parsing, and URL-encoding. No manual `create()` call required!
|
|
172
|
+
4. **Enhanced Network CLI (`thy serve`)**:
|
|
173
|
+
- Automatically binds to `0.0.0.0` with multi-interface discovery for effortless LAN testing across devices.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## 📖 CLI Commands
|
|
178
|
+
|
|
179
|
+
| Command | Description |
|
|
180
|
+
|---------|-------------|
|
|
181
|
+
| `thy run <file.thy>` | Compile and run a ThyScript file with performance stats |
|
|
182
|
+
| `thy serve <file.thy>` | Run a ThyScript file as a live HTTP web server (with LAN access) |
|
|
183
|
+
| `thy panel` / `thys` | Launch the Web Control Panel & Remote Execution Server |
|
|
184
|
+
| `thy compile <file.thy>` | Compile a `.thy` file to standard Node.js JavaScript (`.js`) |
|
|
185
|
+
| `thy check --fix` | Check project dependencies and install missing packages |
|
|
186
|
+
| `thy use <package>` | Install an npm package and configure it for your ThyScript project |
|
|
187
|
+
| `thy new <project>` | Scaffold a new ThyScript project with standard directories |
|
|
188
|
+
| `thy repl` | Start an interactive ThyScript REPL session |
|
|
189
|
+
| `thy test` | Run project test suites |
|
|
190
|
+
| `thy build` | Production build with code optimization |
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 📚 Complete Language Documentation
|
|
195
|
+
|
|
196
|
+
For the full language specification, syntax rules, standard library modules, and a dictionary of all ThyScript keywords, please see:
|
|
197
|
+
|
|
198
|
+
👉 **[DOKUMEN.md](./DOKUMEN.md)**
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 📄 License
|
|
203
|
+
|
|
204
|
+
MIT License © 2026 ThyScript Team. Built with ❤️ on Node.js.
|
package/bin/thy-node.js
CHANGED
|
@@ -66,7 +66,7 @@ function printBanner() {
|
|
|
66
66
|
];
|
|
67
67
|
|
|
68
68
|
const tagline = ' ⚡ High-Performance Language Built on Node.js ⚡';
|
|
69
|
-
const version = ThyModule ? ThyModule.VERSION : '
|
|
69
|
+
const version = ThyModule ? ThyModule.VERSION : '2.0.0';
|
|
70
70
|
const verLine = ` v${version} • ThyScript Runtime • Node.js ${process.version}`;
|
|
71
71
|
|
|
72
72
|
console.log(chalk.cyan(lines.join('\n')));
|
package/bin/thy.js
CHANGED
|
@@ -697,9 +697,9 @@ program
|
|
|
697
697
|
// ╚══════════════════════════════════════╝
|
|
698
698
|
program
|
|
699
699
|
.command('serve <filename>')
|
|
700
|
-
.description('Run a .thy file as
|
|
700
|
+
.description('Run a .thy file as a real live HTTP web server (accessible anywhere)')
|
|
701
701
|
.option('-p, --port <port>', 'Port to listen on', '3000')
|
|
702
|
-
.option('--host <host>', 'Host to bind to', '
|
|
702
|
+
.option('--host <host>', 'Host to bind to', '0.0.0.0')
|
|
703
703
|
.option('--watch', 'Restart on file change')
|
|
704
704
|
.action(async (filename, opts) => {
|
|
705
705
|
miniBanner();
|
|
@@ -707,32 +707,43 @@ program
|
|
|
707
707
|
|
|
708
708
|
const abs = ensureThyFile(filename);
|
|
709
709
|
const port = parseInt(opts.port, 10) || 3000;
|
|
710
|
-
const host = opts.host || '
|
|
711
|
-
|
|
710
|
+
const host = opts.host || '0.0.0.0';
|
|
711
|
+
process.env.PORT = String(port);
|
|
712
|
+
process.env.HOST = host;
|
|
712
713
|
|
|
713
714
|
info(`Starting server: ${path.basename(abs)}`);
|
|
714
|
-
|
|
715
|
-
|
|
715
|
+
|
|
716
|
+
const os = require('os');
|
|
717
|
+
const ifaces = os.networkInterfaces();
|
|
718
|
+
const netAddrs = [];
|
|
719
|
+
for (const name of Object.keys(ifaces)) {
|
|
720
|
+
for (const iface of ifaces[name] || []) {
|
|
721
|
+
if (iface.family === 'IPv4' && !iface.internal) {
|
|
722
|
+
netAddrs.push({ name, address: iface.address });
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
716
726
|
|
|
717
727
|
async function startServer() {
|
|
718
728
|
try {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
729
|
+
const ThyMod = tryRequire('src/index.js');
|
|
730
|
+
if (!ThyMod) {
|
|
731
|
+
fail('ThyScript core not found.');
|
|
732
|
+
process.exit(1);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const source = fs.readFileSync(abs, 'utf8');
|
|
736
|
+
await ThyMod.runSource(source, abs);
|
|
737
|
+
|
|
738
|
+
ok(`Server successfully running on http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`);
|
|
739
|
+
if (netAddrs.length > 0) {
|
|
740
|
+
log('');
|
|
741
|
+
log(chalk.bold.white(' 🌐 Access from any device on your local network (WiFi/LAN):'));
|
|
742
|
+
for (const net of netAddrs) {
|
|
743
|
+
log(chalk.cyan(` ▶ http://${net.address}:${port}`) + chalk.gray(` (${net.name})`));
|
|
728
744
|
}
|
|
729
|
-
const source = fs.readFileSync(abs, 'utf8');
|
|
730
|
-
const app = express();
|
|
731
|
-
app.get('*', (_req, res) =>
|
|
732
|
-
res.send(`<pre>ThyScript stub server\n\nSource:\n${source}</pre>`));
|
|
733
|
-
app.listen(port, host, () =>
|
|
734
|
-
ok(`Server running at http://${host}:${port} (stub mode)`));
|
|
735
745
|
}
|
|
746
|
+
log('');
|
|
736
747
|
} catch (err) {
|
|
737
748
|
if (err.code === 'EADDRINUSE') {
|
|
738
749
|
fail(`Port ${port} is already in use.`);
|