@designliquido/delegua 1.20.1 → 1.21.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.
Files changed (25) hide show
  1. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +1 -0
  2. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
  3. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +46 -40
  4. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
  5. package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts +117 -141
  6. package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -1
  7. package/bibliotecas/dialetos/pitugues/biblioteca-global.js +723 -610
  8. package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -1
  9. package/bibliotecas/dialetos/pitugues/primitivas-vetor.d.ts.map +1 -1
  10. package/bibliotecas/dialetos/pitugues/primitivas-vetor.js +21 -0
  11. package/bibliotecas/dialetos/pitugues/primitivas-vetor.js.map +1 -1
  12. package/bin/package.json +1 -1
  13. package/interpretador/depuracao/interpretador-base-com-depuracao.d.ts.map +1 -1
  14. package/interpretador/depuracao/interpretador-base-com-depuracao.js +12 -1
  15. package/interpretador/depuracao/interpretador-base-com-depuracao.js.map +1 -1
  16. package/lexador/dialetos/palavras-reservadas/pitugues.d.ts +0 -2
  17. package/lexador/dialetos/palavras-reservadas/pitugues.d.ts.map +1 -1
  18. package/lexador/dialetos/palavras-reservadas/pitugues.js +0 -2
  19. package/lexador/dialetos/palavras-reservadas/pitugues.js.map +1 -1
  20. package/package.json +1 -1
  21. package/tradutores/tradutor-assembly-arm.js +151 -151
  22. package/tradutores/tradutor-assembly-risc-v.js +85 -85
  23. package/tradutores/tradutor-assembly-x64.js +176 -176
  24. package/tradutores/tradutor-webassembly.js +29 -29
  25. package/umd/delegua.js +487 -483
package/umd/delegua.js CHANGED
@@ -6692,6 +6692,11 @@ class AvaliadorSintaticoPitugues {
6692
6692
  };
6693
6693
  return '"' + conteudoOriginal.replace(/\{(.*?)\}/g, processarParte) + '"';
6694
6694
  }
6695
+ ignorarComentarios() {
6696
+ while (this.verificarTipoSimboloAtual(pitugues_2.default.COMENTARIO)) {
6697
+ this.avancarEDevolverAnterior();
6698
+ }
6699
+ }
6695
6700
  async primario() {
6696
6701
  const simboloAtual = this.simbolos[this.atual];
6697
6702
  switch (simboloAtual.tipo) {
@@ -6726,6 +6731,7 @@ class AvaliadorSintaticoPitugues {
6726
6731
  return new construtos_1.Dicionario(this.hashArquivo, simboloAtual.linha, chaves, valoresDicionario, esSpread);
6727
6732
  case pitugues_2.default.COLCHETE_ESQUERDO:
6728
6733
  this.avancarEDevolverAnterior();
6734
+ this.ignorarComentarios();
6729
6735
  if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.COLCHETE_DIREITO)) {
6730
6736
  return new construtos_1.Vetor(this.hashArquivo, simboloAtual.linha, [], 'qualquer[]');
6731
6737
  }
@@ -6740,11 +6746,10 @@ class AvaliadorSintaticoPitugues {
6740
6746
  // Aqui já sabemos que não é uma compreensão de lista.
6741
6747
  const valoresVetor = [retornoExpressaoOuPrimeiroValor];
6742
6748
  while (!this.verificarSeSimboloAtualEIgualA(pitugues_2.default.COLCHETE_DIREITO)) {
6743
- if (this.simbolos[this.atual].tipo !== pitugues_2.default.COLCHETE_DIREITO) {
6744
- this.consumir(pitugues_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
6745
- }
6746
- const valor = await this.atribuir();
6747
- valoresVetor.push(valor);
6749
+ this.consumir(pitugues_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
6750
+ this.ignorarComentarios();
6751
+ valoresVetor.push(await this.atribuir());
6752
+ this.ignorarComentarios();
6748
6753
  }
6749
6754
  const tipoVetor = (0, inferenciador_1.inferirTipoVariavel)(valoresVetor);
6750
6755
  return new construtos_1.Vetor(this.hashArquivo, simboloAtual.linha, valoresVetor, tipoVetor);
@@ -7880,86 +7885,87 @@ class AvaliadorSintaticoPitugues {
7880
7885
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('maximo', 'número'),
7881
7886
  ]));
7882
7887
  this.pilhaEscopos.definirInformacoesVariavel('algum', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('algum', 'lógico', true, [
7883
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7888
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iterável', 'qualquer'),
7884
7889
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoPesquisa', 'função'),
7885
7890
  ]));
7886
- this.pilhaEscopos.definirInformacoesVariavel('arredondar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('arredondar', 'numero', true, [
7887
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('numero', 'numero'),
7888
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('casasDecimais', 'numero'),
7891
+ this.pilhaEscopos.definirInformacoesVariavel('combinar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('combinar', 'qualquer', true, [
7892
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7893
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7894
+ ]));
7895
+ this.pilhaEscopos.definirInformacoesVariavel('contar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('contar', 'qualquer', true, [
7896
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7897
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer'),
7889
7898
  ]));
7890
7899
  this.pilhaEscopos.definirInformacoesVariavel('encontrar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('encontrar', 'qualquer', true, [
7891
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7900
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7892
7901
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoPesquisa', 'função'),
7893
7902
  ]));
7894
7903
  this.pilhaEscopos.definirInformacoesVariavel('encontrar_indice', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('encontrar_indice', 'inteiro', true, [
7895
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7904
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7896
7905
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoPesquisa', 'função'),
7897
7906
  ]));
7898
7907
  this.pilhaEscopos.definirInformacoesVariavel('encontrar_ultimo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('encontrar_ultimo', 'inteiro', true, [
7899
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7908
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7900
7909
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoPesquisa', 'função'),
7901
7910
  ]));
7902
7911
  this.pilhaEscopos.definirInformacoesVariavel('encontrar_ultimo_indice', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('encontrar_ultimo_indice', 'inteiro', true, [
7903
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7912
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7904
7913
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoPesquisa', 'função'),
7905
7914
  ]));
7915
+ this.pilhaEscopos.definirInformacoesVariavel('enumerar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('intervalo', 'dicionario', true, [
7916
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7917
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inicio', 'numero', false),
7918
+ ]));
7906
7919
  this.pilhaEscopos.definirInformacoesVariavel('filtrar_por', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('filtrar_por', 'qualquer[]', true, [
7907
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7920
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7908
7921
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoFiltragem', 'função'),
7909
7922
  ]));
7910
7923
  this.pilhaEscopos.definirInformacoesVariavel('incluido', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('incluido', 'lógico', true, [
7911
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7924
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer]'),
7912
7925
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
7913
7926
  ]));
7914
7927
  this.pilhaEscopos.definirInformacoesVariavel('inteiro', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inteiro', 'inteiro', true, [
7915
7928
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
7916
7929
  ]));
7917
- this.pilhaEscopos.definirInformacoesVariavel('longo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('longo', 'longo', true, [
7918
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
7919
- ]));
7920
7930
  this.pilhaEscopos.definirInformacoesVariavel('intervalo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('intervalo', 'inteiro[]', true, [
7921
7931
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorInicial', 'qualquer'),
7922
7932
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorFinal', 'qualquer', false),
7923
7933
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorPasso', 'qualquer', false),
7924
7934
  ]));
7935
+ this.pilhaEscopos.definirInformacoesVariavel('inverter', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inverter', 'qualquer', true, [
7936
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7937
+ ]));
7938
+ this.pilhaEscopos.definirInformacoesVariavel('longo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('longo', 'longo', true, [
7939
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
7940
+ ]));
7925
7941
  this.pilhaEscopos.definirInformacoesVariavel('mapear', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('mapear', 'qualquer[]', true, [
7926
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7942
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7927
7943
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoMapeamento', 'função'),
7928
7944
  ]));
7929
7945
  this.pilhaEscopos.definirInformacoesVariavel('maximo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('maximo', 'número', true, [
7930
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7946
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7931
7947
  ]));
7932
7948
  this.pilhaEscopos.definirInformacoesVariavel('minimo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('minimo', 'número', true, [
7933
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7934
- ]));
7935
- this.pilhaEscopos.definirInformacoesVariavel('numero', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('número', 'número', true, [
7936
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
7937
- ]));
7938
- this.pilhaEscopos.definirInformacoesVariavel('número', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('número', 'número', true, [
7939
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
7949
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7940
7950
  ]));
7941
7951
  this.pilhaEscopos.definirInformacoesVariavel('ordenar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('ordenar', 'qualquer[]', true, [
7942
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7952
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7943
7953
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoOrdenacao', 'função'),
7944
7954
  ]));
7945
7955
  this.pilhaEscopos.definirInformacoesVariavel('para_cada', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('para_cada', 'qualquer[]', true, [
7946
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7947
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoFiltragem', 'função'),
7948
- ]));
7949
- this.pilhaEscopos.definirInformacoesVariavel('primeiro_em_condicao', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('primeiro_em_condicao', 'qualquer', true, [
7950
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7956
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7951
7957
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoFiltragem', 'função'),
7952
7958
  ]));
7953
7959
  this.pilhaEscopos.definirInformacoesVariavel('real', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('real', 'número', true, [
7954
7960
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
7955
7961
  ]));
7956
7962
  this.pilhaEscopos.definirInformacoesVariavel('reduzir', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('reduzir', 'qualquer', true, [
7957
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7963
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7958
7964
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoReducao', 'função'),
7959
7965
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorInicial', 'qualquer'),
7960
7966
  ]));
7961
7967
  this.pilhaEscopos.definirInformacoesVariavel('somar', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('somar', 'número', true, [
7962
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7968
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7963
7969
  ]));
7964
7970
  this.pilhaEscopos.definirInformacoesVariavel('tamanho', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tamanho', 'inteiro', true, [
7965
7971
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('objeto', 'qualquer'),
@@ -7972,16 +7978,16 @@ class AvaliadorSintaticoPitugues {
7972
7978
  ]));
7973
7979
  this.pilhaEscopos.definirInformacoesVariavel('todos', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todos', 'lógico', true, [
7974
7980
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7975
- ]));
7976
- this.pilhaEscopos.definirInformacoesVariavel('todos_em_condicao', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todos_em_condicao', 'lógico', true, [
7977
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7978
7981
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoCondicional', 'função'),
7979
7982
  ]));
7980
7983
  this.pilhaEscopos.definirInformacoesVariavel('tupla', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tupla', 'tupla', true, [
7981
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
7984
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7985
+ ]));
7986
+ this.pilhaEscopos.definirInformacoesVariavel('unico', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('unico', 'qualquer[]', true, [
7987
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7982
7988
  ]));
7983
7989
  this.pilhaEscopos.definirInformacoesVariavel('vetor', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'vetor', true, [
7984
- new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tupla', 'qualquer'),
7990
+ new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
7985
7991
  ]));
7986
7992
  }
7987
7993
  async analisar(retornoLexador, hashArquivo) {
@@ -27870,8 +27876,6 @@ exports.palavrasReservadasPitugues = {
27870
27876
  classe: pitugues_1.default.CLASSE,
27871
27877
  como: pitugues_1.default.COMO,
27872
27878
  construtor: pitugues_1.default.CONSTRUTOR,
27873
- contem: pitugues_1.default.CONTEM,
27874
- contém: pitugues_1.default.CONTEM,
27875
27879
  continua: pitugues_1.default.CONTINUA,
27876
27880
  de: pitugues_1.default.DE,
27877
27881
  e: pitugues_1.default.E,
@@ -43313,10 +43317,10 @@ class TradutorAssemblyARM {
43313
43317
  // Para android: ainda é um binário standalone, mas com rótulo Delegua_main
43314
43318
  // para deixar claro que não é o _start do CRT padrão.
43315
43319
  const entryLabel = this.alvo === 'android' ? 'Delegua_main' : '_start';
43316
- this.text = `
43317
- .text
43318
- .global ${entryLabel}
43319
-
43320
+ this.text = `
43321
+ .text
43322
+ .global ${entryLabel}
43323
+
43320
43324
  ${entryLabel}:`;
43321
43325
  }
43322
43326
  gerarDigitoAleatorio() {
@@ -43357,11 +43361,11 @@ ${entryLabel}:`;
43357
43361
  }
43358
43362
  const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
43359
43363
  const reg = this.obterRegistrador();
43360
- this.text += `
43361
- ldr ${reg}, =${nomeVar}
43362
- ldr r0, =${indice}
43363
- lsl r0, r0, #2 @ multiply index by 4 (word size)
43364
- add ${reg}, ${reg}, r0
43364
+ this.text += `
43365
+ ldr ${reg}, =${nomeVar}
43366
+ ldr r0, =${indice}
43367
+ lsl r0, r0, #2 @ multiply index by 4 (word size)
43368
+ add ${reg}, ${reg}, r0
43365
43369
  ldr r0, [${reg}]`;
43366
43370
  this.liberarRegistrador(reg);
43367
43371
  return 'r0';
@@ -43384,12 +43388,12 @@ ${entryLabel}:`;
43384
43388
  const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
43385
43389
  const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
43386
43390
  const reg = this.obterRegistrador();
43387
- this.text += `
43388
- ldr ${reg}, =${nomeVar}
43389
- ldr r1, =${indice}
43390
- lsl r1, r1, #2 @ multiply by 4
43391
- add ${reg}, ${reg}, r1
43392
- ldr r1, =${valor}
43391
+ this.text += `
43392
+ ldr ${reg}, =${nomeVar}
43393
+ ldr r1, =${indice}
43394
+ lsl r1, r1, #2 @ multiply by 4
43395
+ add ${reg}, ${reg}, r1
43396
+ ldr r1, =${valor}
43393
43397
  str r1, [${reg}]`;
43394
43398
  this.liberarRegistrador(reg);
43395
43399
  }
@@ -43407,9 +43411,9 @@ ${entryLabel}:`;
43407
43411
  this.bss += ` ${varLabel}: .space 4\n`;
43408
43412
  this.variaveis.set(nomeVar, varLabel);
43409
43413
  }
43410
- this.text += `
43411
- ldr r0, =${valor}
43412
- ldr r1, =${this.variaveis.get(nomeVar)}
43414
+ this.text += `
43415
+ ldr r0, =${valor}
43416
+ ldr r1, =${this.variaveis.get(nomeVar)}
43413
43417
  str r0, [r1]`;
43414
43418
  }
43415
43419
  traduzirConstrutoBinario(construto) {
@@ -43419,75 +43423,75 @@ ${entryLabel}:`;
43419
43423
  const reg = this.obterRegistrador();
43420
43424
  // Load left operand into r0
43421
43425
  if (esquerda !== 'r0') {
43422
- this.text += `
43426
+ this.text += `
43423
43427
  ldr r0, =${esquerda}`;
43424
43428
  }
43425
43429
  // Load right operand into reg
43426
- this.text += `
43430
+ this.text += `
43427
43431
  ldr ${reg}, =${direita}`;
43428
43432
  switch (operador) {
43429
43433
  case '+':
43430
- this.text += `
43434
+ this.text += `
43431
43435
  add r0, r0, ${reg}`;
43432
43436
  break;
43433
43437
  case '-':
43434
- this.text += `
43438
+ this.text += `
43435
43439
  sub r0, r0, ${reg}`;
43436
43440
  break;
43437
43441
  case '*':
43438
- this.text += `
43442
+ this.text += `
43439
43443
  mul r0, r0, ${reg}`;
43440
43444
  break;
43441
43445
  case '/':
43442
- this.text += `
43446
+ this.text += `
43443
43447
  sdiv r0, r0, ${reg}`;
43444
43448
  break;
43445
43449
  case '%':
43446
- this.text += `
43447
- sdiv r1, r0, ${reg}
43448
- mul r1, r1, ${reg}
43450
+ this.text += `
43451
+ sdiv r1, r0, ${reg}
43452
+ mul r1, r1, ${reg}
43449
43453
  sub r0, r0, r1 @ r0 = r0 - (r0/reg)*reg`;
43450
43454
  break;
43451
43455
  case '<':
43452
- this.text += `
43453
- cmp r0, ${reg}
43454
- movlt r0, #1
43456
+ this.text += `
43457
+ cmp r0, ${reg}
43458
+ movlt r0, #1
43455
43459
  movge r0, #0`;
43456
43460
  break;
43457
43461
  case '>':
43458
- this.text += `
43459
- cmp r0, ${reg}
43460
- movgt r0, #1
43462
+ this.text += `
43463
+ cmp r0, ${reg}
43464
+ movgt r0, #1
43461
43465
  movle r0, #0`;
43462
43466
  break;
43463
43467
  case '<=':
43464
- this.text += `
43465
- cmp r0, ${reg}
43466
- movle r0, #1
43468
+ this.text += `
43469
+ cmp r0, ${reg}
43470
+ movle r0, #1
43467
43471
  movgt r0, #0`;
43468
43472
  break;
43469
43473
  case '>=':
43470
- this.text += `
43471
- cmp r0, ${reg}
43472
- movge r0, #1
43474
+ this.text += `
43475
+ cmp r0, ${reg}
43476
+ movge r0, #1
43473
43477
  movlt r0, #0`;
43474
43478
  break;
43475
43479
  case '==':
43476
43480
  case '===':
43477
- this.text += `
43478
- cmp r0, ${reg}
43479
- moveq r0, #1
43481
+ this.text += `
43482
+ cmp r0, ${reg}
43483
+ moveq r0, #1
43480
43484
  movne r0, #0`;
43481
43485
  break;
43482
43486
  case '!=':
43483
43487
  case '!==':
43484
- this.text += `
43485
- cmp r0, ${reg}
43486
- movne r0, #1
43488
+ this.text += `
43489
+ cmp r0, ${reg}
43490
+ movne r0, #1
43487
43491
  moveq r0, #0`;
43488
43492
  break;
43489
43493
  default:
43490
- this.text += `
43494
+ this.text += `
43491
43495
  @ Operador ${operador} não implementado`;
43492
43496
  }
43493
43497
  this.liberarRegistrador(reg);
@@ -43504,35 +43508,35 @@ ${entryLabel}:`;
43504
43508
  if (indice < registrosArgs.length) {
43505
43509
  const valorArg = this.dicionarioConstrutos[argumento.constructor.name](argumento);
43506
43510
  if (valorArg !== registrosArgs[indice]) {
43507
- this.text += `
43511
+ this.text += `
43508
43512
  ldr ${registrosArgs[indice]}, =${valorArg}`;
43509
43513
  }
43510
43514
  }
43511
43515
  else {
43512
43516
  // Push extra args on stack
43513
43517
  const valorArg = this.dicionarioConstrutos[argumento.constructor.name](argumento);
43514
- this.text += `
43515
- ldr r0, =${valorArg}
43518
+ this.text += `
43519
+ ldr r0, =${valorArg}
43516
43520
  push {r0}`;
43517
43521
  }
43518
43522
  });
43519
- this.text += `
43523
+ this.text += `
43520
43524
  bl ${nomeFuncao}`;
43521
43525
  }
43522
43526
  traduzirConstrutoDefinirValor(construto) {
43523
43527
  const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
43524
43528
  const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
43525
- this.text += `
43526
- ldr r0, =${valor}
43527
- ldr r1, =${objeto}
43529
+ this.text += `
43530
+ ldr r0, =${valor}
43531
+ ldr r1, =${objeto}
43528
43532
  str r0, [r1]`;
43529
43533
  }
43530
43534
  traduzirFuncaoConstruto(construto) {
43531
43535
  const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
43532
- this.text += `
43533
-
43534
- ${labelFuncao}:
43535
- push {fp, lr}
43536
+ this.text += `
43537
+
43538
+ ${labelFuncao}:
43539
+ push {fp, lr}
43536
43540
  mov fp, sp`;
43537
43541
  // Traduzir corpo da função
43538
43542
  if (construto.corpo && Array.isArray(construto.corpo)) {
@@ -43542,8 +43546,8 @@ ${labelFuncao}:
43542
43546
  }
43543
43547
  });
43544
43548
  }
43545
- this.text += `
43546
- mov sp, fp
43549
+ this.text += `
43550
+ mov sp, fp
43547
43551
  pop {fp, pc}`;
43548
43552
  }
43549
43553
  traduzirConstrutoLiteral(construto) {
@@ -43558,29 +43562,29 @@ ${labelFuncao}:
43558
43562
  const operador = construto.operador.lexema;
43559
43563
  const labelVerdadeiro = this.gerarLabel();
43560
43564
  const labelFim = this.gerarLabel();
43561
- this.text += `
43562
- ldr r0, =${esquerda}
43565
+ this.text += `
43566
+ ldr r0, =${esquerda}
43563
43567
  cmp r0, #0`;
43564
43568
  if (operador === 'e' || operador === '&&') {
43565
- this.text += `
43566
- beq ${labelFim}
43567
- ldr r0, =${direita}
43568
- cmp r0, #0
43569
- beq ${labelFim}
43570
- ${labelVerdadeiro}:
43571
- mov r0, #1
43569
+ this.text += `
43570
+ beq ${labelFim}
43571
+ ldr r0, =${direita}
43572
+ cmp r0, #0
43573
+ beq ${labelFim}
43574
+ ${labelVerdadeiro}:
43575
+ mov r0, #1
43572
43576
  ${labelFim}:`;
43573
43577
  }
43574
43578
  else if (operador === 'ou' || operador === '||') {
43575
- this.text += `
43576
- bne ${labelVerdadeiro}
43577
- ldr r0, =${direita}
43578
- cmp r0, #0
43579
- bne ${labelVerdadeiro}
43580
- mov r0, #0
43581
- b ${labelFim}
43582
- ${labelVerdadeiro}:
43583
- mov r0, #1
43579
+ this.text += `
43580
+ bne ${labelVerdadeiro}
43581
+ ldr r0, =${direita}
43582
+ cmp r0, #0
43583
+ bne ${labelVerdadeiro}
43584
+ mov r0, #0
43585
+ b ${labelFim}
43586
+ ${labelVerdadeiro}:
43587
+ mov r0, #1
43584
43588
  ${labelFim}:`;
43585
43589
  }
43586
43590
  return 'r0';
@@ -43592,16 +43596,16 @@ ${labelFim}:`;
43592
43596
  traduzirConstrutoUnario(construto) {
43593
43597
  const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
43594
43598
  const operador = construto.operador.lexema;
43595
- this.text += `
43599
+ this.text += `
43596
43600
  ldr r0, =${operando}`;
43597
43601
  if (operador === '-') {
43598
- this.text += `
43602
+ this.text += `
43599
43603
  neg r0, r0`;
43600
43604
  }
43601
43605
  else if (operador === '!' || operador === 'nao') {
43602
- this.text += `
43603
- cmp r0, #0
43604
- moveq r0, #1
43606
+ this.text += `
43607
+ cmp r0, #0
43608
+ moveq r0, #1
43605
43609
  movne r0, #0`;
43606
43610
  }
43607
43611
  return 'r0';
@@ -43610,8 +43614,8 @@ ${labelFim}:`;
43610
43614
  const nomeVar = construto.simbolo?.lexema;
43611
43615
  if (nomeVar && this.variaveis.has(nomeVar)) {
43612
43616
  const varLabel = this.variaveis.get(nomeVar);
43613
- this.text += `
43614
- ldr r0, =${varLabel}
43617
+ this.text += `
43618
+ ldr r0, =${varLabel}
43615
43619
  ldr r0, [r0]`;
43616
43620
  return 'r0';
43617
43621
  }
@@ -43625,9 +43629,9 @@ ${labelFim}:`;
43625
43629
  construto.valores.forEach((valor, index) => {
43626
43630
  if (this.dicionarioConstrutos[valor.constructor.name]) {
43627
43631
  const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
43628
- this.text += `
43629
- ldr r0, =${valorTraduzido}
43630
- ldr r1, =${labelVetor}
43632
+ this.text += `
43633
+ ldr r0, =${valorTraduzido}
43634
+ ldr r1, =${labelVetor}
43631
43635
  str r0, [r1, #${index * 4}]`;
43632
43636
  }
43633
43637
  });
@@ -43647,17 +43651,17 @@ ${labelFim}:`;
43647
43651
  traduzirDeclaracaoEnquanto(declaracao) {
43648
43652
  const labelInicio = this.gerarLabel();
43649
43653
  const labelFim = this.gerarLabel();
43650
- this.text += `
43654
+ this.text += `
43651
43655
  ${labelInicio}:`;
43652
43656
  const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
43653
- this.text += `
43654
- cmp ${condicao}, #0
43657
+ this.text += `
43658
+ cmp ${condicao}, #0
43655
43659
  beq ${labelFim}`;
43656
43660
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
43657
43661
  this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
43658
43662
  }
43659
- this.text += `
43660
- b ${labelInicio}
43663
+ this.text += `
43664
+ b ${labelInicio}
43661
43665
  ${labelFim}:`;
43662
43666
  }
43663
43667
  traduzirDeclaracaoEscolha(declaracao) {
@@ -43668,10 +43672,10 @@ ${labelFim}:`;
43668
43672
  const labelProximo = this.gerarLabel();
43669
43673
  if (caminho.condicoes && caminho.condicoes[0]) {
43670
43674
  const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
43671
- this.text += `
43672
- ldr r0, =${valorEscolha}
43673
- ldr r1, =${valorCaso}
43674
- cmp r0, r1
43675
+ this.text += `
43676
+ ldr r0, =${valorEscolha}
43677
+ ldr r1, =${valorCaso}
43678
+ cmp r0, r1
43675
43679
  bne ${labelProximo}`;
43676
43680
  if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
43677
43681
  caminho.declaracoes.forEach((decl) => {
@@ -43680,13 +43684,13 @@ ${labelFim}:`;
43680
43684
  }
43681
43685
  });
43682
43686
  }
43683
- this.text += `
43684
- b ${labelFim}
43687
+ this.text += `
43688
+ b ${labelFim}
43685
43689
  ${labelProximo}:`;
43686
43690
  }
43687
43691
  });
43688
43692
  }
43689
- this.text += `
43693
+ this.text += `
43690
43694
  ${labelFim}:`;
43691
43695
  }
43692
43696
  traduzirDeclaracaoExpressao(declaracao) {
@@ -43697,7 +43701,7 @@ ${labelFim}:`;
43697
43701
  }
43698
43702
  traduzirDeclaracaoFazer(declaracao) {
43699
43703
  const labelInicio = this.gerarLabel();
43700
- this.text += `
43704
+ this.text += `
43701
43705
  ${labelInicio}:`;
43702
43706
  if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
43703
43707
  declaracao.caminhoFazer.declaracoes.forEach((decl) => {
@@ -43708,8 +43712,8 @@ ${labelInicio}:`;
43708
43712
  }
43709
43713
  if (declaracao.condicaoEnquanto) {
43710
43714
  const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
43711
- this.text += `
43712
- cmp ${condicao}, #0
43715
+ this.text += `
43716
+ cmp ${condicao}, #0
43713
43717
  bne ${labelInicio}`;
43714
43718
  }
43715
43719
  }
@@ -43723,18 +43727,18 @@ ${labelInicio}:`;
43723
43727
  mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
43724
43728
  }
43725
43729
  }
43726
- this.text += `
43727
- @ Falhar com mensagem: ${mensagem}
43728
- mov r0, #1
43729
- mov r7, #1 @ sys_exit
43730
+ this.text += `
43731
+ @ Falhar com mensagem: ${mensagem}
43732
+ mov r0, #1
43733
+ mov r7, #1 @ sys_exit
43730
43734
  swi 0`;
43731
43735
  }
43732
43736
  traduzirDeclaracaoFuncao(declaracao) {
43733
43737
  const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
43734
- this.text += `
43735
-
43736
- ${nomeFuncao}:
43737
- push {fp, lr}
43738
+ this.text += `
43739
+
43740
+ ${nomeFuncao}:
43741
+ push {fp, lr}
43738
43742
  mov fp, sp`;
43739
43743
  if (declaracao.funcao &&
43740
43744
  declaracao.funcao.corpo &&
@@ -43745,12 +43749,12 @@ ${nomeFuncao}:
43745
43749
  }
43746
43750
  });
43747
43751
  }
43748
- this.text += `
43749
- mov sp, fp
43752
+ this.text += `
43753
+ mov sp, fp
43750
43754
  pop {fp, pc}`;
43751
43755
  }
43752
43756
  traduzirDeclaracaoImportar(declaracao) {
43753
- this.text += `
43757
+ this.text += `
43754
43758
  @ Importar: ${declaracao.caminho || 'unknown'}`;
43755
43759
  }
43756
43760
  traduzirDeclaracaoLeia(declaracao) {
@@ -43767,11 +43771,11 @@ ${nomeFuncao}:
43767
43771
  this.bss += ` ${varLabel}: .space 256\n`;
43768
43772
  this.variaveis.set(nomeVar, varLabel);
43769
43773
  }
43770
- this.text += `
43771
- ldr r1, =${this.variaveis.get(nomeVar)}
43772
- mov r2, #256
43773
- mov r0, #0 @ stdin
43774
- mov r7, #3 @ sys_read
43774
+ this.text += `
43775
+ ldr r1, =${this.variaveis.get(nomeVar)}
43776
+ mov r2, #256
43777
+ mov r0, #0 @ stdin
43778
+ mov r7, #3 @ sys_read
43775
43779
  swi 0`;
43776
43780
  }
43777
43781
  traduzirDeclaracaoPara(declaracao) {
@@ -43786,12 +43790,12 @@ ${nomeFuncao}:
43786
43790
  this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
43787
43791
  }
43788
43792
  }
43789
- this.text += `
43793
+ this.text += `
43790
43794
  ${labelInicio}:`;
43791
43795
  if (declaracao.condicao) {
43792
43796
  const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
43793
- this.text += `
43794
- cmp ${condicao}, #0
43797
+ this.text += `
43798
+ cmp ${condicao}, #0
43795
43799
  beq ${labelFim}`;
43796
43800
  }
43797
43801
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
@@ -43802,8 +43806,8 @@ ${labelInicio}:`;
43802
43806
  this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
43803
43807
  }
43804
43808
  }
43805
- this.text += `
43806
- b ${labelInicio}
43809
+ this.text += `
43810
+ b ${labelInicio}
43807
43811
  ${labelFim}:`;
43808
43812
  }
43809
43813
  traduzirDeclaracaoParaCada(declaracao) {
@@ -43818,55 +43822,55 @@ ${labelFim}:`;
43818
43822
  if (vetor instanceof construtos_1.Vetor) {
43819
43823
  tamanhoVetor = vetor.tamanho || 0;
43820
43824
  }
43821
- this.text += `
43822
- mov r4, #0 @ counter
43823
- ${labelInicio}:
43824
- cmp r4, #${tamanhoVetor}
43825
+ this.text += `
43826
+ mov r4, #0 @ counter
43827
+ ${labelInicio}:
43828
+ cmp r4, #${tamanhoVetor}
43825
43829
  bge ${labelFim}`;
43826
43830
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
43827
43831
  this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
43828
43832
  }
43829
- this.text += `
43830
- add r4, r4, #1
43831
- b ${labelInicio}
43833
+ this.text += `
43834
+ add r4, r4, #1
43835
+ b ${labelInicio}
43832
43836
  ${labelFim}:`;
43833
43837
  }
43834
43838
  traduzirDeclaracaoRetorna(declaracao) {
43835
43839
  if (declaracao.valor) {
43836
43840
  const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
43837
- this.text += `
43841
+ this.text += `
43838
43842
  ldr r0, =${valor}`;
43839
43843
  }
43840
- this.text += `
43841
- mov sp, fp
43844
+ this.text += `
43845
+ mov sp, fp
43842
43846
  pop {fp, pc}`;
43843
43847
  }
43844
43848
  traduzirDeclaracaoSe(declaracao) {
43845
43849
  const labelSenao = this.gerarLabel();
43846
43850
  const labelFim = this.gerarLabel();
43847
43851
  const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
43848
- this.text += `
43849
- cmp ${condicao}, #0
43852
+ this.text += `
43853
+ cmp ${condicao}, #0
43850
43854
  beq ${labelSenao}`;
43851
43855
  if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
43852
43856
  this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
43853
43857
  }
43854
- this.text += `
43855
- b ${labelFim}
43858
+ this.text += `
43859
+ b ${labelFim}
43856
43860
  ${labelSenao}:`;
43857
43861
  if (declaracao.caminhoSenao &&
43858
43862
  this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
43859
43863
  this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
43860
43864
  }
43861
- this.text += `
43865
+ this.text += `
43862
43866
  ${labelFim}:`;
43863
43867
  }
43864
43868
  traduzirDeclaracaoClasse(declaracao) {
43865
- this.text += `
43869
+ this.text += `
43866
43870
  @ Classe: ${declaracao.simbolo?.lexema || 'unknown'}`;
43867
43871
  }
43868
43872
  traduzirDeclaracaoTente(declaracao) {
43869
- this.text += `
43873
+ this.text += `
43870
43874
  @ Tente-pegue`;
43871
43875
  if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
43872
43876
  declaracao.caminhoTente.forEach((decl) => {
@@ -43903,9 +43907,9 @@ ${labelFim}:`;
43903
43907
  }
43904
43908
  else if (this.dicionarioConstrutos[tipoInicializador]) {
43905
43909
  const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
43906
- this.text += `
43907
- ldr r0, =${valor}
43908
- ldr r1, =${varLabel}
43910
+ this.text += `
43911
+ ldr r0, =${valor}
43912
+ ldr r1, =${varLabel}
43909
43913
  str r0, [r1]`;
43910
43914
  }
43911
43915
  }
@@ -43932,20 +43936,20 @@ ${labelFim}:`;
43932
43936
  // Para ambos linux-arm e android, continuamos usando a convenção
43933
43937
  // de syscall Linux ARM (write). Em Android típico, esse binário
43934
43938
  // seria executado via adb/Termux, onde essa convenção ainda é válida.
43935
- this.text += `
43936
- ldr r1, =${nome_string_literal}
43937
- mov r2, #${tam_string_literal}
43938
- mov r0, #1 @ fd stdout
43939
- mov r7, #4 @ sys_write
43939
+ this.text += `
43940
+ ldr r1, =${nome_string_literal}
43941
+ mov r2, #${tam_string_literal}
43942
+ mov r0, #1 @ fd stdout
43943
+ mov r7, #4 @ sys_write
43940
43944
  swi 0`;
43941
43945
  }
43942
43946
  saidaSistema() {
43943
43947
  // Mesmo comentário da função Escreva: usamos sys_exit Linux.
43944
43948
  // Em um futuro modo Android "NDK/JNI", esta função deveria
43945
43949
  // apenas retornar ao chamador em vez de fazer syscall direta.
43946
- this.text += `
43947
- mov r0, #1 @ exit status
43948
- mov r7, #1 @ sys_exit
43950
+ this.text += `
43951
+ mov r0, #1 @ exit status
43952
+ mov r7, #1 @ sys_exit
43949
43953
  swi 0`;
43950
43954
  }
43951
43955
  traduzir(declaracoes) {
@@ -44021,10 +44025,10 @@ class TradutorAssemblyRISCV {
44021
44025
  Var: this.traduzirDeclaracaoVar.bind(this),
44022
44026
  };
44023
44027
  this.indentacao = 0;
44024
- this.text = `
44025
- .text
44026
- .global _start
44027
-
44028
+ this.text = `
44029
+ .text
44030
+ .global _start
44031
+
44028
44032
  _start:`;
44029
44033
  }
44030
44034
  gerarDigitoAleatorio() {
@@ -44090,9 +44094,9 @@ _start:`;
44090
44094
  const reg = this.obterRegistrador();
44091
44095
  this.text += `\n la ${reg}, ${nomeVar}`;
44092
44096
  this.emitirCarga('a0', indice);
44093
- this.text += `
44094
- slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
44095
- add ${reg}, ${reg}, a0
44097
+ this.text += `
44098
+ slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
44099
+ add ${reg}, ${reg}, a0
44096
44100
  ld a0, 0(${reg})`;
44097
44101
  this.liberarRegistrador(reg);
44098
44102
  return 'a0';
@@ -44116,8 +44120,8 @@ _start:`;
44116
44120
  const reg = this.obterRegistrador();
44117
44121
  this.text += `\n la ${reg}, ${nomeVar}`;
44118
44122
  this.emitirCarga('a1', indice);
44119
- this.text += `
44120
- slli a1, a1, 3 # multiplicar índice por 8
44123
+ this.text += `
44124
+ slli a1, a1, 3 # multiplicar índice por 8
44121
44125
  add ${reg}, ${reg}, a1`;
44122
44126
  this.emitirCarga('a1', valor);
44123
44127
  this.text += `\n sd a1, 0(${reg})`;
@@ -44137,8 +44141,8 @@ _start:`;
44137
44141
  this.variaveis.set(nomeVar, varLabel);
44138
44142
  }
44139
44143
  this.emitirCarga('a0', valor);
44140
- this.text += `
44141
- la a1, ${this.variaveis.get(nomeVar)}
44144
+ this.text += `
44145
+ la a1, ${this.variaveis.get(nomeVar)}
44142
44146
  sd a0, 0(a1)`;
44143
44147
  }
44144
44148
  traduzirConstrutoBinario(construto) {
@@ -44222,18 +44226,18 @@ _start:`;
44222
44226
  const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
44223
44227
  const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
44224
44228
  this.emitirCarga('a0', valor);
44225
- this.text += `
44226
- la a1, ${objeto}
44229
+ this.text += `
44230
+ la a1, ${objeto}
44227
44231
  sd a0, 0(a1)`;
44228
44232
  }
44229
44233
  traduzirFuncaoConstruto(construto) {
44230
44234
  const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
44231
- this.text += `
44232
-
44233
- ${labelFuncao}:
44234
- addi sp, sp, -16
44235
- sd ra, 8(sp)
44236
- sd s0, 0(sp)
44235
+ this.text += `
44236
+
44237
+ ${labelFuncao}:
44238
+ addi sp, sp, -16
44239
+ sd ra, 8(sp)
44240
+ sd s0, 0(sp)
44237
44241
  addi s0, sp, 16`;
44238
44242
  if (construto.corpo && Array.isArray(construto.corpo)) {
44239
44243
  construto.corpo.forEach((declaracao) => {
@@ -44242,10 +44246,10 @@ ${labelFuncao}:
44242
44246
  }
44243
44247
  });
44244
44248
  }
44245
- this.text += `
44246
- ld ra, 8(sp)
44247
- ld s0, 0(sp)
44248
- addi sp, sp, 16
44249
+ this.text += `
44250
+ ld ra, 8(sp)
44251
+ ld s0, 0(sp)
44252
+ addi sp, sp, 16
44249
44253
  ret`;
44250
44254
  }
44251
44255
  traduzirConstrutoLiteral(construto) {
@@ -44269,21 +44273,21 @@ ${labelFuncao}:
44269
44273
  if (operador === 'e' || operador === '&&') {
44270
44274
  this.text += `\n beqz a0, ${labelFim}`;
44271
44275
  this.emitirCarga('a0', direita);
44272
- this.text += `
44273
- beqz a0, ${labelFim}
44274
- ${labelVerdadeiro}:
44275
- li a0, 1
44276
+ this.text += `
44277
+ beqz a0, ${labelFim}
44278
+ ${labelVerdadeiro}:
44279
+ li a0, 1
44276
44280
  ${labelFim}:`;
44277
44281
  }
44278
44282
  else if (operador === 'ou' || operador === '||') {
44279
44283
  this.text += `\n bnez a0, ${labelVerdadeiro}`;
44280
44284
  this.emitirCarga('a0', direita);
44281
- this.text += `
44282
- bnez a0, ${labelVerdadeiro}
44283
- li a0, 0
44284
- j ${labelFim}
44285
- ${labelVerdadeiro}:
44286
- li a0, 1
44285
+ this.text += `
44286
+ bnez a0, ${labelVerdadeiro}
44287
+ li a0, 0
44288
+ j ${labelFim}
44289
+ ${labelVerdadeiro}:
44290
+ li a0, 1
44287
44291
  ${labelFim}:`;
44288
44292
  }
44289
44293
  return 'a0';
@@ -44308,8 +44312,8 @@ ${labelFim}:`;
44308
44312
  const nomeVar = construto.simbolo?.lexema;
44309
44313
  if (nomeVar && this.variaveis.has(nomeVar)) {
44310
44314
  const varLabel = this.variaveis.get(nomeVar);
44311
- this.text += `
44312
- la a0, ${varLabel}
44315
+ this.text += `
44316
+ la a0, ${varLabel}
44313
44317
  ld a0, 0(a0)`;
44314
44318
  return 'a0';
44315
44319
  }
@@ -44325,8 +44329,8 @@ ${labelFim}:`;
44325
44329
  if (this.dicionarioConstrutos[valor.constructor.name]) {
44326
44330
  const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
44327
44331
  this.emitirCarga('a0', valorTraduzido);
44328
- this.text += `
44329
- la a1, ${labelVetor}
44332
+ this.text += `
44333
+ la a1, ${labelVetor}
44330
44334
  sd a0, ${index * 8}(a1)`;
44331
44335
  }
44332
44336
  });
@@ -44354,8 +44358,8 @@ ${labelFim}:`;
44354
44358
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
44355
44359
  this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
44356
44360
  }
44357
- this.text += `
44358
- j ${labelInicio}
44361
+ this.text += `
44362
+ j ${labelInicio}
44359
44363
  ${labelFim}:`;
44360
44364
  }
44361
44365
  traduzirDeclaracaoEscolha(declaracao) {
@@ -44376,8 +44380,8 @@ ${labelFim}:`;
44376
44380
  }
44377
44381
  });
44378
44382
  }
44379
- this.text += `
44380
- j ${labelFim}
44383
+ this.text += `
44384
+ j ${labelFim}
44381
44385
  ${labelProximo}:`;
44382
44386
  }
44383
44387
  });
@@ -44421,20 +44425,20 @@ ${labelProximo}:`;
44421
44425
  mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
44422
44426
  }
44423
44427
  }
44424
- this.text += `
44425
- # Falhar com mensagem: ${mensagem}
44426
- li a0, 1
44427
- li a7, 93 # sys_exit
44428
+ this.text += `
44429
+ # Falhar com mensagem: ${mensagem}
44430
+ li a0, 1
44431
+ li a7, 93 # sys_exit
44428
44432
  ecall`;
44429
44433
  }
44430
44434
  traduzirDeclaracaoFuncao(declaracao) {
44431
44435
  const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
44432
- this.text += `
44433
-
44434
- ${nomeFuncao}:
44435
- addi sp, sp, -16
44436
- sd ra, 8(sp)
44437
- sd s0, 0(sp)
44436
+ this.text += `
44437
+
44438
+ ${nomeFuncao}:
44439
+ addi sp, sp, -16
44440
+ sd ra, 8(sp)
44441
+ sd s0, 0(sp)
44438
44442
  addi s0, sp, 16`;
44439
44443
  if (declaracao.funcao &&
44440
44444
  declaracao.funcao.corpo &&
@@ -44445,10 +44449,10 @@ ${nomeFuncao}:
44445
44449
  }
44446
44450
  });
44447
44451
  }
44448
- this.text += `
44449
- ld ra, 8(sp)
44450
- ld s0, 0(sp)
44451
- addi sp, sp, 16
44452
+ this.text += `
44453
+ ld ra, 8(sp)
44454
+ ld s0, 0(sp)
44455
+ addi sp, sp, 16
44452
44456
  ret`;
44453
44457
  }
44454
44458
  traduzirDeclaracaoImportar(declaracao) {
@@ -44468,11 +44472,11 @@ ${nomeFuncao}:
44468
44472
  this.bss += ` ${varLabel}: .space 256\n`;
44469
44473
  this.variaveis.set(nomeVar, varLabel);
44470
44474
  }
44471
- this.text += `
44472
- li a0, 0 # fd stdin
44473
- la a1, ${this.variaveis.get(nomeVar)}
44474
- li a2, 256
44475
- li a7, 63 # sys_read
44475
+ this.text += `
44476
+ li a0, 0 # fd stdin
44477
+ la a1, ${this.variaveis.get(nomeVar)}
44478
+ li a2, 256
44479
+ li a7, 63 # sys_read
44476
44480
  ecall`;
44477
44481
  }
44478
44482
  traduzirDeclaracaoPara(declaracao) {
@@ -44503,8 +44507,8 @@ ${nomeFuncao}:
44503
44507
  this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
44504
44508
  }
44505
44509
  }
44506
- this.text += `
44507
- j ${labelInicio}
44510
+ this.text += `
44511
+ j ${labelInicio}
44508
44512
  ${labelFim}:`;
44509
44513
  }
44510
44514
  traduzirDeclaracaoParaCada(declaracao) {
@@ -44516,17 +44520,17 @@ ${labelFim}:`;
44516
44520
  tamanhoVetor = vetor.tamanho || 0;
44517
44521
  }
44518
44522
  // t0: contador; t1: limite (caller-saved, seguros aqui)
44519
- this.text += `
44520
- li t0, 0 # contador
44521
- li t1, ${tamanhoVetor}
44522
- ${labelInicio}:
44523
+ this.text += `
44524
+ li t0, 0 # contador
44525
+ li t1, ${tamanhoVetor}
44526
+ ${labelInicio}:
44523
44527
  bge t0, t1, ${labelFim}`;
44524
44528
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
44525
44529
  this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
44526
44530
  }
44527
- this.text += `
44528
- addi t0, t0, 1
44529
- j ${labelInicio}
44531
+ this.text += `
44532
+ addi t0, t0, 1
44533
+ j ${labelInicio}
44530
44534
  ${labelFim}:`;
44531
44535
  }
44532
44536
  traduzirDeclaracaoRetorna(declaracao) {
@@ -44534,10 +44538,10 @@ ${labelFim}:`;
44534
44538
  const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
44535
44539
  this.emitirCarga('a0', valor);
44536
44540
  }
44537
- this.text += `
44538
- ld ra, 8(sp)
44539
- ld s0, 0(sp)
44540
- addi sp, sp, 16
44541
+ this.text += `
44542
+ ld ra, 8(sp)
44543
+ ld s0, 0(sp)
44544
+ addi sp, sp, 16
44541
44545
  ret`;
44542
44546
  }
44543
44547
  traduzirDeclaracaoSe(declaracao) {
@@ -44551,8 +44555,8 @@ ${labelFim}:`;
44551
44555
  if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
44552
44556
  this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
44553
44557
  }
44554
- this.text += `
44555
- j ${labelFim}
44558
+ this.text += `
44559
+ j ${labelFim}
44556
44560
  ${labelSenao}:`;
44557
44561
  if (declaracao.caminhoSenao &&
44558
44562
  this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
@@ -44598,8 +44602,8 @@ ${labelSenao}:`;
44598
44602
  else if (this.dicionarioConstrutos[tipoInicializador]) {
44599
44603
  const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
44600
44604
  this.emitirCarga('a0', valor);
44601
- this.text += `
44602
- la a1, ${varLabel}
44605
+ this.text += `
44606
+ la a1, ${varLabel}
44603
44607
  sd a0, 0(a1)`;
44604
44608
  }
44605
44609
  }
@@ -44626,17 +44630,17 @@ ${labelSenao}:`;
44626
44630
  tamanhoString = String(stringValue.length);
44627
44631
  }
44628
44632
  // sys_write(fd=1, buf, count): a7=64, a0=fd, a1=buf, a2=count
44629
- this.text += `
44630
- la a1, ${nomeStringLiteral}
44631
- li a2, ${tamanhoString}
44632
- li a0, 1 # fd stdout
44633
- li a7, 64 # sys_write
44633
+ this.text += `
44634
+ la a1, ${nomeStringLiteral}
44635
+ li a2, ${tamanhoString}
44636
+ li a0, 1 # fd stdout
44637
+ li a7, 64 # sys_write
44634
44638
  ecall`;
44635
44639
  }
44636
44640
  saidaSistema() {
44637
- this.text += `
44638
- li a0, 0 # código de saída
44639
- li a7, 93 # sys_exit
44641
+ this.text += `
44642
+ li a0, 0 # código de saída
44643
+ li a7, 93 # sys_exit
44640
44644
  ecall`;
44641
44645
  }
44642
44646
  traduzir(declaracoes) {
@@ -44712,14 +44716,14 @@ class TradutorAssemblyX64 {
44712
44716
  Escreva: this.traduzirDeclaracaoEscreva.bind(this),
44713
44717
  };
44714
44718
  this.indentacao = 0;
44715
- this.textoSaida = `
44716
- section .text
44717
- ${this.alvo === 'linux' ? 'global _start' : 'global main'}
44719
+ this.textoSaida = `
44720
+ section .text
44721
+ ${this.alvo === 'linux' ? 'global _start' : 'global main'}
44718
44722
  ${this.alvo === 'linux' ? '_start:' : 'main:'}`;
44719
44723
  if (this.alvo === 'windows') {
44720
44724
  this.textoSaida =
44721
- `
44722
- extern printf
44725
+ `
44726
+ extern printf
44723
44727
  ` + this.textoSaida;
44724
44728
  }
44725
44729
  }
@@ -44779,8 +44783,8 @@ extern printf
44779
44783
  }
44780
44784
  const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
44781
44785
  const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
44782
- this.textoSaida += `
44783
- mov rax, ${valor}
44786
+ this.textoSaida += `
44787
+ mov rax, ${valor}
44784
44788
  mov [${nomeVar} + ${indice} * 8], rax`;
44785
44789
  }
44786
44790
  traduzirConstrutoAtribuir(construto) {
@@ -44798,8 +44802,8 @@ extern printf
44798
44802
  this.bss += ` ${varLabel} resq 1\n`;
44799
44803
  this.variaveis.set(nomeVar, varLabel);
44800
44804
  }
44801
- this.textoSaida += `
44802
- mov rax, ${valor}
44805
+ this.textoSaida += `
44806
+ mov rax, ${valor}
44803
44807
  mov [${this.variaveis.get(nomeVar)}], rax`;
44804
44808
  }
44805
44809
  traduzirConstrutoBinario(construto) {
@@ -44807,71 +44811,71 @@ extern printf
44807
44811
  const direita = this.dicionarioConstrutos[construto.direita.constructor.name](construto.direita);
44808
44812
  const operador = construto.operador.lexema;
44809
44813
  const registrador = this.obterRegistrador();
44810
- this.textoSaida += `
44811
- mov rax, ${esquerda}
44814
+ this.textoSaida += `
44815
+ mov rax, ${esquerda}
44812
44816
  mov ${registrador}, ${direita}`;
44813
44817
  switch (operador) {
44814
44818
  case '+':
44815
- this.textoSaida += `
44819
+ this.textoSaida += `
44816
44820
  add rax, ${registrador}`;
44817
44821
  break;
44818
44822
  case '-':
44819
- this.textoSaida += `
44823
+ this.textoSaida += `
44820
44824
  sub rax, ${registrador}`;
44821
44825
  break;
44822
44826
  case '*':
44823
- this.textoSaida += `
44827
+ this.textoSaida += `
44824
44828
  imul rax, ${registrador}`;
44825
44829
  break;
44826
44830
  case '/':
44827
- this.textoSaida += `
44828
- xor rdx, rdx
44831
+ this.textoSaida += `
44832
+ xor rdx, rdx
44829
44833
  idiv ${registrador}`;
44830
44834
  break;
44831
44835
  case '%':
44832
- this.textoSaida += `
44833
- xor rdx, rdx
44834
- idiv ${registrador}
44836
+ this.textoSaida += `
44837
+ xor rdx, rdx
44838
+ idiv ${registrador}
44835
44839
  mov rax, rdx`;
44836
44840
  break;
44837
44841
  case '<':
44838
- this.textoSaida += `
44839
- cmp rax, ${registrador}
44840
- setl al
44842
+ this.textoSaida += `
44843
+ cmp rax, ${registrador}
44844
+ setl al
44841
44845
  movzx rax, al`;
44842
44846
  break;
44843
44847
  case '>':
44844
- this.textoSaida += `
44845
- cmp rax, ${registrador}
44846
- setg al
44848
+ this.textoSaida += `
44849
+ cmp rax, ${registrador}
44850
+ setg al
44847
44851
  movzx rax, al`;
44848
44852
  break;
44849
44853
  case '<=':
44850
- this.textoSaida += `
44851
- cmp rax, ${registrador}
44852
- setle al
44854
+ this.textoSaida += `
44855
+ cmp rax, ${registrador}
44856
+ setle al
44853
44857
  movzx rax, al`;
44854
44858
  break;
44855
44859
  case '>=':
44856
- this.textoSaida += `
44857
- cmp rax, ${registrador}
44858
- setge al
44860
+ this.textoSaida += `
44861
+ cmp rax, ${registrador}
44862
+ setge al
44859
44863
  movzx rax, al`;
44860
44864
  break;
44861
44865
  case '==':
44862
- this.textoSaida += `
44863
- cmp rax, ${registrador}
44864
- sete al
44866
+ this.textoSaida += `
44867
+ cmp rax, ${registrador}
44868
+ sete al
44865
44869
  movzx rax, al`;
44866
44870
  break;
44867
44871
  case '!=':
44868
- this.textoSaida += `
44869
- cmp rax, ${registrador}
44870
- setne al
44872
+ this.textoSaida += `
44873
+ cmp rax, ${registrador}
44874
+ setne al
44871
44875
  movzx rax, al`;
44872
44876
  break;
44873
44877
  default:
44874
- this.textoSaida += `
44878
+ this.textoSaida += `
44875
44879
  ; Operador ${operador} não implementado`;
44876
44880
  }
44877
44881
  this.liberarRegistrador(registrador);
@@ -44889,28 +44893,28 @@ extern printf
44889
44893
  construto.argumentos.forEach((argumento, indice) => {
44890
44894
  if (indice < registrosArgs.length) {
44891
44895
  const valorArg = this.dicionarioConstrutos[argumento.constructor.name](argumento);
44892
- this.textoSaida += `
44896
+ this.textoSaida += `
44893
44897
  mov ${registrosArgs[indice]}, ${valorArg}`;
44894
44898
  }
44895
44899
  else {
44896
44900
  // TODO: empurrar argumentos extras na pilha de acordo com o ABI alvo
44897
44901
  }
44898
44902
  });
44899
- this.textoSaida += `
44903
+ this.textoSaida += `
44900
44904
  call ${nomeFuncao}`;
44901
44905
  }
44902
44906
  traduzirConstrutoDefinirValor(construto) {
44903
44907
  const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
44904
44908
  const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
44905
- this.textoSaida += `
44906
- mov rax, ${valor}
44909
+ this.textoSaida += `
44910
+ mov rax, ${valor}
44907
44911
  mov [${objeto}], rax`;
44908
44912
  }
44909
44913
  traduzirFuncaoConstruto(construto) {
44910
44914
  const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
44911
- this.textoSaida += `
44912
- ${labelFuncao}:
44913
- push rbp
44915
+ this.textoSaida += `
44916
+ ${labelFuncao}:
44917
+ push rbp
44914
44918
  mov rbp, rsp`;
44915
44919
  // Traduzir corpo da função
44916
44920
  if (construto.corpo && Array.isArray(construto.corpo)) {
@@ -44920,8 +44924,8 @@ ${labelFuncao}:
44920
44924
  }
44921
44925
  });
44922
44926
  }
44923
- this.textoSaida += `
44924
- pop rbp
44927
+ this.textoSaida += `
44928
+ pop rbp
44925
44929
  ret`;
44926
44930
  }
44927
44931
  traduzirConstrutoLiteral(construto) {
@@ -44936,29 +44940,29 @@ ${labelFuncao}:
44936
44940
  const operador = construto.operador.lexema;
44937
44941
  const labelVerdadeiro = this.gerarLabel();
44938
44942
  const labelFim = this.gerarLabel();
44939
- this.textoSaida += `
44940
- mov rax, ${esquerda}
44943
+ this.textoSaida += `
44944
+ mov rax, ${esquerda}
44941
44945
  cmp rax, 0`;
44942
44946
  if (operador === 'e' || operador === '&&') {
44943
- this.textoSaida += `
44944
- je ${labelFim}
44945
- mov rax, ${direita}
44946
- cmp rax, 0
44947
- je ${labelFim}
44948
- ${labelVerdadeiro}:
44949
- mov rax, 1
44947
+ this.textoSaida += `
44948
+ je ${labelFim}
44949
+ mov rax, ${direita}
44950
+ cmp rax, 0
44951
+ je ${labelFim}
44952
+ ${labelVerdadeiro}:
44953
+ mov rax, 1
44950
44954
  ${labelFim}:`;
44951
44955
  }
44952
44956
  else if (operador === 'ou' || operador === '||') {
44953
- this.textoSaida += `
44954
- jne ${labelVerdadeiro}
44955
- mov rax, ${direita}
44956
- cmp rax, 0
44957
- jne ${labelVerdadeiro}
44958
- mov rax, 0
44959
- jmp ${labelFim}
44960
- ${labelVerdadeiro}:
44961
- mov rax, 1
44957
+ this.textoSaida += `
44958
+ jne ${labelVerdadeiro}
44959
+ mov rax, ${direita}
44960
+ cmp rax, 0
44961
+ jne ${labelVerdadeiro}
44962
+ mov rax, 0
44963
+ jmp ${labelFim}
44964
+ ${labelVerdadeiro}:
44965
+ mov rax, 1
44962
44966
  ${labelFim}:`;
44963
44967
  }
44964
44968
  return 'rax';
@@ -44971,26 +44975,26 @@ ${labelFim}:`;
44971
44975
  traduzirConstrutoUnario(construto) {
44972
44976
  const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
44973
44977
  const operador = construto.operador.lexema;
44974
- this.textoSaida += `
44978
+ this.textoSaida += `
44975
44979
  mov rax, ${operando}`;
44976
44980
  if (operador === '-') {
44977
- this.textoSaida += `
44981
+ this.textoSaida += `
44978
44982
  neg rax`;
44979
44983
  }
44980
44984
  else if (operador === '!' || operador === 'nao') {
44981
- this.textoSaida += `
44982
- cmp rax, 0
44983
- sete al
44985
+ this.textoSaida += `
44986
+ cmp rax, 0
44987
+ sete al
44984
44988
  movzx rax, al`;
44985
44989
  }
44986
44990
  else if (operador === '++') {
44987
- this.textoSaida += `
44988
- inc rax
44991
+ this.textoSaida += `
44992
+ inc rax
44989
44993
  mov ${operando}, rax`;
44990
44994
  }
44991
44995
  else if (operador === '--') {
44992
- this.textoSaida += `
44993
- dec rax
44996
+ this.textoSaida += `
44997
+ dec rax
44994
44998
  mov ${operando}, rax`;
44995
44999
  }
44996
45000
  return 'rax';
@@ -45010,8 +45014,8 @@ ${labelFim}:`;
45010
45014
  construto.valores.forEach((valor, index) => {
45011
45015
  if (this.dicionarioConstrutos[valor.constructor.name]) {
45012
45016
  const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
45013
- this.textoSaida += `
45014
- mov rax, ${valorTraduzido}
45017
+ this.textoSaida += `
45018
+ mov rax, ${valorTraduzido}
45015
45019
  mov [${rotuloVetor} + ${index * 8}], rax`;
45016
45020
  }
45017
45021
  });
@@ -45031,17 +45035,17 @@ ${labelFim}:`;
45031
45035
  traduzirDeclaracaoEnquanto(declaracao) {
45032
45036
  const labelInicio = this.gerarLabel();
45033
45037
  const labelFim = this.gerarLabel();
45034
- this.textoSaida += `
45038
+ this.textoSaida += `
45035
45039
  ${labelInicio}:`;
45036
45040
  const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
45037
- this.textoSaida += `
45038
- cmp ${condicao}, 0
45041
+ this.textoSaida += `
45042
+ cmp ${condicao}, 0
45039
45043
  je ${labelFim}`;
45040
45044
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
45041
45045
  this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
45042
45046
  }
45043
- this.textoSaida += `
45044
- jmp ${labelInicio}
45047
+ this.textoSaida += `
45048
+ jmp ${labelInicio}
45045
45049
  ${labelFim}:`;
45046
45050
  }
45047
45051
  traduzirDeclaracaoEscolha(declaracao) {
@@ -45052,9 +45056,9 @@ ${labelFim}:`;
45052
45056
  const labelProximo = this.gerarLabel();
45053
45057
  if (caminho.condicoes && caminho.condicoes[0]) {
45054
45058
  const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
45055
- this.textoSaida += `
45056
- mov rax, ${valorEscolha}
45057
- cmp rax, ${valorCaso}
45059
+ this.textoSaida += `
45060
+ mov rax, ${valorEscolha}
45061
+ cmp rax, ${valorCaso}
45058
45062
  jne ${labelProximo}`;
45059
45063
  if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
45060
45064
  caminho.declaracoes.forEach((declaracao) => {
@@ -45063,13 +45067,13 @@ ${labelFim}:`;
45063
45067
  }
45064
45068
  });
45065
45069
  }
45066
- this.textoSaida += `
45067
- jmp ${labelFim}
45070
+ this.textoSaida += `
45071
+ jmp ${labelFim}
45068
45072
  ${labelProximo}:`;
45069
45073
  }
45070
45074
  });
45071
45075
  }
45072
- this.textoSaida += `
45076
+ this.textoSaida += `
45073
45077
  ${labelFim}:`;
45074
45078
  }
45075
45079
  traduzirDeclaracaoExpressao(declaracao) {
@@ -45080,7 +45084,7 @@ ${labelFim}:`;
45080
45084
  }
45081
45085
  traduzirDeclaracaoFazer(declaracao) {
45082
45086
  const labelInicio = this.gerarLabel();
45083
- this.textoSaida += `
45087
+ this.textoSaida += `
45084
45088
  ${labelInicio}:`;
45085
45089
  // Em Delégua, fazer-enquanto tem caminhoFazer que é um Bloco
45086
45090
  if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
@@ -45092,8 +45096,8 @@ ${labelInicio}:`;
45092
45096
  }
45093
45097
  if (declaracao.condicaoEnquanto) {
45094
45098
  const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
45095
- this.textoSaida += `
45096
- cmp ${condicao}, 0
45099
+ this.textoSaida += `
45100
+ cmp ${condicao}, 0
45097
45101
  jne ${labelInicio}`;
45098
45102
  }
45099
45103
  }
@@ -45108,24 +45112,24 @@ ${labelInicio}:`;
45108
45112
  }
45109
45113
  }
45110
45114
  if (this.alvo === 'linux') {
45111
- this.textoSaida += `
45112
- ; Falhar com mensagem: ${mensagem}
45113
- mov eax, 1
45114
- mov ebx, 1
45115
+ this.textoSaida += `
45116
+ ; Falhar com mensagem: ${mensagem}
45117
+ mov eax, 1
45118
+ mov ebx, 1
45115
45119
  int 0x80`;
45116
45120
  }
45117
45121
  else {
45118
- this.textoSaida += `
45119
- ; Falhar com mensagem: ${mensagem}
45120
- mov eax, 1
45122
+ this.textoSaida += `
45123
+ ; Falhar com mensagem: ${mensagem}
45124
+ mov eax, 1
45121
45125
  ret`;
45122
45126
  }
45123
45127
  }
45124
45128
  traduzirDeclaracaoFuncao(declaracao) {
45125
45129
  const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
45126
- this.textoSaida += `
45127
- ${nomeFuncao}:
45128
- push rbp
45130
+ this.textoSaida += `
45131
+ ${nomeFuncao}:
45132
+ push rbp
45129
45133
  mov rbp, rsp`;
45130
45134
  if (declaracao.funcao &&
45131
45135
  declaracao.funcao.corpo &&
@@ -45136,13 +45140,13 @@ ${nomeFuncao}:
45136
45140
  }
45137
45141
  });
45138
45142
  }
45139
- this.textoSaida += `
45140
- pop rbp
45143
+ this.textoSaida += `
45144
+ pop rbp
45141
45145
  ret`;
45142
45146
  }
45143
45147
  traduzirDeclaracaoImportar(declaracao) {
45144
45148
  // Importação é tratada em tempo de linkagem
45145
- this.textoSaida += `
45149
+ this.textoSaida += `
45146
45150
  ; Importar: ${declaracao.caminho || 'unknown'}`;
45147
45151
  }
45148
45152
  traduzirDeclaracaoLeia(declaracao) {
@@ -45159,11 +45163,11 @@ ${nomeFuncao}:
45159
45163
  this.bss += ` ${varLabel} resb 256\n`;
45160
45164
  this.variaveis.set(nomeVar, varLabel);
45161
45165
  }
45162
- this.textoSaida += `
45163
- mov eax, 3
45164
- mov ebx, 0
45165
- mov ecx, ${this.variaveis.get(nomeVar)}
45166
- mov edx, 256
45166
+ this.textoSaida += `
45167
+ mov eax, 3
45168
+ mov ebx, 0
45169
+ mov ecx, ${this.variaveis.get(nomeVar)}
45170
+ mov edx, 256
45167
45171
  int 0x80`;
45168
45172
  }
45169
45173
  traduzirDeclaracaoPara(declaracao) {
@@ -45189,12 +45193,12 @@ ${nomeFuncao}:
45189
45193
  }
45190
45194
  }
45191
45195
  }
45192
- this.textoSaida += `
45196
+ this.textoSaida += `
45193
45197
  ${labelInicio}:`;
45194
45198
  if (declaracao.condicao) {
45195
45199
  const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
45196
- this.textoSaida += `
45197
- cmp ${condicao}, 0
45200
+ this.textoSaida += `
45201
+ cmp ${condicao}, 0
45198
45202
  je ${labelFim}`;
45199
45203
  }
45200
45204
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
@@ -45205,8 +45209,8 @@ ${labelInicio}:`;
45205
45209
  this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
45206
45210
  }
45207
45211
  }
45208
- this.textoSaida += `
45209
- jmp ${labelInicio}
45212
+ this.textoSaida += `
45213
+ jmp ${labelInicio}
45210
45214
  ${labelFim}:`;
45211
45215
  }
45212
45216
  traduzirDeclaracaoParaCada(declaracao) {
@@ -45221,57 +45225,57 @@ ${labelFim}:`;
45221
45225
  if (vetor instanceof construtos_1.Vetor) {
45222
45226
  tamanhoVetor = vetor.tamanho || 0;
45223
45227
  }
45224
- this.textoSaida += `
45225
- xor rcx, rcx
45226
- ${rotuloInicio}:
45227
- cmp rcx, ${tamanhoVetor}
45228
+ this.textoSaida += `
45229
+ xor rcx, rcx
45230
+ ${rotuloInicio}:
45231
+ cmp rcx, ${tamanhoVetor}
45228
45232
  jge ${rotuloFim}`;
45229
45233
  if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
45230
45234
  this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
45231
45235
  }
45232
- this.textoSaida += `
45233
- inc rcx
45234
- jmp ${rotuloInicio}
45236
+ this.textoSaida += `
45237
+ inc rcx
45238
+ jmp ${rotuloInicio}
45235
45239
  ${rotuloFim}:`;
45236
45240
  }
45237
45241
  traduzirDeclaracaoRetorna(declaracao) {
45238
45242
  if (declaracao.valor) {
45239
45243
  const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
45240
- this.textoSaida += `
45244
+ this.textoSaida += `
45241
45245
  mov rax, ${valor}`;
45242
45246
  }
45243
- this.textoSaida += `
45244
- pop rbp
45247
+ this.textoSaida += `
45248
+ pop rbp
45245
45249
  ret`;
45246
45250
  }
45247
45251
  traduzirDeclaracaoSe(declaracao) {
45248
45252
  const rotuloSenao = this.gerarLabel();
45249
45253
  const rotuloFim = this.gerarLabel();
45250
45254
  const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
45251
- this.textoSaida += `
45252
- cmp ${condicao}, 0
45255
+ this.textoSaida += `
45256
+ cmp ${condicao}, 0
45253
45257
  je ${rotuloSenao}`;
45254
45258
  if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
45255
45259
  this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
45256
45260
  }
45257
- this.textoSaida += `
45258
- jmp ${rotuloFim}
45261
+ this.textoSaida += `
45262
+ jmp ${rotuloFim}
45259
45263
  ${rotuloSenao}:`;
45260
45264
  if (declaracao.caminhoSenao &&
45261
45265
  this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
45262
45266
  this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
45263
45267
  }
45264
- this.textoSaida += `
45268
+ this.textoSaida += `
45265
45269
  ${rotuloFim}:`;
45266
45270
  }
45267
45271
  traduzirDeclaracaoClasse(declaracao) {
45268
45272
  // Classes em assembly são complexas - implementação básica
45269
- this.textoSaida += `
45273
+ this.textoSaida += `
45270
45274
  ; Classe: ${declaracao.simbolo?.lexema || 'unknown'}`;
45271
45275
  }
45272
45276
  traduzirDeclaracaoTente(declaracao) {
45273
45277
  // Try-catch em assembly requer handler complexo
45274
- this.textoSaida += `
45278
+ this.textoSaida += `
45275
45279
  ; Tente-pegue`;
45276
45280
  if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
45277
45281
  declaracao.caminhoTente.forEach((declaracao) => {
@@ -45308,8 +45312,8 @@ ${rotuloFim}:`;
45308
45312
  }
45309
45313
  else if (this.dicionarioConstrutos[tipoInicializador]) {
45310
45314
  const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
45311
- this.textoSaida += `
45312
- mov rax, ${valor}
45315
+ this.textoSaida += `
45316
+ mov rax, ${valor}
45313
45317
  mov [${varLabel}], rax`;
45314
45318
  }
45315
45319
  }
@@ -45329,33 +45333,33 @@ ${rotuloFim}:`;
45329
45333
  return;
45330
45334
  this.helperPrintIntEmitido = true;
45331
45335
  this.bss += ` __print_buf resb 24\n`;
45332
- this.helpers += `
45333
- __delegua_print_int:
45334
- push rbx
45335
- push rcx
45336
- push rdx
45337
- push rsi
45338
- mov rcx, 10
45339
- lea rsi, [__print_buf + 22]
45340
- mov byte [rsi], 10
45341
- .print_digitloop:
45342
- xor rdx, rdx
45343
- div rcx
45344
- add dl, '0'
45345
- dec rsi
45346
- mov [rsi], dl
45347
- test rax, rax
45348
- jnz .print_digitloop
45349
- lea rdx, [__print_buf + 23]
45350
- sub rdx, rsi
45351
- mov ecx, esi
45352
- mov ebx, 1
45353
- mov eax, 4
45354
- int 0x80
45355
- pop rsi
45356
- pop rdx
45357
- pop rcx
45358
- pop rbx
45336
+ this.helpers += `
45337
+ __delegua_print_int:
45338
+ push rbx
45339
+ push rcx
45340
+ push rdx
45341
+ push rsi
45342
+ mov rcx, 10
45343
+ lea rsi, [__print_buf + 22]
45344
+ mov byte [rsi], 10
45345
+ .print_digitloop:
45346
+ xor rdx, rdx
45347
+ div rcx
45348
+ add dl, '0'
45349
+ dec rsi
45350
+ mov [rsi], dl
45351
+ test rax, rax
45352
+ jnz .print_digitloop
45353
+ lea rdx, [__print_buf + 23]
45354
+ sub rdx, rsi
45355
+ mov ecx, esi
45356
+ mov ebx, 1
45357
+ mov eax, 4
45358
+ int 0x80
45359
+ pop rsi
45360
+ pop rdx
45361
+ pop rcx
45362
+ pop rbx
45359
45363
  ret`;
45360
45364
  }
45361
45365
  traduzirDeclaracaoEscreva(declaracaoEscreva) {
@@ -45364,16 +45368,16 @@ __delegua_print_int:
45364
45368
  const nome_string_literal = this.criaStringLiteral(arg);
45365
45369
  const tam_string_literal = this.criaTamanhoNaMemoriaReferenteAVar(nome_string_literal);
45366
45370
  if (this.alvo === 'linux') {
45367
- this.textoSaida += `
45368
- mov edx, ${tam_string_literal}
45369
- mov ecx, ${nome_string_literal}
45370
- mov ebx, 1 ; fd stdout
45371
- mov eax, 4 ; sys_write
45371
+ this.textoSaida += `
45372
+ mov edx, ${tam_string_literal}
45373
+ mov ecx, ${nome_string_literal}
45374
+ mov ebx, 1 ; fd stdout
45375
+ mov eax, 4 ; sys_write
45372
45376
  int 0x80`;
45373
45377
  }
45374
45378
  else {
45375
- this.textoSaida += `
45376
- lea rcx, [rel ${nome_string_literal}]
45379
+ this.textoSaida += `
45380
+ lea rcx, [rel ${nome_string_literal}]
45377
45381
  call printf`;
45378
45382
  }
45379
45383
  }
@@ -45381,8 +45385,8 @@ __delegua_print_int:
45381
45385
  const valor = this.dicionarioConstrutos[arg.constructor.name](arg);
45382
45386
  if (this.alvo === 'linux') {
45383
45387
  this.emitirHelperPrintInt();
45384
- this.textoSaida += `
45385
- mov rax, ${valor}
45388
+ this.textoSaida += `
45389
+ mov rax, ${valor}
45386
45390
  call __delegua_print_int`;
45387
45391
  }
45388
45392
  else {
@@ -45390,24 +45394,24 @@ __delegua_print_int:
45390
45394
  this.data += ` __fmt_int db '%d', 10, 0\n`;
45391
45395
  this.fmtIntWindowsEmitido = true;
45392
45396
  }
45393
- this.textoSaida += `
45394
- mov rdx, ${valor}
45395
- lea rcx, [rel __fmt_int]
45397
+ this.textoSaida += `
45398
+ mov rdx, ${valor}
45399
+ lea rcx, [rel __fmt_int]
45396
45400
  call printf`;
45397
45401
  }
45398
45402
  }
45399
45403
  }
45400
45404
  saidaSistema() {
45401
45405
  if (this.alvo === 'linux') {
45402
- this.textoSaida += `
45403
- mov eax, 1 ; sys_exit
45404
- xor ebx, ebx ; status 0
45406
+ this.textoSaida += `
45407
+ mov eax, 1 ; sys_exit
45408
+ xor ebx, ebx ; status 0
45405
45409
  int 0x80`;
45406
45410
  }
45407
45411
  else {
45408
45412
  // Windows: return from main with 0 in EAX
45409
- this.textoSaida += `
45410
- xor eax, eax
45413
+ this.textoSaida += `
45414
+ xor eax, eax
45411
45415
  ret`;
45412
45416
  }
45413
45417
  }
@@ -53824,35 +53828,35 @@ class TradutorWebAssembly {
53824
53828
  * Fornece os imports necessários (`delegua.escreva_texto`, `delegua.escreva_inteiro`).
53825
53829
  */
53826
53830
  gerarArquivoHost() {
53827
- return `// Gerado por Delégua -> WebAssembly
53828
- // Uso: node delegua-host.mjs <arquivo.wasm>
53829
- import { readFileSync } from 'fs';
53830
-
53831
- const args = process.argv.slice(2);
53832
- const wasmPath = args[0] ?? 'saida.wasm';
53833
-
53834
- let memoryExport;
53835
-
53836
- const importObject = {
53837
- delegua: {
53838
- /** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
53839
- escreva_texto(ptr, len) {
53840
- const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
53841
- process.stdout.write(new TextDecoder('utf-8').decode(bytes));
53842
- },
53843
- /** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
53844
- escreva_inteiro(valor) {
53845
- process.stdout.write(String(valor));
53846
- },
53847
- }
53848
- };
53849
-
53850
- const wasmBuffer = readFileSync(wasmPath);
53851
- const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
53852
- memoryExport = instance.exports.memory;
53853
-
53854
- const codigoSaida = Number(instance.exports.principal());
53855
- process.exit(codigoSaida);
53831
+ return `// Gerado por Delégua -> WebAssembly
53832
+ // Uso: node delegua-host.mjs <arquivo.wasm>
53833
+ import { readFileSync } from 'fs';
53834
+
53835
+ const args = process.argv.slice(2);
53836
+ const wasmPath = args[0] ?? 'saida.wasm';
53837
+
53838
+ let memoryExport;
53839
+
53840
+ const importObject = {
53841
+ delegua: {
53842
+ /** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
53843
+ escreva_texto(ptr, len) {
53844
+ const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
53845
+ process.stdout.write(new TextDecoder('utf-8').decode(bytes));
53846
+ },
53847
+ /** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
53848
+ escreva_inteiro(valor) {
53849
+ process.stdout.write(String(valor));
53850
+ },
53851
+ }
53852
+ };
53853
+
53854
+ const wasmBuffer = readFileSync(wasmPath);
53855
+ const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
53856
+ memoryExport = instance.exports.memory;
53857
+
53858
+ const codigoSaida = Number(instance.exports.principal());
53859
+ process.exit(codigoSaida);
53856
53860
  `;
53857
53861
  }
53858
53862
  }