@designliquido/delegua 0.68.0 → 0.69.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/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts +2 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +11 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts +15 -12
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +120 -79
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +2 -2
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +42 -13
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts +11 -6
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +81 -41
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.d.ts +5 -0
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.js +46 -5
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/pilha-escopos.d.ts +1 -0
- package/avaliador-sintatico/pilha-escopos.d.ts.map +1 -1
- package/avaliador-sintatico/pilha-escopos.js +9 -0
- package/avaliador-sintatico/pilha-escopos.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/ajuda-como-construto.d.ts +18 -0
- package/construtos/ajuda-como-construto.d.ts.map +1 -0
- package/construtos/ajuda-como-construto.js +32 -0
- package/construtos/ajuda-como-construto.js.map +1 -0
- package/construtos/index.d.ts +1 -0
- package/construtos/index.d.ts.map +1 -1
- package/construtos/index.js +1 -0
- package/construtos/index.js.map +1 -1
- package/declaracoes/ajuda.d.ts +13 -0
- package/declaracoes/ajuda.d.ts.map +1 -0
- package/declaracoes/ajuda.js +25 -0
- package/declaracoes/ajuda.js.map +1 -0
- package/declaracoes/index.d.ts +1 -0
- package/declaracoes/index.d.ts.map +1 -1
- package/declaracoes/index.js +1 -0
- package/declaracoes/index.js.map +1 -1
- package/declaracoes/var.d.ts +1 -0
- package/declaracoes/var.d.ts.map +1 -1
- package/declaracoes/var.js +1 -0
- package/declaracoes/var.js.map +1 -1
- package/interfaces/visitante-delegua-interface.d.ts +4 -2
- package/interfaces/visitante-delegua-interface.d.ts.map +1 -1
- package/interpretador/comum.d.ts +1 -0
- package/interpretador/comum.d.ts.map +1 -1
- package/interpretador/comum.js +300 -0
- package/interpretador/comum.js.map +1 -1
- package/interpretador/interpretador.d.ts +11 -2
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +25 -0
- package/interpretador/interpretador.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js +20 -3
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/palavras-reservadas.d.ts +1 -0
- package/lexador/palavras-reservadas.d.ts.map +1 -1
- package/lexador/palavras-reservadas.js +1 -0
- package/lexador/palavras-reservadas.js.map +1 -1
- package/package.json +1 -1
- package/tipos-de-simbolos/delegua.d.ts +2 -1
- package/tipos-de-simbolos/delegua.d.ts.map +1 -1
- package/tipos-de-simbolos/delegua.js +2 -1
- package/tipos-de-simbolos/delegua.js.map +1 -1
- package/tipos-de-simbolos/pitugues.d.ts +1 -0
- package/tipos-de-simbolos/pitugues.d.ts.map +1 -1
- package/tipos-de-simbolos/pitugues.js +1 -0
- package/tipos-de-simbolos/pitugues.js.map +1 -1
- package/tradutores/tradutor-assembly-x64.js +122 -122
- package/umd/delegua.js +1686 -704
|
@@ -54,13 +54,13 @@ class TradutorAssemblyX64 {
|
|
|
54
54
|
Escreva: this.traduzirDeclaracaoEscreva.bind(this),
|
|
55
55
|
};
|
|
56
56
|
this.indentacao = 0;
|
|
57
|
-
this.text = `
|
|
58
|
-
section .text
|
|
59
|
-
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
57
|
+
this.text = `
|
|
58
|
+
section .text
|
|
59
|
+
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
60
60
|
${this.alvo === 'linux' ? '_start:' : 'main:'}`;
|
|
61
61
|
if (this.alvo === 'windows') {
|
|
62
|
-
this.text = `
|
|
63
|
-
extern printf
|
|
62
|
+
this.text = `
|
|
63
|
+
extern printf
|
|
64
64
|
` + this.text;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -122,8 +122,8 @@ extern printf
|
|
|
122
122
|
}
|
|
123
123
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
124
124
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
125
|
-
this.text += `
|
|
126
|
-
mov rax, ${valor}
|
|
125
|
+
this.text += `
|
|
126
|
+
mov rax, ${valor}
|
|
127
127
|
mov [${nomeVar} + ${indice} * 8], rax`;
|
|
128
128
|
}
|
|
129
129
|
traduzirConstrutoAtribuir(construto) {
|
|
@@ -142,8 +142,8 @@ extern printf
|
|
|
142
142
|
this.bss += ` ${varLabel} resq 1\n`;
|
|
143
143
|
this.variaveis.set(nomeVar, varLabel);
|
|
144
144
|
}
|
|
145
|
-
this.text += `
|
|
146
|
-
mov rax, ${valor}
|
|
145
|
+
this.text += `
|
|
146
|
+
mov rax, ${valor}
|
|
147
147
|
mov [${this.variaveis.get(nomeVar)}], rax`;
|
|
148
148
|
}
|
|
149
149
|
traduzirConstrutoBinario(construto) {
|
|
@@ -151,35 +151,35 @@ extern printf
|
|
|
151
151
|
const direita = this.dicionarioConstrutos[construto.direita.constructor.name](construto.direita);
|
|
152
152
|
const operador = construto.operador.lexema;
|
|
153
153
|
const reg = this.obterRegistrador();
|
|
154
|
-
this.text += `
|
|
155
|
-
mov rax, ${esquerda}
|
|
154
|
+
this.text += `
|
|
155
|
+
mov rax, ${esquerda}
|
|
156
156
|
mov ${reg}, ${direita}`;
|
|
157
157
|
switch (operador) {
|
|
158
158
|
case '+':
|
|
159
|
-
this.text += `
|
|
159
|
+
this.text += `
|
|
160
160
|
add rax, ${reg}`;
|
|
161
161
|
break;
|
|
162
162
|
case '-':
|
|
163
|
-
this.text += `
|
|
163
|
+
this.text += `
|
|
164
164
|
sub rax, ${reg}`;
|
|
165
165
|
break;
|
|
166
166
|
case '*':
|
|
167
|
-
this.text += `
|
|
167
|
+
this.text += `
|
|
168
168
|
imul rax, ${reg}`;
|
|
169
169
|
break;
|
|
170
170
|
case '/':
|
|
171
|
-
this.text += `
|
|
172
|
-
xor rdx, rdx
|
|
171
|
+
this.text += `
|
|
172
|
+
xor rdx, rdx
|
|
173
173
|
idiv ${reg}`;
|
|
174
174
|
break;
|
|
175
175
|
case '%':
|
|
176
|
-
this.text += `
|
|
177
|
-
xor rdx, rdx
|
|
178
|
-
idiv ${reg}
|
|
176
|
+
this.text += `
|
|
177
|
+
xor rdx, rdx
|
|
178
|
+
idiv ${reg}
|
|
179
179
|
mov rax, rdx`;
|
|
180
180
|
break;
|
|
181
181
|
default:
|
|
182
|
-
this.text += `
|
|
182
|
+
this.text += `
|
|
183
183
|
; Operador ${operador} não implementado`;
|
|
184
184
|
}
|
|
185
185
|
this.liberarRegistrador(reg);
|
|
@@ -198,28 +198,28 @@ extern printf
|
|
|
198
198
|
construto.argumentos.forEach((arg, index) => {
|
|
199
199
|
if (index < registrosArgs.length) {
|
|
200
200
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
201
|
-
this.text += `
|
|
201
|
+
this.text += `
|
|
202
202
|
mov ${registrosArgs[index]}, ${valorArg}`;
|
|
203
203
|
}
|
|
204
204
|
else {
|
|
205
205
|
// TODO: push extra args on stack according to target ABI
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
|
-
this.text += `
|
|
208
|
+
this.text += `
|
|
209
209
|
call ${nomeFuncao}`;
|
|
210
210
|
}
|
|
211
211
|
traduzirConstrutoDefinirValor(construto) {
|
|
212
212
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
213
213
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
214
|
-
this.text += `
|
|
215
|
-
mov rax, ${valor}
|
|
214
|
+
this.text += `
|
|
215
|
+
mov rax, ${valor}
|
|
216
216
|
mov [${objeto}], rax`;
|
|
217
217
|
}
|
|
218
218
|
traduzirFuncaoConstruto(construto) {
|
|
219
219
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
220
|
-
this.text += `
|
|
221
|
-
${labelFuncao}:
|
|
222
|
-
push rbp
|
|
220
|
+
this.text += `
|
|
221
|
+
${labelFuncao}:
|
|
222
|
+
push rbp
|
|
223
223
|
mov rbp, rsp`;
|
|
224
224
|
// Traduzir corpo da função
|
|
225
225
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -229,8 +229,8 @@ ${labelFuncao}:
|
|
|
229
229
|
}
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
|
-
this.text += `
|
|
233
|
-
pop rbp
|
|
232
|
+
this.text += `
|
|
233
|
+
pop rbp
|
|
234
234
|
ret`;
|
|
235
235
|
}
|
|
236
236
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -245,29 +245,29 @@ ${labelFuncao}:
|
|
|
245
245
|
const operador = construto.operador.lexema;
|
|
246
246
|
const labelVerdadeiro = this.gerarLabel();
|
|
247
247
|
const labelFim = this.gerarLabel();
|
|
248
|
-
this.text += `
|
|
249
|
-
mov rax, ${esquerda}
|
|
248
|
+
this.text += `
|
|
249
|
+
mov rax, ${esquerda}
|
|
250
250
|
cmp rax, 0`;
|
|
251
251
|
if (operador === 'e' || operador === '&&') {
|
|
252
|
-
this.text += `
|
|
253
|
-
je ${labelFim}
|
|
254
|
-
mov rax, ${direita}
|
|
255
|
-
cmp rax, 0
|
|
256
|
-
je ${labelFim}
|
|
257
|
-
${labelVerdadeiro}:
|
|
258
|
-
mov rax, 1
|
|
252
|
+
this.text += `
|
|
253
|
+
je ${labelFim}
|
|
254
|
+
mov rax, ${direita}
|
|
255
|
+
cmp rax, 0
|
|
256
|
+
je ${labelFim}
|
|
257
|
+
${labelVerdadeiro}:
|
|
258
|
+
mov rax, 1
|
|
259
259
|
${labelFim}:`;
|
|
260
260
|
}
|
|
261
261
|
else if (operador === 'ou' || operador === '||') {
|
|
262
|
-
this.text += `
|
|
263
|
-
jne ${labelVerdadeiro}
|
|
264
|
-
mov rax, ${direita}
|
|
265
|
-
cmp rax, 0
|
|
266
|
-
jne ${labelVerdadeiro}
|
|
267
|
-
mov rax, 0
|
|
268
|
-
jmp ${labelFim}
|
|
269
|
-
${labelVerdadeiro}:
|
|
270
|
-
mov rax, 1
|
|
262
|
+
this.text += `
|
|
263
|
+
jne ${labelVerdadeiro}
|
|
264
|
+
mov rax, ${direita}
|
|
265
|
+
cmp rax, 0
|
|
266
|
+
jne ${labelVerdadeiro}
|
|
267
|
+
mov rax, 0
|
|
268
|
+
jmp ${labelFim}
|
|
269
|
+
${labelVerdadeiro}:
|
|
270
|
+
mov rax, 1
|
|
271
271
|
${labelFim}:`;
|
|
272
272
|
}
|
|
273
273
|
return 'rax';
|
|
@@ -280,16 +280,16 @@ ${labelFim}:`;
|
|
|
280
280
|
traduzirConstrutoUnario(construto) {
|
|
281
281
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
282
282
|
const operador = construto.operador.lexema;
|
|
283
|
-
this.text += `
|
|
283
|
+
this.text += `
|
|
284
284
|
mov rax, ${operando}`;
|
|
285
285
|
if (operador === '-') {
|
|
286
|
-
this.text += `
|
|
286
|
+
this.text += `
|
|
287
287
|
neg rax`;
|
|
288
288
|
}
|
|
289
289
|
else if (operador === '!' || operador === 'nao') {
|
|
290
|
-
this.text += `
|
|
291
|
-
cmp rax, 0
|
|
292
|
-
sete al
|
|
290
|
+
this.text += `
|
|
291
|
+
cmp rax, 0
|
|
292
|
+
sete al
|
|
293
293
|
movzx rax, al`;
|
|
294
294
|
}
|
|
295
295
|
return 'rax';
|
|
@@ -311,8 +311,8 @@ ${labelFim}:`;
|
|
|
311
311
|
construto.valores.forEach((valor, index) => {
|
|
312
312
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
313
313
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
314
|
-
this.text += `
|
|
315
|
-
mov rax, ${valorTraduzido}
|
|
314
|
+
this.text += `
|
|
315
|
+
mov rax, ${valorTraduzido}
|
|
316
316
|
mov [${labelVetor} + ${index * 8}], rax`;
|
|
317
317
|
}
|
|
318
318
|
});
|
|
@@ -332,17 +332,17 @@ ${labelFim}:`;
|
|
|
332
332
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
333
333
|
const labelInicio = this.gerarLabel();
|
|
334
334
|
const labelFim = this.gerarLabel();
|
|
335
|
-
this.text += `
|
|
335
|
+
this.text += `
|
|
336
336
|
${labelInicio}:`;
|
|
337
337
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
338
|
-
this.text += `
|
|
339
|
-
cmp ${condicao}, 0
|
|
338
|
+
this.text += `
|
|
339
|
+
cmp ${condicao}, 0
|
|
340
340
|
je ${labelFim}`;
|
|
341
341
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
342
342
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
343
343
|
}
|
|
344
|
-
this.text += `
|
|
345
|
-
jmp ${labelInicio}
|
|
344
|
+
this.text += `
|
|
345
|
+
jmp ${labelInicio}
|
|
346
346
|
${labelFim}:`;
|
|
347
347
|
}
|
|
348
348
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -353,9 +353,9 @@ ${labelFim}:`;
|
|
|
353
353
|
const labelProximo = this.gerarLabel();
|
|
354
354
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
355
355
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
356
|
-
this.text += `
|
|
357
|
-
mov rax, ${valorEscolha}
|
|
358
|
-
cmp rax, ${valorCaso}
|
|
356
|
+
this.text += `
|
|
357
|
+
mov rax, ${valorEscolha}
|
|
358
|
+
cmp rax, ${valorCaso}
|
|
359
359
|
jne ${labelProximo}`;
|
|
360
360
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
361
361
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -364,13 +364,13 @@ ${labelFim}:`;
|
|
|
364
364
|
}
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
|
-
this.text += `
|
|
368
|
-
jmp ${labelFim}
|
|
367
|
+
this.text += `
|
|
368
|
+
jmp ${labelFim}
|
|
369
369
|
${labelProximo}:`;
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
372
|
}
|
|
373
|
-
this.text += `
|
|
373
|
+
this.text += `
|
|
374
374
|
${labelFim}:`;
|
|
375
375
|
}
|
|
376
376
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
@@ -380,7 +380,7 @@ ${labelFim}:`;
|
|
|
380
380
|
}
|
|
381
381
|
traduzirDeclaracaoFazer(declaracao) {
|
|
382
382
|
const labelInicio = this.gerarLabel();
|
|
383
|
-
this.text += `
|
|
383
|
+
this.text += `
|
|
384
384
|
${labelInicio}:`;
|
|
385
385
|
// Em Delégua, fazer-enquanto tem caminhoFazer que é um Bloco
|
|
386
386
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
@@ -392,8 +392,8 @@ ${labelInicio}:`;
|
|
|
392
392
|
}
|
|
393
393
|
if (declaracao.condicaoEnquanto) {
|
|
394
394
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
395
|
-
this.text += `
|
|
396
|
-
cmp ${condicao}, 0
|
|
395
|
+
this.text += `
|
|
396
|
+
cmp ${condicao}, 0
|
|
397
397
|
jne ${labelInicio}`;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
@@ -406,25 +406,25 @@ ${labelInicio}:`;
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
if (this.alvo === 'linux') {
|
|
409
|
-
this.text += `
|
|
410
|
-
; Falhar com mensagem: ${mensagem}
|
|
411
|
-
mov eax, 1
|
|
412
|
-
mov ebx, 1
|
|
409
|
+
this.text += `
|
|
410
|
+
; Falhar com mensagem: ${mensagem}
|
|
411
|
+
mov eax, 1
|
|
412
|
+
mov ebx, 1
|
|
413
413
|
int 0x80`;
|
|
414
414
|
}
|
|
415
415
|
else {
|
|
416
|
-
this.text += `
|
|
417
|
-
; Falhar com mensagem: ${mensagem}
|
|
418
|
-
mov eax, 1
|
|
416
|
+
this.text += `
|
|
417
|
+
; Falhar com mensagem: ${mensagem}
|
|
418
|
+
mov eax, 1
|
|
419
419
|
ret`;
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
423
423
|
var _a;
|
|
424
424
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
425
|
-
this.text += `
|
|
426
|
-
${nomeFuncao}:
|
|
427
|
-
push rbp
|
|
425
|
+
this.text += `
|
|
426
|
+
${nomeFuncao}:
|
|
427
|
+
push rbp
|
|
428
428
|
mov rbp, rsp`;
|
|
429
429
|
if (declaracao.funcao && declaracao.funcao.corpo && Array.isArray(declaracao.funcao.corpo)) {
|
|
430
430
|
declaracao.funcao.corpo.forEach((decl) => {
|
|
@@ -433,13 +433,13 @@ ${nomeFuncao}:
|
|
|
433
433
|
}
|
|
434
434
|
});
|
|
435
435
|
}
|
|
436
|
-
this.text += `
|
|
437
|
-
pop rbp
|
|
436
|
+
this.text += `
|
|
437
|
+
pop rbp
|
|
438
438
|
ret`;
|
|
439
439
|
}
|
|
440
440
|
traduzirDeclaracaoImportar(declaracao) {
|
|
441
441
|
// Importação é tratada em tempo de linkagem
|
|
442
|
-
this.text += `
|
|
442
|
+
this.text += `
|
|
443
443
|
; Importar: ${declaracao.caminho || 'unknown'}`;
|
|
444
444
|
}
|
|
445
445
|
traduzirDeclaracaoLeia(declaracao) {
|
|
@@ -455,11 +455,11 @@ ${nomeFuncao}:
|
|
|
455
455
|
this.bss += ` ${varLabel} resb 256\n`;
|
|
456
456
|
this.variaveis.set(nomeVar, varLabel);
|
|
457
457
|
}
|
|
458
|
-
this.text += `
|
|
459
|
-
mov eax, 3
|
|
460
|
-
mov ebx, 0
|
|
461
|
-
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
462
|
-
mov edx, 256
|
|
458
|
+
this.text += `
|
|
459
|
+
mov eax, 3
|
|
460
|
+
mov ebx, 0
|
|
461
|
+
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
462
|
+
mov edx, 256
|
|
463
463
|
int 0x80`;
|
|
464
464
|
}
|
|
465
465
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -475,12 +475,12 @@ ${nomeFuncao}:
|
|
|
475
475
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
this.text += `
|
|
478
|
+
this.text += `
|
|
479
479
|
${labelInicio}:`;
|
|
480
480
|
if (declaracao.condicao) {
|
|
481
481
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
482
|
-
this.text += `
|
|
483
|
-
cmp ${condicao}, 0
|
|
482
|
+
this.text += `
|
|
483
|
+
cmp ${condicao}, 0
|
|
484
484
|
je ${labelFim}`;
|
|
485
485
|
}
|
|
486
486
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -491,8 +491,8 @@ ${labelInicio}:`;
|
|
|
491
491
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
|
-
this.text += `
|
|
495
|
-
jmp ${labelInicio}
|
|
494
|
+
this.text += `
|
|
495
|
+
jmp ${labelInicio}
|
|
496
496
|
${labelFim}:`;
|
|
497
497
|
}
|
|
498
498
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -508,57 +508,57 @@ ${labelFim}:`;
|
|
|
508
508
|
if (vetor instanceof construtos_1.Vetor) {
|
|
509
509
|
tamanhoVetor = vetor.tamanho || 0;
|
|
510
510
|
}
|
|
511
|
-
this.text += `
|
|
512
|
-
xor rcx, rcx
|
|
513
|
-
${labelInicio}:
|
|
514
|
-
cmp rcx, ${tamanhoVetor}
|
|
511
|
+
this.text += `
|
|
512
|
+
xor rcx, rcx
|
|
513
|
+
${labelInicio}:
|
|
514
|
+
cmp rcx, ${tamanhoVetor}
|
|
515
515
|
jge ${labelFim}`;
|
|
516
516
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
517
517
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
518
518
|
}
|
|
519
|
-
this.text += `
|
|
520
|
-
inc rcx
|
|
521
|
-
jmp ${labelInicio}
|
|
519
|
+
this.text += `
|
|
520
|
+
inc rcx
|
|
521
|
+
jmp ${labelInicio}
|
|
522
522
|
${labelFim}:`;
|
|
523
523
|
}
|
|
524
524
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
525
525
|
if (declaracao.valor) {
|
|
526
526
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
527
|
-
this.text += `
|
|
527
|
+
this.text += `
|
|
528
528
|
mov rax, ${valor}`;
|
|
529
529
|
}
|
|
530
|
-
this.text += `
|
|
531
|
-
pop rbp
|
|
530
|
+
this.text += `
|
|
531
|
+
pop rbp
|
|
532
532
|
ret`;
|
|
533
533
|
}
|
|
534
534
|
traduzirDeclaracaoSe(declaracao) {
|
|
535
535
|
const labelSenao = this.gerarLabel();
|
|
536
536
|
const labelFim = this.gerarLabel();
|
|
537
537
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
538
|
-
this.text += `
|
|
539
|
-
cmp ${condicao}, 0
|
|
538
|
+
this.text += `
|
|
539
|
+
cmp ${condicao}, 0
|
|
540
540
|
je ${labelSenao}`;
|
|
541
541
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
542
542
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
543
543
|
}
|
|
544
|
-
this.text += `
|
|
545
|
-
jmp ${labelFim}
|
|
544
|
+
this.text += `
|
|
545
|
+
jmp ${labelFim}
|
|
546
546
|
${labelSenao}:`;
|
|
547
547
|
if (declaracao.caminhoSenao && this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
548
548
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
549
549
|
}
|
|
550
|
-
this.text += `
|
|
550
|
+
this.text += `
|
|
551
551
|
${labelFim}:`;
|
|
552
552
|
}
|
|
553
553
|
traduzirDeclaracaoClasse(declaracao) {
|
|
554
554
|
var _a;
|
|
555
555
|
// Classes em assembly são complexas - implementação básica
|
|
556
|
-
this.text += `
|
|
556
|
+
this.text += `
|
|
557
557
|
; Classe: ${((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'unknown'}`;
|
|
558
558
|
}
|
|
559
559
|
traduzirDeclaracaoTente(declaracao) {
|
|
560
560
|
// Try-catch em assembly requer handler complexo
|
|
561
|
-
this.text += `
|
|
561
|
+
this.text += `
|
|
562
562
|
; Tente-pegue`;
|
|
563
563
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
564
564
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -597,8 +597,8 @@ ${labelFim}:`;
|
|
|
597
597
|
}
|
|
598
598
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
599
599
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
600
|
-
this.text += `
|
|
601
|
-
mov rax, ${valor}
|
|
600
|
+
this.text += `
|
|
601
|
+
mov rax, ${valor}
|
|
602
602
|
mov [${varLabel}], rax`;
|
|
603
603
|
}
|
|
604
604
|
}
|
|
@@ -621,32 +621,32 @@ ${labelFim}:`;
|
|
|
621
621
|
tam_string_literal = this.criaTamanhoNaMemoriaReferenteAVar(nome_string_literal);
|
|
622
622
|
}
|
|
623
623
|
if (this.alvo === 'linux') {
|
|
624
|
-
this.text += `
|
|
625
|
-
mov edx, ${tam_string_literal}
|
|
626
|
-
mov ecx, ${nome_string_literal}
|
|
627
|
-
mov ebx, 1 ; fd stdout
|
|
628
|
-
mov eax, 4 ; sys_write
|
|
624
|
+
this.text += `
|
|
625
|
+
mov edx, ${tam_string_literal}
|
|
626
|
+
mov ecx, ${nome_string_literal}
|
|
627
|
+
mov ebx, 1 ; fd stdout
|
|
628
|
+
mov eax, 4 ; sys_write
|
|
629
629
|
int 0x80`;
|
|
630
630
|
}
|
|
631
631
|
else {
|
|
632
632
|
// Windows: prototype `extern printf` and follow Win64 calling convention
|
|
633
633
|
// RCX = format pointer; here we use the literal directly as a C string
|
|
634
|
-
this.text += `
|
|
635
|
-
lea rcx, [rel ${nome_string_literal}]
|
|
634
|
+
this.text += `
|
|
635
|
+
lea rcx, [rel ${nome_string_literal}]
|
|
636
636
|
call printf`;
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
639
|
saidaSistema() {
|
|
640
640
|
if (this.alvo === 'linux') {
|
|
641
|
-
this.text += `
|
|
642
|
-
mov eax, 1 ; sys_exit
|
|
643
|
-
xor ebx, ebx ; status 0
|
|
641
|
+
this.text += `
|
|
642
|
+
mov eax, 1 ; sys_exit
|
|
643
|
+
xor ebx, ebx ; status 0
|
|
644
644
|
int 0x80`;
|
|
645
645
|
}
|
|
646
646
|
else {
|
|
647
647
|
// Windows: return from main with 0 in EAX
|
|
648
|
-
this.text += `
|
|
649
|
-
xor eax, eax
|
|
648
|
+
this.text += `
|
|
649
|
+
xor eax, eax
|
|
650
650
|
ret`;
|
|
651
651
|
}
|
|
652
652
|
}
|