@designliquido/delegua 1.18.3 → 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 +155 -16
- 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 +7 -5
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.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 +40 -15
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js +17 -9
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +23 -13
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.js +4 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +3 -6
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.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/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js +1 -4
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-texto.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-texto.js +15 -16
- package/bibliotecas/dialetos/pitugues/primitivas-texto.js.map +1 -1
- package/bibliotecas/dialetos/prisma/biblioteca-global.js +4 -12
- package/bibliotecas/dialetos/prisma/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/tenda/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/tenda/biblioteca-global.js +141 -47
- package/bibliotecas/dialetos/tenda/biblioteca-global.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/ajuda-como-construto.d.ts.map +1 -1
- package/construtos/ajuda-como-construto.js.map +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/estilizador/quebrador-linha.d.ts.map +1 -1
- package/estilizador/quebrador-linha.js.map +1 -1
- package/estilizador/regras/regra-convencao-nomenclatura.d.ts.map +1 -1
- package/estilizador/regras/regra-convencao-nomenclatura.js.map +1 -1
- package/estilizador/regras/regra-explicitar-tipos-parametros.d.ts.map +1 -1
- package/estilizador/regras/regra-explicitar-tipos-parametros.js.map +1 -1
- package/estilizador/regras/regra-paradigma-consistente.d.ts.map +1 -1
- package/estilizador/regras/regra-paradigma-consistente.js.map +1 -1
- package/interfaces/declaracoes/caminho-se-senao-interface.d.ts +2 -2
- package/interfaces/estilizador/opcoes-paradigma-consistente-interface.d.ts +1 -1
- package/interfaces/estilizador/regra-estilizacao-interface.d.ts +2 -2
- package/interfaces/formatador/index.d.ts +1 -1
- package/interfaces/formatador/opcoes-formatador-delegua-interface.d.ts +1 -1
- package/interpretador/dialetos/calango/interpretador-calango.d.ts.map +1 -1
- package/interpretador/dialetos/calango/interpretador-calango.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/interpretador/dialetos/pitugues/comum.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/comum.js +10 -14
- package/interpretador/dialetos/pitugues/comum.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 +41 -3
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.d.ts.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js +91 -39
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js.map +1 -1
- package/interpretador/dialetos/tenda/interpretador-tenda.d.ts.map +1 -1
- package/interpretador/dialetos/tenda/interpretador-tenda.js.map +1 -1
- package/interpretador/estruturas/delegua-funcao.d.ts.map +1 -1
- package/interpretador/estruturas/delegua-funcao.js +1 -1
- package/interpretador/estruturas/delegua-funcao.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 +32 -13
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +20 -10
- package/interpretador/interpretador.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js +3 -5
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/lexador/dialetos/lexador-calango.d.ts.map +1 -1
- package/lexador/dialetos/lexador-calango.js +3 -1
- package/lexador/dialetos/lexador-calango.js.map +1 -1
- package/lexador/lexador.d.ts.map +1 -1
- package/lexador/lexador.js +4 -2
- package/lexador/lexador.js.map +1 -1
- package/lexador/palavras-reservadas.d.ts.map +1 -1
- package/lexador/palavras-reservadas.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-assemblyscript.d.ts.map +1 -1
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-elixir.d.ts.map +1 -1
- package/tradutores/tradutor-elixir.js +18 -8
- package/tradutores/tradutor-elixir.js.map +1 -1
- package/tradutores/tradutor-portugol-ipt.d.ts.map +1 -1
- package/tradutores/tradutor-portugol-ipt.js +65 -35
- package/tradutores/tradutor-portugol-ipt.js.map +1 -1
- package/tradutores/tradutor-reverso-calango.d.ts.map +1 -1
- package/tradutores/tradutor-reverso-calango.js +3 -1
- package/tradutores/tradutor-reverso-calango.js.map +1 -1
- package/tradutores/tradutor-reverso-python.d.ts.map +1 -1
- package/tradutores/tradutor-reverso-python.js +37 -14
- package/tradutores/tradutor-reverso-python.js.map +1 -1
- package/tradutores/tradutor-webassembly.js +29 -29
- package/umd/delegua.js +880 -584
package/umd/delegua.js
CHANGED
|
@@ -642,13 +642,47 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
642
642
|
visitarChamadaPorVariavel(entidadeChamadaVariavel, argumentos) {
|
|
643
643
|
const variavel = entidadeChamadaVariavel;
|
|
644
644
|
const nomeFuncao = variavel.simbolo.lexema;
|
|
645
|
-
const funcoesNativas = [
|
|
645
|
+
const funcoesNativas = [
|
|
646
|
+
'aleatorio',
|
|
647
|
+
'aleatorioEntre',
|
|
648
|
+
'algum',
|
|
649
|
+
'arredondar',
|
|
650
|
+
'clonar',
|
|
651
|
+
'encontrar',
|
|
652
|
+
'encontrarIndice',
|
|
653
|
+
'encontrarUltimo',
|
|
654
|
+
'encontrarUltimoIndice',
|
|
655
|
+
'escreva',
|
|
656
|
+
'filtrarPor',
|
|
657
|
+
'incluido',
|
|
658
|
+
'inteiro',
|
|
659
|
+
'intervalo',
|
|
660
|
+
'leia',
|
|
661
|
+
'longo',
|
|
662
|
+
'mapear',
|
|
663
|
+
'maximo',
|
|
664
|
+
'minimo',
|
|
665
|
+
'numero',
|
|
666
|
+
'número',
|
|
667
|
+
'ordenar',
|
|
668
|
+
'paraCada',
|
|
669
|
+
'primeiroEmCondicao',
|
|
670
|
+
'real',
|
|
671
|
+
'reduzir',
|
|
672
|
+
'somar',
|
|
673
|
+
'tamanho',
|
|
674
|
+
'texto',
|
|
675
|
+
'tipo',
|
|
676
|
+
'todos',
|
|
677
|
+
'todosEmCondicao',
|
|
678
|
+
'tupla',
|
|
679
|
+
'vetor',
|
|
680
|
+
];
|
|
646
681
|
const pareceSerClasse = nomeFuncao[0] === nomeFuncao[0].toUpperCase();
|
|
647
682
|
if (funcoesNativas.includes(nomeFuncao) || pareceSerClasse) {
|
|
648
683
|
return Promise.resolve();
|
|
649
684
|
}
|
|
650
|
-
const funcaoChamada = this.gerenciadorEscopos.buscar(nomeFuncao) ||
|
|
651
|
-
this.funcoes[nomeFuncao];
|
|
685
|
+
const funcaoChamada = this.gerenciadorEscopos.buscar(nomeFuncao) || this.funcoes[nomeFuncao];
|
|
652
686
|
if (!funcaoChamada) {
|
|
653
687
|
this.erro(entidadeChamadaVariavel.simbolo, `Chamada da função '${nomeFuncao}' não existe.`);
|
|
654
688
|
return Promise.resolve();
|
|
@@ -819,11 +853,15 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
819
853
|
}
|
|
820
854
|
return Promise.resolve();
|
|
821
855
|
}
|
|
822
|
-
visitarDeclaracaoEscolha(declaracao) {
|
|
856
|
+
async visitarDeclaracaoEscolha(declaracao) {
|
|
823
857
|
const identificadorOuLiteral = declaracao.identificadorOuLiteral;
|
|
824
858
|
const tipo = identificadorOuLiteral.tipo || 'qualquer';
|
|
825
859
|
const tiposLiteraisCasos = [];
|
|
860
|
+
this.marcarVariaveisUsadasEmExpressao(identificadorOuLiteral);
|
|
826
861
|
for (let caminho of declaracao.caminhos) {
|
|
862
|
+
for (const declaracao of caminho.declaracoes) {
|
|
863
|
+
await declaracao.aceitar(this);
|
|
864
|
+
}
|
|
827
865
|
for (let condicao of caminho.condicoes) {
|
|
828
866
|
switch (condicao.constructor) {
|
|
829
867
|
case construtos_1.Literal:
|
|
@@ -831,7 +869,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
831
869
|
const tiposNumericos = ['inteiro', 'número', 'real'];
|
|
832
870
|
const ambosSaoNumericos = tiposNumericos.includes(condicaoLiteral.tipo) &&
|
|
833
871
|
tiposNumericos.includes(tipo);
|
|
834
|
-
if (condicaoLiteral.tipo !== tipo &&
|
|
872
|
+
if (condicaoLiteral.tipo !== tipo &&
|
|
873
|
+
!ambosSaoNumericos &&
|
|
874
|
+
tipo !== 'qualquer') {
|
|
835
875
|
this.erro({
|
|
836
876
|
lexema: condicaoLiteral.valor,
|
|
837
877
|
tipo: condicaoLiteral.tipo,
|
|
@@ -852,23 +892,32 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
852
892
|
}
|
|
853
893
|
}
|
|
854
894
|
}
|
|
855
|
-
if (tipo === 'qualquer' &&
|
|
895
|
+
if (tipo === 'qualquer' &&
|
|
896
|
+
tiposLiteraisCasos.length > 0 &&
|
|
897
|
+
identificadorOuLiteral instanceof construtos_1.Variavel) {
|
|
856
898
|
const tiposUnicos = [...new Set(tiposLiteraisCasos)];
|
|
857
899
|
if (tiposUnicos.length === 1) {
|
|
858
900
|
const tipoInferido = tiposUnicos[0];
|
|
859
901
|
const variavelEscopo = this.gerenciadorEscopos.buscar(identificadorOuLiteral.simbolo.lexema);
|
|
860
902
|
if (variavelEscopo) {
|
|
861
|
-
this.sugestao(identificadorOuLiteral.simbolo, `Um tipo melhor pode ser inferido para '${identificadorOuLiteral.simbolo.lexema}': '${tipoInferido}'`, [
|
|
903
|
+
this.sugestao(identificadorOuLiteral.simbolo, `Um tipo melhor pode ser inferido para '${identificadorOuLiteral.simbolo.lexema}': '${tipoInferido}'`, [
|
|
904
|
+
{
|
|
862
905
|
titulo: `Alterar tipo de '${identificadorOuLiteral.simbolo.lexema}' para '${tipoInferido}'`,
|
|
863
906
|
textoOriginal: 'qualquer',
|
|
864
907
|
textoSubstituto: tipoInferido,
|
|
865
908
|
linha: variavelEscopo.linha,
|
|
866
909
|
colunaInicio: 0,
|
|
867
910
|
colunaFim: 0,
|
|
868
|
-
}
|
|
911
|
+
},
|
|
912
|
+
]);
|
|
869
913
|
}
|
|
870
914
|
}
|
|
871
915
|
}
|
|
916
|
+
if (declaracao.caminhoPadrao) {
|
|
917
|
+
for (const decl of declaracao.caminhoPadrao.declaracoes) {
|
|
918
|
+
await decl.aceitar(this);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
872
921
|
return Promise.resolve();
|
|
873
922
|
}
|
|
874
923
|
async visitarDeclaracaoEnquanto(declaracao) {
|
|
@@ -921,9 +970,48 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
921
970
|
}
|
|
922
971
|
return Promise.resolve();
|
|
923
972
|
}
|
|
924
|
-
visitarDeclaracaoParaCada(declaracao) {
|
|
925
|
-
// Marca o vetor/dicionário como usado
|
|
973
|
+
async visitarDeclaracaoParaCada(declaracao) {
|
|
926
974
|
this.marcarVariaveisUsadasEmExpressao(declaracao.vetorOuDicionario);
|
|
975
|
+
this.gerenciadorEscopos.empilharEscopo();
|
|
976
|
+
try {
|
|
977
|
+
if (declaracao.variavelIteracao instanceof construtos_1.Variavel) {
|
|
978
|
+
const nome = declaracao.variavelIteracao.simbolo.lexema;
|
|
979
|
+
this.gerenciadorEscopos.declarar(nome, {
|
|
980
|
+
nome,
|
|
981
|
+
tipo: 'qualquer',
|
|
982
|
+
imutavel: false,
|
|
983
|
+
valor: null,
|
|
984
|
+
inicializada: true,
|
|
985
|
+
usada: false,
|
|
986
|
+
hashArquivo: declaracao.hashArquivo,
|
|
987
|
+
linha: declaracao.linha,
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
else if (declaracao.variavelIteracao instanceof construtos_1.Dupla) {
|
|
991
|
+
const dupla = declaracao.variavelIteracao;
|
|
992
|
+
for (const parte of [dupla.primeiro, dupla.segundo]) {
|
|
993
|
+
if (parte instanceof construtos_1.Variavel) {
|
|
994
|
+
const nome = parte.simbolo.lexema;
|
|
995
|
+
this.gerenciadorEscopos.declarar(nome, {
|
|
996
|
+
nome,
|
|
997
|
+
tipo: 'qualquer',
|
|
998
|
+
imutavel: false,
|
|
999
|
+
valor: null,
|
|
1000
|
+
inicializada: true,
|
|
1001
|
+
usada: false,
|
|
1002
|
+
hashArquivo: declaracao.hashArquivo,
|
|
1003
|
+
linha: declaracao.linha,
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (declaracao.corpo) {
|
|
1009
|
+
await declaracao.corpo.aceitar(this);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
finally {
|
|
1013
|
+
this.gerenciadorEscopos.desempilharEscopo();
|
|
1014
|
+
}
|
|
927
1015
|
return Promise.resolve();
|
|
928
1016
|
}
|
|
929
1017
|
async visitarDeclaracaoSe(declaracao) {
|
|
@@ -998,6 +1086,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
998
1086
|
verificarVariavel(variavel) {
|
|
999
1087
|
const variavelEscopo = this.gerenciadorEscopos.buscar(variavel.simbolo.lexema);
|
|
1000
1088
|
if (!variavelEscopo) {
|
|
1089
|
+
if (this.funcoes[variavel.simbolo.lexema]) {
|
|
1090
|
+
return Promise.resolve();
|
|
1091
|
+
}
|
|
1001
1092
|
this.erro(variavel.simbolo, `Variável '${variavel.simbolo.lexema}' ainda não foi declarada até este ponto.`);
|
|
1002
1093
|
return Promise.resolve();
|
|
1003
1094
|
}
|
|
@@ -1202,14 +1293,40 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1202
1293
|
const nomeFuncao = entidadeChamadaVariavel.simbolo.lexema;
|
|
1203
1294
|
// Lista de funções embutidas que não precisam ser declaradas
|
|
1204
1295
|
const funcoesEmbutidas = [
|
|
1296
|
+
'aleatorio',
|
|
1297
|
+
'aleatorioEntre',
|
|
1298
|
+
'algum',
|
|
1299
|
+
'arredondar',
|
|
1300
|
+
'clonar',
|
|
1301
|
+
'encontrar',
|
|
1302
|
+
'encontrarIndice',
|
|
1303
|
+
'encontrarUltimo',
|
|
1304
|
+
'encontrarUltimoIndice',
|
|
1305
|
+
'escreva',
|
|
1306
|
+
'filtrarPor',
|
|
1307
|
+
'incluido',
|
|
1205
1308
|
'inteiro',
|
|
1206
|
-
'
|
|
1309
|
+
'intervalo',
|
|
1310
|
+
'leia',
|
|
1311
|
+
'longo',
|
|
1312
|
+
'mapear',
|
|
1313
|
+
'maximo',
|
|
1314
|
+
'minimo',
|
|
1207
1315
|
'numero',
|
|
1208
1316
|
'número',
|
|
1317
|
+
'ordenar',
|
|
1318
|
+
'paraCada',
|
|
1319
|
+
'primeiroEmCondicao',
|
|
1320
|
+
'real',
|
|
1321
|
+
'reduzir',
|
|
1322
|
+
'somar',
|
|
1323
|
+
'tamanho',
|
|
1209
1324
|
'texto',
|
|
1210
|
-
'leia',
|
|
1211
|
-
'escreva',
|
|
1212
1325
|
'tipo',
|
|
1326
|
+
'todos',
|
|
1327
|
+
'todosEmCondicao',
|
|
1328
|
+
'tupla',
|
|
1329
|
+
'vetor',
|
|
1213
1330
|
];
|
|
1214
1331
|
// Classes/construtores geralmente começam com letra maiúscula
|
|
1215
1332
|
const pareceSerClasse = nomeFuncao[0] === nomeFuncao[0].toUpperCase();
|
|
@@ -1435,6 +1552,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1435
1552
|
return Promise.resolve();
|
|
1436
1553
|
}
|
|
1437
1554
|
visitarExpressaoRetornar(declaracao) {
|
|
1555
|
+
if (declaracao.valor) {
|
|
1556
|
+
this.marcarVariaveisUsadasEmExpressao(declaracao.valor);
|
|
1557
|
+
}
|
|
1438
1558
|
return Promise.resolve(undefined);
|
|
1439
1559
|
}
|
|
1440
1560
|
visitarExpressaoDeVariavel(expressao) {
|
|
@@ -1517,7 +1637,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1517
1637
|
if (nomeSuperclasse === declaracao.simbolo.lexema) {
|
|
1518
1638
|
this.erro(superClasseVariavel.simbolo, `A classe '${declaracao.simbolo.lexema}' não pode herdar de si mesma.`);
|
|
1519
1639
|
}
|
|
1520
|
-
else if (!this.classesDeclaradas.has(nomeSuperclasse) &&
|
|
1640
|
+
else if (!this.classesDeclaradas.has(nomeSuperclasse) &&
|
|
1641
|
+
!this.classesExternasConhecidas.has(nomeSuperclasse)) {
|
|
1521
1642
|
this.erro(superClasseVariavel.simbolo, `Superclasse '${nomeSuperclasse}' não foi declarada.`);
|
|
1522
1643
|
}
|
|
1523
1644
|
}
|
|
@@ -1554,8 +1675,26 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1554
1675
|
metodo.funcao.corpo.length === 0) {
|
|
1555
1676
|
this.aviso(metodo.simbolo, `Método especifica tipo de retorno '${tipoRetornoMetodo}', mas não há qualquer retorno correspondente no corpo do método.`);
|
|
1556
1677
|
}
|
|
1557
|
-
|
|
1558
|
-
|
|
1678
|
+
this.gerenciadorEscopos.empilharEscopo();
|
|
1679
|
+
try {
|
|
1680
|
+
for (const parametro of metodo.funcao.parametros) {
|
|
1681
|
+
this.gerenciadorEscopos.declarar(parametro.nome.lexema, {
|
|
1682
|
+
nome: parametro.nome.lexema,
|
|
1683
|
+
tipo: parametro.tipoDado || 'qualquer',
|
|
1684
|
+
imutavel: false,
|
|
1685
|
+
valor: undefined,
|
|
1686
|
+
inicializada: true,
|
|
1687
|
+
usada: true,
|
|
1688
|
+
hashArquivo: parametro.nome.hashArquivo,
|
|
1689
|
+
linha: parametro.nome.linha,
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
for (const declaracao of metodo.funcao.corpo) {
|
|
1693
|
+
await declaracao.aceitar(this);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
finally {
|
|
1697
|
+
this.gerenciadorEscopos.desempilharEscopo();
|
|
1559
1698
|
}
|
|
1560
1699
|
}
|
|
1561
1700
|
}
|
|
@@ -2676,7 +2815,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2676
2815
|
construto = new construtos_1.AcessoMetodo(construtoTipado.hashArquivo, construtoTipado.objeto, construtoTipado.simbolo.lexema, primitivaVetorSelecionada.tipoRetorno);
|
|
2677
2816
|
break;
|
|
2678
2817
|
default:
|
|
2679
|
-
if (construtoTipado.tipo &&
|
|
2818
|
+
if (construtoTipado.tipo &&
|
|
2819
|
+
construtoTipado.tipo in this.tiposDefinidosEmCodigo) {
|
|
2680
2820
|
const tipoCorrespondente = this.tiposDefinidosEmCodigo[construtoTipado.tipo];
|
|
2681
2821
|
const possivelMetodo = tipoCorrespondente.metodos.filter((m) => m.simbolo.lexema === construtoTipado.simbolo.lexema);
|
|
2682
2822
|
if (possivelMetodo.length > 0) {
|
|
@@ -3036,10 +3176,29 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3036
3176
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.NAO, delegua_2.default.NEGACAO, delegua_2.default.ADICAO, delegua_2.default.SUBTRACAO, delegua_2.default.BIT_NOT, delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR)) {
|
|
3037
3177
|
const operador = this.simbolos[this.atual - 1];
|
|
3038
3178
|
const direito = await this.unario();
|
|
3179
|
+
if (operador.tipo === delegua_2.default.NEGACAO ||
|
|
3180
|
+
operador.tipo === delegua_2.default.NAO) {
|
|
3181
|
+
this.verificarOperandoNegacao(operador, direito);
|
|
3182
|
+
}
|
|
3039
3183
|
return new construtos_1.Unario(this.hashArquivo, operador, direito, 'ANTES');
|
|
3040
3184
|
}
|
|
3041
3185
|
return await this.chamar();
|
|
3042
3186
|
}
|
|
3187
|
+
verificarOperandoNegacao(operador, operando) {
|
|
3188
|
+
if (operando instanceof construtos_1.Literal) {
|
|
3189
|
+
if (operando.tipo !== 'lógico') {
|
|
3190
|
+
this.erros.push(this.erro(operador, `Operador '!' só pode ser usado com valores lógicos. Tipo recebido: ${operando.tipo}.`));
|
|
3191
|
+
}
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
if (operando instanceof construtos_1.Unario) {
|
|
3195
|
+
const tipoOp = operando.operador.tipo;
|
|
3196
|
+
if (tipoOp === delegua_2.default.NEGACAO || tipoOp === delegua_2.default.NAO) {
|
|
3197
|
+
return;
|
|
3198
|
+
}
|
|
3199
|
+
this.verificarOperandoNegacao(operador, operando.operando);
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3043
3202
|
/**
|
|
3044
3203
|
* A exponenciacão é uma exceção na ordem de avaliação (resolve primeiro à direita).
|
|
3045
3204
|
* Por isso `direito` chama `exponenciacao()`, e não `unario()`.
|
|
@@ -3407,7 +3566,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3407
3566
|
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
|
|
3408
3567
|
const declaracoes = [];
|
|
3409
3568
|
do {
|
|
3410
|
-
declaracoes.push(await this.resolverDeclaracao());
|
|
3569
|
+
declaracoes.push((await this.resolverDeclaracao()));
|
|
3411
3570
|
} while (!this.verificarTipoSimboloAtual(delegua_2.default.CASO) &&
|
|
3412
3571
|
!this.verificarTipoSimboloAtual(delegua_2.default.PADRAO) &&
|
|
3413
3572
|
!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA));
|
|
@@ -3480,7 +3639,9 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3480
3639
|
const simboloNao = new simbolo_1.Simbolo(delegua_2.default.NEGACAO, 'nao', null, Number(simboloAssercao.linha), simboloAssercao.hashArquivo, simboloAssercao.colunaInicio, simboloAssercao.colunaFim);
|
|
3481
3640
|
const condicaoNegada = new construtos_1.Unario(simboloAssercao.hashArquivo, simboloNao, condicao, 'ANTES');
|
|
3482
3641
|
const declaracaoFalhar = new declaracoes_1.Falhar(simboloAssercao, mensagemFalha);
|
|
3483
|
-
const blocoFalha = new declaracoes_1.Bloco(simboloAssercao.hashArquivo, Number(simboloAssercao.linha), [
|
|
3642
|
+
const blocoFalha = new declaracoes_1.Bloco(simboloAssercao.hashArquivo, Number(simboloAssercao.linha), [
|
|
3643
|
+
declaracaoFalhar,
|
|
3644
|
+
]);
|
|
3484
3645
|
return new declaracoes_1.Se(condicaoNegada, blocoFalha);
|
|
3485
3646
|
}
|
|
3486
3647
|
async logicaComumFazer() {
|
|
@@ -3540,7 +3701,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3540
3701
|
construtoCaminhoModulo = new construtos_1.Literal(identificadorModulo.hashArquivo, Number(identificadorModulo.linha), identificadorModulo.lexema);
|
|
3541
3702
|
break;
|
|
3542
3703
|
default:
|
|
3543
|
-
throw this.erro(this.simbolos[this.atual],
|
|
3704
|
+
throw this.erro(this.simbolos[this.atual], 'Esperado caminho do módulo como texto ou identificador em declaração de importação.');
|
|
3544
3705
|
}
|
|
3545
3706
|
const importar = new declaracoes_1.Importar(construtoCaminhoModulo);
|
|
3546
3707
|
if (identificadorDeTudo !== null) {
|
|
@@ -3713,7 +3874,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3713
3874
|
const caminhoEntao = (await this.resolverDeclaracao());
|
|
3714
3875
|
let caminhoSenao = undefined;
|
|
3715
3876
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
3716
|
-
caminhoSenao = await this.resolverDeclaracao();
|
|
3877
|
+
caminhoSenao = (await this.resolverDeclaracao());
|
|
3717
3878
|
}
|
|
3718
3879
|
return new declaracoes_1.Se(condicao, caminhoEntao, [], caminhoSenao);
|
|
3719
3880
|
}
|
|
@@ -3848,11 +4009,11 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3848
4009
|
const classeDefinida = this.tiposDefinidosEmCodigo[tipoObjeto];
|
|
3849
4010
|
if (classeDefinida instanceof declaracoes_1.Classe) {
|
|
3850
4011
|
const nomeMembro = entidadeChamada.simbolo.lexema;
|
|
3851
|
-
const metodo = classeDefinida.metodos?.find(m => m.simbolo.lexema === nomeMembro);
|
|
4012
|
+
const metodo = classeDefinida.metodos?.find((m) => m.simbolo.lexema === nomeMembro);
|
|
3852
4013
|
if (metodo) {
|
|
3853
4014
|
return metodo.tipo || 'qualquer';
|
|
3854
4015
|
}
|
|
3855
|
-
const propriedade = classeDefinida.propriedades?.find(p => p.nome.lexema === nomeMembro);
|
|
4016
|
+
const propriedade = classeDefinida.propriedades?.find((p) => p.nome.lexema === nomeMembro);
|
|
3856
4017
|
if (propriedade) {
|
|
3857
4018
|
return propriedade.tipo || 'qualquer';
|
|
3858
4019
|
}
|
|
@@ -3878,7 +4039,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3878
4039
|
if (entidadeChamada.objeto instanceof construtos_1.Isto) {
|
|
3879
4040
|
if (this.metodosClasseAtualEmAnalise) {
|
|
3880
4041
|
const nomeMembro = entidadeChamada.simbolo.lexema;
|
|
3881
|
-
const metodo = this.metodosClasseAtualEmAnalise.find(m => m.simbolo.lexema === nomeMembro);
|
|
4042
|
+
const metodo = this.metodosClasseAtualEmAnalise.find((m) => m.simbolo.lexema === nomeMembro);
|
|
3882
4043
|
if (metodo) {
|
|
3883
4044
|
return metodo.tipo || 'qualquer';
|
|
3884
4045
|
}
|
|
@@ -4027,7 +4188,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4027
4188
|
}
|
|
4028
4189
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
4029
4190
|
const tipoOriginal = tipo; // Preserva o tipo antes da inferência
|
|
4030
|
-
tipo =
|
|
4191
|
+
tipo =
|
|
4192
|
+
this.logicaComumInferenciaTiposVariaveisEConstantes(inicializadores[indice], tipo) ?? tipo;
|
|
4031
4193
|
if (tipo !== 'dicionário') {
|
|
4032
4194
|
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
4033
4195
|
}
|
|
@@ -4095,7 +4257,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4095
4257
|
let retorno = [];
|
|
4096
4258
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
4097
4259
|
// Se tipo ainda não foi definido, infere.
|
|
4098
|
-
tipo =
|
|
4260
|
+
tipo =
|
|
4261
|
+
this.logicaComumInferenciaTiposVariaveisEConstantes(inicializadores[indice], tipo) ?? tipo;
|
|
4099
4262
|
if (tipo !== 'dicionário') {
|
|
4100
4263
|
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
4101
4264
|
}
|
|
@@ -4404,7 +4567,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4404
4567
|
this.erros.push(erro);
|
|
4405
4568
|
}
|
|
4406
4569
|
if (this.erros.length > quantidadeErrosAntesCorpoOp) {
|
|
4407
|
-
this.atual =
|
|
4570
|
+
this.atual =
|
|
4571
|
+
this.encontrarIndiceAposFechamentoDeBloco(indiceAberturaCorpoOp);
|
|
4408
4572
|
corpoOp = [];
|
|
4409
4573
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
4410
4574
|
}
|
|
@@ -4442,7 +4606,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4442
4606
|
// Método de classe estrangeira não pode ter corpo.
|
|
4443
4607
|
if (ehEstrangeira &&
|
|
4444
4608
|
this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
4445
|
-
throw this.erro(this.simbolos[this.atual],
|
|
4609
|
+
throw this.erro(this.simbolos[this.atual], 'Métodos de classe estrangeira não podem ter corpo.');
|
|
4446
4610
|
}
|
|
4447
4611
|
// Método é abstrato quando: (a) está dentro de um bloco `abstrato {}`,
|
|
4448
4612
|
// ou (b) a classe é abstrata/estrangeira e o próximo token não é `{`.
|
|
@@ -4475,7 +4639,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4475
4639
|
this.erros.push(erro);
|
|
4476
4640
|
}
|
|
4477
4641
|
if (this.erros.length > quantidadeErrosAntesCorpo) {
|
|
4478
|
-
this.atual =
|
|
4642
|
+
this.atual =
|
|
4643
|
+
this.encontrarIndiceAposFechamentoDeBloco(indiceAberturaCorpo);
|
|
4479
4644
|
corpo = [];
|
|
4480
4645
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
4481
4646
|
}
|
|
@@ -4553,8 +4718,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4553
4718
|
catch (erro) {
|
|
4554
4719
|
this.erros.push(erro);
|
|
4555
4720
|
}
|
|
4556
|
-
if (this.erros.length >
|
|
4557
|
-
quantidadeErrosAntesCorpoAcessor) {
|
|
4721
|
+
if (this.erros.length > quantidadeErrosAntesCorpoAcessor) {
|
|
4558
4722
|
this.atual = this.encontrarIndiceAposFechamentoDeBloco(indiceAberturaCorpoAcessor);
|
|
4559
4723
|
corpoAcessor = [];
|
|
4560
4724
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
@@ -6400,9 +6564,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6400
6564
|
}
|
|
6401
6565
|
// Modo formatação: {expressao:formato}
|
|
6402
6566
|
if (mioloLimpo.includes(':')) {
|
|
6403
|
-
const [variavel, formato] = mioloLimpo
|
|
6404
|
-
.split(':')
|
|
6405
|
-
.map(s => s.trim());
|
|
6567
|
+
const [variavel, formato] = mioloLimpo.split(':').map((s) => s.trim());
|
|
6406
6568
|
if (variavel) {
|
|
6407
6569
|
return `" + "{:${formato}}".formatar(${variavel}) + "`;
|
|
6408
6570
|
}
|
|
@@ -6526,8 +6688,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6526
6688
|
case pitugues_2.default.INTERPOLACAO:
|
|
6527
6689
|
const simboloInterpolacao = this.avancarEDevolverAnterior();
|
|
6528
6690
|
const conteudoOriginal = simboloInterpolacao.literal;
|
|
6529
|
-
const codigoTransformado = this
|
|
6530
|
-
.transformarInterpolacaoEmFormatacao(conteudoOriginal);
|
|
6691
|
+
const codigoTransformado = this.transformarInterpolacaoEmFormatacao(conteudoOriginal);
|
|
6531
6692
|
const microLexador = new micro_lexador_pitugues_1.MicroLexadorPitugues();
|
|
6532
6693
|
const retornoMicroLexador = microLexador.mapear(codigoTransformado);
|
|
6533
6694
|
const microAvaliadorSintatico = new micro_avaliador_sintatico_pitugues_1.MicroAvaliadorSintaticoPitugues();
|
|
@@ -7329,24 +7490,37 @@ class AvaliadorSintaticoPitugues {
|
|
|
7329
7490
|
this.consumir(pitugues_2.default.DOIS_PONTOS, "Esperado ':' antes do escopo da classe.");
|
|
7330
7491
|
const possivelDocumentacao = this.declaracaoTextoDeDocumentacao();
|
|
7331
7492
|
const metodos = [];
|
|
7332
|
-
const
|
|
7333
|
-
const indentacaoLinha = this
|
|
7493
|
+
const propriedadesDeClasse = [];
|
|
7494
|
+
const indentacaoLinha = this
|
|
7495
|
+
.localizacoes[this.simboloAtual().linha]
|
|
7496
|
+
.espacosIndentacao;
|
|
7334
7497
|
while (!this.estaNoFinal() &&
|
|
7335
7498
|
this.localizacoes[this.simboloAtual().linha].espacosIndentacao === indentacaoLinha &&
|
|
7336
7499
|
this.verificarSeSimboloAtualEIgualA(pitugues_2.default.CONSTRUTOR, pitugues_2.default.FUNCAO, pitugues_2.default.FUNÇÃO, pitugues_2.default.IDENTIFICADOR)) {
|
|
7337
7500
|
const simboloAnterior = this.simbolos[this.atual - 1];
|
|
7338
7501
|
if (simboloAnterior.tipo === pitugues_2.default.IDENTIFICADOR) {
|
|
7339
|
-
this.
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7502
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS)) {
|
|
7503
|
+
const simboloTipo = this.consumir(pitugues_2.default.IDENTIFICADOR, 'Esperado tipo da propriedade após os dois pontos.');
|
|
7504
|
+
const propriedade = new declaracoes_1.PropriedadeClasse(simboloAnterior, simboloTipo.lexema, [], 'publico', false, undefined);
|
|
7505
|
+
propriedadesDeClasse.push(propriedade);
|
|
7506
|
+
}
|
|
7507
|
+
else if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.IGUAL)) {
|
|
7508
|
+
const valorPropriedade = await this.expressao();
|
|
7509
|
+
const propriedade = new declaracoes_1.PropriedadeClasse(simboloAnterior, undefined, [], 'publico', true, valorPropriedade);
|
|
7510
|
+
propriedadesDeClasse.push(propriedade);
|
|
7511
|
+
}
|
|
7512
|
+
else {
|
|
7513
|
+
throw this.erro(this.simboloAtual(), "Esperado ':' (para tipo) ou '=' (para valor) após o nome da propriedade.");
|
|
7514
|
+
}
|
|
7343
7515
|
}
|
|
7344
7516
|
else {
|
|
7345
|
-
|
|
7517
|
+
const ehConstrutor = simboloAnterior.tipo === pitugues_2.default.CONSTRUTOR;
|
|
7518
|
+
const metodoResolvido = await this.funcao('método', ehConstrutor);
|
|
7519
|
+
metodos.push(metodoResolvido);
|
|
7346
7520
|
}
|
|
7347
7521
|
}
|
|
7348
7522
|
this.superclasseAtual = undefined;
|
|
7349
|
-
const definicaoClasse = new declaracoes_1.Classe(simbolo, superClasse ? [superClasse] : [], metodos,
|
|
7523
|
+
const definicaoClasse = new declaracoes_1.Classe(simbolo, superClasse ? [superClasse] : [], metodos, propriedadesDeClasse);
|
|
7350
7524
|
if (possivelDocumentacao) {
|
|
7351
7525
|
definicaoClasse.documentacao = possivelDocumentacao;
|
|
7352
7526
|
}
|
|
@@ -8052,7 +8226,10 @@ class AvaliadorSintaticoPortugolIpt extends avaliador_sintatico_base_1.Avaliador
|
|
|
8052
8226
|
else if (this.verificarSeSimboloAtualEIgualA(portugol_ipt_1.default.DEFEITO)) {
|
|
8053
8227
|
this.consumir(portugol_ipt_1.default.DOIS_PONTOS, "Esperado ':' após 'defeito'.");
|
|
8054
8228
|
this.consumirQuebrasLinha();
|
|
8055
|
-
const bloco = await this.resolverBloco([
|
|
8229
|
+
const bloco = await this.resolverBloco([
|
|
8230
|
+
portugol_ipt_1.default.FIMESCOLHE,
|
|
8231
|
+
portugol_ipt_1.default.FIM,
|
|
8232
|
+
]);
|
|
8056
8233
|
caminhoPadrao = { condicoes: [], declaracoes: bloco.declaracoes };
|
|
8057
8234
|
}
|
|
8058
8235
|
else {
|
|
@@ -8781,11 +8958,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
8781
8958
|
const simboloTente = this.simboloAnterior();
|
|
8782
8959
|
const blocoTente = [];
|
|
8783
8960
|
while (!this.estaNoFinal() &&
|
|
8784
|
-
![
|
|
8785
|
-
prisma_1.default.PEGUE,
|
|
8786
|
-
prisma_1.default.FINALMENTE,
|
|
8787
|
-
prisma_1.default.FIM,
|
|
8788
|
-
].includes(this.simbolos[this.atual].tipo)) {
|
|
8961
|
+
![prisma_1.default.PEGUE, prisma_1.default.FINALMENTE, prisma_1.default.FIM].includes(this.simbolos[this.atual].tipo)) {
|
|
8789
8962
|
blocoTente.push(await this.resolverDeclaracaoForaDeBloco());
|
|
8790
8963
|
}
|
|
8791
8964
|
let blocoPegue = null;
|
|
@@ -9053,7 +9226,8 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
9053
9226
|
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
9054
9227
|
this.consumir(prisma_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do corpo do método.");
|
|
9055
9228
|
const declaracoesCorpo = [];
|
|
9056
|
-
while (!this.estaNoFinal() &&
|
|
9229
|
+
while (!this.estaNoFinal() &&
|
|
9230
|
+
!this.verificarTipoSimboloAtual(prisma_1.default.CHAVE_DIREITA)) {
|
|
9057
9231
|
declaracoesCorpo.push(await this.resolverDeclaracaoForaDeBloco());
|
|
9058
9232
|
}
|
|
9059
9233
|
this.consumir(prisma_1.default.CHAVE_DIREITA, "Esperado '}' após o corpo do método.");
|
|
@@ -10768,10 +10942,28 @@ class MicroAvaliadorSintatico extends micro_avaliador_sintatico_base_1.MicroAval
|
|
|
10768
10942
|
}
|
|
10769
10943
|
return expressao;
|
|
10770
10944
|
}
|
|
10945
|
+
verificarOperandoNegacao(operador, operando) {
|
|
10946
|
+
if (operando instanceof construtos_1.Literal) {
|
|
10947
|
+
if (operando.tipo !== 'lógico') {
|
|
10948
|
+
this.erro(operador, `Operador '!' só pode ser usado com valores lógicos. Tipo recebido: ${operando.tipo}.`);
|
|
10949
|
+
}
|
|
10950
|
+
return;
|
|
10951
|
+
}
|
|
10952
|
+
if (operando instanceof construtos_1.Unario) {
|
|
10953
|
+
const tipoOp = operando.operador.tipo;
|
|
10954
|
+
if (tipoOp === delegua_1.default.NEGACAO) {
|
|
10955
|
+
return;
|
|
10956
|
+
}
|
|
10957
|
+
this.verificarOperandoNegacao(operador, operando.operando);
|
|
10958
|
+
}
|
|
10959
|
+
}
|
|
10771
10960
|
unario() {
|
|
10772
10961
|
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.NEGACAO, delegua_1.default.SUBTRACAO, delegua_1.default.BIT_NOT, delegua_1.default.INCREMENTAR, delegua_1.default.DECREMENTAR)) {
|
|
10773
10962
|
const operador = this.simbolos[this.atual - 1];
|
|
10774
10963
|
const direito = this.unario();
|
|
10964
|
+
if (operador.tipo === delegua_1.default.NEGACAO) {
|
|
10965
|
+
this.verificarOperandoNegacao(operador, direito);
|
|
10966
|
+
}
|
|
10775
10967
|
return new construtos_1.Unario(-1, operador, direito, 'ANTES');
|
|
10776
10968
|
}
|
|
10777
10969
|
return this.chamar();
|
|
@@ -15615,7 +15807,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15615
15807
|
exports.PropriedadeClasse = void 0;
|
|
15616
15808
|
const declaracao_1 = require("./declaracao");
|
|
15617
15809
|
class PropriedadeClasse extends declaracao_1.Declaracao {
|
|
15618
|
-
constructor(nome, tipo, decoradores = [], acesso = 'publico', estatico = false) {
|
|
15810
|
+
constructor(nome, tipo, decoradores = [], acesso = 'publico', estatico = false, valorInicial) {
|
|
15619
15811
|
super(Number(nome.linha), nome.hashArquivo);
|
|
15620
15812
|
this.nome = nome;
|
|
15621
15813
|
this.tipo = tipo;
|
|
@@ -15624,6 +15816,7 @@ class PropriedadeClasse extends declaracao_1.Declaracao {
|
|
|
15624
15816
|
this.estatico = estatico;
|
|
15625
15817
|
this.autoObter = false;
|
|
15626
15818
|
this.autoDefinir = false;
|
|
15819
|
+
this.valorInicial = valorInicial;
|
|
15627
15820
|
}
|
|
15628
15821
|
async aceitar(visitante) {
|
|
15629
15822
|
return Promise.reject(new Error('Não utilizado por enquanto.'));
|
|
@@ -19403,7 +19596,7 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
|
|
|
19403
19596
|
this.eInicializador = eInicializador;
|
|
19404
19597
|
}
|
|
19405
19598
|
aridade() {
|
|
19406
|
-
return this.declaracao?.parametros?.filter(p => p.abrangencia !== 'multiplo').length || 0;
|
|
19599
|
+
return this.declaracao?.parametros?.filter((p) => p.abrangencia !== 'multiplo').length || 0;
|
|
19407
19600
|
}
|
|
19408
19601
|
/**
|
|
19409
19602
|
* Método utilizado por Delégua para representar esta função quando impressa.
|
|
@@ -19622,6 +19815,7 @@ class DescritorTipoClasse extends chamavel_1.Chamavel {
|
|
|
19622
19815
|
constructor(simboloOriginal, superClasses, metodos, propriedades) {
|
|
19623
19816
|
super();
|
|
19624
19817
|
this.dialetoRequerExpansaoPropriedadesEspacoMemoria = false;
|
|
19818
|
+
this.sombrearPropriedadesDeClasse = false;
|
|
19625
19819
|
this.simboloOriginal = simboloOriginal;
|
|
19626
19820
|
if (Array.isArray(superClasses)) {
|
|
19627
19821
|
this.superClasses = superClasses;
|
|
@@ -20427,7 +20621,13 @@ class ObjetoDeleguaClasse {
|
|
|
20427
20621
|
throw new excecoes_1.ErroEmTempoDeExecucao(simbolo, `Propriedade '${simbolo.lexema}' é somente-leitura.`);
|
|
20428
20622
|
}
|
|
20429
20623
|
if (Object.prototype.hasOwnProperty.call(this.classe.membrosEstaticos, simbolo.lexema)) {
|
|
20430
|
-
|
|
20624
|
+
if (this.classe.sombrearPropriedadesDeClasse) {
|
|
20625
|
+
this.verificarAcessoLeitura(simbolo.lexema, simbolo, visitante);
|
|
20626
|
+
this.propriedades[simbolo.lexema] = valor;
|
|
20627
|
+
}
|
|
20628
|
+
else {
|
|
20629
|
+
await this.classe.definirEstatico(simbolo.lexema, valor, visitante);
|
|
20630
|
+
}
|
|
20431
20631
|
return;
|
|
20432
20632
|
}
|
|
20433
20633
|
// Verificar acesso antes da atribuição.
|
|
@@ -20823,7 +21023,8 @@ class InterpretadorBase {
|
|
|
20823
21023
|
];
|
|
20824
21024
|
const valores = [];
|
|
20825
21025
|
for (let propriedade of propriedadesValidas) {
|
|
20826
|
-
if (expressao.hasOwnProperty(propriedade) &&
|
|
21026
|
+
if (expressao.hasOwnProperty(propriedade) &&
|
|
21027
|
+
expressao[propriedade] !== undefined) {
|
|
20827
21028
|
const valor = await this.avaliar(expressao[propriedade]);
|
|
20828
21029
|
valores.push(valor);
|
|
20829
21030
|
}
|
|
@@ -21172,7 +21373,9 @@ class InterpretadorBase {
|
|
|
21172
21373
|
valor: valorDireito,
|
|
21173
21374
|
imutavel: false,
|
|
21174
21375
|
};
|
|
21175
|
-
return await metodoASerChamado.chamar(this, [
|
|
21376
|
+
return await metodoASerChamado.chamar(this, [
|
|
21377
|
+
{ nome: null, valor: argumentoOperador },
|
|
21378
|
+
]);
|
|
21176
21379
|
}
|
|
21177
21380
|
}
|
|
21178
21381
|
const tipoEsquerdo = esquerda?.hasOwnProperty('tipo')
|
|
@@ -21186,7 +21389,8 @@ class InterpretadorBase {
|
|
|
21186
21389
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21187
21390
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
21188
21391
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
21189
|
-
return this.converterParaBigInt(valorEsquerdo) **
|
|
21392
|
+
return (this.converterParaBigInt(valorEsquerdo) **
|
|
21393
|
+
this.converterParaBigInt(valorDireito));
|
|
21190
21394
|
}
|
|
21191
21395
|
const resultadoExponenciacao = Math.pow(valorEsquerdo, valorDireito);
|
|
21192
21396
|
return resultadoExponenciacao;
|
|
@@ -21213,7 +21417,8 @@ class InterpretadorBase {
|
|
|
21213
21417
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21214
21418
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
21215
21419
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
21216
|
-
return this.converterParaBigInt(valorEsquerdo) -
|
|
21420
|
+
return (this.converterParaBigInt(valorEsquerdo) -
|
|
21421
|
+
this.converterParaBigInt(valorDireito));
|
|
21217
21422
|
}
|
|
21218
21423
|
return Number(valorEsquerdo) - Number(valorDireito);
|
|
21219
21424
|
case delegua_1.default.ADICAO:
|
|
@@ -21248,8 +21453,10 @@ class InterpretadorBase {
|
|
|
21248
21453
|
}
|
|
21249
21454
|
// TODO: Se tipo for 'qualquer', seria uma boa confiar nos operadores
|
|
21250
21455
|
// tradicionais do JavaScript?
|
|
21251
|
-
if (tipoEsquerdo === 'qualquer' ||
|
|
21252
|
-
|
|
21456
|
+
if (tipoEsquerdo === 'qualquer' ||
|
|
21457
|
+
tipoDireito === 'qualquer' ||
|
|
21458
|
+
tipoEsquerdo === 'nulo' ||
|
|
21459
|
+
tipoDireito === 'nulo') {
|
|
21253
21460
|
return valorEsquerdo + valorDireito;
|
|
21254
21461
|
}
|
|
21255
21462
|
return this.paraTexto(valorEsquerdo) + this.paraTexto(valorDireito);
|
|
@@ -21338,7 +21545,8 @@ class InterpretadorBase {
|
|
|
21338
21545
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21339
21546
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
21340
21547
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
21341
|
-
return this.converterParaBigInt(valorEsquerdo) &
|
|
21548
|
+
return (this.converterParaBigInt(valorEsquerdo) &
|
|
21549
|
+
this.converterParaBigInt(valorDireito));
|
|
21342
21550
|
}
|
|
21343
21551
|
return Number(valorEsquerdo) & Number(valorDireito);
|
|
21344
21552
|
case delegua_1.default.CIRCUMFLEXO:
|
|
@@ -21348,7 +21556,8 @@ class InterpretadorBase {
|
|
|
21348
21556
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21349
21557
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
21350
21558
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
21351
|
-
return this.converterParaBigInt(valorEsquerdo) ^
|
|
21559
|
+
return (this.converterParaBigInt(valorEsquerdo) ^
|
|
21560
|
+
this.converterParaBigInt(valorDireito));
|
|
21352
21561
|
}
|
|
21353
21562
|
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
21354
21563
|
case delegua_1.default.BIT_OR:
|
|
@@ -21358,21 +21567,28 @@ class InterpretadorBase {
|
|
|
21358
21567
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21359
21568
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
21360
21569
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
21361
|
-
return this.converterParaBigInt(valorEsquerdo) |
|
|
21570
|
+
return (this.converterParaBigInt(valorEsquerdo) |
|
|
21571
|
+
this.converterParaBigInt(valorDireito));
|
|
21362
21572
|
}
|
|
21363
21573
|
return Number(valorEsquerdo) | Number(valorDireito);
|
|
21364
21574
|
case delegua_1.default.MENOR_MENOR:
|
|
21365
21575
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21366
21576
|
// Auto-promove para BigInt (interno para longo) se qualquer operando for BigInt ou se deslocamento >= 32
|
|
21367
|
-
if (typeof valorEsquerdo === 'bigint' ||
|
|
21368
|
-
|
|
21577
|
+
if (typeof valorEsquerdo === 'bigint' ||
|
|
21578
|
+
typeof valorDireito === 'bigint' ||
|
|
21579
|
+
Number(valorDireito) >= 32) {
|
|
21580
|
+
return (this.converterParaBigInt(valorEsquerdo) <<
|
|
21581
|
+
this.converterParaBigInt(valorDireito));
|
|
21369
21582
|
}
|
|
21370
21583
|
return Number(valorEsquerdo) << Number(valorDireito);
|
|
21371
21584
|
case delegua_1.default.MAIOR_MAIOR:
|
|
21372
21585
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
21373
21586
|
// Auto-promove para BigInt (interno para longo) se qualquer operando for BigInt ou se deslocamento >= 32
|
|
21374
|
-
if (typeof valorEsquerdo === 'bigint' ||
|
|
21375
|
-
|
|
21587
|
+
if (typeof valorEsquerdo === 'bigint' ||
|
|
21588
|
+
typeof valorDireito === 'bigint' ||
|
|
21589
|
+
Number(valorDireito) >= 32) {
|
|
21590
|
+
return (this.converterParaBigInt(valorEsquerdo) >>
|
|
21591
|
+
this.converterParaBigInt(valorDireito));
|
|
21376
21592
|
}
|
|
21377
21593
|
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
21378
21594
|
case delegua_1.default.DIFERENTE:
|
|
@@ -22395,6 +22611,9 @@ class InterpretadorBase {
|
|
|
22395
22611
|
if (tipoResolvido.startsWith('função<')) {
|
|
22396
22612
|
tipoResolvido = tipoResolvido.replace('função<', '').replace('>', '');
|
|
22397
22613
|
}
|
|
22614
|
+
if (!declaracao.tipoExplicito && tipoResolvido === delegua_2.default.QUALQUER && valorFinal instanceof Array) {
|
|
22615
|
+
tipoResolvido = (0, inferenciador_1.inferirTipoVariavel)(valorFinal);
|
|
22616
|
+
}
|
|
22398
22617
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorFinal, tipoResolvido, declaracao.tipoExplicito && declaracao.tipoOriginal !== 'qualquer');
|
|
22399
22618
|
// TODO: É relevante registrar uma declaração de variável no
|
|
22400
22619
|
// resultado do interpretador?
|
|
@@ -23519,7 +23738,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23519
23738
|
// Objeto simples do JavaScript, ou dicionário de Delégua.
|
|
23520
23739
|
if (objeto.constructor === Object) {
|
|
23521
23740
|
if (expressao.nomeMetodo in primitivas_dicionario_1.default) {
|
|
23522
|
-
const metodoDePrimitivaDicionario = primitivas_dicionario_1.default[expressao.nomeMetodo]
|
|
23741
|
+
const metodoDePrimitivaDicionario = primitivas_dicionario_1.default[expressao.nomeMetodo]
|
|
23742
|
+
.implementacao;
|
|
23523
23743
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaDicionario, expressao.nomeMetodo, 'dicionário');
|
|
23524
23744
|
}
|
|
23525
23745
|
return objeto[expressao.nomeMetodo] || null;
|
|
@@ -23558,7 +23778,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23558
23778
|
case delegua_1.default.NUMERO:
|
|
23559
23779
|
case delegua_1.default.NÚMERO:
|
|
23560
23780
|
if (expressao.nomeMetodo in primitivas_numero_1.default) {
|
|
23561
|
-
const metodoDePrimitivaNumero = primitivas_numero_1.default[expressao.nomeMetodo]
|
|
23781
|
+
const metodoDePrimitivaNumero = primitivas_numero_1.default[expressao.nomeMetodo]
|
|
23782
|
+
.implementacao;
|
|
23562
23783
|
if (metodoDePrimitivaNumero) {
|
|
23563
23784
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaNumero, expressao.nomeMetodo, tipoObjeto);
|
|
23564
23785
|
}
|
|
@@ -23571,7 +23792,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23571
23792
|
break;
|
|
23572
23793
|
case delegua_1.default.TEXTO:
|
|
23573
23794
|
if (expressao.nomeMetodo in primitivas_texto_1.default) {
|
|
23574
|
-
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.nomeMetodo]
|
|
23795
|
+
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.nomeMetodo]
|
|
23796
|
+
.implementacao;
|
|
23575
23797
|
if (metodoDePrimitivaTexto) {
|
|
23576
23798
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaTexto, expressao.nomeMetodo, 'texto');
|
|
23577
23799
|
}
|
|
@@ -23591,7 +23813,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23591
23813
|
case delegua_1.default.VETOR_QUALQUER:
|
|
23592
23814
|
case delegua_1.default.VETOR_TEXTO:
|
|
23593
23815
|
if (expressao.nomeMetodo in primitivas_vetor_1.default) {
|
|
23594
|
-
const metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.nomeMetodo]
|
|
23816
|
+
const metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.nomeMetodo]
|
|
23817
|
+
.implementacao;
|
|
23595
23818
|
if (metodoDePrimitivaVetor) {
|
|
23596
23819
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaVetor, expressao.nomeMetodo, tipoObjeto);
|
|
23597
23820
|
}
|
|
@@ -23692,7 +23915,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23692
23915
|
// Objeto simples do JavaScript, ou dicionário de Delégua.
|
|
23693
23916
|
if (objeto.constructor === Object) {
|
|
23694
23917
|
if (expressao.simbolo.lexema in primitivas_dicionario_1.default) {
|
|
23695
|
-
const metodoDePrimitivaDicionario = primitivas_dicionario_1.default[expressao.simbolo.lexema]
|
|
23918
|
+
const metodoDePrimitivaDicionario = primitivas_dicionario_1.default[expressao.simbolo.lexema]
|
|
23919
|
+
.implementacao;
|
|
23696
23920
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaDicionario, expressao.simbolo.lexema, 'dicionário');
|
|
23697
23921
|
}
|
|
23698
23922
|
return objeto[expressao.simbolo.lexema];
|
|
@@ -23705,7 +23929,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23705
23929
|
return funcaoExt.funcaoPorExtensao(objeto);
|
|
23706
23930
|
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simbolo, `Método de primitiva '${expressao.simbolo.lexema}' não existe para o tipo texto.`);
|
|
23707
23931
|
}
|
|
23708
|
-
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema]
|
|
23932
|
+
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema]
|
|
23933
|
+
.implementacao;
|
|
23709
23934
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaTexto, expressao.simbolo.lexema, 'texto');
|
|
23710
23935
|
}
|
|
23711
23936
|
// A partir daqui, presume-se que o objeto é uma das estruturas
|
|
@@ -23730,7 +23955,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23730
23955
|
return funcaoExt.funcaoPorExtensao(objeto);
|
|
23731
23956
|
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simbolo, `Método de primitiva '${expressao.simbolo.lexema}' não existe para o tipo ${tipoObjeto}.`);
|
|
23732
23957
|
}
|
|
23733
|
-
const metodoDePrimitivaNumero = primitivas_numero_1.default[expressao.simbolo.lexema]
|
|
23958
|
+
const metodoDePrimitivaNumero = primitivas_numero_1.default[expressao.simbolo.lexema]
|
|
23959
|
+
.implementacao;
|
|
23734
23960
|
if (metodoDePrimitivaNumero) {
|
|
23735
23961
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaNumero, expressao.simbolo.lexema, 'número');
|
|
23736
23962
|
}
|
|
@@ -23743,7 +23969,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23743
23969
|
return funcaoExt.funcaoPorExtensao(objeto);
|
|
23744
23970
|
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simbolo, `Método de primitiva '${expressao.simbolo.lexema}' não existe para o tipo ${tipoObjeto}.`);
|
|
23745
23971
|
}
|
|
23746
|
-
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema]
|
|
23972
|
+
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema]
|
|
23973
|
+
.implementacao;
|
|
23747
23974
|
if (metodoDePrimitivaTexto) {
|
|
23748
23975
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaTexto, expressao.simbolo.lexema, 'texto');
|
|
23749
23976
|
}
|
|
@@ -23763,7 +23990,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23763
23990
|
return funcaoExt.funcaoPorExtensao(objeto);
|
|
23764
23991
|
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simbolo, `Método de primitiva '${expressao.simbolo.lexema}' não existe para o tipo ${tipoObjeto}.`);
|
|
23765
23992
|
}
|
|
23766
|
-
const metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema]
|
|
23993
|
+
const metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema]
|
|
23994
|
+
.implementacao;
|
|
23767
23995
|
if (metodoDePrimitivaVetor) {
|
|
23768
23996
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaVetor, expressao.simbolo.lexema, tipoObjeto);
|
|
23769
23997
|
}
|
|
@@ -23811,7 +24039,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
23811
24039
|
// Objeto simples do JavaScript, ou dicionário de Delégua.
|
|
23812
24040
|
if (objeto.constructor === Object) {
|
|
23813
24041
|
if (expressao.nomePropriedade in primitivas_dicionario_1.default) {
|
|
23814
|
-
const metodoDePrimitivaDicionario = primitivas_dicionario_1.default[expressao.nomePropriedade]
|
|
24042
|
+
const metodoDePrimitivaDicionario = primitivas_dicionario_1.default[expressao.nomePropriedade]
|
|
24043
|
+
.implementacao;
|
|
23815
24044
|
return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodoDePrimitivaDicionario, expressao.nomePropriedade, 'dicionário');
|
|
23816
24045
|
}
|
|
23817
24046
|
return objeto[expressao.nomePropriedade] || null;
|
|
@@ -24487,9 +24716,9 @@ class PilhaEscoposExecucao {
|
|
|
24487
24716
|
}
|
|
24488
24717
|
espacoMemoriaAncestral.valores[simbolo.lexema] = {
|
|
24489
24718
|
valor,
|
|
24490
|
-
tipo:
|
|
24719
|
+
tipo: variavel.tipo === 'nulo' && !variavel.tipoExplicito
|
|
24491
24720
|
? (0, inferenciador_1.inferirTipoVariavel)(valor)
|
|
24492
|
-
:
|
|
24721
|
+
: variavel.tipo || (0, inferenciador_1.inferirTipoVariavel)(valor),
|
|
24493
24722
|
imutavel: false,
|
|
24494
24723
|
tipoExplicito: variavel.tipoExplicito,
|
|
24495
24724
|
};
|
|
@@ -24510,9 +24739,7 @@ class PilhaEscoposExecucao {
|
|
|
24510
24739
|
}
|
|
24511
24740
|
const tipoAtual = variavel && variavel.hasOwnProperty('tipo') ? variavel.tipo : null;
|
|
24512
24741
|
const deveLiberarTipo = tipoAtual === 'nulo' && !variavel.tipoExplicito;
|
|
24513
|
-
const tipoInferido = tipoAtual && !deveLiberarTipo
|
|
24514
|
-
? tipoAtual
|
|
24515
|
-
: (0, inferenciador_1.inferirTipoVariavel)(valor);
|
|
24742
|
+
const tipoInferido = tipoAtual && !deveLiberarTipo ? tipoAtual : (0, inferenciador_1.inferirTipoVariavel)(valor);
|
|
24516
24743
|
const tipo = (tipoInferido || 'objeto').toLowerCase();
|
|
24517
24744
|
const valorResolvido = this.converterValor(tipo, valor);
|
|
24518
24745
|
if (indice !== undefined && indice !== null) {
|
|
@@ -24784,7 +25011,9 @@ class LexadorCalango {
|
|
|
24784
25011
|
const linhaPrimeiroCaracter = this.linha;
|
|
24785
25012
|
// Restringe leitura à linha atual (como analisarNumero), evitando
|
|
24786
25013
|
// que avancar() mude this.linha e corrompa o cálculo do substring.
|
|
24787
|
-
while (this.simboloAtual() !== "'" &&
|
|
25014
|
+
while (this.simboloAtual() !== "'" &&
|
|
25015
|
+
this.linha === linhaPrimeiroCaracter &&
|
|
25016
|
+
!this.eFinalDoCodigo()) {
|
|
24788
25017
|
this.avancar();
|
|
24789
25018
|
}
|
|
24790
25019
|
if (this.linha !== linhaPrimeiroCaracter || this.eFinalDoCodigo()) {
|
|
@@ -27860,10 +28089,12 @@ class Lexador {
|
|
|
27860
28089
|
break;
|
|
27861
28090
|
}
|
|
27862
28091
|
}
|
|
27863
|
-
valor +=
|
|
28092
|
+
valor +=
|
|
28093
|
+
hex.length === 2 ? String.fromCharCode(parseInt(hex, 16)) : '\\x' + hex;
|
|
27864
28094
|
break;
|
|
27865
28095
|
}
|
|
27866
|
-
case '\0':
|
|
28096
|
+
case '\0':
|
|
28097
|
+
break; // barra invertida no fim de linha: ignora e continua na próxima linha
|
|
27867
28098
|
default:
|
|
27868
28099
|
valor += '\\' + proximoCaractere;
|
|
27869
28100
|
break;
|
|
@@ -42580,10 +42811,10 @@ class TradutorAssemblyARM {
|
|
|
42580
42811
|
// Para android: ainda é um binário standalone, mas com rótulo Delegua_main
|
|
42581
42812
|
// para deixar claro que não é o _start do CRT padrão.
|
|
42582
42813
|
const entryLabel = this.alvo === 'android' ? 'Delegua_main' : '_start';
|
|
42583
|
-
this.text = `
|
|
42584
|
-
.text
|
|
42585
|
-
.global ${entryLabel}
|
|
42586
|
-
|
|
42814
|
+
this.text = `
|
|
42815
|
+
.text
|
|
42816
|
+
.global ${entryLabel}
|
|
42817
|
+
|
|
42587
42818
|
${entryLabel}:`;
|
|
42588
42819
|
}
|
|
42589
42820
|
gerarDigitoAleatorio() {
|
|
@@ -42624,11 +42855,11 @@ ${entryLabel}:`;
|
|
|
42624
42855
|
}
|
|
42625
42856
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
42626
42857
|
const reg = this.obterRegistrador();
|
|
42627
|
-
this.text += `
|
|
42628
|
-
ldr ${reg}, =${nomeVar}
|
|
42629
|
-
ldr r0, =${indice}
|
|
42630
|
-
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
42631
|
-
add ${reg}, ${reg}, r0
|
|
42858
|
+
this.text += `
|
|
42859
|
+
ldr ${reg}, =${nomeVar}
|
|
42860
|
+
ldr r0, =${indice}
|
|
42861
|
+
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
42862
|
+
add ${reg}, ${reg}, r0
|
|
42632
42863
|
ldr r0, [${reg}]`;
|
|
42633
42864
|
this.liberarRegistrador(reg);
|
|
42634
42865
|
return 'r0';
|
|
@@ -42651,12 +42882,12 @@ ${entryLabel}:`;
|
|
|
42651
42882
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
42652
42883
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
42653
42884
|
const reg = this.obterRegistrador();
|
|
42654
|
-
this.text += `
|
|
42655
|
-
ldr ${reg}, =${nomeVar}
|
|
42656
|
-
ldr r1, =${indice}
|
|
42657
|
-
lsl r1, r1, #2 @ multiply by 4
|
|
42658
|
-
add ${reg}, ${reg}, r1
|
|
42659
|
-
ldr r1, =${valor}
|
|
42885
|
+
this.text += `
|
|
42886
|
+
ldr ${reg}, =${nomeVar}
|
|
42887
|
+
ldr r1, =${indice}
|
|
42888
|
+
lsl r1, r1, #2 @ multiply by 4
|
|
42889
|
+
add ${reg}, ${reg}, r1
|
|
42890
|
+
ldr r1, =${valor}
|
|
42660
42891
|
str r1, [${reg}]`;
|
|
42661
42892
|
this.liberarRegistrador(reg);
|
|
42662
42893
|
}
|
|
@@ -42674,9 +42905,9 @@ ${entryLabel}:`;
|
|
|
42674
42905
|
this.bss += ` ${varLabel}: .space 4\n`;
|
|
42675
42906
|
this.variaveis.set(nomeVar, varLabel);
|
|
42676
42907
|
}
|
|
42677
|
-
this.text += `
|
|
42678
|
-
ldr r0, =${valor}
|
|
42679
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
42908
|
+
this.text += `
|
|
42909
|
+
ldr r0, =${valor}
|
|
42910
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
42680
42911
|
str r0, [r1]`;
|
|
42681
42912
|
}
|
|
42682
42913
|
traduzirConstrutoBinario(construto) {
|
|
@@ -42686,75 +42917,75 @@ ${entryLabel}:`;
|
|
|
42686
42917
|
const reg = this.obterRegistrador();
|
|
42687
42918
|
// Load left operand into r0
|
|
42688
42919
|
if (esquerda !== 'r0') {
|
|
42689
|
-
this.text += `
|
|
42920
|
+
this.text += `
|
|
42690
42921
|
ldr r0, =${esquerda}`;
|
|
42691
42922
|
}
|
|
42692
42923
|
// Load right operand into reg
|
|
42693
|
-
this.text += `
|
|
42924
|
+
this.text += `
|
|
42694
42925
|
ldr ${reg}, =${direita}`;
|
|
42695
42926
|
switch (operador) {
|
|
42696
42927
|
case '+':
|
|
42697
|
-
this.text += `
|
|
42928
|
+
this.text += `
|
|
42698
42929
|
add r0, r0, ${reg}`;
|
|
42699
42930
|
break;
|
|
42700
42931
|
case '-':
|
|
42701
|
-
this.text += `
|
|
42932
|
+
this.text += `
|
|
42702
42933
|
sub r0, r0, ${reg}`;
|
|
42703
42934
|
break;
|
|
42704
42935
|
case '*':
|
|
42705
|
-
this.text += `
|
|
42936
|
+
this.text += `
|
|
42706
42937
|
mul r0, r0, ${reg}`;
|
|
42707
42938
|
break;
|
|
42708
42939
|
case '/':
|
|
42709
|
-
this.text += `
|
|
42940
|
+
this.text += `
|
|
42710
42941
|
sdiv r0, r0, ${reg}`;
|
|
42711
42942
|
break;
|
|
42712
42943
|
case '%':
|
|
42713
|
-
this.text += `
|
|
42714
|
-
sdiv r1, r0, ${reg}
|
|
42715
|
-
mul r1, r1, ${reg}
|
|
42944
|
+
this.text += `
|
|
42945
|
+
sdiv r1, r0, ${reg}
|
|
42946
|
+
mul r1, r1, ${reg}
|
|
42716
42947
|
sub r0, r0, r1 @ r0 = r0 - (r0/reg)*reg`;
|
|
42717
42948
|
break;
|
|
42718
42949
|
case '<':
|
|
42719
|
-
this.text += `
|
|
42720
|
-
cmp r0, ${reg}
|
|
42721
|
-
movlt r0, #1
|
|
42950
|
+
this.text += `
|
|
42951
|
+
cmp r0, ${reg}
|
|
42952
|
+
movlt r0, #1
|
|
42722
42953
|
movge r0, #0`;
|
|
42723
42954
|
break;
|
|
42724
42955
|
case '>':
|
|
42725
|
-
this.text += `
|
|
42726
|
-
cmp r0, ${reg}
|
|
42727
|
-
movgt r0, #1
|
|
42956
|
+
this.text += `
|
|
42957
|
+
cmp r0, ${reg}
|
|
42958
|
+
movgt r0, #1
|
|
42728
42959
|
movle r0, #0`;
|
|
42729
42960
|
break;
|
|
42730
42961
|
case '<=':
|
|
42731
|
-
this.text += `
|
|
42732
|
-
cmp r0, ${reg}
|
|
42733
|
-
movle r0, #1
|
|
42962
|
+
this.text += `
|
|
42963
|
+
cmp r0, ${reg}
|
|
42964
|
+
movle r0, #1
|
|
42734
42965
|
movgt r0, #0`;
|
|
42735
42966
|
break;
|
|
42736
42967
|
case '>=':
|
|
42737
|
-
this.text += `
|
|
42738
|
-
cmp r0, ${reg}
|
|
42739
|
-
movge r0, #1
|
|
42968
|
+
this.text += `
|
|
42969
|
+
cmp r0, ${reg}
|
|
42970
|
+
movge r0, #1
|
|
42740
42971
|
movlt r0, #0`;
|
|
42741
42972
|
break;
|
|
42742
42973
|
case '==':
|
|
42743
42974
|
case '===':
|
|
42744
|
-
this.text += `
|
|
42745
|
-
cmp r0, ${reg}
|
|
42746
|
-
moveq r0, #1
|
|
42975
|
+
this.text += `
|
|
42976
|
+
cmp r0, ${reg}
|
|
42977
|
+
moveq r0, #1
|
|
42747
42978
|
movne r0, #0`;
|
|
42748
42979
|
break;
|
|
42749
42980
|
case '!=':
|
|
42750
42981
|
case '!==':
|
|
42751
|
-
this.text += `
|
|
42752
|
-
cmp r0, ${reg}
|
|
42753
|
-
movne r0, #1
|
|
42982
|
+
this.text += `
|
|
42983
|
+
cmp r0, ${reg}
|
|
42984
|
+
movne r0, #1
|
|
42754
42985
|
moveq r0, #0`;
|
|
42755
42986
|
break;
|
|
42756
42987
|
default:
|
|
42757
|
-
this.text += `
|
|
42988
|
+
this.text += `
|
|
42758
42989
|
@ Operador ${operador} não implementado`;
|
|
42759
42990
|
}
|
|
42760
42991
|
this.liberarRegistrador(reg);
|
|
@@ -42771,35 +43002,35 @@ ${entryLabel}:`;
|
|
|
42771
43002
|
if (index < registrosArgs.length) {
|
|
42772
43003
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
42773
43004
|
if (valorArg !== registrosArgs[index]) {
|
|
42774
|
-
this.text += `
|
|
43005
|
+
this.text += `
|
|
42775
43006
|
ldr ${registrosArgs[index]}, =${valorArg}`;
|
|
42776
43007
|
}
|
|
42777
43008
|
}
|
|
42778
43009
|
else {
|
|
42779
43010
|
// Push extra args on stack
|
|
42780
43011
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
42781
|
-
this.text += `
|
|
42782
|
-
ldr r0, =${valorArg}
|
|
43012
|
+
this.text += `
|
|
43013
|
+
ldr r0, =${valorArg}
|
|
42783
43014
|
push {r0}`;
|
|
42784
43015
|
}
|
|
42785
43016
|
});
|
|
42786
|
-
this.text += `
|
|
43017
|
+
this.text += `
|
|
42787
43018
|
bl ${nomeFuncao}`;
|
|
42788
43019
|
}
|
|
42789
43020
|
traduzirConstrutoDefinirValor(construto) {
|
|
42790
43021
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
42791
43022
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
42792
|
-
this.text += `
|
|
42793
|
-
ldr r0, =${valor}
|
|
42794
|
-
ldr r1, =${objeto}
|
|
43023
|
+
this.text += `
|
|
43024
|
+
ldr r0, =${valor}
|
|
43025
|
+
ldr r1, =${objeto}
|
|
42795
43026
|
str r0, [r1]`;
|
|
42796
43027
|
}
|
|
42797
43028
|
traduzirFuncaoConstruto(construto) {
|
|
42798
43029
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
42799
|
-
this.text += `
|
|
42800
|
-
|
|
42801
|
-
${labelFuncao}:
|
|
42802
|
-
push {fp, lr}
|
|
43030
|
+
this.text += `
|
|
43031
|
+
|
|
43032
|
+
${labelFuncao}:
|
|
43033
|
+
push {fp, lr}
|
|
42803
43034
|
mov fp, sp`;
|
|
42804
43035
|
// Traduzir corpo da função
|
|
42805
43036
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -42809,8 +43040,8 @@ ${labelFuncao}:
|
|
|
42809
43040
|
}
|
|
42810
43041
|
});
|
|
42811
43042
|
}
|
|
42812
|
-
this.text += `
|
|
42813
|
-
mov sp, fp
|
|
43043
|
+
this.text += `
|
|
43044
|
+
mov sp, fp
|
|
42814
43045
|
pop {fp, pc}`;
|
|
42815
43046
|
}
|
|
42816
43047
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -42825,29 +43056,29 @@ ${labelFuncao}:
|
|
|
42825
43056
|
const operador = construto.operador.lexema;
|
|
42826
43057
|
const labelVerdadeiro = this.gerarLabel();
|
|
42827
43058
|
const labelFim = this.gerarLabel();
|
|
42828
|
-
this.text += `
|
|
42829
|
-
ldr r0, =${esquerda}
|
|
43059
|
+
this.text += `
|
|
43060
|
+
ldr r0, =${esquerda}
|
|
42830
43061
|
cmp r0, #0`;
|
|
42831
43062
|
if (operador === 'e' || operador === '&&') {
|
|
42832
|
-
this.text += `
|
|
42833
|
-
beq ${labelFim}
|
|
42834
|
-
ldr r0, =${direita}
|
|
42835
|
-
cmp r0, #0
|
|
42836
|
-
beq ${labelFim}
|
|
42837
|
-
${labelVerdadeiro}:
|
|
42838
|
-
mov r0, #1
|
|
43063
|
+
this.text += `
|
|
43064
|
+
beq ${labelFim}
|
|
43065
|
+
ldr r0, =${direita}
|
|
43066
|
+
cmp r0, #0
|
|
43067
|
+
beq ${labelFim}
|
|
43068
|
+
${labelVerdadeiro}:
|
|
43069
|
+
mov r0, #1
|
|
42839
43070
|
${labelFim}:`;
|
|
42840
43071
|
}
|
|
42841
43072
|
else if (operador === 'ou' || operador === '||') {
|
|
42842
|
-
this.text += `
|
|
42843
|
-
bne ${labelVerdadeiro}
|
|
42844
|
-
ldr r0, =${direita}
|
|
42845
|
-
cmp r0, #0
|
|
42846
|
-
bne ${labelVerdadeiro}
|
|
42847
|
-
mov r0, #0
|
|
42848
|
-
b ${labelFim}
|
|
42849
|
-
${labelVerdadeiro}:
|
|
42850
|
-
mov r0, #1
|
|
43073
|
+
this.text += `
|
|
43074
|
+
bne ${labelVerdadeiro}
|
|
43075
|
+
ldr r0, =${direita}
|
|
43076
|
+
cmp r0, #0
|
|
43077
|
+
bne ${labelVerdadeiro}
|
|
43078
|
+
mov r0, #0
|
|
43079
|
+
b ${labelFim}
|
|
43080
|
+
${labelVerdadeiro}:
|
|
43081
|
+
mov r0, #1
|
|
42851
43082
|
${labelFim}:`;
|
|
42852
43083
|
}
|
|
42853
43084
|
return 'r0';
|
|
@@ -42859,16 +43090,16 @@ ${labelFim}:`;
|
|
|
42859
43090
|
traduzirConstrutoUnario(construto) {
|
|
42860
43091
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
42861
43092
|
const operador = construto.operador.lexema;
|
|
42862
|
-
this.text += `
|
|
43093
|
+
this.text += `
|
|
42863
43094
|
ldr r0, =${operando}`;
|
|
42864
43095
|
if (operador === '-') {
|
|
42865
|
-
this.text += `
|
|
43096
|
+
this.text += `
|
|
42866
43097
|
neg r0, r0`;
|
|
42867
43098
|
}
|
|
42868
43099
|
else if (operador === '!' || operador === 'nao') {
|
|
42869
|
-
this.text += `
|
|
42870
|
-
cmp r0, #0
|
|
42871
|
-
moveq r0, #1
|
|
43100
|
+
this.text += `
|
|
43101
|
+
cmp r0, #0
|
|
43102
|
+
moveq r0, #1
|
|
42872
43103
|
movne r0, #0`;
|
|
42873
43104
|
}
|
|
42874
43105
|
return 'r0';
|
|
@@ -42877,8 +43108,8 @@ ${labelFim}:`;
|
|
|
42877
43108
|
const nomeVar = construto.simbolo?.lexema;
|
|
42878
43109
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
42879
43110
|
const varLabel = this.variaveis.get(nomeVar);
|
|
42880
|
-
this.text += `
|
|
42881
|
-
ldr r0, =${varLabel}
|
|
43111
|
+
this.text += `
|
|
43112
|
+
ldr r0, =${varLabel}
|
|
42882
43113
|
ldr r0, [r0]`;
|
|
42883
43114
|
return 'r0';
|
|
42884
43115
|
}
|
|
@@ -42892,9 +43123,9 @@ ${labelFim}:`;
|
|
|
42892
43123
|
construto.valores.forEach((valor, index) => {
|
|
42893
43124
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
42894
43125
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
42895
|
-
this.text += `
|
|
42896
|
-
ldr r0, =${valorTraduzido}
|
|
42897
|
-
ldr r1, =${labelVetor}
|
|
43126
|
+
this.text += `
|
|
43127
|
+
ldr r0, =${valorTraduzido}
|
|
43128
|
+
ldr r1, =${labelVetor}
|
|
42898
43129
|
str r0, [r1, #${index * 4}]`;
|
|
42899
43130
|
}
|
|
42900
43131
|
});
|
|
@@ -42914,17 +43145,17 @@ ${labelFim}:`;
|
|
|
42914
43145
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
42915
43146
|
const labelInicio = this.gerarLabel();
|
|
42916
43147
|
const labelFim = this.gerarLabel();
|
|
42917
|
-
this.text += `
|
|
43148
|
+
this.text += `
|
|
42918
43149
|
${labelInicio}:`;
|
|
42919
43150
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
42920
|
-
this.text += `
|
|
42921
|
-
cmp ${condicao}, #0
|
|
43151
|
+
this.text += `
|
|
43152
|
+
cmp ${condicao}, #0
|
|
42922
43153
|
beq ${labelFim}`;
|
|
42923
43154
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
42924
43155
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
42925
43156
|
}
|
|
42926
|
-
this.text += `
|
|
42927
|
-
b ${labelInicio}
|
|
43157
|
+
this.text += `
|
|
43158
|
+
b ${labelInicio}
|
|
42928
43159
|
${labelFim}:`;
|
|
42929
43160
|
}
|
|
42930
43161
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -42935,10 +43166,10 @@ ${labelFim}:`;
|
|
|
42935
43166
|
const labelProximo = this.gerarLabel();
|
|
42936
43167
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
42937
43168
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
42938
|
-
this.text += `
|
|
42939
|
-
ldr r0, =${valorEscolha}
|
|
42940
|
-
ldr r1, =${valorCaso}
|
|
42941
|
-
cmp r0, r1
|
|
43169
|
+
this.text += `
|
|
43170
|
+
ldr r0, =${valorEscolha}
|
|
43171
|
+
ldr r1, =${valorCaso}
|
|
43172
|
+
cmp r0, r1
|
|
42942
43173
|
bne ${labelProximo}`;
|
|
42943
43174
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
42944
43175
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -42947,13 +43178,13 @@ ${labelFim}:`;
|
|
|
42947
43178
|
}
|
|
42948
43179
|
});
|
|
42949
43180
|
}
|
|
42950
|
-
this.text += `
|
|
42951
|
-
b ${labelFim}
|
|
43181
|
+
this.text += `
|
|
43182
|
+
b ${labelFim}
|
|
42952
43183
|
${labelProximo}:`;
|
|
42953
43184
|
}
|
|
42954
43185
|
});
|
|
42955
43186
|
}
|
|
42956
|
-
this.text += `
|
|
43187
|
+
this.text += `
|
|
42957
43188
|
${labelFim}:`;
|
|
42958
43189
|
}
|
|
42959
43190
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
@@ -42964,7 +43195,7 @@ ${labelFim}:`;
|
|
|
42964
43195
|
}
|
|
42965
43196
|
traduzirDeclaracaoFazer(declaracao) {
|
|
42966
43197
|
const labelInicio = this.gerarLabel();
|
|
42967
|
-
this.text += `
|
|
43198
|
+
this.text += `
|
|
42968
43199
|
${labelInicio}:`;
|
|
42969
43200
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
42970
43201
|
declaracao.caminhoFazer.declaracoes.forEach((decl) => {
|
|
@@ -42975,8 +43206,8 @@ ${labelInicio}:`;
|
|
|
42975
43206
|
}
|
|
42976
43207
|
if (declaracao.condicaoEnquanto) {
|
|
42977
43208
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
42978
|
-
this.text += `
|
|
42979
|
-
cmp ${condicao}, #0
|
|
43209
|
+
this.text += `
|
|
43210
|
+
cmp ${condicao}, #0
|
|
42980
43211
|
bne ${labelInicio}`;
|
|
42981
43212
|
}
|
|
42982
43213
|
}
|
|
@@ -42990,18 +43221,18 @@ ${labelInicio}:`;
|
|
|
42990
43221
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
42991
43222
|
}
|
|
42992
43223
|
}
|
|
42993
|
-
this.text += `
|
|
42994
|
-
@ Falhar com mensagem: ${mensagem}
|
|
42995
|
-
mov r0, #1
|
|
42996
|
-
mov r7, #1 @ sys_exit
|
|
43224
|
+
this.text += `
|
|
43225
|
+
@ Falhar com mensagem: ${mensagem}
|
|
43226
|
+
mov r0, #1
|
|
43227
|
+
mov r7, #1 @ sys_exit
|
|
42997
43228
|
swi 0`;
|
|
42998
43229
|
}
|
|
42999
43230
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
43000
43231
|
const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
|
|
43001
|
-
this.text += `
|
|
43002
|
-
|
|
43003
|
-
${nomeFuncao}:
|
|
43004
|
-
push {fp, lr}
|
|
43232
|
+
this.text += `
|
|
43233
|
+
|
|
43234
|
+
${nomeFuncao}:
|
|
43235
|
+
push {fp, lr}
|
|
43005
43236
|
mov fp, sp`;
|
|
43006
43237
|
if (declaracao.funcao &&
|
|
43007
43238
|
declaracao.funcao.corpo &&
|
|
@@ -43012,12 +43243,12 @@ ${nomeFuncao}:
|
|
|
43012
43243
|
}
|
|
43013
43244
|
});
|
|
43014
43245
|
}
|
|
43015
|
-
this.text += `
|
|
43016
|
-
mov sp, fp
|
|
43246
|
+
this.text += `
|
|
43247
|
+
mov sp, fp
|
|
43017
43248
|
pop {fp, pc}`;
|
|
43018
43249
|
}
|
|
43019
43250
|
traduzirDeclaracaoImportar(declaracao) {
|
|
43020
|
-
this.text += `
|
|
43251
|
+
this.text += `
|
|
43021
43252
|
@ Importar: ${declaracao.caminho || 'unknown'}`;
|
|
43022
43253
|
}
|
|
43023
43254
|
traduzirDeclaracaoLeia(declaracao) {
|
|
@@ -43034,11 +43265,11 @@ ${nomeFuncao}:
|
|
|
43034
43265
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
43035
43266
|
this.variaveis.set(nomeVar, varLabel);
|
|
43036
43267
|
}
|
|
43037
|
-
this.text += `
|
|
43038
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
43039
|
-
mov r2, #256
|
|
43040
|
-
mov r0, #0 @ stdin
|
|
43041
|
-
mov r7, #3 @ sys_read
|
|
43268
|
+
this.text += `
|
|
43269
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
43270
|
+
mov r2, #256
|
|
43271
|
+
mov r0, #0 @ stdin
|
|
43272
|
+
mov r7, #3 @ sys_read
|
|
43042
43273
|
swi 0`;
|
|
43043
43274
|
}
|
|
43044
43275
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -43053,12 +43284,12 @@ ${nomeFuncao}:
|
|
|
43053
43284
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
43054
43285
|
}
|
|
43055
43286
|
}
|
|
43056
|
-
this.text += `
|
|
43287
|
+
this.text += `
|
|
43057
43288
|
${labelInicio}:`;
|
|
43058
43289
|
if (declaracao.condicao) {
|
|
43059
43290
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
43060
|
-
this.text += `
|
|
43061
|
-
cmp ${condicao}, #0
|
|
43291
|
+
this.text += `
|
|
43292
|
+
cmp ${condicao}, #0
|
|
43062
43293
|
beq ${labelFim}`;
|
|
43063
43294
|
}
|
|
43064
43295
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -43069,8 +43300,8 @@ ${labelInicio}:`;
|
|
|
43069
43300
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
43070
43301
|
}
|
|
43071
43302
|
}
|
|
43072
|
-
this.text += `
|
|
43073
|
-
b ${labelInicio}
|
|
43303
|
+
this.text += `
|
|
43304
|
+
b ${labelInicio}
|
|
43074
43305
|
${labelFim}:`;
|
|
43075
43306
|
}
|
|
43076
43307
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -43085,55 +43316,55 @@ ${labelFim}:`;
|
|
|
43085
43316
|
if (vetor instanceof construtos_1.Vetor) {
|
|
43086
43317
|
tamanhoVetor = vetor.tamanho || 0;
|
|
43087
43318
|
}
|
|
43088
|
-
this.text += `
|
|
43089
|
-
mov r4, #0 @ counter
|
|
43090
|
-
${labelInicio}:
|
|
43091
|
-
cmp r4, #${tamanhoVetor}
|
|
43319
|
+
this.text += `
|
|
43320
|
+
mov r4, #0 @ counter
|
|
43321
|
+
${labelInicio}:
|
|
43322
|
+
cmp r4, #${tamanhoVetor}
|
|
43092
43323
|
bge ${labelFim}`;
|
|
43093
43324
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
43094
43325
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
43095
43326
|
}
|
|
43096
|
-
this.text += `
|
|
43097
|
-
add r4, r4, #1
|
|
43098
|
-
b ${labelInicio}
|
|
43327
|
+
this.text += `
|
|
43328
|
+
add r4, r4, #1
|
|
43329
|
+
b ${labelInicio}
|
|
43099
43330
|
${labelFim}:`;
|
|
43100
43331
|
}
|
|
43101
43332
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
43102
43333
|
if (declaracao.valor) {
|
|
43103
43334
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
43104
|
-
this.text += `
|
|
43335
|
+
this.text += `
|
|
43105
43336
|
ldr r0, =${valor}`;
|
|
43106
43337
|
}
|
|
43107
|
-
this.text += `
|
|
43108
|
-
mov sp, fp
|
|
43338
|
+
this.text += `
|
|
43339
|
+
mov sp, fp
|
|
43109
43340
|
pop {fp, pc}`;
|
|
43110
43341
|
}
|
|
43111
43342
|
traduzirDeclaracaoSe(declaracao) {
|
|
43112
43343
|
const labelSenao = this.gerarLabel();
|
|
43113
43344
|
const labelFim = this.gerarLabel();
|
|
43114
43345
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
43115
|
-
this.text += `
|
|
43116
|
-
cmp ${condicao}, #0
|
|
43346
|
+
this.text += `
|
|
43347
|
+
cmp ${condicao}, #0
|
|
43117
43348
|
beq ${labelSenao}`;
|
|
43118
43349
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
43119
43350
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
43120
43351
|
}
|
|
43121
|
-
this.text += `
|
|
43122
|
-
b ${labelFim}
|
|
43352
|
+
this.text += `
|
|
43353
|
+
b ${labelFim}
|
|
43123
43354
|
${labelSenao}:`;
|
|
43124
43355
|
if (declaracao.caminhoSenao &&
|
|
43125
43356
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
43126
43357
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
43127
43358
|
}
|
|
43128
|
-
this.text += `
|
|
43359
|
+
this.text += `
|
|
43129
43360
|
${labelFim}:`;
|
|
43130
43361
|
}
|
|
43131
43362
|
traduzirDeclaracaoClasse(declaracao) {
|
|
43132
|
-
this.text += `
|
|
43363
|
+
this.text += `
|
|
43133
43364
|
@ Classe: ${declaracao.simbolo?.lexema || 'unknown'}`;
|
|
43134
43365
|
}
|
|
43135
43366
|
traduzirDeclaracaoTente(declaracao) {
|
|
43136
|
-
this.text += `
|
|
43367
|
+
this.text += `
|
|
43137
43368
|
@ Tente-pegue`;
|
|
43138
43369
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
43139
43370
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -43170,9 +43401,9 @@ ${labelFim}:`;
|
|
|
43170
43401
|
}
|
|
43171
43402
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
43172
43403
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
43173
|
-
this.text += `
|
|
43174
|
-
ldr r0, =${valor}
|
|
43175
|
-
ldr r1, =${varLabel}
|
|
43404
|
+
this.text += `
|
|
43405
|
+
ldr r0, =${valor}
|
|
43406
|
+
ldr r1, =${varLabel}
|
|
43176
43407
|
str r0, [r1]`;
|
|
43177
43408
|
}
|
|
43178
43409
|
}
|
|
@@ -43199,20 +43430,20 @@ ${labelFim}:`;
|
|
|
43199
43430
|
// Para ambos linux-arm e android, continuamos usando a convenção
|
|
43200
43431
|
// de syscall Linux ARM (write). Em Android típico, esse binário
|
|
43201
43432
|
// seria executado via adb/Termux, onde essa convenção ainda é válida.
|
|
43202
|
-
this.text += `
|
|
43203
|
-
ldr r1, =${nome_string_literal}
|
|
43204
|
-
mov r2, #${tam_string_literal}
|
|
43205
|
-
mov r0, #1 @ fd stdout
|
|
43206
|
-
mov r7, #4 @ sys_write
|
|
43433
|
+
this.text += `
|
|
43434
|
+
ldr r1, =${nome_string_literal}
|
|
43435
|
+
mov r2, #${tam_string_literal}
|
|
43436
|
+
mov r0, #1 @ fd stdout
|
|
43437
|
+
mov r7, #4 @ sys_write
|
|
43207
43438
|
swi 0`;
|
|
43208
43439
|
}
|
|
43209
43440
|
saidaSistema() {
|
|
43210
43441
|
// Mesmo comentário da função Escreva: usamos sys_exit Linux.
|
|
43211
43442
|
// Em um futuro modo Android "NDK/JNI", esta função deveria
|
|
43212
43443
|
// apenas retornar ao chamador em vez de fazer syscall direta.
|
|
43213
|
-
this.text += `
|
|
43214
|
-
mov r0, #1 @ exit status
|
|
43215
|
-
mov r7, #1 @ sys_exit
|
|
43444
|
+
this.text += `
|
|
43445
|
+
mov r0, #1 @ exit status
|
|
43446
|
+
mov r7, #1 @ sys_exit
|
|
43216
43447
|
swi 0`;
|
|
43217
43448
|
}
|
|
43218
43449
|
traduzir(declaracoes) {
|
|
@@ -43288,10 +43519,10 @@ class TradutorAssemblyRISCV {
|
|
|
43288
43519
|
Var: this.traduzirDeclaracaoVar.bind(this),
|
|
43289
43520
|
};
|
|
43290
43521
|
this.indentacao = 0;
|
|
43291
|
-
this.text = `
|
|
43292
|
-
.text
|
|
43293
|
-
.global _start
|
|
43294
|
-
|
|
43522
|
+
this.text = `
|
|
43523
|
+
.text
|
|
43524
|
+
.global _start
|
|
43525
|
+
|
|
43295
43526
|
_start:`;
|
|
43296
43527
|
}
|
|
43297
43528
|
gerarDigitoAleatorio() {
|
|
@@ -43357,9 +43588,9 @@ _start:`;
|
|
|
43357
43588
|
const reg = this.obterRegistrador();
|
|
43358
43589
|
this.text += `\n la ${reg}, ${nomeVar}`;
|
|
43359
43590
|
this.emitirCarga('a0', indice);
|
|
43360
|
-
this.text += `
|
|
43361
|
-
slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
|
|
43362
|
-
add ${reg}, ${reg}, a0
|
|
43591
|
+
this.text += `
|
|
43592
|
+
slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
|
|
43593
|
+
add ${reg}, ${reg}, a0
|
|
43363
43594
|
ld a0, 0(${reg})`;
|
|
43364
43595
|
this.liberarRegistrador(reg);
|
|
43365
43596
|
return 'a0';
|
|
@@ -43383,8 +43614,8 @@ _start:`;
|
|
|
43383
43614
|
const reg = this.obterRegistrador();
|
|
43384
43615
|
this.text += `\n la ${reg}, ${nomeVar}`;
|
|
43385
43616
|
this.emitirCarga('a1', indice);
|
|
43386
|
-
this.text += `
|
|
43387
|
-
slli a1, a1, 3 # multiplicar índice por 8
|
|
43617
|
+
this.text += `
|
|
43618
|
+
slli a1, a1, 3 # multiplicar índice por 8
|
|
43388
43619
|
add ${reg}, ${reg}, a1`;
|
|
43389
43620
|
this.emitirCarga('a1', valor);
|
|
43390
43621
|
this.text += `\n sd a1, 0(${reg})`;
|
|
@@ -43404,8 +43635,8 @@ _start:`;
|
|
|
43404
43635
|
this.variaveis.set(nomeVar, varLabel);
|
|
43405
43636
|
}
|
|
43406
43637
|
this.emitirCarga('a0', valor);
|
|
43407
|
-
this.text += `
|
|
43408
|
-
la a1, ${this.variaveis.get(nomeVar)}
|
|
43638
|
+
this.text += `
|
|
43639
|
+
la a1, ${this.variaveis.get(nomeVar)}
|
|
43409
43640
|
sd a0, 0(a1)`;
|
|
43410
43641
|
}
|
|
43411
43642
|
traduzirConstrutoBinario(construto) {
|
|
@@ -43489,18 +43720,18 @@ _start:`;
|
|
|
43489
43720
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
43490
43721
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
43491
43722
|
this.emitirCarga('a0', valor);
|
|
43492
|
-
this.text += `
|
|
43493
|
-
la a1, ${objeto}
|
|
43723
|
+
this.text += `
|
|
43724
|
+
la a1, ${objeto}
|
|
43494
43725
|
sd a0, 0(a1)`;
|
|
43495
43726
|
}
|
|
43496
43727
|
traduzirFuncaoConstruto(construto) {
|
|
43497
43728
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
43498
|
-
this.text += `
|
|
43499
|
-
|
|
43500
|
-
${labelFuncao}:
|
|
43501
|
-
addi sp, sp, -16
|
|
43502
|
-
sd ra, 8(sp)
|
|
43503
|
-
sd s0, 0(sp)
|
|
43729
|
+
this.text += `
|
|
43730
|
+
|
|
43731
|
+
${labelFuncao}:
|
|
43732
|
+
addi sp, sp, -16
|
|
43733
|
+
sd ra, 8(sp)
|
|
43734
|
+
sd s0, 0(sp)
|
|
43504
43735
|
addi s0, sp, 16`;
|
|
43505
43736
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
43506
43737
|
construto.corpo.forEach((declaracao) => {
|
|
@@ -43509,10 +43740,10 @@ ${labelFuncao}:
|
|
|
43509
43740
|
}
|
|
43510
43741
|
});
|
|
43511
43742
|
}
|
|
43512
|
-
this.text += `
|
|
43513
|
-
ld ra, 8(sp)
|
|
43514
|
-
ld s0, 0(sp)
|
|
43515
|
-
addi sp, sp, 16
|
|
43743
|
+
this.text += `
|
|
43744
|
+
ld ra, 8(sp)
|
|
43745
|
+
ld s0, 0(sp)
|
|
43746
|
+
addi sp, sp, 16
|
|
43516
43747
|
ret`;
|
|
43517
43748
|
}
|
|
43518
43749
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -43536,21 +43767,21 @@ ${labelFuncao}:
|
|
|
43536
43767
|
if (operador === 'e' || operador === '&&') {
|
|
43537
43768
|
this.text += `\n beqz a0, ${labelFim}`;
|
|
43538
43769
|
this.emitirCarga('a0', direita);
|
|
43539
|
-
this.text += `
|
|
43540
|
-
beqz a0, ${labelFim}
|
|
43541
|
-
${labelVerdadeiro}:
|
|
43542
|
-
li a0, 1
|
|
43770
|
+
this.text += `
|
|
43771
|
+
beqz a0, ${labelFim}
|
|
43772
|
+
${labelVerdadeiro}:
|
|
43773
|
+
li a0, 1
|
|
43543
43774
|
${labelFim}:`;
|
|
43544
43775
|
}
|
|
43545
43776
|
else if (operador === 'ou' || operador === '||') {
|
|
43546
43777
|
this.text += `\n bnez a0, ${labelVerdadeiro}`;
|
|
43547
43778
|
this.emitirCarga('a0', direita);
|
|
43548
|
-
this.text += `
|
|
43549
|
-
bnez a0, ${labelVerdadeiro}
|
|
43550
|
-
li a0, 0
|
|
43551
|
-
j ${labelFim}
|
|
43552
|
-
${labelVerdadeiro}:
|
|
43553
|
-
li a0, 1
|
|
43779
|
+
this.text += `
|
|
43780
|
+
bnez a0, ${labelVerdadeiro}
|
|
43781
|
+
li a0, 0
|
|
43782
|
+
j ${labelFim}
|
|
43783
|
+
${labelVerdadeiro}:
|
|
43784
|
+
li a0, 1
|
|
43554
43785
|
${labelFim}:`;
|
|
43555
43786
|
}
|
|
43556
43787
|
return 'a0';
|
|
@@ -43575,8 +43806,8 @@ ${labelFim}:`;
|
|
|
43575
43806
|
const nomeVar = construto.simbolo?.lexema;
|
|
43576
43807
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
43577
43808
|
const varLabel = this.variaveis.get(nomeVar);
|
|
43578
|
-
this.text += `
|
|
43579
|
-
la a0, ${varLabel}
|
|
43809
|
+
this.text += `
|
|
43810
|
+
la a0, ${varLabel}
|
|
43580
43811
|
ld a0, 0(a0)`;
|
|
43581
43812
|
return 'a0';
|
|
43582
43813
|
}
|
|
@@ -43592,8 +43823,8 @@ ${labelFim}:`;
|
|
|
43592
43823
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
43593
43824
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
43594
43825
|
this.emitirCarga('a0', valorTraduzido);
|
|
43595
|
-
this.text += `
|
|
43596
|
-
la a1, ${labelVetor}
|
|
43826
|
+
this.text += `
|
|
43827
|
+
la a1, ${labelVetor}
|
|
43597
43828
|
sd a0, ${index * 8}(a1)`;
|
|
43598
43829
|
}
|
|
43599
43830
|
});
|
|
@@ -43621,8 +43852,8 @@ ${labelFim}:`;
|
|
|
43621
43852
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
43622
43853
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
43623
43854
|
}
|
|
43624
|
-
this.text += `
|
|
43625
|
-
j ${labelInicio}
|
|
43855
|
+
this.text += `
|
|
43856
|
+
j ${labelInicio}
|
|
43626
43857
|
${labelFim}:`;
|
|
43627
43858
|
}
|
|
43628
43859
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -43643,8 +43874,8 @@ ${labelFim}:`;
|
|
|
43643
43874
|
}
|
|
43644
43875
|
});
|
|
43645
43876
|
}
|
|
43646
|
-
this.text += `
|
|
43647
|
-
j ${labelFim}
|
|
43877
|
+
this.text += `
|
|
43878
|
+
j ${labelFim}
|
|
43648
43879
|
${labelProximo}:`;
|
|
43649
43880
|
}
|
|
43650
43881
|
});
|
|
@@ -43688,20 +43919,20 @@ ${labelProximo}:`;
|
|
|
43688
43919
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
43689
43920
|
}
|
|
43690
43921
|
}
|
|
43691
|
-
this.text += `
|
|
43692
|
-
# Falhar com mensagem: ${mensagem}
|
|
43693
|
-
li a0, 1
|
|
43694
|
-
li a7, 93 # sys_exit
|
|
43922
|
+
this.text += `
|
|
43923
|
+
# Falhar com mensagem: ${mensagem}
|
|
43924
|
+
li a0, 1
|
|
43925
|
+
li a7, 93 # sys_exit
|
|
43695
43926
|
ecall`;
|
|
43696
43927
|
}
|
|
43697
43928
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
43698
43929
|
const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
|
|
43699
|
-
this.text += `
|
|
43700
|
-
|
|
43701
|
-
${nomeFuncao}:
|
|
43702
|
-
addi sp, sp, -16
|
|
43703
|
-
sd ra, 8(sp)
|
|
43704
|
-
sd s0, 0(sp)
|
|
43930
|
+
this.text += `
|
|
43931
|
+
|
|
43932
|
+
${nomeFuncao}:
|
|
43933
|
+
addi sp, sp, -16
|
|
43934
|
+
sd ra, 8(sp)
|
|
43935
|
+
sd s0, 0(sp)
|
|
43705
43936
|
addi s0, sp, 16`;
|
|
43706
43937
|
if (declaracao.funcao &&
|
|
43707
43938
|
declaracao.funcao.corpo &&
|
|
@@ -43712,10 +43943,10 @@ ${nomeFuncao}:
|
|
|
43712
43943
|
}
|
|
43713
43944
|
});
|
|
43714
43945
|
}
|
|
43715
|
-
this.text += `
|
|
43716
|
-
ld ra, 8(sp)
|
|
43717
|
-
ld s0, 0(sp)
|
|
43718
|
-
addi sp, sp, 16
|
|
43946
|
+
this.text += `
|
|
43947
|
+
ld ra, 8(sp)
|
|
43948
|
+
ld s0, 0(sp)
|
|
43949
|
+
addi sp, sp, 16
|
|
43719
43950
|
ret`;
|
|
43720
43951
|
}
|
|
43721
43952
|
traduzirDeclaracaoImportar(declaracao) {
|
|
@@ -43735,11 +43966,11 @@ ${nomeFuncao}:
|
|
|
43735
43966
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
43736
43967
|
this.variaveis.set(nomeVar, varLabel);
|
|
43737
43968
|
}
|
|
43738
|
-
this.text += `
|
|
43739
|
-
li a0, 0 # fd stdin
|
|
43740
|
-
la a1, ${this.variaveis.get(nomeVar)}
|
|
43741
|
-
li a2, 256
|
|
43742
|
-
li a7, 63 # sys_read
|
|
43969
|
+
this.text += `
|
|
43970
|
+
li a0, 0 # fd stdin
|
|
43971
|
+
la a1, ${this.variaveis.get(nomeVar)}
|
|
43972
|
+
li a2, 256
|
|
43973
|
+
li a7, 63 # sys_read
|
|
43743
43974
|
ecall`;
|
|
43744
43975
|
}
|
|
43745
43976
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -43770,8 +44001,8 @@ ${nomeFuncao}:
|
|
|
43770
44001
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
43771
44002
|
}
|
|
43772
44003
|
}
|
|
43773
|
-
this.text += `
|
|
43774
|
-
j ${labelInicio}
|
|
44004
|
+
this.text += `
|
|
44005
|
+
j ${labelInicio}
|
|
43775
44006
|
${labelFim}:`;
|
|
43776
44007
|
}
|
|
43777
44008
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -43783,17 +44014,17 @@ ${labelFim}:`;
|
|
|
43783
44014
|
tamanhoVetor = vetor.tamanho || 0;
|
|
43784
44015
|
}
|
|
43785
44016
|
// t0: contador; t1: limite (caller-saved, seguros aqui)
|
|
43786
|
-
this.text += `
|
|
43787
|
-
li t0, 0 # contador
|
|
43788
|
-
li t1, ${tamanhoVetor}
|
|
43789
|
-
${labelInicio}:
|
|
44017
|
+
this.text += `
|
|
44018
|
+
li t0, 0 # contador
|
|
44019
|
+
li t1, ${tamanhoVetor}
|
|
44020
|
+
${labelInicio}:
|
|
43790
44021
|
bge t0, t1, ${labelFim}`;
|
|
43791
44022
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
43792
44023
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
43793
44024
|
}
|
|
43794
|
-
this.text += `
|
|
43795
|
-
addi t0, t0, 1
|
|
43796
|
-
j ${labelInicio}
|
|
44025
|
+
this.text += `
|
|
44026
|
+
addi t0, t0, 1
|
|
44027
|
+
j ${labelInicio}
|
|
43797
44028
|
${labelFim}:`;
|
|
43798
44029
|
}
|
|
43799
44030
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
@@ -43801,10 +44032,10 @@ ${labelFim}:`;
|
|
|
43801
44032
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
43802
44033
|
this.emitirCarga('a0', valor);
|
|
43803
44034
|
}
|
|
43804
|
-
this.text += `
|
|
43805
|
-
ld ra, 8(sp)
|
|
43806
|
-
ld s0, 0(sp)
|
|
43807
|
-
addi sp, sp, 16
|
|
44035
|
+
this.text += `
|
|
44036
|
+
ld ra, 8(sp)
|
|
44037
|
+
ld s0, 0(sp)
|
|
44038
|
+
addi sp, sp, 16
|
|
43808
44039
|
ret`;
|
|
43809
44040
|
}
|
|
43810
44041
|
traduzirDeclaracaoSe(declaracao) {
|
|
@@ -43818,8 +44049,8 @@ ${labelFim}:`;
|
|
|
43818
44049
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
43819
44050
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
43820
44051
|
}
|
|
43821
|
-
this.text += `
|
|
43822
|
-
j ${labelFim}
|
|
44052
|
+
this.text += `
|
|
44053
|
+
j ${labelFim}
|
|
43823
44054
|
${labelSenao}:`;
|
|
43824
44055
|
if (declaracao.caminhoSenao &&
|
|
43825
44056
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
@@ -43865,8 +44096,8 @@ ${labelSenao}:`;
|
|
|
43865
44096
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
43866
44097
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
43867
44098
|
this.emitirCarga('a0', valor);
|
|
43868
|
-
this.text += `
|
|
43869
|
-
la a1, ${varLabel}
|
|
44099
|
+
this.text += `
|
|
44100
|
+
la a1, ${varLabel}
|
|
43870
44101
|
sd a0, 0(a1)`;
|
|
43871
44102
|
}
|
|
43872
44103
|
}
|
|
@@ -43893,17 +44124,17 @@ ${labelSenao}:`;
|
|
|
43893
44124
|
tamanhoString = String(stringValue.length);
|
|
43894
44125
|
}
|
|
43895
44126
|
// sys_write(fd=1, buf, count): a7=64, a0=fd, a1=buf, a2=count
|
|
43896
|
-
this.text += `
|
|
43897
|
-
la a1, ${nomeStringLiteral}
|
|
43898
|
-
li a2, ${tamanhoString}
|
|
43899
|
-
li a0, 1 # fd stdout
|
|
43900
|
-
li a7, 64 # sys_write
|
|
44127
|
+
this.text += `
|
|
44128
|
+
la a1, ${nomeStringLiteral}
|
|
44129
|
+
li a2, ${tamanhoString}
|
|
44130
|
+
li a0, 1 # fd stdout
|
|
44131
|
+
li a7, 64 # sys_write
|
|
43901
44132
|
ecall`;
|
|
43902
44133
|
}
|
|
43903
44134
|
saidaSistema() {
|
|
43904
|
-
this.text += `
|
|
43905
|
-
li a0, 0 # código de saída
|
|
43906
|
-
li a7, 93 # sys_exit
|
|
44135
|
+
this.text += `
|
|
44136
|
+
li a0, 0 # código de saída
|
|
44137
|
+
li a7, 93 # sys_exit
|
|
43907
44138
|
ecall`;
|
|
43908
44139
|
}
|
|
43909
44140
|
traduzir(declaracoes) {
|
|
@@ -43979,14 +44210,14 @@ class TradutorAssemblyX64 {
|
|
|
43979
44210
|
Escreva: this.traduzirDeclaracaoEscreva.bind(this),
|
|
43980
44211
|
};
|
|
43981
44212
|
this.indentacao = 0;
|
|
43982
|
-
this.textoSaida = `
|
|
43983
|
-
section .text
|
|
43984
|
-
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
44213
|
+
this.textoSaida = `
|
|
44214
|
+
section .text
|
|
44215
|
+
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
43985
44216
|
${this.alvo === 'linux' ? '_start:' : 'main:'}`;
|
|
43986
44217
|
if (this.alvo === 'windows') {
|
|
43987
44218
|
this.textoSaida =
|
|
43988
|
-
`
|
|
43989
|
-
extern printf
|
|
44219
|
+
`
|
|
44220
|
+
extern printf
|
|
43990
44221
|
` + this.textoSaida;
|
|
43991
44222
|
}
|
|
43992
44223
|
}
|
|
@@ -44046,8 +44277,8 @@ extern printf
|
|
|
44046
44277
|
}
|
|
44047
44278
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
44048
44279
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
44049
|
-
this.textoSaida += `
|
|
44050
|
-
mov rax, ${valor}
|
|
44280
|
+
this.textoSaida += `
|
|
44281
|
+
mov rax, ${valor}
|
|
44051
44282
|
mov [${nomeVar} + ${indice} * 8], rax`;
|
|
44052
44283
|
}
|
|
44053
44284
|
traduzirConstrutoAtribuir(construto) {
|
|
@@ -44065,8 +44296,8 @@ extern printf
|
|
|
44065
44296
|
this.bss += ` ${varLabel} resq 1\n`;
|
|
44066
44297
|
this.variaveis.set(nomeVar, varLabel);
|
|
44067
44298
|
}
|
|
44068
|
-
this.textoSaida += `
|
|
44069
|
-
mov rax, ${valor}
|
|
44299
|
+
this.textoSaida += `
|
|
44300
|
+
mov rax, ${valor}
|
|
44070
44301
|
mov [${this.variaveis.get(nomeVar)}], rax`;
|
|
44071
44302
|
}
|
|
44072
44303
|
traduzirConstrutoBinario(construto) {
|
|
@@ -44074,71 +44305,71 @@ extern printf
|
|
|
44074
44305
|
const direita = this.dicionarioConstrutos[construto.direita.constructor.name](construto.direita);
|
|
44075
44306
|
const operador = construto.operador.lexema;
|
|
44076
44307
|
const registrador = this.obterRegistrador();
|
|
44077
|
-
this.textoSaida += `
|
|
44078
|
-
mov rax, ${esquerda}
|
|
44308
|
+
this.textoSaida += `
|
|
44309
|
+
mov rax, ${esquerda}
|
|
44079
44310
|
mov ${registrador}, ${direita}`;
|
|
44080
44311
|
switch (operador) {
|
|
44081
44312
|
case '+':
|
|
44082
|
-
this.textoSaida += `
|
|
44313
|
+
this.textoSaida += `
|
|
44083
44314
|
add rax, ${registrador}`;
|
|
44084
44315
|
break;
|
|
44085
44316
|
case '-':
|
|
44086
|
-
this.textoSaida += `
|
|
44317
|
+
this.textoSaida += `
|
|
44087
44318
|
sub rax, ${registrador}`;
|
|
44088
44319
|
break;
|
|
44089
44320
|
case '*':
|
|
44090
|
-
this.textoSaida += `
|
|
44321
|
+
this.textoSaida += `
|
|
44091
44322
|
imul rax, ${registrador}`;
|
|
44092
44323
|
break;
|
|
44093
44324
|
case '/':
|
|
44094
|
-
this.textoSaida += `
|
|
44095
|
-
xor rdx, rdx
|
|
44325
|
+
this.textoSaida += `
|
|
44326
|
+
xor rdx, rdx
|
|
44096
44327
|
idiv ${registrador}`;
|
|
44097
44328
|
break;
|
|
44098
44329
|
case '%':
|
|
44099
|
-
this.textoSaida += `
|
|
44100
|
-
xor rdx, rdx
|
|
44101
|
-
idiv ${registrador}
|
|
44330
|
+
this.textoSaida += `
|
|
44331
|
+
xor rdx, rdx
|
|
44332
|
+
idiv ${registrador}
|
|
44102
44333
|
mov rax, rdx`;
|
|
44103
44334
|
break;
|
|
44104
44335
|
case '<':
|
|
44105
|
-
this.textoSaida += `
|
|
44106
|
-
cmp rax, ${registrador}
|
|
44107
|
-
setl al
|
|
44336
|
+
this.textoSaida += `
|
|
44337
|
+
cmp rax, ${registrador}
|
|
44338
|
+
setl al
|
|
44108
44339
|
movzx rax, al`;
|
|
44109
44340
|
break;
|
|
44110
44341
|
case '>':
|
|
44111
|
-
this.textoSaida += `
|
|
44112
|
-
cmp rax, ${registrador}
|
|
44113
|
-
setg al
|
|
44342
|
+
this.textoSaida += `
|
|
44343
|
+
cmp rax, ${registrador}
|
|
44344
|
+
setg al
|
|
44114
44345
|
movzx rax, al`;
|
|
44115
44346
|
break;
|
|
44116
44347
|
case '<=':
|
|
44117
|
-
this.textoSaida += `
|
|
44118
|
-
cmp rax, ${registrador}
|
|
44119
|
-
setle al
|
|
44348
|
+
this.textoSaida += `
|
|
44349
|
+
cmp rax, ${registrador}
|
|
44350
|
+
setle al
|
|
44120
44351
|
movzx rax, al`;
|
|
44121
44352
|
break;
|
|
44122
44353
|
case '>=':
|
|
44123
|
-
this.textoSaida += `
|
|
44124
|
-
cmp rax, ${registrador}
|
|
44125
|
-
setge al
|
|
44354
|
+
this.textoSaida += `
|
|
44355
|
+
cmp rax, ${registrador}
|
|
44356
|
+
setge al
|
|
44126
44357
|
movzx rax, al`;
|
|
44127
44358
|
break;
|
|
44128
44359
|
case '==':
|
|
44129
|
-
this.textoSaida += `
|
|
44130
|
-
cmp rax, ${registrador}
|
|
44131
|
-
sete al
|
|
44360
|
+
this.textoSaida += `
|
|
44361
|
+
cmp rax, ${registrador}
|
|
44362
|
+
sete al
|
|
44132
44363
|
movzx rax, al`;
|
|
44133
44364
|
break;
|
|
44134
44365
|
case '!=':
|
|
44135
|
-
this.textoSaida += `
|
|
44136
|
-
cmp rax, ${registrador}
|
|
44137
|
-
setne al
|
|
44366
|
+
this.textoSaida += `
|
|
44367
|
+
cmp rax, ${registrador}
|
|
44368
|
+
setne al
|
|
44138
44369
|
movzx rax, al`;
|
|
44139
44370
|
break;
|
|
44140
44371
|
default:
|
|
44141
|
-
this.textoSaida += `
|
|
44372
|
+
this.textoSaida += `
|
|
44142
44373
|
; Operador ${operador} não implementado`;
|
|
44143
44374
|
}
|
|
44144
44375
|
this.liberarRegistrador(registrador);
|
|
@@ -44156,28 +44387,28 @@ extern printf
|
|
|
44156
44387
|
construto.argumentos.forEach((arg, index) => {
|
|
44157
44388
|
if (index < registrosArgs.length) {
|
|
44158
44389
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
44159
|
-
this.textoSaida += `
|
|
44390
|
+
this.textoSaida += `
|
|
44160
44391
|
mov ${registrosArgs[index]}, ${valorArg}`;
|
|
44161
44392
|
}
|
|
44162
44393
|
else {
|
|
44163
44394
|
// TODO: push extra args on stack according to target ABI
|
|
44164
44395
|
}
|
|
44165
44396
|
});
|
|
44166
|
-
this.textoSaida += `
|
|
44397
|
+
this.textoSaida += `
|
|
44167
44398
|
call ${nomeFuncao}`;
|
|
44168
44399
|
}
|
|
44169
44400
|
traduzirConstrutoDefinirValor(construto) {
|
|
44170
44401
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
44171
44402
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
44172
|
-
this.textoSaida += `
|
|
44173
|
-
mov rax, ${valor}
|
|
44403
|
+
this.textoSaida += `
|
|
44404
|
+
mov rax, ${valor}
|
|
44174
44405
|
mov [${objeto}], rax`;
|
|
44175
44406
|
}
|
|
44176
44407
|
traduzirFuncaoConstruto(construto) {
|
|
44177
44408
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
44178
|
-
this.textoSaida += `
|
|
44179
|
-
${labelFuncao}:
|
|
44180
|
-
push rbp
|
|
44409
|
+
this.textoSaida += `
|
|
44410
|
+
${labelFuncao}:
|
|
44411
|
+
push rbp
|
|
44181
44412
|
mov rbp, rsp`;
|
|
44182
44413
|
// Traduzir corpo da função
|
|
44183
44414
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -44187,8 +44418,8 @@ ${labelFuncao}:
|
|
|
44187
44418
|
}
|
|
44188
44419
|
});
|
|
44189
44420
|
}
|
|
44190
|
-
this.textoSaida += `
|
|
44191
|
-
pop rbp
|
|
44421
|
+
this.textoSaida += `
|
|
44422
|
+
pop rbp
|
|
44192
44423
|
ret`;
|
|
44193
44424
|
}
|
|
44194
44425
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -44203,29 +44434,29 @@ ${labelFuncao}:
|
|
|
44203
44434
|
const operador = construto.operador.lexema;
|
|
44204
44435
|
const labelVerdadeiro = this.gerarLabel();
|
|
44205
44436
|
const labelFim = this.gerarLabel();
|
|
44206
|
-
this.textoSaida += `
|
|
44207
|
-
mov rax, ${esquerda}
|
|
44437
|
+
this.textoSaida += `
|
|
44438
|
+
mov rax, ${esquerda}
|
|
44208
44439
|
cmp rax, 0`;
|
|
44209
44440
|
if (operador === 'e' || operador === '&&') {
|
|
44210
|
-
this.textoSaida += `
|
|
44211
|
-
je ${labelFim}
|
|
44212
|
-
mov rax, ${direita}
|
|
44213
|
-
cmp rax, 0
|
|
44214
|
-
je ${labelFim}
|
|
44215
|
-
${labelVerdadeiro}:
|
|
44216
|
-
mov rax, 1
|
|
44441
|
+
this.textoSaida += `
|
|
44442
|
+
je ${labelFim}
|
|
44443
|
+
mov rax, ${direita}
|
|
44444
|
+
cmp rax, 0
|
|
44445
|
+
je ${labelFim}
|
|
44446
|
+
${labelVerdadeiro}:
|
|
44447
|
+
mov rax, 1
|
|
44217
44448
|
${labelFim}:`;
|
|
44218
44449
|
}
|
|
44219
44450
|
else if (operador === 'ou' || operador === '||') {
|
|
44220
|
-
this.textoSaida += `
|
|
44221
|
-
jne ${labelVerdadeiro}
|
|
44222
|
-
mov rax, ${direita}
|
|
44223
|
-
cmp rax, 0
|
|
44224
|
-
jne ${labelVerdadeiro}
|
|
44225
|
-
mov rax, 0
|
|
44226
|
-
jmp ${labelFim}
|
|
44227
|
-
${labelVerdadeiro}:
|
|
44228
|
-
mov rax, 1
|
|
44451
|
+
this.textoSaida += `
|
|
44452
|
+
jne ${labelVerdadeiro}
|
|
44453
|
+
mov rax, ${direita}
|
|
44454
|
+
cmp rax, 0
|
|
44455
|
+
jne ${labelVerdadeiro}
|
|
44456
|
+
mov rax, 0
|
|
44457
|
+
jmp ${labelFim}
|
|
44458
|
+
${labelVerdadeiro}:
|
|
44459
|
+
mov rax, 1
|
|
44229
44460
|
${labelFim}:`;
|
|
44230
44461
|
}
|
|
44231
44462
|
return 'rax';
|
|
@@ -44238,26 +44469,26 @@ ${labelFim}:`;
|
|
|
44238
44469
|
traduzirConstrutoUnario(construto) {
|
|
44239
44470
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
44240
44471
|
const operador = construto.operador.lexema;
|
|
44241
|
-
this.textoSaida += `
|
|
44472
|
+
this.textoSaida += `
|
|
44242
44473
|
mov rax, ${operando}`;
|
|
44243
44474
|
if (operador === '-') {
|
|
44244
|
-
this.textoSaida += `
|
|
44475
|
+
this.textoSaida += `
|
|
44245
44476
|
neg rax`;
|
|
44246
44477
|
}
|
|
44247
44478
|
else if (operador === '!' || operador === 'nao') {
|
|
44248
|
-
this.textoSaida += `
|
|
44249
|
-
cmp rax, 0
|
|
44250
|
-
sete al
|
|
44479
|
+
this.textoSaida += `
|
|
44480
|
+
cmp rax, 0
|
|
44481
|
+
sete al
|
|
44251
44482
|
movzx rax, al`;
|
|
44252
44483
|
}
|
|
44253
44484
|
else if (operador === '++') {
|
|
44254
|
-
this.textoSaida += `
|
|
44255
|
-
inc rax
|
|
44485
|
+
this.textoSaida += `
|
|
44486
|
+
inc rax
|
|
44256
44487
|
mov ${operando}, rax`;
|
|
44257
44488
|
}
|
|
44258
44489
|
else if (operador === '--') {
|
|
44259
|
-
this.textoSaida += `
|
|
44260
|
-
dec rax
|
|
44490
|
+
this.textoSaida += `
|
|
44491
|
+
dec rax
|
|
44261
44492
|
mov ${operando}, rax`;
|
|
44262
44493
|
}
|
|
44263
44494
|
return 'rax';
|
|
@@ -44277,8 +44508,8 @@ ${labelFim}:`;
|
|
|
44277
44508
|
construto.valores.forEach((valor, index) => {
|
|
44278
44509
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
44279
44510
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
44280
|
-
this.textoSaida += `
|
|
44281
|
-
mov rax, ${valorTraduzido}
|
|
44511
|
+
this.textoSaida += `
|
|
44512
|
+
mov rax, ${valorTraduzido}
|
|
44282
44513
|
mov [${rotuloVetor} + ${index * 8}], rax`;
|
|
44283
44514
|
}
|
|
44284
44515
|
});
|
|
@@ -44298,17 +44529,17 @@ ${labelFim}:`;
|
|
|
44298
44529
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
44299
44530
|
const labelInicio = this.gerarLabel();
|
|
44300
44531
|
const labelFim = this.gerarLabel();
|
|
44301
|
-
this.textoSaida += `
|
|
44532
|
+
this.textoSaida += `
|
|
44302
44533
|
${labelInicio}:`;
|
|
44303
44534
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
44304
|
-
this.textoSaida += `
|
|
44305
|
-
cmp ${condicao}, 0
|
|
44535
|
+
this.textoSaida += `
|
|
44536
|
+
cmp ${condicao}, 0
|
|
44306
44537
|
je ${labelFim}`;
|
|
44307
44538
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
44308
44539
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
44309
44540
|
}
|
|
44310
|
-
this.textoSaida += `
|
|
44311
|
-
jmp ${labelInicio}
|
|
44541
|
+
this.textoSaida += `
|
|
44542
|
+
jmp ${labelInicio}
|
|
44312
44543
|
${labelFim}:`;
|
|
44313
44544
|
}
|
|
44314
44545
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -44319,9 +44550,9 @@ ${labelFim}:`;
|
|
|
44319
44550
|
const labelProximo = this.gerarLabel();
|
|
44320
44551
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
44321
44552
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
44322
|
-
this.textoSaida += `
|
|
44323
|
-
mov rax, ${valorEscolha}
|
|
44324
|
-
cmp rax, ${valorCaso}
|
|
44553
|
+
this.textoSaida += `
|
|
44554
|
+
mov rax, ${valorEscolha}
|
|
44555
|
+
cmp rax, ${valorCaso}
|
|
44325
44556
|
jne ${labelProximo}`;
|
|
44326
44557
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
44327
44558
|
caminho.declaracoes.forEach((declaracao) => {
|
|
@@ -44330,13 +44561,13 @@ ${labelFim}:`;
|
|
|
44330
44561
|
}
|
|
44331
44562
|
});
|
|
44332
44563
|
}
|
|
44333
|
-
this.textoSaida += `
|
|
44334
|
-
jmp ${labelFim}
|
|
44564
|
+
this.textoSaida += `
|
|
44565
|
+
jmp ${labelFim}
|
|
44335
44566
|
${labelProximo}:`;
|
|
44336
44567
|
}
|
|
44337
44568
|
});
|
|
44338
44569
|
}
|
|
44339
|
-
this.textoSaida += `
|
|
44570
|
+
this.textoSaida += `
|
|
44340
44571
|
${labelFim}:`;
|
|
44341
44572
|
}
|
|
44342
44573
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
@@ -44347,7 +44578,7 @@ ${labelFim}:`;
|
|
|
44347
44578
|
}
|
|
44348
44579
|
traduzirDeclaracaoFazer(declaracao) {
|
|
44349
44580
|
const labelInicio = this.gerarLabel();
|
|
44350
|
-
this.textoSaida += `
|
|
44581
|
+
this.textoSaida += `
|
|
44351
44582
|
${labelInicio}:`;
|
|
44352
44583
|
// Em Delégua, fazer-enquanto tem caminhoFazer que é um Bloco
|
|
44353
44584
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
@@ -44359,8 +44590,8 @@ ${labelInicio}:`;
|
|
|
44359
44590
|
}
|
|
44360
44591
|
if (declaracao.condicaoEnquanto) {
|
|
44361
44592
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
44362
|
-
this.textoSaida += `
|
|
44363
|
-
cmp ${condicao}, 0
|
|
44593
|
+
this.textoSaida += `
|
|
44594
|
+
cmp ${condicao}, 0
|
|
44364
44595
|
jne ${labelInicio}`;
|
|
44365
44596
|
}
|
|
44366
44597
|
}
|
|
@@ -44375,24 +44606,24 @@ ${labelInicio}:`;
|
|
|
44375
44606
|
}
|
|
44376
44607
|
}
|
|
44377
44608
|
if (this.alvo === 'linux') {
|
|
44378
|
-
this.textoSaida += `
|
|
44379
|
-
; Falhar com mensagem: ${mensagem}
|
|
44380
|
-
mov eax, 1
|
|
44381
|
-
mov ebx, 1
|
|
44609
|
+
this.textoSaida += `
|
|
44610
|
+
; Falhar com mensagem: ${mensagem}
|
|
44611
|
+
mov eax, 1
|
|
44612
|
+
mov ebx, 1
|
|
44382
44613
|
int 0x80`;
|
|
44383
44614
|
}
|
|
44384
44615
|
else {
|
|
44385
|
-
this.textoSaida += `
|
|
44386
|
-
; Falhar com mensagem: ${mensagem}
|
|
44387
|
-
mov eax, 1
|
|
44616
|
+
this.textoSaida += `
|
|
44617
|
+
; Falhar com mensagem: ${mensagem}
|
|
44618
|
+
mov eax, 1
|
|
44388
44619
|
ret`;
|
|
44389
44620
|
}
|
|
44390
44621
|
}
|
|
44391
44622
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
44392
44623
|
const nomeFuncao = declaracao.simbolo?.lexema || 'funcao';
|
|
44393
|
-
this.textoSaida += `
|
|
44394
|
-
${nomeFuncao}:
|
|
44395
|
-
push rbp
|
|
44624
|
+
this.textoSaida += `
|
|
44625
|
+
${nomeFuncao}:
|
|
44626
|
+
push rbp
|
|
44396
44627
|
mov rbp, rsp`;
|
|
44397
44628
|
if (declaracao.funcao &&
|
|
44398
44629
|
declaracao.funcao.corpo &&
|
|
@@ -44403,13 +44634,13 @@ ${nomeFuncao}:
|
|
|
44403
44634
|
}
|
|
44404
44635
|
});
|
|
44405
44636
|
}
|
|
44406
|
-
this.textoSaida += `
|
|
44407
|
-
pop rbp
|
|
44637
|
+
this.textoSaida += `
|
|
44638
|
+
pop rbp
|
|
44408
44639
|
ret`;
|
|
44409
44640
|
}
|
|
44410
44641
|
traduzirDeclaracaoImportar(declaracao) {
|
|
44411
44642
|
// Importação é tratada em tempo de linkagem
|
|
44412
|
-
this.textoSaida += `
|
|
44643
|
+
this.textoSaida += `
|
|
44413
44644
|
; Importar: ${declaracao.caminho || 'unknown'}`;
|
|
44414
44645
|
}
|
|
44415
44646
|
traduzirDeclaracaoLeia(declaracao) {
|
|
@@ -44426,11 +44657,11 @@ ${nomeFuncao}:
|
|
|
44426
44657
|
this.bss += ` ${varLabel} resb 256\n`;
|
|
44427
44658
|
this.variaveis.set(nomeVar, varLabel);
|
|
44428
44659
|
}
|
|
44429
|
-
this.textoSaida += `
|
|
44430
|
-
mov eax, 3
|
|
44431
|
-
mov ebx, 0
|
|
44432
|
-
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
44433
|
-
mov edx, 256
|
|
44660
|
+
this.textoSaida += `
|
|
44661
|
+
mov eax, 3
|
|
44662
|
+
mov ebx, 0
|
|
44663
|
+
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
44664
|
+
mov edx, 256
|
|
44434
44665
|
int 0x80`;
|
|
44435
44666
|
}
|
|
44436
44667
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -44456,12 +44687,12 @@ ${nomeFuncao}:
|
|
|
44456
44687
|
}
|
|
44457
44688
|
}
|
|
44458
44689
|
}
|
|
44459
|
-
this.textoSaida += `
|
|
44690
|
+
this.textoSaida += `
|
|
44460
44691
|
${labelInicio}:`;
|
|
44461
44692
|
if (declaracao.condicao) {
|
|
44462
44693
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
44463
|
-
this.textoSaida += `
|
|
44464
|
-
cmp ${condicao}, 0
|
|
44694
|
+
this.textoSaida += `
|
|
44695
|
+
cmp ${condicao}, 0
|
|
44465
44696
|
je ${labelFim}`;
|
|
44466
44697
|
}
|
|
44467
44698
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -44472,8 +44703,8 @@ ${labelInicio}:`;
|
|
|
44472
44703
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
44473
44704
|
}
|
|
44474
44705
|
}
|
|
44475
|
-
this.textoSaida += `
|
|
44476
|
-
jmp ${labelInicio}
|
|
44706
|
+
this.textoSaida += `
|
|
44707
|
+
jmp ${labelInicio}
|
|
44477
44708
|
${labelFim}:`;
|
|
44478
44709
|
}
|
|
44479
44710
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -44488,57 +44719,57 @@ ${labelFim}:`;
|
|
|
44488
44719
|
if (vetor instanceof construtos_1.Vetor) {
|
|
44489
44720
|
tamanhoVetor = vetor.tamanho || 0;
|
|
44490
44721
|
}
|
|
44491
|
-
this.textoSaida += `
|
|
44492
|
-
xor rcx, rcx
|
|
44493
|
-
${rotuloInicio}:
|
|
44494
|
-
cmp rcx, ${tamanhoVetor}
|
|
44722
|
+
this.textoSaida += `
|
|
44723
|
+
xor rcx, rcx
|
|
44724
|
+
${rotuloInicio}:
|
|
44725
|
+
cmp rcx, ${tamanhoVetor}
|
|
44495
44726
|
jge ${rotuloFim}`;
|
|
44496
44727
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
44497
44728
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
44498
44729
|
}
|
|
44499
|
-
this.textoSaida += `
|
|
44500
|
-
inc rcx
|
|
44501
|
-
jmp ${rotuloInicio}
|
|
44730
|
+
this.textoSaida += `
|
|
44731
|
+
inc rcx
|
|
44732
|
+
jmp ${rotuloInicio}
|
|
44502
44733
|
${rotuloFim}:`;
|
|
44503
44734
|
}
|
|
44504
44735
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
44505
44736
|
if (declaracao.valor) {
|
|
44506
44737
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
44507
|
-
this.textoSaida += `
|
|
44738
|
+
this.textoSaida += `
|
|
44508
44739
|
mov rax, ${valor}`;
|
|
44509
44740
|
}
|
|
44510
|
-
this.textoSaida += `
|
|
44511
|
-
pop rbp
|
|
44741
|
+
this.textoSaida += `
|
|
44742
|
+
pop rbp
|
|
44512
44743
|
ret`;
|
|
44513
44744
|
}
|
|
44514
44745
|
traduzirDeclaracaoSe(declaracao) {
|
|
44515
44746
|
const rotuloSenao = this.gerarLabel();
|
|
44516
44747
|
const rotuloFim = this.gerarLabel();
|
|
44517
44748
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
44518
|
-
this.textoSaida += `
|
|
44519
|
-
cmp ${condicao}, 0
|
|
44749
|
+
this.textoSaida += `
|
|
44750
|
+
cmp ${condicao}, 0
|
|
44520
44751
|
je ${rotuloSenao}`;
|
|
44521
44752
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
44522
44753
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
44523
44754
|
}
|
|
44524
|
-
this.textoSaida += `
|
|
44525
|
-
jmp ${rotuloFim}
|
|
44755
|
+
this.textoSaida += `
|
|
44756
|
+
jmp ${rotuloFim}
|
|
44526
44757
|
${rotuloSenao}:`;
|
|
44527
44758
|
if (declaracao.caminhoSenao &&
|
|
44528
44759
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
44529
44760
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
44530
44761
|
}
|
|
44531
|
-
this.textoSaida += `
|
|
44762
|
+
this.textoSaida += `
|
|
44532
44763
|
${rotuloFim}:`;
|
|
44533
44764
|
}
|
|
44534
44765
|
traduzirDeclaracaoClasse(declaracao) {
|
|
44535
44766
|
// Classes em assembly são complexas - implementação básica
|
|
44536
|
-
this.textoSaida += `
|
|
44767
|
+
this.textoSaida += `
|
|
44537
44768
|
; Classe: ${declaracao.simbolo?.lexema || 'unknown'}`;
|
|
44538
44769
|
}
|
|
44539
44770
|
traduzirDeclaracaoTente(declaracao) {
|
|
44540
44771
|
// Try-catch em assembly requer handler complexo
|
|
44541
|
-
this.textoSaida += `
|
|
44772
|
+
this.textoSaida += `
|
|
44542
44773
|
; Tente-pegue`;
|
|
44543
44774
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
44544
44775
|
declaracao.caminhoTente.forEach((declaracao) => {
|
|
@@ -44575,8 +44806,8 @@ ${rotuloFim}:`;
|
|
|
44575
44806
|
}
|
|
44576
44807
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
44577
44808
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
44578
|
-
this.textoSaida += `
|
|
44579
|
-
mov rax, ${valor}
|
|
44809
|
+
this.textoSaida += `
|
|
44810
|
+
mov rax, ${valor}
|
|
44580
44811
|
mov [${varLabel}], rax`;
|
|
44581
44812
|
}
|
|
44582
44813
|
}
|
|
@@ -44596,33 +44827,33 @@ ${rotuloFim}:`;
|
|
|
44596
44827
|
return;
|
|
44597
44828
|
this.helperPrintIntEmitido = true;
|
|
44598
44829
|
this.bss += ` __print_buf resb 24\n`;
|
|
44599
|
-
this.helpers += `
|
|
44600
|
-
__delegua_print_int:
|
|
44601
|
-
push rbx
|
|
44602
|
-
push rcx
|
|
44603
|
-
push rdx
|
|
44604
|
-
push rsi
|
|
44605
|
-
mov rcx, 10
|
|
44606
|
-
lea rsi, [__print_buf + 22]
|
|
44607
|
-
mov byte [rsi], 10
|
|
44608
|
-
.print_digitloop:
|
|
44609
|
-
xor rdx, rdx
|
|
44610
|
-
div rcx
|
|
44611
|
-
add dl, '0'
|
|
44612
|
-
dec rsi
|
|
44613
|
-
mov [rsi], dl
|
|
44614
|
-
test rax, rax
|
|
44615
|
-
jnz .print_digitloop
|
|
44616
|
-
lea rdx, [__print_buf + 23]
|
|
44617
|
-
sub rdx, rsi
|
|
44618
|
-
mov ecx, esi
|
|
44619
|
-
mov ebx, 1
|
|
44620
|
-
mov eax, 4
|
|
44621
|
-
int 0x80
|
|
44622
|
-
pop rsi
|
|
44623
|
-
pop rdx
|
|
44624
|
-
pop rcx
|
|
44625
|
-
pop rbx
|
|
44830
|
+
this.helpers += `
|
|
44831
|
+
__delegua_print_int:
|
|
44832
|
+
push rbx
|
|
44833
|
+
push rcx
|
|
44834
|
+
push rdx
|
|
44835
|
+
push rsi
|
|
44836
|
+
mov rcx, 10
|
|
44837
|
+
lea rsi, [__print_buf + 22]
|
|
44838
|
+
mov byte [rsi], 10
|
|
44839
|
+
.print_digitloop:
|
|
44840
|
+
xor rdx, rdx
|
|
44841
|
+
div rcx
|
|
44842
|
+
add dl, '0'
|
|
44843
|
+
dec rsi
|
|
44844
|
+
mov [rsi], dl
|
|
44845
|
+
test rax, rax
|
|
44846
|
+
jnz .print_digitloop
|
|
44847
|
+
lea rdx, [__print_buf + 23]
|
|
44848
|
+
sub rdx, rsi
|
|
44849
|
+
mov ecx, esi
|
|
44850
|
+
mov ebx, 1
|
|
44851
|
+
mov eax, 4
|
|
44852
|
+
int 0x80
|
|
44853
|
+
pop rsi
|
|
44854
|
+
pop rdx
|
|
44855
|
+
pop rcx
|
|
44856
|
+
pop rbx
|
|
44626
44857
|
ret`;
|
|
44627
44858
|
}
|
|
44628
44859
|
traduzirDeclaracaoEscreva(declaracaoEscreva) {
|
|
@@ -44631,16 +44862,16 @@ __delegua_print_int:
|
|
|
44631
44862
|
const nome_string_literal = this.criaStringLiteral(arg);
|
|
44632
44863
|
const tam_string_literal = this.criaTamanhoNaMemoriaReferenteAVar(nome_string_literal);
|
|
44633
44864
|
if (this.alvo === 'linux') {
|
|
44634
|
-
this.textoSaida += `
|
|
44635
|
-
mov edx, ${tam_string_literal}
|
|
44636
|
-
mov ecx, ${nome_string_literal}
|
|
44637
|
-
mov ebx, 1 ; fd stdout
|
|
44638
|
-
mov eax, 4 ; sys_write
|
|
44865
|
+
this.textoSaida += `
|
|
44866
|
+
mov edx, ${tam_string_literal}
|
|
44867
|
+
mov ecx, ${nome_string_literal}
|
|
44868
|
+
mov ebx, 1 ; fd stdout
|
|
44869
|
+
mov eax, 4 ; sys_write
|
|
44639
44870
|
int 0x80`;
|
|
44640
44871
|
}
|
|
44641
44872
|
else {
|
|
44642
|
-
this.textoSaida += `
|
|
44643
|
-
lea rcx, [rel ${nome_string_literal}]
|
|
44873
|
+
this.textoSaida += `
|
|
44874
|
+
lea rcx, [rel ${nome_string_literal}]
|
|
44644
44875
|
call printf`;
|
|
44645
44876
|
}
|
|
44646
44877
|
}
|
|
@@ -44648,8 +44879,8 @@ __delegua_print_int:
|
|
|
44648
44879
|
const valor = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
44649
44880
|
if (this.alvo === 'linux') {
|
|
44650
44881
|
this.emitirHelperPrintInt();
|
|
44651
|
-
this.textoSaida += `
|
|
44652
|
-
mov rax, ${valor}
|
|
44882
|
+
this.textoSaida += `
|
|
44883
|
+
mov rax, ${valor}
|
|
44653
44884
|
call __delegua_print_int`;
|
|
44654
44885
|
}
|
|
44655
44886
|
else {
|
|
@@ -44657,24 +44888,24 @@ __delegua_print_int:
|
|
|
44657
44888
|
this.data += ` __fmt_int db '%d', 10, 0\n`;
|
|
44658
44889
|
this.fmtIntWindowsEmitido = true;
|
|
44659
44890
|
}
|
|
44660
|
-
this.textoSaida += `
|
|
44661
|
-
mov rdx, ${valor}
|
|
44662
|
-
lea rcx, [rel __fmt_int]
|
|
44891
|
+
this.textoSaida += `
|
|
44892
|
+
mov rdx, ${valor}
|
|
44893
|
+
lea rcx, [rel __fmt_int]
|
|
44663
44894
|
call printf`;
|
|
44664
44895
|
}
|
|
44665
44896
|
}
|
|
44666
44897
|
}
|
|
44667
44898
|
saidaSistema() {
|
|
44668
44899
|
if (this.alvo === 'linux') {
|
|
44669
|
-
this.textoSaida += `
|
|
44670
|
-
mov eax, 1 ; sys_exit
|
|
44671
|
-
xor ebx, ebx ; status 0
|
|
44900
|
+
this.textoSaida += `
|
|
44901
|
+
mov eax, 1 ; sys_exit
|
|
44902
|
+
xor ebx, ebx ; status 0
|
|
44672
44903
|
int 0x80`;
|
|
44673
44904
|
}
|
|
44674
44905
|
else {
|
|
44675
44906
|
// Windows: return from main with 0 in EAX
|
|
44676
|
-
this.textoSaida += `
|
|
44677
|
-
xor eax, eax
|
|
44907
|
+
this.textoSaida += `
|
|
44908
|
+
xor eax, eax
|
|
44678
44909
|
ret`;
|
|
44679
44910
|
}
|
|
44680
44911
|
}
|
|
@@ -45975,13 +46206,19 @@ class TradutorElixir {
|
|
|
45975
46206
|
}
|
|
45976
46207
|
mapearTipoParaTypespec(tipo) {
|
|
45977
46208
|
switch (tipo) {
|
|
45978
|
-
case 'texto':
|
|
46209
|
+
case 'texto':
|
|
46210
|
+
return 'String.t()';
|
|
45979
46211
|
case 'numero':
|
|
45980
|
-
case 'inteiro':
|
|
45981
|
-
|
|
45982
|
-
case '
|
|
45983
|
-
|
|
45984
|
-
|
|
46212
|
+
case 'inteiro':
|
|
46213
|
+
return 'integer()';
|
|
46214
|
+
case 'real':
|
|
46215
|
+
return 'float()';
|
|
46216
|
+
case 'logico':
|
|
46217
|
+
return 'boolean()';
|
|
46218
|
+
case 'vazio':
|
|
46219
|
+
return 'no_return()';
|
|
46220
|
+
default:
|
|
46221
|
+
return 'term()';
|
|
45985
46222
|
}
|
|
45986
46223
|
}
|
|
45987
46224
|
/**
|
|
@@ -46070,11 +46307,15 @@ class TradutorElixir {
|
|
|
46070
46307
|
this.moduloAtual = nomeModulo;
|
|
46071
46308
|
if (declaracao.estrangeira) {
|
|
46072
46309
|
// Classe estrangeira: emitir @callback para cada método, definindo a interface esperada do módulo.
|
|
46073
|
-
resultado +=
|
|
46310
|
+
resultado +=
|
|
46311
|
+
this.adicionarIndentacao() +
|
|
46312
|
+
`@moduledoc "Classe estrangeira — implementação externa."\n`;
|
|
46074
46313
|
for (const metodo of declaracao.metodos) {
|
|
46075
46314
|
const params = metodo.funcao.parametros.map(() => 'term()').join(', ');
|
|
46076
46315
|
const retorno = this.mapearTipoParaTypespec(metodo.funcao.tipo);
|
|
46077
|
-
resultado +=
|
|
46316
|
+
resultado +=
|
|
46317
|
+
this.adicionarIndentacao() +
|
|
46318
|
+
`@callback ${metodo.simbolo.lexema}(${params}) :: ${retorno}\n`;
|
|
46078
46319
|
}
|
|
46079
46320
|
}
|
|
46080
46321
|
else {
|
|
@@ -48551,22 +48792,38 @@ class TradutorPortugolIpt {
|
|
|
48551
48792
|
// ── Operadores ───────────────────────────────────────────────────────────────
|
|
48552
48793
|
traduzirOperador(tipo) {
|
|
48553
48794
|
switch (tipo) {
|
|
48554
|
-
case portugol_ipt_1.default.ADICAO:
|
|
48555
|
-
|
|
48556
|
-
case portugol_ipt_1.default.
|
|
48557
|
-
|
|
48558
|
-
case portugol_ipt_1.default.
|
|
48559
|
-
|
|
48560
|
-
case portugol_ipt_1.default.
|
|
48561
|
-
|
|
48562
|
-
case portugol_ipt_1.default.
|
|
48563
|
-
|
|
48564
|
-
case portugol_ipt_1.default.
|
|
48565
|
-
|
|
48566
|
-
case portugol_ipt_1.default.
|
|
48567
|
-
|
|
48568
|
-
case portugol_ipt_1.default.
|
|
48569
|
-
|
|
48795
|
+
case portugol_ipt_1.default.ADICAO:
|
|
48796
|
+
return '+';
|
|
48797
|
+
case portugol_ipt_1.default.SUBTRACAO:
|
|
48798
|
+
return '-';
|
|
48799
|
+
case portugol_ipt_1.default.MULTIPLICACAO:
|
|
48800
|
+
return '*';
|
|
48801
|
+
case portugol_ipt_1.default.DIVISAO:
|
|
48802
|
+
return '/';
|
|
48803
|
+
case portugol_ipt_1.default.MODULO:
|
|
48804
|
+
return '%';
|
|
48805
|
+
case portugol_ipt_1.default.EXPONENCIACAO:
|
|
48806
|
+
return '**';
|
|
48807
|
+
case portugol_ipt_1.default.IGUAL:
|
|
48808
|
+
return '==';
|
|
48809
|
+
case portugol_ipt_1.default.DIFERENTE:
|
|
48810
|
+
return '!=';
|
|
48811
|
+
case portugol_ipt_1.default.MAIOR:
|
|
48812
|
+
return '>';
|
|
48813
|
+
case portugol_ipt_1.default.MAIOR_IGUAL:
|
|
48814
|
+
return '>=';
|
|
48815
|
+
case portugol_ipt_1.default.MENOR:
|
|
48816
|
+
return '<';
|
|
48817
|
+
case portugol_ipt_1.default.MENOR_IGUAL:
|
|
48818
|
+
return '<=';
|
|
48819
|
+
case portugol_ipt_1.default.E:
|
|
48820
|
+
return '&&';
|
|
48821
|
+
case portugol_ipt_1.default.OU:
|
|
48822
|
+
return '||';
|
|
48823
|
+
case portugol_ipt_1.default.XOU:
|
|
48824
|
+
return '^^';
|
|
48825
|
+
default:
|
|
48826
|
+
return tipo;
|
|
48570
48827
|
}
|
|
48571
48828
|
}
|
|
48572
48829
|
// ── Construtos ───────────────────────────────────────────────────────────────
|
|
@@ -48608,10 +48865,13 @@ class TradutorPortugolIpt {
|
|
|
48608
48865
|
traduzirConstrutoUnario(unario) {
|
|
48609
48866
|
const operando = this.traduzirConstruto(unario.operando);
|
|
48610
48867
|
switch (unario.operador.tipo) {
|
|
48611
|
-
case portugol_ipt_1.default.SUBTRACAO:
|
|
48868
|
+
case portugol_ipt_1.default.SUBTRACAO:
|
|
48869
|
+
return `-${operando}`;
|
|
48612
48870
|
case portugol_ipt_1.default.NEGACAO:
|
|
48613
|
-
case portugol_ipt_1.default.NAO:
|
|
48614
|
-
|
|
48871
|
+
case portugol_ipt_1.default.NAO:
|
|
48872
|
+
return `!(${operando})`;
|
|
48873
|
+
default:
|
|
48874
|
+
return `!(${operando})`;
|
|
48615
48875
|
}
|
|
48616
48876
|
}
|
|
48617
48877
|
traduzirConstrutoAtribuir(atribuir) {
|
|
@@ -48656,24 +48916,36 @@ class TradutorPortugolIpt {
|
|
|
48656
48916
|
}
|
|
48657
48917
|
tipoParaDelégua(tipo) {
|
|
48658
48918
|
switch (tipo) {
|
|
48659
|
-
case 'inteiro':
|
|
48660
|
-
|
|
48661
|
-
case '
|
|
48919
|
+
case 'inteiro':
|
|
48920
|
+
return 'inteiro';
|
|
48921
|
+
case 'texto':
|
|
48922
|
+
return 'texto';
|
|
48923
|
+
case 'real':
|
|
48924
|
+
return 'real';
|
|
48662
48925
|
case 'lógico':
|
|
48663
|
-
case 'logico':
|
|
48664
|
-
|
|
48665
|
-
|
|
48926
|
+
case 'logico':
|
|
48927
|
+
return 'logico';
|
|
48928
|
+
case 'caracter':
|
|
48929
|
+
return 'caracter';
|
|
48930
|
+
default:
|
|
48931
|
+
return tipo;
|
|
48666
48932
|
}
|
|
48667
48933
|
}
|
|
48668
48934
|
valorPadraoPorTipo(tipo) {
|
|
48669
48935
|
switch (tipo) {
|
|
48670
|
-
case 'inteiro':
|
|
48671
|
-
|
|
48672
|
-
case '
|
|
48936
|
+
case 'inteiro':
|
|
48937
|
+
return '0';
|
|
48938
|
+
case 'texto':
|
|
48939
|
+
return "''";
|
|
48940
|
+
case 'real':
|
|
48941
|
+
return '0.0';
|
|
48673
48942
|
case 'lógico':
|
|
48674
|
-
case 'logico':
|
|
48675
|
-
|
|
48676
|
-
|
|
48943
|
+
case 'logico':
|
|
48944
|
+
return 'falso';
|
|
48945
|
+
case 'caracter':
|
|
48946
|
+
return "' '";
|
|
48947
|
+
default:
|
|
48948
|
+
return 'nulo';
|
|
48677
48949
|
}
|
|
48678
48950
|
}
|
|
48679
48951
|
traduzirDeclaracaoVar(declaracaoVar) {
|
|
@@ -48766,9 +49038,7 @@ class TradutorPortugolIpt {
|
|
|
48766
49038
|
init = this.traduzirDeclaracao(ini);
|
|
48767
49039
|
}
|
|
48768
49040
|
}
|
|
48769
|
-
const cond = declaracaoPara.condicao
|
|
48770
|
-
? this.traduzirConstruto(declaracaoPara.condicao)
|
|
48771
|
-
: '';
|
|
49041
|
+
const cond = declaracaoPara.condicao ? this.traduzirConstruto(declaracaoPara.condicao) : '';
|
|
48772
49042
|
const incr = declaracaoPara.incrementar
|
|
48773
49043
|
? this.traduzirConstruto(declaracaoPara.incrementar)
|
|
48774
49044
|
: '';
|
|
@@ -48788,7 +49058,8 @@ class TradutorPortugolIpt {
|
|
|
48788
49058
|
this.indentacao += 4;
|
|
48789
49059
|
if (caminho.condicoes && caminho.condicoes.length > 0) {
|
|
48790
49060
|
for (const cond of caminho.condicoes) {
|
|
48791
|
-
resultado +=
|
|
49061
|
+
resultado +=
|
|
49062
|
+
' '.repeat(this.indentacao) + `caso ${this.traduzirConstruto(cond)}:\n`;
|
|
48792
49063
|
}
|
|
48793
49064
|
}
|
|
48794
49065
|
else {
|
|
@@ -49802,7 +50073,9 @@ class TradutorReversoCalango {
|
|
|
49802
50073
|
.map((parametro) => this.traduzirParametro(parametro))
|
|
49803
50074
|
.filter((p) => p)
|
|
49804
50075
|
.join(', ');
|
|
49805
|
-
const tipoRetorno = declaracaoFuncao.tipo &&
|
|
50076
|
+
const tipoRetorno = declaracaoFuncao.tipo &&
|
|
50077
|
+
declaracaoFuncao.tipo !== 'qualquer' &&
|
|
50078
|
+
declaracaoFuncao.tipo !== 'vazio'
|
|
49806
50079
|
? `: ${declaracaoFuncao.tipo}`
|
|
49807
50080
|
: '';
|
|
49808
50081
|
let resultado = `funcao ${declaracaoFuncao.simbolo.lexema}(${parametros})${tipoRetorno} `;
|
|
@@ -50330,10 +50603,16 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50330
50603
|
return node.text;
|
|
50331
50604
|
}
|
|
50332
50605
|
visitFile_input(ctx) {
|
|
50333
|
-
return ctx
|
|
50606
|
+
return ctx
|
|
50607
|
+
.stmt()
|
|
50608
|
+
.map((s) => this.visit(s))
|
|
50609
|
+
.join('\n');
|
|
50334
50610
|
}
|
|
50335
50611
|
visitSimple_stmt(ctx) {
|
|
50336
|
-
return ctx
|
|
50612
|
+
return ctx
|
|
50613
|
+
.small_stmt()
|
|
50614
|
+
.map((s) => this.visit(s))
|
|
50615
|
+
.join('; ');
|
|
50337
50616
|
}
|
|
50338
50617
|
visitExpr_stmt(ctx) {
|
|
50339
50618
|
const lhs = this.visit(ctx.testlist_star_expr());
|
|
@@ -50348,11 +50627,7 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50348
50627
|
const op = this.visitAugassign(ctx.augassign());
|
|
50349
50628
|
const testlist = ctx.testlist();
|
|
50350
50629
|
const yieldExpr = ctx.yield_expr();
|
|
50351
|
-
const rhs = testlist
|
|
50352
|
-
? this.visit(testlist)
|
|
50353
|
-
: yieldExpr
|
|
50354
|
-
? this.visit(yieldExpr)
|
|
50355
|
-
: '';
|
|
50630
|
+
const rhs = testlist ? this.visit(testlist) : yieldExpr ? this.visit(yieldExpr) : '';
|
|
50356
50631
|
return `${lhs} ${op} ${rhs}`;
|
|
50357
50632
|
}
|
|
50358
50633
|
return lhs;
|
|
@@ -50389,10 +50664,16 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50389
50664
|
return ctx.text;
|
|
50390
50665
|
}
|
|
50391
50666
|
visitTestlist_star_expr(ctx) {
|
|
50392
|
-
return ctx
|
|
50667
|
+
return ctx
|
|
50668
|
+
.test()
|
|
50669
|
+
.map((t) => this.visit(t))
|
|
50670
|
+
.join(', ');
|
|
50393
50671
|
}
|
|
50394
50672
|
visitTestlist(ctx) {
|
|
50395
|
-
return ctx
|
|
50673
|
+
return ctx
|
|
50674
|
+
.test()
|
|
50675
|
+
.map((t) => this.visit(t))
|
|
50676
|
+
.join(', ');
|
|
50396
50677
|
}
|
|
50397
50678
|
visitTest(ctx) {
|
|
50398
50679
|
const orTests = ctx.or_test();
|
|
@@ -50405,10 +50686,16 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50405
50686
|
return this.visitChildren(ctx);
|
|
50406
50687
|
}
|
|
50407
50688
|
visitOr_test(ctx) {
|
|
50408
|
-
return ctx
|
|
50689
|
+
return ctx
|
|
50690
|
+
.and_test()
|
|
50691
|
+
.map((t) => this.visit(t))
|
|
50692
|
+
.join(' ou ');
|
|
50409
50693
|
}
|
|
50410
50694
|
visitAnd_test(ctx) {
|
|
50411
|
-
return ctx
|
|
50695
|
+
return ctx
|
|
50696
|
+
.not_test()
|
|
50697
|
+
.map((t) => this.visit(t))
|
|
50698
|
+
.join(' e ');
|
|
50412
50699
|
}
|
|
50413
50700
|
visitNot_test(ctx) {
|
|
50414
50701
|
if (ctx.NOT()) {
|
|
@@ -50594,7 +50881,10 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50594
50881
|
return ctx.text;
|
|
50595
50882
|
}
|
|
50596
50883
|
visitArglist(ctx) {
|
|
50597
|
-
return ctx
|
|
50884
|
+
return ctx
|
|
50885
|
+
.argument()
|
|
50886
|
+
.map((a) => this.visit(a))
|
|
50887
|
+
.join(', ');
|
|
50598
50888
|
}
|
|
50599
50889
|
visitArgument(ctx) {
|
|
50600
50890
|
const testes = ctx.test();
|
|
@@ -50612,7 +50902,10 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50612
50902
|
if (compFor) {
|
|
50613
50903
|
return this.traduzirCompreensao(ctx.test(0), compFor);
|
|
50614
50904
|
}
|
|
50615
|
-
return ctx
|
|
50905
|
+
return ctx
|
|
50906
|
+
.test()
|
|
50907
|
+
.map((t) => this.visit(t))
|
|
50908
|
+
.join(', ');
|
|
50616
50909
|
}
|
|
50617
50910
|
traduzirCompreensao(exprCtx, compFor) {
|
|
50618
50911
|
const variavel = this.visit(compFor.exprlist());
|
|
@@ -50669,7 +50962,10 @@ class TradutorReversoPython extends AbstractParseTreeVisitor_1.AbstractParseTree
|
|
|
50669
50962
|
return tests.map((t) => this.visit(t)).join(', ');
|
|
50670
50963
|
}
|
|
50671
50964
|
visitSubscriptlist(ctx) {
|
|
50672
|
-
return ctx
|
|
50965
|
+
return ctx
|
|
50966
|
+
.subscript()
|
|
50967
|
+
.map((s) => this.visitSubscript(s))
|
|
50968
|
+
.join(', ');
|
|
50673
50969
|
}
|
|
50674
50970
|
visitSubscript(ctx) {
|
|
50675
50971
|
const tests = ctx.test();
|
|
@@ -53021,35 +53317,35 @@ class TradutorWebAssembly {
|
|
|
53021
53317
|
* Fornece os imports necessários (`delegua.escreva_texto`, `delegua.escreva_inteiro`).
|
|
53022
53318
|
*/
|
|
53023
53319
|
gerarArquivoHost() {
|
|
53024
|
-
return `// Gerado por Delégua -> WebAssembly
|
|
53025
|
-
// Uso: node delegua-host.mjs <arquivo.wasm>
|
|
53026
|
-
import { readFileSync } from 'fs';
|
|
53027
|
-
|
|
53028
|
-
const args = process.argv.slice(2);
|
|
53029
|
-
const wasmPath = args[0] ?? 'saida.wasm';
|
|
53030
|
-
|
|
53031
|
-
let memoryExport;
|
|
53032
|
-
|
|
53033
|
-
const importObject = {
|
|
53034
|
-
delegua: {
|
|
53035
|
-
/** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
|
|
53036
|
-
escreva_texto(ptr, len) {
|
|
53037
|
-
const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
|
|
53038
|
-
process.stdout.write(new TextDecoder('utf-8').decode(bytes));
|
|
53039
|
-
},
|
|
53040
|
-
/** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
|
|
53041
|
-
escreva_inteiro(valor) {
|
|
53042
|
-
process.stdout.write(String(valor));
|
|
53043
|
-
},
|
|
53044
|
-
}
|
|
53045
|
-
};
|
|
53046
|
-
|
|
53047
|
-
const wasmBuffer = readFileSync(wasmPath);
|
|
53048
|
-
const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
|
|
53049
|
-
memoryExport = instance.exports.memory;
|
|
53050
|
-
|
|
53051
|
-
const codigoSaida = Number(instance.exports.principal());
|
|
53052
|
-
process.exit(codigoSaida);
|
|
53320
|
+
return `// Gerado por Delégua -> WebAssembly
|
|
53321
|
+
// Uso: node delegua-host.mjs <arquivo.wasm>
|
|
53322
|
+
import { readFileSync } from 'fs';
|
|
53323
|
+
|
|
53324
|
+
const args = process.argv.slice(2);
|
|
53325
|
+
const wasmPath = args[0] ?? 'saida.wasm';
|
|
53326
|
+
|
|
53327
|
+
let memoryExport;
|
|
53328
|
+
|
|
53329
|
+
const importObject = {
|
|
53330
|
+
delegua: {
|
|
53331
|
+
/** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
|
|
53332
|
+
escreva_texto(ptr, len) {
|
|
53333
|
+
const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
|
|
53334
|
+
process.stdout.write(new TextDecoder('utf-8').decode(bytes));
|
|
53335
|
+
},
|
|
53336
|
+
/** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
|
|
53337
|
+
escreva_inteiro(valor) {
|
|
53338
|
+
process.stdout.write(String(valor));
|
|
53339
|
+
},
|
|
53340
|
+
}
|
|
53341
|
+
};
|
|
53342
|
+
|
|
53343
|
+
const wasmBuffer = readFileSync(wasmPath);
|
|
53344
|
+
const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
|
|
53345
|
+
memoryExport = instance.exports.memory;
|
|
53346
|
+
|
|
53347
|
+
const codigoSaida = Number(instance.exports.principal());
|
|
53348
|
+
process.exit(codigoSaida);
|
|
53053
53349
|
`;
|
|
53054
53350
|
}
|
|
53055
53351
|
}
|