@designliquido/delegua 1.18.4 → 1.18.5
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 +6 -0
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +3 -0
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +3 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts +1 -0
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +19 -0
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +22 -9
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.d.ts +1 -0
- package/avaliador-sintatico/micro-avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.js +18 -0
- package/avaliador-sintatico/micro-avaliador-sintatico.js.map +1 -1
- package/bin/package.json +1 -1
- package/declaracoes/propriedade-classe.d.ts +3 -2
- package/declaracoes/propriedade-classe.d.ts.map +1 -1
- package/declaracoes/propriedade-classe.js +2 -1
- package/declaracoes/propriedade-classe.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts +5 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js +40 -3
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/estruturas/descritor-tipo-classe.d.ts +1 -0
- package/interpretador/estruturas/descritor-tipo-classe.d.ts.map +1 -1
- package/interpretador/estruturas/descritor-tipo-classe.js +1 -0
- package/interpretador/estruturas/descritor-tipo-classe.js.map +1 -1
- package/interpretador/estruturas/objeto-delegua-classe.d.ts.map +1 -1
- package/interpretador/estruturas/objeto-delegua-classe.js +7 -1
- package/interpretador/estruturas/objeto-delegua-classe.js.map +1 -1
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +3 -0
- package/interpretador/interpretador-base.js.map +1 -1
- package/package.json +1 -1
- package/tradutores/tradutor-assembly-arm.js +151 -151
- package/tradutores/tradutor-assembly-risc-v.js +85 -85
- package/tradutores/tradutor-assembly-x64.js +176 -176
- package/tradutores/tradutor-webassembly.js +29 -29
- package/umd/delegua.js +516 -452
|
@@ -59,10 +59,10 @@ class TradutorAssemblyARM {
|
|
|
59
59
|
// Para android: ainda é um binário standalone, mas com rótulo Delegua_main
|
|
60
60
|
// para deixar claro que não é o _start do CRT padrão.
|
|
61
61
|
const entryLabel = this.alvo === 'android' ? 'Delegua_main' : '_start';
|
|
62
|
-
this.text = `
|
|
63
|
-
.text
|
|
64
|
-
.global ${entryLabel}
|
|
65
|
-
|
|
62
|
+
this.text = `
|
|
63
|
+
.text
|
|
64
|
+
.global ${entryLabel}
|
|
65
|
+
|
|
66
66
|
${entryLabel}:`;
|
|
67
67
|
}
|
|
68
68
|
gerarDigitoAleatorio() {
|
|
@@ -103,11 +103,11 @@ ${entryLabel}:`;
|
|
|
103
103
|
}
|
|
104
104
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
105
105
|
const reg = this.obterRegistrador();
|
|
106
|
-
this.text += `
|
|
107
|
-
ldr ${reg}, =${nomeVar}
|
|
108
|
-
ldr r0, =${indice}
|
|
109
|
-
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
110
|
-
add ${reg}, ${reg}, r0
|
|
106
|
+
this.text += `
|
|
107
|
+
ldr ${reg}, =${nomeVar}
|
|
108
|
+
ldr r0, =${indice}
|
|
109
|
+
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
110
|
+
add ${reg}, ${reg}, r0
|
|
111
111
|
ldr r0, [${reg}]`;
|
|
112
112
|
this.liberarRegistrador(reg);
|
|
113
113
|
return 'r0';
|
|
@@ -130,12 +130,12 @@ ${entryLabel}:`;
|
|
|
130
130
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
131
131
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
132
132
|
const reg = this.obterRegistrador();
|
|
133
|
-
this.text += `
|
|
134
|
-
ldr ${reg}, =${nomeVar}
|
|
135
|
-
ldr r1, =${indice}
|
|
136
|
-
lsl r1, r1, #2 @ multiply by 4
|
|
137
|
-
add ${reg}, ${reg}, r1
|
|
138
|
-
ldr r1, =${valor}
|
|
133
|
+
this.text += `
|
|
134
|
+
ldr ${reg}, =${nomeVar}
|
|
135
|
+
ldr r1, =${indice}
|
|
136
|
+
lsl r1, r1, #2 @ multiply by 4
|
|
137
|
+
add ${reg}, ${reg}, r1
|
|
138
|
+
ldr r1, =${valor}
|
|
139
139
|
str r1, [${reg}]`;
|
|
140
140
|
this.liberarRegistrador(reg);
|
|
141
141
|
}
|
|
@@ -153,9 +153,9 @@ ${entryLabel}:`;
|
|
|
153
153
|
this.bss += ` ${varLabel}: .space 4\n`;
|
|
154
154
|
this.variaveis.set(nomeVar, varLabel);
|
|
155
155
|
}
|
|
156
|
-
this.text += `
|
|
157
|
-
ldr r0, =${valor}
|
|
158
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
156
|
+
this.text += `
|
|
157
|
+
ldr r0, =${valor}
|
|
158
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
159
159
|
str r0, [r1]`;
|
|
160
160
|
}
|
|
161
161
|
traduzirConstrutoBinario(construto) {
|
|
@@ -165,75 +165,75 @@ ${entryLabel}:`;
|
|
|
165
165
|
const reg = this.obterRegistrador();
|
|
166
166
|
// Load left operand into r0
|
|
167
167
|
if (esquerda !== 'r0') {
|
|
168
|
-
this.text += `
|
|
168
|
+
this.text += `
|
|
169
169
|
ldr r0, =${esquerda}`;
|
|
170
170
|
}
|
|
171
171
|
// Load right operand into reg
|
|
172
|
-
this.text += `
|
|
172
|
+
this.text += `
|
|
173
173
|
ldr ${reg}, =${direita}`;
|
|
174
174
|
switch (operador) {
|
|
175
175
|
case '+':
|
|
176
|
-
this.text += `
|
|
176
|
+
this.text += `
|
|
177
177
|
add r0, r0, ${reg}`;
|
|
178
178
|
break;
|
|
179
179
|
case '-':
|
|
180
|
-
this.text += `
|
|
180
|
+
this.text += `
|
|
181
181
|
sub r0, r0, ${reg}`;
|
|
182
182
|
break;
|
|
183
183
|
case '*':
|
|
184
|
-
this.text += `
|
|
184
|
+
this.text += `
|
|
185
185
|
mul r0, r0, ${reg}`;
|
|
186
186
|
break;
|
|
187
187
|
case '/':
|
|
188
|
-
this.text += `
|
|
188
|
+
this.text += `
|
|
189
189
|
sdiv r0, r0, ${reg}`;
|
|
190
190
|
break;
|
|
191
191
|
case '%':
|
|
192
|
-
this.text += `
|
|
193
|
-
sdiv r1, r0, ${reg}
|
|
194
|
-
mul r1, r1, ${reg}
|
|
192
|
+
this.text += `
|
|
193
|
+
sdiv r1, r0, ${reg}
|
|
194
|
+
mul r1, r1, ${reg}
|
|
195
195
|
sub r0, r0, r1 @ r0 = r0 - (r0/reg)*reg`;
|
|
196
196
|
break;
|
|
197
197
|
case '<':
|
|
198
|
-
this.text += `
|
|
199
|
-
cmp r0, ${reg}
|
|
200
|
-
movlt r0, #1
|
|
198
|
+
this.text += `
|
|
199
|
+
cmp r0, ${reg}
|
|
200
|
+
movlt r0, #1
|
|
201
201
|
movge r0, #0`;
|
|
202
202
|
break;
|
|
203
203
|
case '>':
|
|
204
|
-
this.text += `
|
|
205
|
-
cmp r0, ${reg}
|
|
206
|
-
movgt r0, #1
|
|
204
|
+
this.text += `
|
|
205
|
+
cmp r0, ${reg}
|
|
206
|
+
movgt r0, #1
|
|
207
207
|
movle r0, #0`;
|
|
208
208
|
break;
|
|
209
209
|
case '<=':
|
|
210
|
-
this.text += `
|
|
211
|
-
cmp r0, ${reg}
|
|
212
|
-
movle r0, #1
|
|
210
|
+
this.text += `
|
|
211
|
+
cmp r0, ${reg}
|
|
212
|
+
movle r0, #1
|
|
213
213
|
movgt r0, #0`;
|
|
214
214
|
break;
|
|
215
215
|
case '>=':
|
|
216
|
-
this.text += `
|
|
217
|
-
cmp r0, ${reg}
|
|
218
|
-
movge r0, #1
|
|
216
|
+
this.text += `
|
|
217
|
+
cmp r0, ${reg}
|
|
218
|
+
movge r0, #1
|
|
219
219
|
movlt r0, #0`;
|
|
220
220
|
break;
|
|
221
221
|
case '==':
|
|
222
222
|
case '===':
|
|
223
|
-
this.text += `
|
|
224
|
-
cmp r0, ${reg}
|
|
225
|
-
moveq r0, #1
|
|
223
|
+
this.text += `
|
|
224
|
+
cmp r0, ${reg}
|
|
225
|
+
moveq r0, #1
|
|
226
226
|
movne r0, #0`;
|
|
227
227
|
break;
|
|
228
228
|
case '!=':
|
|
229
229
|
case '!==':
|
|
230
|
-
this.text += `
|
|
231
|
-
cmp r0, ${reg}
|
|
232
|
-
movne r0, #1
|
|
230
|
+
this.text += `
|
|
231
|
+
cmp r0, ${reg}
|
|
232
|
+
movne r0, #1
|
|
233
233
|
moveq r0, #0`;
|
|
234
234
|
break;
|
|
235
235
|
default:
|
|
236
|
-
this.text += `
|
|
236
|
+
this.text += `
|
|
237
237
|
@ Operador ${operador} não implementado`;
|
|
238
238
|
}
|
|
239
239
|
this.liberarRegistrador(reg);
|
|
@@ -250,35 +250,35 @@ ${entryLabel}:`;
|
|
|
250
250
|
if (index < registrosArgs.length) {
|
|
251
251
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
252
252
|
if (valorArg !== registrosArgs[index]) {
|
|
253
|
-
this.text += `
|
|
253
|
+
this.text += `
|
|
254
254
|
ldr ${registrosArgs[index]}, =${valorArg}`;
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
else {
|
|
258
258
|
// Push extra args on stack
|
|
259
259
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
260
|
-
this.text += `
|
|
261
|
-
ldr r0, =${valorArg}
|
|
260
|
+
this.text += `
|
|
261
|
+
ldr r0, =${valorArg}
|
|
262
262
|
push {r0}`;
|
|
263
263
|
}
|
|
264
264
|
});
|
|
265
|
-
this.text += `
|
|
265
|
+
this.text += `
|
|
266
266
|
bl ${nomeFuncao}`;
|
|
267
267
|
}
|
|
268
268
|
traduzirConstrutoDefinirValor(construto) {
|
|
269
269
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
270
270
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
271
|
-
this.text += `
|
|
272
|
-
ldr r0, =${valor}
|
|
273
|
-
ldr r1, =${objeto}
|
|
271
|
+
this.text += `
|
|
272
|
+
ldr r0, =${valor}
|
|
273
|
+
ldr r1, =${objeto}
|
|
274
274
|
str r0, [r1]`;
|
|
275
275
|
}
|
|
276
276
|
traduzirFuncaoConstruto(construto) {
|
|
277
277
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
278
|
-
this.text += `
|
|
279
|
-
|
|
280
|
-
${labelFuncao}:
|
|
281
|
-
push {fp, lr}
|
|
278
|
+
this.text += `
|
|
279
|
+
|
|
280
|
+
${labelFuncao}:
|
|
281
|
+
push {fp, lr}
|
|
282
282
|
mov fp, sp`;
|
|
283
283
|
// Traduzir corpo da função
|
|
284
284
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -288,8 +288,8 @@ ${labelFuncao}:
|
|
|
288
288
|
}
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
this.text += `
|
|
292
|
-
mov sp, fp
|
|
291
|
+
this.text += `
|
|
292
|
+
mov sp, fp
|
|
293
293
|
pop {fp, pc}`;
|
|
294
294
|
}
|
|
295
295
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -304,29 +304,29 @@ ${labelFuncao}:
|
|
|
304
304
|
const operador = construto.operador.lexema;
|
|
305
305
|
const labelVerdadeiro = this.gerarLabel();
|
|
306
306
|
const labelFim = this.gerarLabel();
|
|
307
|
-
this.text += `
|
|
308
|
-
ldr r0, =${esquerda}
|
|
307
|
+
this.text += `
|
|
308
|
+
ldr r0, =${esquerda}
|
|
309
309
|
cmp r0, #0`;
|
|
310
310
|
if (operador === 'e' || operador === '&&') {
|
|
311
|
-
this.text += `
|
|
312
|
-
beq ${labelFim}
|
|
313
|
-
ldr r0, =${direita}
|
|
314
|
-
cmp r0, #0
|
|
315
|
-
beq ${labelFim}
|
|
316
|
-
${labelVerdadeiro}:
|
|
317
|
-
mov r0, #1
|
|
311
|
+
this.text += `
|
|
312
|
+
beq ${labelFim}
|
|
313
|
+
ldr r0, =${direita}
|
|
314
|
+
cmp r0, #0
|
|
315
|
+
beq ${labelFim}
|
|
316
|
+
${labelVerdadeiro}:
|
|
317
|
+
mov r0, #1
|
|
318
318
|
${labelFim}:`;
|
|
319
319
|
}
|
|
320
320
|
else if (operador === 'ou' || operador === '||') {
|
|
321
|
-
this.text += `
|
|
322
|
-
bne ${labelVerdadeiro}
|
|
323
|
-
ldr r0, =${direita}
|
|
324
|
-
cmp r0, #0
|
|
325
|
-
bne ${labelVerdadeiro}
|
|
326
|
-
mov r0, #0
|
|
327
|
-
b ${labelFim}
|
|
328
|
-
${labelVerdadeiro}:
|
|
329
|
-
mov r0, #1
|
|
321
|
+
this.text += `
|
|
322
|
+
bne ${labelVerdadeiro}
|
|
323
|
+
ldr r0, =${direita}
|
|
324
|
+
cmp r0, #0
|
|
325
|
+
bne ${labelVerdadeiro}
|
|
326
|
+
mov r0, #0
|
|
327
|
+
b ${labelFim}
|
|
328
|
+
${labelVerdadeiro}:
|
|
329
|
+
mov r0, #1
|
|
330
330
|
${labelFim}:`;
|
|
331
331
|
}
|
|
332
332
|
return 'r0';
|
|
@@ -338,16 +338,16 @@ ${labelFim}:`;
|
|
|
338
338
|
traduzirConstrutoUnario(construto) {
|
|
339
339
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
340
340
|
const operador = construto.operador.lexema;
|
|
341
|
-
this.text += `
|
|
341
|
+
this.text += `
|
|
342
342
|
ldr r0, =${operando}`;
|
|
343
343
|
if (operador === '-') {
|
|
344
|
-
this.text += `
|
|
344
|
+
this.text += `
|
|
345
345
|
neg r0, r0`;
|
|
346
346
|
}
|
|
347
347
|
else if (operador === '!' || operador === 'nao') {
|
|
348
|
-
this.text += `
|
|
349
|
-
cmp r0, #0
|
|
350
|
-
moveq r0, #1
|
|
348
|
+
this.text += `
|
|
349
|
+
cmp r0, #0
|
|
350
|
+
moveq r0, #1
|
|
351
351
|
movne r0, #0`;
|
|
352
352
|
}
|
|
353
353
|
return 'r0';
|
|
@@ -356,8 +356,8 @@ ${labelFim}:`;
|
|
|
356
356
|
const nomeVar = construto.simbolo?.lexema;
|
|
357
357
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
358
358
|
const varLabel = this.variaveis.get(nomeVar);
|
|
359
|
-
this.text += `
|
|
360
|
-
ldr r0, =${varLabel}
|
|
359
|
+
this.text += `
|
|
360
|
+
ldr r0, =${varLabel}
|
|
361
361
|
ldr r0, [r0]`;
|
|
362
362
|
return 'r0';
|
|
363
363
|
}
|
|
@@ -371,9 +371,9 @@ ${labelFim}:`;
|
|
|
371
371
|
construto.valores.forEach((valor, index) => {
|
|
372
372
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
373
373
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
374
|
-
this.text += `
|
|
375
|
-
ldr r0, =${valorTraduzido}
|
|
376
|
-
ldr r1, =${labelVetor}
|
|
374
|
+
this.text += `
|
|
375
|
+
ldr r0, =${valorTraduzido}
|
|
376
|
+
ldr r1, =${labelVetor}
|
|
377
377
|
str r0, [r1, #${index * 4}]`;
|
|
378
378
|
}
|
|
379
379
|
});
|
|
@@ -393,17 +393,17 @@ ${labelFim}:`;
|
|
|
393
393
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
394
394
|
const labelInicio = this.gerarLabel();
|
|
395
395
|
const labelFim = this.gerarLabel();
|
|
396
|
-
this.text += `
|
|
396
|
+
this.text += `
|
|
397
397
|
${labelInicio}:`;
|
|
398
398
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
399
|
-
this.text += `
|
|
400
|
-
cmp ${condicao}, #0
|
|
399
|
+
this.text += `
|
|
400
|
+
cmp ${condicao}, #0
|
|
401
401
|
beq ${labelFim}`;
|
|
402
402
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
403
403
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
404
404
|
}
|
|
405
|
-
this.text += `
|
|
406
|
-
b ${labelInicio}
|
|
405
|
+
this.text += `
|
|
406
|
+
b ${labelInicio}
|
|
407
407
|
${labelFim}:`;
|
|
408
408
|
}
|
|
409
409
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -414,10 +414,10 @@ ${labelFim}:`;
|
|
|
414
414
|
const labelProximo = this.gerarLabel();
|
|
415
415
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
416
416
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
417
|
-
this.text += `
|
|
418
|
-
ldr r0, =${valorEscolha}
|
|
419
|
-
ldr r1, =${valorCaso}
|
|
420
|
-
cmp r0, r1
|
|
417
|
+
this.text += `
|
|
418
|
+
ldr r0, =${valorEscolha}
|
|
419
|
+
ldr r1, =${valorCaso}
|
|
420
|
+
cmp r0, r1
|
|
421
421
|
bne ${labelProximo}`;
|
|
422
422
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
423
423
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -426,13 +426,13 @@ ${labelFim}:`;
|
|
|
426
426
|
}
|
|
427
427
|
});
|
|
428
428
|
}
|
|
429
|
-
this.text += `
|
|
430
|
-
b ${labelFim}
|
|
429
|
+
this.text += `
|
|
430
|
+
b ${labelFim}
|
|
431
431
|
${labelProximo}:`;
|
|
432
432
|
}
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
|
-
this.text += `
|
|
435
|
+
this.text += `
|
|
436
436
|
${labelFim}:`;
|
|
437
437
|
}
|
|
438
438
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
@@ -443,7 +443,7 @@ ${labelFim}:`;
|
|
|
443
443
|
}
|
|
444
444
|
traduzirDeclaracaoFazer(declaracao) {
|
|
445
445
|
const labelInicio = this.gerarLabel();
|
|
446
|
-
this.text += `
|
|
446
|
+
this.text += `
|
|
447
447
|
${labelInicio}:`;
|
|
448
448
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
449
449
|
declaracao.caminhoFazer.declaracoes.forEach((decl) => {
|
|
@@ -454,8 +454,8 @@ ${labelInicio}:`;
|
|
|
454
454
|
}
|
|
455
455
|
if (declaracao.condicaoEnquanto) {
|
|
456
456
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
457
|
-
this.text += `
|
|
458
|
-
cmp ${condicao}, #0
|
|
457
|
+
this.text += `
|
|
458
|
+
cmp ${condicao}, #0
|
|
459
459
|
bne ${labelInicio}`;
|
|
460
460
|
}
|
|
461
461
|
}
|
|
@@ -469,18 +469,18 @@ ${labelInicio}:`;
|
|
|
469
469
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
this.text += `
|
|
473
|
-
@ Falhar com mensagem: ${mensagem}
|
|
474
|
-
mov r0, #1
|
|
475
|
-
mov r7, #1 @ sys_exit
|
|
472
|
+
this.text += `
|
|
473
|
+
@ Falhar com mensagem: ${mensagem}
|
|
474
|
+
mov r0, #1
|
|
475
|
+
mov r7, #1 @ sys_exit
|
|
476
476
|
swi 0`;
|
|
477
477
|
}
|
|
478
478
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
479
479
|
const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
|
|
480
|
-
this.text += `
|
|
481
|
-
|
|
482
|
-
${nomeFuncao}:
|
|
483
|
-
push {fp, lr}
|
|
480
|
+
this.text += `
|
|
481
|
+
|
|
482
|
+
${nomeFuncao}:
|
|
483
|
+
push {fp, lr}
|
|
484
484
|
mov fp, sp`;
|
|
485
485
|
if (declaracao.funcao &&
|
|
486
486
|
declaracao.funcao.corpo &&
|
|
@@ -491,12 +491,12 @@ ${nomeFuncao}:
|
|
|
491
491
|
}
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
|
-
this.text += `
|
|
495
|
-
mov sp, fp
|
|
494
|
+
this.text += `
|
|
495
|
+
mov sp, fp
|
|
496
496
|
pop {fp, pc}`;
|
|
497
497
|
}
|
|
498
498
|
traduzirDeclaracaoImportar(declaracao) {
|
|
499
|
-
this.text += `
|
|
499
|
+
this.text += `
|
|
500
500
|
@ Importar: ${declaracao.caminho || 'unknown'}`;
|
|
501
501
|
}
|
|
502
502
|
traduzirDeclaracaoLeia(declaracao) {
|
|
@@ -513,11 +513,11 @@ ${nomeFuncao}:
|
|
|
513
513
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
514
514
|
this.variaveis.set(nomeVar, varLabel);
|
|
515
515
|
}
|
|
516
|
-
this.text += `
|
|
517
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
518
|
-
mov r2, #256
|
|
519
|
-
mov r0, #0 @ stdin
|
|
520
|
-
mov r7, #3 @ sys_read
|
|
516
|
+
this.text += `
|
|
517
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
518
|
+
mov r2, #256
|
|
519
|
+
mov r0, #0 @ stdin
|
|
520
|
+
mov r7, #3 @ sys_read
|
|
521
521
|
swi 0`;
|
|
522
522
|
}
|
|
523
523
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -532,12 +532,12 @@ ${nomeFuncao}:
|
|
|
532
532
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
|
-
this.text += `
|
|
535
|
+
this.text += `
|
|
536
536
|
${labelInicio}:`;
|
|
537
537
|
if (declaracao.condicao) {
|
|
538
538
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
539
|
-
this.text += `
|
|
540
|
-
cmp ${condicao}, #0
|
|
539
|
+
this.text += `
|
|
540
|
+
cmp ${condicao}, #0
|
|
541
541
|
beq ${labelFim}`;
|
|
542
542
|
}
|
|
543
543
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -548,8 +548,8 @@ ${labelInicio}:`;
|
|
|
548
548
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
|
-
this.text += `
|
|
552
|
-
b ${labelInicio}
|
|
551
|
+
this.text += `
|
|
552
|
+
b ${labelInicio}
|
|
553
553
|
${labelFim}:`;
|
|
554
554
|
}
|
|
555
555
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -564,55 +564,55 @@ ${labelFim}:`;
|
|
|
564
564
|
if (vetor instanceof construtos_1.Vetor) {
|
|
565
565
|
tamanhoVetor = vetor.tamanho || 0;
|
|
566
566
|
}
|
|
567
|
-
this.text += `
|
|
568
|
-
mov r4, #0 @ counter
|
|
569
|
-
${labelInicio}:
|
|
570
|
-
cmp r4, #${tamanhoVetor}
|
|
567
|
+
this.text += `
|
|
568
|
+
mov r4, #0 @ counter
|
|
569
|
+
${labelInicio}:
|
|
570
|
+
cmp r4, #${tamanhoVetor}
|
|
571
571
|
bge ${labelFim}`;
|
|
572
572
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
573
573
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
574
574
|
}
|
|
575
|
-
this.text += `
|
|
576
|
-
add r4, r4, #1
|
|
577
|
-
b ${labelInicio}
|
|
575
|
+
this.text += `
|
|
576
|
+
add r4, r4, #1
|
|
577
|
+
b ${labelInicio}
|
|
578
578
|
${labelFim}:`;
|
|
579
579
|
}
|
|
580
580
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
581
581
|
if (declaracao.valor) {
|
|
582
582
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
583
|
-
this.text += `
|
|
583
|
+
this.text += `
|
|
584
584
|
ldr r0, =${valor}`;
|
|
585
585
|
}
|
|
586
|
-
this.text += `
|
|
587
|
-
mov sp, fp
|
|
586
|
+
this.text += `
|
|
587
|
+
mov sp, fp
|
|
588
588
|
pop {fp, pc}`;
|
|
589
589
|
}
|
|
590
590
|
traduzirDeclaracaoSe(declaracao) {
|
|
591
591
|
const labelSenao = this.gerarLabel();
|
|
592
592
|
const labelFim = this.gerarLabel();
|
|
593
593
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
594
|
-
this.text += `
|
|
595
|
-
cmp ${condicao}, #0
|
|
594
|
+
this.text += `
|
|
595
|
+
cmp ${condicao}, #0
|
|
596
596
|
beq ${labelSenao}`;
|
|
597
597
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
598
598
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
599
599
|
}
|
|
600
|
-
this.text += `
|
|
601
|
-
b ${labelFim}
|
|
600
|
+
this.text += `
|
|
601
|
+
b ${labelFim}
|
|
602
602
|
${labelSenao}:`;
|
|
603
603
|
if (declaracao.caminhoSenao &&
|
|
604
604
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
605
605
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
606
606
|
}
|
|
607
|
-
this.text += `
|
|
607
|
+
this.text += `
|
|
608
608
|
${labelFim}:`;
|
|
609
609
|
}
|
|
610
610
|
traduzirDeclaracaoClasse(declaracao) {
|
|
611
|
-
this.text += `
|
|
611
|
+
this.text += `
|
|
612
612
|
@ Classe: ${declaracao.simbolo?.lexema || 'unknown'}`;
|
|
613
613
|
}
|
|
614
614
|
traduzirDeclaracaoTente(declaracao) {
|
|
615
|
-
this.text += `
|
|
615
|
+
this.text += `
|
|
616
616
|
@ Tente-pegue`;
|
|
617
617
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
618
618
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -649,9 +649,9 @@ ${labelFim}:`;
|
|
|
649
649
|
}
|
|
650
650
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
651
651
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
652
|
-
this.text += `
|
|
653
|
-
ldr r0, =${valor}
|
|
654
|
-
ldr r1, =${varLabel}
|
|
652
|
+
this.text += `
|
|
653
|
+
ldr r0, =${valor}
|
|
654
|
+
ldr r1, =${varLabel}
|
|
655
655
|
str r0, [r1]`;
|
|
656
656
|
}
|
|
657
657
|
}
|
|
@@ -678,20 +678,20 @@ ${labelFim}:`;
|
|
|
678
678
|
// Para ambos linux-arm e android, continuamos usando a convenção
|
|
679
679
|
// de syscall Linux ARM (write). Em Android típico, esse binário
|
|
680
680
|
// seria executado via adb/Termux, onde essa convenção ainda é válida.
|
|
681
|
-
this.text += `
|
|
682
|
-
ldr r1, =${nome_string_literal}
|
|
683
|
-
mov r2, #${tam_string_literal}
|
|
684
|
-
mov r0, #1 @ fd stdout
|
|
685
|
-
mov r7, #4 @ sys_write
|
|
681
|
+
this.text += `
|
|
682
|
+
ldr r1, =${nome_string_literal}
|
|
683
|
+
mov r2, #${tam_string_literal}
|
|
684
|
+
mov r0, #1 @ fd stdout
|
|
685
|
+
mov r7, #4 @ sys_write
|
|
686
686
|
swi 0`;
|
|
687
687
|
}
|
|
688
688
|
saidaSistema() {
|
|
689
689
|
// Mesmo comentário da função Escreva: usamos sys_exit Linux.
|
|
690
690
|
// Em um futuro modo Android "NDK/JNI", esta função deveria
|
|
691
691
|
// apenas retornar ao chamador em vez de fazer syscall direta.
|
|
692
|
-
this.text += `
|
|
693
|
-
mov r0, #1 @ exit status
|
|
694
|
-
mov r7, #1 @ sys_exit
|
|
692
|
+
this.text += `
|
|
693
|
+
mov r0, #1 @ exit status
|
|
694
|
+
mov r7, #1 @ sys_exit
|
|
695
695
|
swi 0`;
|
|
696
696
|
}
|
|
697
697
|
traduzir(declaracoes) {
|