xanascript 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/README.md +132 -0
- package/VERSION +1 -0
- package/llms.txt +322 -0
- package/package.json +33 -0
- package/src/ast.js +65 -0
- package/src/bench.js +68 -0
- package/src/bytecode/compiler.js +189 -0
- package/src/bytecode/opcodes.js +36 -0
- package/src/bytecode/vm.js +216 -0
- package/src/cli.js +535 -0
- package/src/codegen.js +101 -0
- package/src/codegen_opt.js +352 -0
- package/src/codegen_wasm.js +306 -0
- package/src/docsgen.js +262 -0
- package/src/errors.js +162 -0
- package/src/interpreter.js +471 -0
- package/src/lexer.js +195 -0
- package/src/lsp.js +304 -0
- package/src/macros.js +132 -0
- package/src/optimizer.js +175 -0
- package/src/orm.js +120 -0
- package/src/parser.js +819 -0
- package/src/pkgmgr.js +273 -0
- package/src/runtime.js +171 -0
- package/src/sourcemap.js +120 -0
- package/src/testrunner.js +118 -0
- package/src/wasm_binary.js +573 -0
- package/std/math.xs +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# XanaScript
|
|
2
|
+
|
|
3
|
+
Program in Portuguese. Run on WebAssembly. Real performance.
|
|
4
|
+
|
|
5
|
+
XanaScript is a programming language with Portuguese syntax, optimizing compiler (JavaScript + WebAssembly), built-in ORM, compile-time macros, LSP, and zero runtime dependencies.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g xanascript
|
|
9
|
+
xs run app.xs
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```xs
|
|
13
|
+
PARTIU()
|
|
14
|
+
CHAMA ESSE CARA fib(n) {
|
|
15
|
+
SE LIGA SO (n <= 1) { VOLTA n }
|
|
16
|
+
VOLTA fib(n - 1) + fib(n - 2)
|
|
17
|
+
}
|
|
18
|
+
SOLTA O GRITO("fib(10) =", fib(10))
|
|
19
|
+
ACABOU()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Via npm (requires Node.js)
|
|
28
|
+
npm install -g xanascript
|
|
29
|
+
xs run app.xs
|
|
30
|
+
|
|
31
|
+
# Via source
|
|
32
|
+
git clone https://github.com/xanascr/xs.git
|
|
33
|
+
cd xs
|
|
34
|
+
npm install
|
|
35
|
+
node src/cli.js run app.xs
|
|
36
|
+
|
|
37
|
+
# Native binary (requires bun)
|
|
38
|
+
npm run build
|
|
39
|
+
dist/xs run app.xs
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
- [Full documentation](docs/en/getting-started.md) - English
|
|
45
|
+
- [Documentacao completa](docs/pt-br/comecando.md) - Portugues
|
|
46
|
+
- [Documentacion completa](docs/es/introduccion.md) - Espanol
|
|
47
|
+
- [Examples](https://github.com/xanascr/xs-examples)
|
|
48
|
+
- [Installer](https://github.com/xanascr/xs-installer)
|
|
49
|
+
- [VS Code Extension](https://github.com/xanascr/xs-vscode)
|
|
50
|
+
- [LLM Reference](llms.txt) - Complete reference for AI assistants
|
|
51
|
+
|
|
52
|
+
## Architecture
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
.xs source -> Lexer -> Parser -> Optimizer -> Codegen (JS / Wasm)
|
|
56
|
+
-> Runtime (interpreter)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| Module | File | Purpose |
|
|
60
|
+
|--------|------|---------|
|
|
61
|
+
| Lexer | `src/lexer.js` | Tokenization with line/col tracking |
|
|
62
|
+
| Parser | `src/parser.js` | AST generation |
|
|
63
|
+
| Optimizer | `src/optimizer.js` | Macros, constant folding, dead branches |
|
|
64
|
+
| Interpreter | `src/interpreter.js` | AST walking interpreter |
|
|
65
|
+
| Runtime | `src/runtime.js` | Built-ins and environment |
|
|
66
|
+
| Codegen JS | `src/codegen.js` | JavaScript generation |
|
|
67
|
+
| Codegen Opt | `src/codegen_opt.js` | Optimized JS (TypedArrays, int32) |
|
|
68
|
+
| Codegen Wasm | `src/codegen_wasm.js` | WebAssembly text format |
|
|
69
|
+
| Wasm Binary | `src/wasm_binary.js` | Direct Wasm binary (no wabt.js) |
|
|
70
|
+
| Errors | `src/errors.js` | Rust-style error reporting |
|
|
71
|
+
| CLI | `src/cli.js` | Command-line interface |
|
|
72
|
+
| ORM | `src/orm.js` | Built-in ORM (TABLE -> CRUD) |
|
|
73
|
+
| Macros | `src/macros.js` | Compile-time expansion |
|
|
74
|
+
| LSP | `src/lsp.js` | Language Server Protocol |
|
|
75
|
+
| Test Runner | `src/testrunner.js` | Native test runner |
|
|
76
|
+
| Docs Gen | `src/docsgen.js` | HTML documentation generator |
|
|
77
|
+
| Pkg Manager | `src/pkgmgr.js` | Package manager |
|
|
78
|
+
| Source Map | `src/sourcemap.js` | Source maps |
|
|
79
|
+
| Bytecode VM | `src/bytecode/` | Stack-based VM |
|
|
80
|
+
|
|
81
|
+
## CLI
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
xs run <file> Execute .xs
|
|
85
|
+
xs check <file> Check syntax
|
|
86
|
+
xs build <file> Generate JavaScript
|
|
87
|
+
xs build --opt <file> Optimized JavaScript
|
|
88
|
+
xs build --wasm <file> WebAssembly
|
|
89
|
+
xs build --standalone Single JS with runtime
|
|
90
|
+
xs test . Run tests
|
|
91
|
+
xs dev <file> Hot reload
|
|
92
|
+
xs repl Interactive mode
|
|
93
|
+
xs lsp Language Server
|
|
94
|
+
xs fmt <file> Format code
|
|
95
|
+
xs docs src/ docs/ HTML documentation
|
|
96
|
+
xs init <name> New project
|
|
97
|
+
xs install <pkg> Install package
|
|
98
|
+
xs publish Publish package
|
|
99
|
+
xs bench Benchmark
|
|
100
|
+
xs vm <file> Bytecode VM
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Tests
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
node test/lexer.test.js
|
|
107
|
+
node test/parser.test.js
|
|
108
|
+
node test/interpreter.test.js
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Structure
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
xs/
|
|
115
|
+
src/ Compiler (20 modules)
|
|
116
|
+
test/ Unit tests
|
|
117
|
+
std/ Standard library
|
|
118
|
+
scripts/ Build scripts
|
|
119
|
+
docs/ Documentation (en, pt-br, es)
|
|
120
|
+
package.json
|
|
121
|
+
VERSION
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Ecosystem
|
|
125
|
+
|
|
126
|
+
| Repository | Description |
|
|
127
|
+
|---|---|
|
|
128
|
+
| [xanascript/xs](https://github.com/xanascr/xs) | Core language |
|
|
129
|
+
| [xanascript/xs-site](https://github.com/xanascr/xs-site) | Website and documentation |
|
|
130
|
+
| [xanascript/xs-vscode](https://github.com/xanascr/xs-vscode) | VS Code extension |
|
|
131
|
+
| [xanascript/xs-examples](https://github.com/xanascr/xs-examples) | Code examples |
|
|
132
|
+
| [xanascript/xs-installer](https://github.com/xanascr/xs-installer) | Windows installer |
|
package/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.0.0
|
package/llms.txt
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# XanaScript - LLM Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
XanaScript is a programming language with Portuguese syntax, an optimizing compiler (JavaScript + WebAssembly), built-in ORM, compile-time macros, LSP, and zero runtime dependencies.
|
|
6
|
+
|
|
7
|
+
- Repository: https://github.com/xanascr/xs
|
|
8
|
+
- License: MIT
|
|
9
|
+
- Language: Portuguese keywords, JavaScript/WebAssembly compilation target
|
|
10
|
+
|
|
11
|
+
## Project Structure
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
xs/
|
|
15
|
+
src/ Compiler source (20 modules)
|
|
16
|
+
test/ Unit tests
|
|
17
|
+
std/ Standard library
|
|
18
|
+
scripts/ Build scripts
|
|
19
|
+
docs/ Documentation (en, pt-br, es)
|
|
20
|
+
package.json npm package
|
|
21
|
+
VERSION Version file
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Key source files:
|
|
25
|
+
|
|
26
|
+
| File | Purpose |
|
|
27
|
+
|------|---------|
|
|
28
|
+
| src/lexer.js | Tokenization with line/col tracking |
|
|
29
|
+
| src/parser.js | AST generation via recursive descent |
|
|
30
|
+
| src/ast.js | AST node constructors |
|
|
31
|
+
| src/optimizer.js | Constant folding, dead branch elimination, macro expansion |
|
|
32
|
+
| src/interpreter.js | AST-walking interpreter |
|
|
33
|
+
| src/runtime.js | Built-in functions and execution environment |
|
|
34
|
+
| src/codegen.js | Standard JavaScript code generation |
|
|
35
|
+
| src/codegen_opt.js | Optimized JS with TypedArrays |
|
|
36
|
+
| src/codegen_wasm.js | WebAssembly text format generation |
|
|
37
|
+
| src/wasm_binary.js | Direct WebAssembly binary emission |
|
|
38
|
+
| src/errors.js | Rust-style error formatting |
|
|
39
|
+
| src/cli.js | CLI entry point |
|
|
40
|
+
| src/orm.js | Built-in ORM |
|
|
41
|
+
| src/macros.js | Compile-time macro expansion |
|
|
42
|
+
| src/lsp.js | Language Server Protocol |
|
|
43
|
+
| src/testrunner.js | Unit test runner |
|
|
44
|
+
| src/docsgen.js | HTML documentation generator |
|
|
45
|
+
| src/pkgmgr.js | Package manager |
|
|
46
|
+
| src/sourcemap.js | Source map generation |
|
|
47
|
+
| src/bytecode/compiler.js | Bytecode compiler |
|
|
48
|
+
| src/bytecode/vm.js | Bytecode VM |
|
|
49
|
+
| src/bytecode/opcodes.js | Opcode definitions |
|
|
50
|
+
| src/bench.js | Benchmark runner |
|
|
51
|
+
|
|
52
|
+
## Language Syntax
|
|
53
|
+
|
|
54
|
+
### Program Structure
|
|
55
|
+
|
|
56
|
+
All XanaScript programs are wrapped in PARTIU() / ACABOU():
|
|
57
|
+
|
|
58
|
+
```xs
|
|
59
|
+
PARTIU()
|
|
60
|
+
// code here
|
|
61
|
+
ACABOU()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Keywords
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
PARTIU, ACABOU, CRIA, SE, LIGA, SO, SENAO, REPETE, NA, MORAL, AI,
|
|
68
|
+
CHAMA, ESSE, CARA, VOLTA, IMPORTA, EXPORTA, SOLTA, O, GRITO,
|
|
69
|
+
FALA, BAIXO, AGORA, VAI, ESPERA, AI, SORTEIA, PARSEIA, OUVE, AQUI,
|
|
70
|
+
VERDADEIRO, FALSO, NULO, TENTA, PEGA, ERRO, ASSINCRONO, VOA,
|
|
71
|
+
CONTINUA, CLASSE, HERDA, CONSTRUTOR, ISTO, NOVA, METODO, ESCOLHE,
|
|
72
|
+
CASO, PADRAO, COMBINA, SERVIDOR, PARA, TAMANHO, DIVIDE, TEXTO,
|
|
73
|
+
ENCONTRA, DECODIFICA, URL, JUNTAR, TESTE, AFIRMA, ASSUNTO, TAREFA,
|
|
74
|
+
TABELA, MACRO, TIPO, CRUD
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Data Types
|
|
78
|
+
|
|
79
|
+
| Type | Examples |
|
|
80
|
+
|------|----------|
|
|
81
|
+
| Number | `10`, `3.14`, `-5` |
|
|
82
|
+
| String | `"texto"`, `'texto'` |
|
|
83
|
+
| Boolean | `VERDADEIRO`, `FALSO` |
|
|
84
|
+
| Null | `NULO` |
|
|
85
|
+
| Array | `[1, 2, 3]` |
|
|
86
|
+
| Object | `{ nome: "Joao", idade: 30 }` |
|
|
87
|
+
| Template | `` `Hello ${name}` `` |
|
|
88
|
+
|
|
89
|
+
### Operators
|
|
90
|
+
|
|
91
|
+
**Arithmetic:** `+` `-` `*` `/` `%`
|
|
92
|
+
**Comparison:** `==` `!=` `>` `<` `>=` `<=` `~=`
|
|
93
|
+
**Logical:** `&&` `||` `!`
|
|
94
|
+
**Compound:** `+=` `-=` `*=` `/=` `%=`
|
|
95
|
+
**Ternary:** `test ? cons : alt`
|
|
96
|
+
|
|
97
|
+
### Variables
|
|
98
|
+
|
|
99
|
+
```xs
|
|
100
|
+
CRIA x = 10
|
|
101
|
+
CRIA nome = "Maria"
|
|
102
|
+
CRIA ativo = VERDADEIRO
|
|
103
|
+
CRIA valor = NULO
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Control Flow
|
|
107
|
+
|
|
108
|
+
**If/Else:**
|
|
109
|
+
```xs
|
|
110
|
+
SE LIGA SO (cond) { } SENAO { }
|
|
111
|
+
SENAO SE LIGA SO (cond) { }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**While:**
|
|
115
|
+
```xs
|
|
116
|
+
REPETE AI (cond) { }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**For:**
|
|
120
|
+
```xs
|
|
121
|
+
REPETE NA MORAL (init; test; update) { }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Break/Continue:**
|
|
125
|
+
```xs
|
|
126
|
+
VOA() // break
|
|
127
|
+
CONTINUA() // continue
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Switch:**
|
|
131
|
+
```xs
|
|
132
|
+
ESCOLHE (expr) {
|
|
133
|
+
CASO valor: code
|
|
134
|
+
PADRAO: code
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Pattern Matching:**
|
|
139
|
+
```xs
|
|
140
|
+
COMBINA (expr) {
|
|
141
|
+
CASO pattern: code
|
|
142
|
+
CASO _: code
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Functions
|
|
147
|
+
|
|
148
|
+
```xs
|
|
149
|
+
CHAMA ESSE CARA nome(params) { }
|
|
150
|
+
VOLTA expr
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Arrow functions:
|
|
154
|
+
```xs
|
|
155
|
+
(params) => expr
|
|
156
|
+
(params) => { }
|
|
157
|
+
ASSINCRONO (params) => { }
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Classes / OOP
|
|
161
|
+
|
|
162
|
+
```xs
|
|
163
|
+
CLASSE Nome {
|
|
164
|
+
CONSTRUTOR(params) { }
|
|
165
|
+
METODO nome(params) { }
|
|
166
|
+
}
|
|
167
|
+
CLASSE Filha HERDA Pai { }
|
|
168
|
+
ISTO // this
|
|
169
|
+
NOVA Classe() // new
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Error Handling
|
|
173
|
+
|
|
174
|
+
```xs
|
|
175
|
+
TENTA { } PEGA(erro) { }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Modules
|
|
179
|
+
|
|
180
|
+
```xs
|
|
181
|
+
IMPORTA "path"
|
|
182
|
+
IMPORTA "path" as alias
|
|
183
|
+
IMPORTA nome
|
|
184
|
+
EXPORTA nome
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Macros (Compile-time)
|
|
188
|
+
|
|
189
|
+
```xs
|
|
190
|
+
MACRO nome(params) { body }
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### ORM
|
|
194
|
+
|
|
195
|
+
```xs
|
|
196
|
+
TABELA Nome { campo: TIPO }
|
|
197
|
+
CRIA repo = TABELA("Nome")
|
|
198
|
+
repo.criar(obj)
|
|
199
|
+
repo.listar()
|
|
200
|
+
repo.buscar(id)
|
|
201
|
+
repo.atualizar(id, obj)
|
|
202
|
+
repo.deletar(id)
|
|
203
|
+
repo.buscarOnde(filter)
|
|
204
|
+
repo.contar()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Testing
|
|
208
|
+
|
|
209
|
+
```xs
|
|
210
|
+
TESTE("name") { AFIRMA(cond) }
|
|
211
|
+
ASSUNTO(actual, expected)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Tasks
|
|
215
|
+
|
|
216
|
+
```xs
|
|
217
|
+
TAREFA("name") { }
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Built-in Functions
|
|
221
|
+
|
|
222
|
+
| Function | Description | Signature |
|
|
223
|
+
|----------|-------------|-----------|
|
|
224
|
+
| SOLTA_O_GRITO | Prints to stdout | SOLTA_O_GRITO(...args) |
|
|
225
|
+
| FALA_BAIXO | Prints to stderr | FALA_BAIXO(...args) |
|
|
226
|
+
| AGORA_VAI | HTTP GET request | AGORA_VAI(url) |
|
|
227
|
+
| ESPERA_AI | Sleep/delay | ESPERA_AI(ms) |
|
|
228
|
+
| SORTEIA | Random integer | SORTEIA(min, max) |
|
|
229
|
+
| PARSEIA | JSON parse | PARSEIA(json) |
|
|
230
|
+
| OUVE_AQUI | Environment variable | OUVE_AQUI(chave) |
|
|
231
|
+
| TAMANHO | Length of array/string | TAMANHO(valor) |
|
|
232
|
+
| DIVIDE_TEXTO | String split | DIVIDE_TEXTO(texto, separador) |
|
|
233
|
+
| DECODIFICA_URL | URL decode | DECODIFICA_URL(url) |
|
|
234
|
+
| CRIA_SERVIDOR | HTTP server | CRIA_SERVIDOR(porta, handler) |
|
|
235
|
+
| PARA_SERVIDOR | Stop server | PARA_SERVIDOR(server) |
|
|
236
|
+
|
|
237
|
+
## CLI Commands
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
xs run <file> Execute .xs file (AST Interpreter)
|
|
241
|
+
xs vm <file> Execute .xs file (Bytecode VM)
|
|
242
|
+
xs check <file> Check syntax only
|
|
243
|
+
xs build <file> Generate JavaScript
|
|
244
|
+
xs build --opt <file> Generate optimized JavaScript
|
|
245
|
+
xs build --wasm <file>Generate WebAssembly (.wat + .wasm)
|
|
246
|
+
xs build --standalone <file> Generate single .js with runtime
|
|
247
|
+
xs test <dir> Run test files
|
|
248
|
+
xs dev <file> Watch mode with hot reload
|
|
249
|
+
xs fmt <file> Format .xs file
|
|
250
|
+
xs repl Interactive REPL
|
|
251
|
+
xs lsp Language Server Protocol (stdin/stdout)
|
|
252
|
+
xs docs <src> <out> Generate HTML documentation
|
|
253
|
+
xs init <name> Create new project scaffold
|
|
254
|
+
xs install <pkg> Install a package
|
|
255
|
+
xs publish Publish current package
|
|
256
|
+
xs bench Run benchmarks
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Compilation Pipeline
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
.xs source -> Lexer -> Parser -> Optimizer -> Codegen -> Output
|
|
263
|
+
|-> JS
|
|
264
|
+
|-> Opt JS (TypedArrays)
|
|
265
|
+
|-> Wasm text
|
|
266
|
+
|-> Wasm binary
|
|
267
|
+
|-> Bytecode -> VM
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
1. **Lexer** (lexer.js): Converts source text to tokens with position tracking
|
|
271
|
+
2. **Parser** (parser.js): Recursive descent parser, generates AST
|
|
272
|
+
3. **Optimizer** (optimizer.js): Constant folding, dead branch elimination, macro expansion
|
|
273
|
+
4. **Code Generation**: Multiple backends
|
|
274
|
+
- codegen.js: Standard JavaScript
|
|
275
|
+
- codegen_opt.js: Optimized JS with int32 TypedArrays
|
|
276
|
+
- codegen_wasm.js: WebAssembly text (.wat) format
|
|
277
|
+
- wasm_binary.js: Direct binary Wasm emission
|
|
278
|
+
- bytecode/compiler.js + bytecode/vm.js: Stack-based bytecode
|
|
279
|
+
|
|
280
|
+
## Error System
|
|
281
|
+
|
|
282
|
+
Rust-style errors with source code preview, arrow pointing to exact location, and hints:
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
XSError: message
|
|
286
|
+
--> file.xs:line:col
|
|
287
|
+
1 | code
|
|
288
|
+
| ^
|
|
289
|
+
hint: suggestion
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Error codes: E001-E005, E999, I001
|
|
293
|
+
|
|
294
|
+
## Bytecode VM (26 opcodes)
|
|
295
|
+
|
|
296
|
+
Opcodes include: PUSH, POP, ADD, SUB, MUL, DIV, MOD, EQ, NEQ, GT, LT, GTE, LTE, AND, OR, NOT, NEG, JMP, JIF, LOAD, STORE, CALL, RET, PRN, NEWA, NEWO, LDAT, STAT, DUP, SWAP, HALT
|
|
297
|
+
|
|
298
|
+
## ORM (Object-Relational Mapping)
|
|
299
|
+
|
|
300
|
+
SQLite-backed repository with JSON file storage. Field types: TEXTO, NUMERO, BOOLEANO, DATA. Data stored in `.xs-data/` directory.
|
|
301
|
+
|
|
302
|
+
## LSP (Language Server Protocol)
|
|
303
|
+
|
|
304
|
+
Provides autocomplete, hover information, go-to-definition, diagnostics, and signature help via stdin/stdout.
|
|
305
|
+
|
|
306
|
+
## Package Manager
|
|
307
|
+
|
|
308
|
+
Registry: https://api.xanascript.dev/packages
|
|
309
|
+
Fallback: npm with `xanascript-` prefix
|
|
310
|
+
Commands: xs init, xs install, xs publish
|
|
311
|
+
|
|
312
|
+
## Source Maps
|
|
313
|
+
|
|
314
|
+
VLQ-encoded source mappings between generated JS and original .xs lines. Comment format: `//# sourceMappingURL=data:application/json;base64,...`
|
|
315
|
+
|
|
316
|
+
## Build Process
|
|
317
|
+
|
|
318
|
+
Requires bun for native compilation:
|
|
319
|
+
```bash
|
|
320
|
+
node scripts/build-all.js
|
|
321
|
+
```
|
|
322
|
+
Outputs standalone binary `dist/xs(.exe)` with zero dependencies. Bundles all 147 modules into single executable.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xanascript",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Programming language with Portuguese syntax, optimizing compiler, built-in ORM, and WebAssembly support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"xs": "./src/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "node scripts/build-all.js",
|
|
11
|
+
"test": "node test/lexer.test.js && node test/parser.test.js && node test/interpreter.test.js"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/xanascr/xs.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": ["xanascript", "language", "portuguese", "programming", "compiler", "wasm"],
|
|
18
|
+
"author": "XanaScript",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/xanascr/xs/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://xanascript.xyz",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18.0.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"src",
|
|
29
|
+
"std",
|
|
30
|
+
"llms.txt",
|
|
31
|
+
"VERSION"
|
|
32
|
+
]
|
|
33
|
+
}
|
package/src/ast.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
let _loc = null;
|
|
2
|
+
export function setLoc(loc) { _loc = loc; }
|
|
3
|
+
|
|
4
|
+
function loc() {
|
|
5
|
+
const l = _loc;
|
|
6
|
+
_loc = null;
|
|
7
|
+
return l;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Program = body => ({ type: "Program", body, loc: loc() });
|
|
11
|
+
export const VarDecl = (id, init, typeHint) => ({ type: "VarDecl", id, init, typeHint, loc: loc() });
|
|
12
|
+
export const Assign = (left, right) => ({ type: "Assign", left, right, loc: loc() });
|
|
13
|
+
export const Binary = (op, left, right) => ({ type: "Binary", op, left, right, loc: loc() });
|
|
14
|
+
export const Unary = (op, arg) => ({ type: "Unary", op, arg, loc: loc() });
|
|
15
|
+
export const IfStmt = (test, cons, alt) => ({ type: "IfStmt", test, cons, alt, loc: loc() });
|
|
16
|
+
export const ForStmt = (init, test, update, body) => ({ type: "ForStmt", init, test, update, body, loc: loc() });
|
|
17
|
+
export const Block = body => ({ type: "Block", body, loc: loc() });
|
|
18
|
+
export const Call = (callee, args) => ({ type: "Call", callee, args, loc: loc() });
|
|
19
|
+
export const Member = (obj, prop) => ({ type: "Member", obj, prop, loc: loc() });
|
|
20
|
+
export const FunctionDecl = (name, params, body) => ({ type: "FunctionDecl", name, params, body, loc: loc() });
|
|
21
|
+
export const ReturnStmt = arg => ({ type: "ReturnStmt", arg, loc: loc() });
|
|
22
|
+
export const ExportStmt = name => ({ type: "ExportStmt", name, loc: loc() });
|
|
23
|
+
export const ImportExpr = path => ({ type: "ImportExpr", path, loc: loc() });
|
|
24
|
+
export const Ident = name => ({ type: "Ident", name, loc: loc() });
|
|
25
|
+
export const Num = value => ({ type: "Num", value, loc: loc() });
|
|
26
|
+
export const Str = value => ({ type: "Str", value, loc: loc() });
|
|
27
|
+
export const Bool = value => ({ type: "Bool", value, loc: loc() });
|
|
28
|
+
export const Nil = () => ({ type: "Nil", loc: loc() });
|
|
29
|
+
export const ArrayExpr = (items) => ({ type: "ArrayExpr", items, loc: loc() });
|
|
30
|
+
export const ObjectExpr = (props) => ({ type: "ObjectExpr", props, loc: loc() });
|
|
31
|
+
export const ArrowFunction = (params, body, isAsync = false) => ({ type: "ArrowFunction", params, body, isAsync, loc: loc() });
|
|
32
|
+
export const TryCatchStmt = (tryBlock, catchParam, catchBlock) => ({ type: "TryCatchStmt", tryBlock, catchParam, catchBlock, loc: loc() });
|
|
33
|
+
export const IndexExpr = (obj, index) => ({ type: "IndexExpr", obj, index, loc: loc() });
|
|
34
|
+
export const ImportStmt = (path, alias) => ({ type: "ImportStmt", path, alias, loc: loc() });
|
|
35
|
+
export const WhileStmt = (test, body) => ({ type: "WhileStmt", test, body, loc: loc() });
|
|
36
|
+
export const BreakStmt = () => ({ type: "BreakStmt", loc: loc() });
|
|
37
|
+
export const ContinueStmt = () => ({ type: "ContinueStmt", loc: loc() });
|
|
38
|
+
export const Ternary = (test, cons, alt) => ({ type: "Ternary", test, cons, alt, loc: loc() });
|
|
39
|
+
|
|
40
|
+
export const ClassDecl = (name, superClass, methods) => ({ type: "ClassDecl", name, superClass, methods, loc: loc() });
|
|
41
|
+
export const Method = (name, params, body, isConstructor) => ({ type: "Method", name, params, body, isConstructor, loc: loc() });
|
|
42
|
+
export const ThisExpr = () => ({ type: "ThisExpr", loc: loc() });
|
|
43
|
+
export const NewExpr = (callee, args) => ({ type: "NewExpr", callee, args, loc: loc() });
|
|
44
|
+
|
|
45
|
+
export const SwitchStmt = (test, cases) => ({ type: "SwitchStmt", test, cases, loc: loc() });
|
|
46
|
+
export const SwitchCase = (test, body) => ({ type: "SwitchCase", test, body, loc: loc() });
|
|
47
|
+
|
|
48
|
+
export const MatchExpr = (test, cases) => ({ type: "MatchExpr", test, cases, loc: loc() });
|
|
49
|
+
export const MatchCase = (pattern, body, guard) => ({ type: "MatchCase", pattern, body, guard, loc: loc() });
|
|
50
|
+
export const PatternLiteral = value => ({ type: "PatternLiteral", value, loc: loc() });
|
|
51
|
+
export const PatternIdent = name => ({ type: "PatternIdent", name, loc: loc() });
|
|
52
|
+
export const PatternArray = (elements) => ({ type: "PatternArray", elements, loc: loc() });
|
|
53
|
+
export const PatternObject = (props) => ({ type: "PatternObject", props, loc: loc() });
|
|
54
|
+
export const PatternRest = () => ({ type: "PatternRest", loc: loc() });
|
|
55
|
+
export const PatternGuard = (expr) => ({ type: "PatternGuard", expr, loc: loc() });
|
|
56
|
+
|
|
57
|
+
export const TestStmt = (name, body) => ({ type: "TestStmt", name, body, loc: loc() });
|
|
58
|
+
export const AssertStmt = (test, expected) => ({ type: "AssertStmt", test, expected, loc: loc() });
|
|
59
|
+
|
|
60
|
+
export const TaskDecl = (name, body) => ({ type: "TaskDecl", name, body, loc: loc() });
|
|
61
|
+
|
|
62
|
+
export const TableDecl = (name, props) => ({ type: "TableDecl", name, props, loc: loc() });
|
|
63
|
+
export const TableProp = (name, type) => ({ name, type, loc: loc() });
|
|
64
|
+
|
|
65
|
+
export const MacroDecl = (name, params, body) => ({ type: "MacroDecl", name, params, body, loc: loc() });
|
package/src/bench.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { lex } from "./lexer.js";
|
|
2
|
+
import { parse } from "./parser.js";
|
|
3
|
+
import { optimize } from "./optimizer.js";
|
|
4
|
+
import { runXS } from "./runtime.js";
|
|
5
|
+
|
|
6
|
+
export async function runBench() {
|
|
7
|
+
console.log("\n XanaScript Benchmark\n");
|
|
8
|
+
|
|
9
|
+
const xsCode = `
|
|
10
|
+
CHAMA ESSE CARA fib(n) {
|
|
11
|
+
SE LIGA SO (n <= 1) {
|
|
12
|
+
VOLTA n
|
|
13
|
+
}
|
|
14
|
+
VOLTA fib(n - 1) + fib(n - 2)
|
|
15
|
+
}
|
|
16
|
+
fib(20)
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const jsCode = `
|
|
20
|
+
function fib(n) {
|
|
21
|
+
if (n <= 1) return n;
|
|
22
|
+
return fib(n - 1) + fib(n - 2);
|
|
23
|
+
}
|
|
24
|
+
fib(20)
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const ITERATIONS = 3;
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < 2; i++) {
|
|
30
|
+
await runXS(xsCode);
|
|
31
|
+
eval(jsCode);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let xsTotal = 0;
|
|
35
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
36
|
+
const start = performance.now();
|
|
37
|
+
await runXS(xsCode);
|
|
38
|
+
xsTotal += performance.now() - start;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let jsTotal = 0;
|
|
42
|
+
for (let i = 0; i < ITERATIONS; i++) {
|
|
43
|
+
const start = performance.now();
|
|
44
|
+
eval(jsCode);
|
|
45
|
+
jsTotal += performance.now() - start;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const xsAvg = (xsTotal / ITERATIONS).toFixed(2);
|
|
49
|
+
const jsAvg = (jsTotal / ITERATIONS).toFixed(2);
|
|
50
|
+
const ratio = (xsTotal / jsTotal).toFixed(2);
|
|
51
|
+
|
|
52
|
+
console.log(` XanaScript: ${xsAvg}ms (avg)`);
|
|
53
|
+
console.log(` JavaScript: ${jsAvg}ms (avg)`);
|
|
54
|
+
console.log(` Ratio: ${ratio}x (${ratio > 1 ? "slower" : "faster"})`);
|
|
55
|
+
|
|
56
|
+
console.log("\n --- Constant Folding ---");
|
|
57
|
+
const optCode = "CRIA x = 10 + 20 * 3 + (100 / 5)";
|
|
58
|
+
const tokens = lex(optCode);
|
|
59
|
+
let ast = parse(tokens);
|
|
60
|
+
ast = optimize(ast);
|
|
61
|
+
const folded = ast.body[0].init;
|
|
62
|
+
console.log(` Input: 10 + 20 * 3 + (100 / 5)`);
|
|
63
|
+
console.log(` Output: ${folded.value} (folded at compile time)`);
|
|
64
|
+
console.log(` Savings: 4 operations eliminated\n`);
|
|
65
|
+
|
|
66
|
+
console.log(" XanaScript compiler eliminates constant expressions at compile-time,");
|
|
67
|
+
console.log(" something raw JS cannot do without a bundler.\n");
|
|
68
|
+
}
|