@designliquido/delegua 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analisador-documentario/index.d.ts +1 -1
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +12 -2
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +10 -0
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts +25 -5
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js +301 -25
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +4 -10
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js +33 -2
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +3 -7
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/tenda/biblioteca-global.d.ts +3 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.d.ts.map +1 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.js +365 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.js.map +1 -0
- package/bin/package.json +1 -1
- package/construtos/vetor.d.ts.map +1 -1
- package/construtos/vetor.js.map +1 -1
- package/interfaces/documentario/documentario-analisado.d.ts +2 -2
- package/interfaces/documentario/index.d.ts +3 -3
- package/interpretador/depuracao/interpretador-com-depuracao.d.ts.map +1 -1
- package/interpretador/depuracao/interpretador-com-depuracao.js +8 -0
- package/interpretador/depuracao/interpretador-com-depuracao.js.map +1 -1
- package/interpretador/dialetos/calango/interpretador-calango.d.ts +2 -0
- package/interpretador/dialetos/calango/interpretador-calango.d.ts.map +1 -1
- package/interpretador/dialetos/calango/interpretador-calango.js +15 -0
- package/interpretador/dialetos/calango/interpretador-calango.js.map +1 -1
- package/interpretador/dialetos/index.d.ts +1 -0
- package/interpretador/dialetos/index.d.ts.map +1 -1
- package/interpretador/dialetos/index.js +1 -0
- package/interpretador/dialetos/index.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/dialetos/tenda/index.d.ts +2 -0
- package/interpretador/dialetos/tenda/index.d.ts.map +1 -0
- package/interpretador/dialetos/tenda/index.js +18 -0
- package/interpretador/dialetos/tenda/index.js.map +1 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.d.ts +13 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.d.ts.map +1 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.js +31 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.js.map +1 -0
- package/interpretador/interpretador.d.ts +2 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +24 -1
- package/interpretador/interpretador.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js +3 -0
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/lexador/dialetos/lexador-calango.d.ts +1 -0
- package/lexador/dialetos/lexador-calango.d.ts.map +1 -1
- package/lexador/dialetos/lexador-calango.js +77 -0
- package/lexador/dialetos/lexador-calango.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js +2 -4
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/dialetos/palavras-reservadas/calango.d.ts +31 -4
- package/lexador/dialetos/palavras-reservadas/calango.d.ts.map +1 -1
- package/lexador/dialetos/palavras-reservadas/calango.js +31 -4
- package/lexador/dialetos/palavras-reservadas/calango.js.map +1 -1
- package/package.json +1 -1
- package/tipos-de-simbolos/calango.d.ts +28 -0
- package/tipos-de-simbolos/calango.d.ts.map +1 -1
- package/tipos-de-simbolos/calango.js +28 -0
- package/tipos-de-simbolos/calango.js.map +1 -1
- package/tradutores/tradutor-assembly-risc-v.d.ts.map +1 -1
- package/tradutores/tradutor-assembly-risc-v.js +85 -85
- package/tradutores/tradutor-assembly-risc-v.js.map +1 -1
- package/tradutores/tradutor-assemblyscript.js +1 -1
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-webassembly.d.ts.map +1 -1
- package/tradutores/tradutor-webassembly.js +52 -46
- package/tradutores/tradutor-webassembly.js.map +1 -1
- package/umd/delegua.js +365 -162
package/umd/delegua.js
CHANGED
|
@@ -762,7 +762,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
762
762
|
switch (condicao.constructor) {
|
|
763
763
|
case construtos_1.Literal:
|
|
764
764
|
const condicaoLiteral = condicao;
|
|
765
|
-
|
|
765
|
+
const tiposNumericos = ['inteiro', 'número', 'real'];
|
|
766
|
+
const ambosSaoNumericos = tiposNumericos.includes(condicaoLiteral.tipo) &&
|
|
767
|
+
tiposNumericos.includes(tipo);
|
|
768
|
+
if (condicaoLiteral.tipo !== tipo && !ambosSaoNumericos) {
|
|
766
769
|
this.erro({
|
|
767
770
|
lexema: condicaoLiteral.valor,
|
|
768
771
|
tipo: condicaoLiteral.tipo,
|
|
@@ -881,7 +884,14 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
881
884
|
this.verificarOperadorBinario(binario.direita);
|
|
882
885
|
}
|
|
883
886
|
const operadoresMatematicos = ['ADICAO', 'SUBTRACAO', 'MULTIPLICACAO', 'DIVISAO', 'MODULO'];
|
|
884
|
-
const operadoresComparacao = [
|
|
887
|
+
const operadoresComparacao = [
|
|
888
|
+
'MAIOR',
|
|
889
|
+
'MAIOR_IGUAL',
|
|
890
|
+
'MENOR',
|
|
891
|
+
'MENOR_IGUAL',
|
|
892
|
+
'IGUAL',
|
|
893
|
+
'DIFERENTE',
|
|
894
|
+
];
|
|
885
895
|
if (operadoresMatematicos.includes(binario.operador.tipo)) {
|
|
886
896
|
this.verificarTiposOperandos(binario);
|
|
887
897
|
}
|
|
@@ -2679,6 +2689,16 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2679
2689
|
}
|
|
2680
2690
|
if (entidadeChamada.constructor === construtos_1.Variavel) {
|
|
2681
2691
|
const entidadeChamadaResolvidaVariavel = entidadeChamada;
|
|
2692
|
+
const informacoesFuncaoBibliotecaGlobal = this.pilhaEscopos.obterBibliotecaGlobal(entidadeChamadaResolvidaVariavel.simbolo.lexema);
|
|
2693
|
+
if (informacoesFuncaoBibliotecaGlobal &&
|
|
2694
|
+
Array.isArray(informacoesFuncaoBibliotecaGlobal.subElementos) &&
|
|
2695
|
+
informacoesFuncaoBibliotecaGlobal.subElementos.length > 0) {
|
|
2696
|
+
const erros = this.validarArgumentosEntidadeChamada(informacoesFuncaoBibliotecaGlobal.subElementos, argumentos);
|
|
2697
|
+
if (erros.length > 0) {
|
|
2698
|
+
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamadaResolvidaVariavel.simbolo, `Erros ao resolver argumentos de chamada a ${entidadeChamadaResolvidaVariavel.simbolo.lexema}: \n${erros.reduce((mensagem, erro) => (mensagem += `${erro}\n`), '')}`);
|
|
2699
|
+
}
|
|
2700
|
+
return entidadeChamadaResolvidaVariavel;
|
|
2701
|
+
}
|
|
2682
2702
|
if (tipoPrimitiva === 'qualquer') {
|
|
2683
2703
|
// Provavelmente uma chamada a alguma função da biblioteca global.
|
|
2684
2704
|
// Até então, é sempre do tipo `InformacaoElementoSintatico`.
|
|
@@ -6264,7 +6284,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6264
6284
|
while (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SE)) {
|
|
6265
6285
|
const operador = this.simbolos[this.atual - 1];
|
|
6266
6286
|
const expressaoOuCondicao = await this.seTernario();
|
|
6267
|
-
this.consumir(pitugues_2.default.SENAO, `Esperado 'senão' ou 'senao' após caminho positivo em se ternário. Atual:
|
|
6287
|
+
this.consumir(pitugues_2.default.SENAO, `Esperado 'senão' ou 'senao' após caminho positivo em se ternário. Atual:
|
|
6268
6288
|
${this.simbolos[this.atual].lexema}.`);
|
|
6269
6289
|
const expressaoSenao = await this.seTernario();
|
|
6270
6290
|
expressaoEntao = new construtos_1.SeTernario(this.hashArquivo, expressaoOuCondicao, expressaoEntao, operador, expressaoSenao);
|
|
@@ -6373,12 +6393,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
6373
6393
|
}
|
|
6374
6394
|
else {
|
|
6375
6395
|
// Bloco de múltiplas linhas baseado em indentação
|
|
6376
|
-
let espacosAtual = this
|
|
6377
|
-
|
|
6378
|
-
.espacosIndentacao;
|
|
6379
|
-
const espacosAnterior = this
|
|
6380
|
-
.localizacoes[simboloAnterior.linha]
|
|
6381
|
-
.espacosIndentacao;
|
|
6396
|
+
let espacosAtual = this.localizacoes[simboloAtual.linha].espacosIndentacao;
|
|
6397
|
+
const espacosAnterior = this.localizacoes[simboloAnterior.linha].espacosIndentacao;
|
|
6382
6398
|
if (espacosAtual <= espacosAnterior) {
|
|
6383
6399
|
throw this.erro(simboloAtual, `Indentação inconsistente na linha ${simboloAtual.linha}. ` +
|
|
6384
6400
|
`Esperado: >= ${espacosAnterior}. ` +
|
|
@@ -6392,9 +6408,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6392
6408
|
declaracoes = declaracoes.concat(retorno);
|
|
6393
6409
|
simboloAtual = this.simboloAtual();
|
|
6394
6410
|
if (simboloAtual) {
|
|
6395
|
-
espacosAtual = this
|
|
6396
|
-
.localizacoes[simboloAtual.linha]
|
|
6397
|
-
.espacosIndentacao;
|
|
6411
|
+
espacosAtual = this.localizacoes[simboloAtual.linha].espacosIndentacao;
|
|
6398
6412
|
}
|
|
6399
6413
|
}
|
|
6400
6414
|
}
|
|
@@ -8313,6 +8327,16 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8313
8327
|
this.avancarEDevolverAnterior();
|
|
8314
8328
|
return new construtos_1.ExpressaoRegular(this.hashArquivo, simboloAtual, valor);
|
|
8315
8329
|
}
|
|
8330
|
+
case tenda_1.default.BIBLIOTECA_GLOBAL: {
|
|
8331
|
+
const simboloBiblioteca = this.avancarEDevolverAnterior();
|
|
8332
|
+
return new construtos_1.Variavel(this.hashArquivo, simboloBiblioteca, 'qualquer');
|
|
8333
|
+
}
|
|
8334
|
+
case tenda_1.default.INFINITO:
|
|
8335
|
+
this.avancarEDevolverAnterior();
|
|
8336
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), Infinity, 'número');
|
|
8337
|
+
case tenda_1.default.NAN:
|
|
8338
|
+
this.avancarEDevolverAnterior();
|
|
8339
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), NaN, 'número');
|
|
8316
8340
|
case tenda_1.default.FALSO:
|
|
8317
8341
|
this.avancarEDevolverAnterior();
|
|
8318
8342
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), false, 'lógico');
|
|
@@ -8371,6 +8395,7 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8371
8395
|
throw this.erro(this.simbolos[this.atual], 'Esperado expressão.');
|
|
8372
8396
|
}
|
|
8373
8397
|
async chamar() {
|
|
8398
|
+
var _a;
|
|
8374
8399
|
let expressao = await this.primario();
|
|
8375
8400
|
while (true) {
|
|
8376
8401
|
let tipoPrimitiva = undefined;
|
|
@@ -8378,7 +8403,21 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8378
8403
|
expressao = await this.finalizarChamada(expressao, tipoPrimitiva);
|
|
8379
8404
|
}
|
|
8380
8405
|
else if (this.verificarSeSimboloAtualEIgualA(tenda_1.default.PONTO)) {
|
|
8381
|
-
|
|
8406
|
+
// Alguns tokens de biblioteca global são palavras reservadas (ex: `exiba`, `leia`, `entrada`),
|
|
8407
|
+
// mas precisam ser aceitos como nomes de métodos após o ponto.
|
|
8408
|
+
const tiposAceitosComoNomeDeMetodo = [
|
|
8409
|
+
tenda_1.default.IDENTIFICADOR,
|
|
8410
|
+
tenda_1.default.EXIBA,
|
|
8411
|
+
tenda_1.default.LEIA,
|
|
8412
|
+
tenda_1.default.ENTRADA,
|
|
8413
|
+
];
|
|
8414
|
+
let nome;
|
|
8415
|
+
if (tiposAceitosComoNomeDeMetodo.includes((_a = this.simbolos[this.atual]) === null || _a === void 0 ? void 0 : _a.tipo)) {
|
|
8416
|
+
nome = this.avancarEDevolverAnterior();
|
|
8417
|
+
}
|
|
8418
|
+
else {
|
|
8419
|
+
nome = this.consumir(tenda_1.default.IDENTIFICADOR, "Esperado nome de método ou propriedade após '.'.");
|
|
8420
|
+
}
|
|
8382
8421
|
tipoPrimitiva = expressao.tipo;
|
|
8383
8422
|
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
8384
8423
|
}
|
|
@@ -8919,7 +8958,9 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8919
8958
|
if (this.primitivasConhecidas.hasOwnProperty(entidadeChamadaAcessoMetodoOuPropriedade.simbolo.lexema)) {
|
|
8920
8959
|
return this.primitivasConhecidas[entidadeChamadaAcessoMetodoOuPropriedade.simbolo.lexema].tipo;
|
|
8921
8960
|
}
|
|
8922
|
-
|
|
8961
|
+
// Para métodos de namespaces da biblioteca global (Lista, Matemática, etc.),
|
|
8962
|
+
// o tipo não é conhecido estaticamente. Retorna 'qualquer'.
|
|
8963
|
+
return 'qualquer';
|
|
8923
8964
|
case construtos_1.AcessoPropriedade:
|
|
8924
8965
|
const entidadeChamadaAcessoPropriedade = entidadeChamadaChamada;
|
|
8925
8966
|
return entidadeChamadaAcessoPropriedade.tipoRetornoPropriedade;
|
|
@@ -9067,6 +9108,10 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
9067
9108
|
inicializarPilhaEscopos() {
|
|
9068
9109
|
this.pilhaEscopos = new pilha_escopos_1.PilhaEscopos();
|
|
9069
9110
|
this.pilhaEscopos.empilhar(new informacao_escopo_1.InformacaoEscopo());
|
|
9111
|
+
// Registrar namespaces da biblioteca global de Tenda.
|
|
9112
|
+
for (const nomeBiblioteca of ['Data', 'Lista', 'Matemática', 'Saída', 'Texto']) {
|
|
9113
|
+
this.pilhaEscopos.definirInformacoesVariavel(nomeBiblioteca, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(nomeBiblioteca, 'qualquer'));
|
|
9114
|
+
}
|
|
9070
9115
|
// TODO: Escrever algum tipo de validação aqui.
|
|
9071
9116
|
for (const tipos of Object.values(this.tiposDeFerramentasExternas)) {
|
|
9072
9117
|
for (const [nomeTipo, tipo] of Object.entries(tipos)) {
|
|
@@ -10065,15 +10110,13 @@ async function aleatorio(interpretador) {
|
|
|
10065
10110
|
* @returns {Promise<number>} Um número real entre os valores máximo e mínimo especificados.
|
|
10066
10111
|
*/
|
|
10067
10112
|
async function aleatorioEntre(interpretador, minimo, maximo) {
|
|
10068
|
-
if (arguments.length <=
|
|
10113
|
+
if (arguments.length <= 1) {
|
|
10069
10114
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10070
10115
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
10071
10116
|
linha: interpretador.linhaDeclaracaoAtual,
|
|
10072
10117
|
}, 'A função recebe ao menos um parâmetro.'));
|
|
10073
10118
|
}
|
|
10074
|
-
const valorMinimo =
|
|
10075
|
-
? minimo.valor
|
|
10076
|
-
: minimo;
|
|
10119
|
+
const valorMinimo = interpretador.resolverValor(minimo);
|
|
10077
10120
|
if (arguments.length === 2) {
|
|
10078
10121
|
if (typeof valorMinimo !== 'number') {
|
|
10079
10122
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
@@ -10089,9 +10132,7 @@ async function aleatorioEntre(interpretador, minimo, maximo) {
|
|
|
10089
10132
|
linha: interpretador.linhaDeclaracaoAtual,
|
|
10090
10133
|
}, 'A quantidade de parâmetros máxima para esta função é 2.'));
|
|
10091
10134
|
}
|
|
10092
|
-
const valorMaximo =
|
|
10093
|
-
? maximo.valor
|
|
10094
|
-
: maximo;
|
|
10135
|
+
const valorMaximo = interpretador.resolverValor(maximo);
|
|
10095
10136
|
if (typeof valorMinimo !== 'number' || typeof valorMaximo !== 'number') {
|
|
10096
10137
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10097
10138
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
@@ -21087,6 +21128,27 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21087
21128
|
pontoInicializacaoBibliotecasGlobais() {
|
|
21088
21129
|
(0, comum_1.carregarBibliotecasGlobais)(this.pilhaEscoposExecucao);
|
|
21089
21130
|
}
|
|
21131
|
+
async avaliarArgumentosEscreva(argumentos) {
|
|
21132
|
+
if (this.constructor !== Interpretador) {
|
|
21133
|
+
return await super.avaliarArgumentosEscreva(argumentos);
|
|
21134
|
+
}
|
|
21135
|
+
let formatoTexto = '';
|
|
21136
|
+
for (const argumento of argumentos) {
|
|
21137
|
+
let resultadoAvaliacao = await this.avaliar(argumento);
|
|
21138
|
+
if (resultadoAvaliacao &&
|
|
21139
|
+
resultadoAvaliacao.hasOwnProperty &&
|
|
21140
|
+
resultadoAvaliacao.hasOwnProperty('valorRetornado')) {
|
|
21141
|
+
resultadoAvaliacao = resultadoAvaliacao.valorRetornado;
|
|
21142
|
+
}
|
|
21143
|
+
if (argumento instanceof construtos_1.Atribuir || argumento instanceof construtos_1.AtribuicaoPorIndice) {
|
|
21144
|
+
formatoTexto += `${argumento.paraTexto()} `;
|
|
21145
|
+
continue;
|
|
21146
|
+
}
|
|
21147
|
+
const valor = this.resolverValor(resultadoAvaliacao);
|
|
21148
|
+
formatoTexto += `${this.paraTexto(valor)} `;
|
|
21149
|
+
}
|
|
21150
|
+
return formatoTexto.trimEnd();
|
|
21151
|
+
}
|
|
21090
21152
|
resolverReferenciaMontao(referenciaMontao) {
|
|
21091
21153
|
const valorMontao = this.montao.obterReferencia(this.hashArquivoDeclaracaoAtual, this.linhaDeclaracaoAtual, referenciaMontao.endereco);
|
|
21092
21154
|
return valorMontao;
|
|
@@ -21248,7 +21310,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21248
21310
|
const nomeDecorador = decorador.nome.slice(1);
|
|
21249
21311
|
const variavelDecoradora = this.pilhaEscoposExecucao.obterVariavelPorNome(nomeDecorador);
|
|
21250
21312
|
const funcaoDecoradora = variavelDecoradora.valor;
|
|
21251
|
-
const resultado = await funcaoDecoradora.chamar(this, [
|
|
21313
|
+
const resultado = await funcaoDecoradora.chamar(this, [
|
|
21314
|
+
{ nome: null, valor: funcao },
|
|
21315
|
+
]);
|
|
21252
21316
|
funcao = this.resolverValorRecursivo(resultado);
|
|
21253
21317
|
}
|
|
21254
21318
|
}
|
|
@@ -22363,6 +22427,7 @@ const lexador_1 = require("../lexador");
|
|
|
22363
22427
|
const inferenciador_1 = require("../inferenciador");
|
|
22364
22428
|
const delegua_1 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
22365
22429
|
const tiposNumericos = ['inteiro', 'número', 'numero', 'real', 'longo'];
|
|
22430
|
+
const tiposLogicos = ['logico', 'lógico'];
|
|
22366
22431
|
class PilhaEscoposExecucao {
|
|
22367
22432
|
constructor() {
|
|
22368
22433
|
this.pilha = [];
|
|
@@ -22394,6 +22459,8 @@ class PilhaEscoposExecucao {
|
|
|
22394
22459
|
return true;
|
|
22395
22460
|
if (tiposNumericos.includes(tipoVariavel) && tiposNumericos.includes(tipoValor))
|
|
22396
22461
|
return true;
|
|
22462
|
+
if (tiposLogicos.includes(tipoVariavel) && tiposLogicos.includes(tipoValor))
|
|
22463
|
+
return true;
|
|
22397
22464
|
return false;
|
|
22398
22465
|
}
|
|
22399
22466
|
converterValor(tipo, valor) {
|
|
@@ -22808,6 +22875,24 @@ class LexadorCalango {
|
|
|
22808
22875
|
const textoCompleto = this.codigo[this.linha].substring(this.inicioSimbolo + 1, this.atual);
|
|
22809
22876
|
this.simbolos.push(new simbolo_1.Simbolo(calango_2.default.TEXTO, textoCompleto, textoCompleto, linhaPrimeiroCaracter + 1, this.hashArquivo));
|
|
22810
22877
|
}
|
|
22878
|
+
analisarCaracter() {
|
|
22879
|
+
const linhaPrimeiroCaracter = this.linha;
|
|
22880
|
+
// Restringe leitura à linha atual (como analisarNumero), evitando
|
|
22881
|
+
// que avancar() mude this.linha e corrompa o cálculo do substring.
|
|
22882
|
+
while (this.simboloAtual() !== "'" && this.linha === linhaPrimeiroCaracter && !this.eFinalDoCodigo()) {
|
|
22883
|
+
this.avancar();
|
|
22884
|
+
}
|
|
22885
|
+
if (this.linha !== linhaPrimeiroCaracter || this.eFinalDoCodigo()) {
|
|
22886
|
+
this.erros.push({
|
|
22887
|
+
linha: linhaPrimeiroCaracter + 1,
|
|
22888
|
+
caractere: this.simboloAnterior(),
|
|
22889
|
+
mensagem: 'Caractere não finalizado.',
|
|
22890
|
+
});
|
|
22891
|
+
return;
|
|
22892
|
+
}
|
|
22893
|
+
const valorCaracter = this.codigo[linhaPrimeiroCaracter].substring(this.inicioSimbolo + 1, this.atual);
|
|
22894
|
+
this.simbolos.push(new simbolo_1.Simbolo(calango_2.default.LITERAL_CARACTER, valorCaracter, valorCaracter, linhaPrimeiroCaracter + 1, this.hashArquivo));
|
|
22895
|
+
}
|
|
22811
22896
|
analisarNumero() {
|
|
22812
22897
|
const linhaPrimeiroDigito = this.linha;
|
|
22813
22898
|
while (this.eDigito(this.simboloAtual()) && this.linha === linhaPrimeiroDigito) {
|
|
@@ -22870,6 +22955,23 @@ class LexadorCalango {
|
|
|
22870
22955
|
this.analisarTexto('"');
|
|
22871
22956
|
this.avancar();
|
|
22872
22957
|
break;
|
|
22958
|
+
case "'":
|
|
22959
|
+
this.avancar();
|
|
22960
|
+
this.analisarCaracter();
|
|
22961
|
+
this.avancar();
|
|
22962
|
+
break;
|
|
22963
|
+
case ':':
|
|
22964
|
+
this.adicionarSimbolo(calango_2.default.DOIS_PONTOS);
|
|
22965
|
+
this.avancar();
|
|
22966
|
+
break;
|
|
22967
|
+
case '[':
|
|
22968
|
+
this.adicionarSimbolo(calango_2.default.COLCHETE_ESQUERDO);
|
|
22969
|
+
this.avancar();
|
|
22970
|
+
break;
|
|
22971
|
+
case ']':
|
|
22972
|
+
this.adicionarSimbolo(calango_2.default.COLCHETE_DIREITO);
|
|
22973
|
+
this.avancar();
|
|
22974
|
+
break;
|
|
22873
22975
|
case '(':
|
|
22874
22976
|
this.adicionarSimbolo(calango_2.default.PARENTESE_ESQUERDO);
|
|
22875
22977
|
this.avancar();
|
|
@@ -22878,6 +22980,36 @@ class LexadorCalango {
|
|
|
22878
22980
|
this.adicionarSimbolo(calango_2.default.PARENTESE_DIREITO);
|
|
22879
22981
|
this.avancar();
|
|
22880
22982
|
break;
|
|
22983
|
+
case ',':
|
|
22984
|
+
this.adicionarSimbolo(calango_2.default.VIRGULA);
|
|
22985
|
+
this.avancar();
|
|
22986
|
+
break;
|
|
22987
|
+
case '+':
|
|
22988
|
+
this.adicionarSimbolo(calango_2.default.ADICAO);
|
|
22989
|
+
this.avancar();
|
|
22990
|
+
break;
|
|
22991
|
+
case '-':
|
|
22992
|
+
this.adicionarSimbolo(calango_2.default.SUBTRACAO);
|
|
22993
|
+
this.avancar();
|
|
22994
|
+
break;
|
|
22995
|
+
case '*':
|
|
22996
|
+
this.adicionarSimbolo(calango_2.default.MULTIPLICACAO);
|
|
22997
|
+
this.avancar();
|
|
22998
|
+
break;
|
|
22999
|
+
case '/':
|
|
23000
|
+
if (this.proximoSimbolo() === '/') {
|
|
23001
|
+
// Comentário de linha: consumir até ao fim da linha sem emitir símbolo.
|
|
23002
|
+
// Guardamos o número da linha para parar quando avancar() mudar para a próxima.
|
|
23003
|
+
const linhaComentario = this.linha;
|
|
23004
|
+
while (this.linha === linhaComentario && !this.eFinalDoCodigo()) {
|
|
23005
|
+
this.avancar();
|
|
23006
|
+
}
|
|
23007
|
+
}
|
|
23008
|
+
else {
|
|
23009
|
+
this.adicionarSimbolo(calango_2.default.DIVISAO);
|
|
23010
|
+
this.avancar();
|
|
23011
|
+
}
|
|
23012
|
+
break;
|
|
22881
23013
|
case '=':
|
|
22882
23014
|
this.adicionarSimbolo(calango_2.default.IGUAL_ATRIBUICAO);
|
|
22883
23015
|
this.avancar();
|
|
@@ -22898,10 +23030,22 @@ class LexadorCalango {
|
|
|
22898
23030
|
this.adicionarSimbolo(calango_2.default.MENOR_IGUAL, '<=');
|
|
22899
23031
|
this.avancar();
|
|
22900
23032
|
}
|
|
23033
|
+
else if (this.simboloAtual() === '>') {
|
|
23034
|
+
this.adicionarSimbolo(calango_2.default.DIFERENTE, '<>');
|
|
23035
|
+
this.avancar();
|
|
23036
|
+
}
|
|
22901
23037
|
else {
|
|
22902
23038
|
this.adicionarSimbolo(calango_2.default.MENOR);
|
|
22903
23039
|
}
|
|
22904
23040
|
break;
|
|
23041
|
+
case '%':
|
|
23042
|
+
this.adicionarSimbolo(calango_2.default.MODULO);
|
|
23043
|
+
this.avancar();
|
|
23044
|
+
break;
|
|
23045
|
+
case '^':
|
|
23046
|
+
this.adicionarSimbolo(calango_2.default.EXPONENCIACAO);
|
|
23047
|
+
this.avancar();
|
|
23048
|
+
break;
|
|
22905
23049
|
default:
|
|
22906
23050
|
if (this.eDigito(caractere))
|
|
22907
23051
|
this.analisarNumero();
|
|
@@ -23555,15 +23699,13 @@ class LexadorPitugues {
|
|
|
23555
23699
|
}
|
|
23556
23700
|
analisarNumero() {
|
|
23557
23701
|
const linhaInicial = this.linha;
|
|
23558
|
-
while (this.linha === linhaInicial &&
|
|
23559
|
-
this.eDigito(this.simboloAtual()))
|
|
23702
|
+
while (this.linha === linhaInicial && this.eDigito(this.simboloAtual()))
|
|
23560
23703
|
this.avancar();
|
|
23561
23704
|
const temPonto = this.simboloAtual() === '.';
|
|
23562
23705
|
const proximoEhDigito = this.eDigito(this.proximoSimbolo());
|
|
23563
23706
|
if (this.linha === linhaInicial && temPonto && proximoEhDigito) {
|
|
23564
23707
|
this.avancar();
|
|
23565
|
-
while (this.linha === linhaInicial &&
|
|
23566
|
-
this.eDigito(this.simboloAtual()))
|
|
23708
|
+
while (this.linha === linhaInicial && this.eDigito(this.simboloAtual()))
|
|
23567
23709
|
this.avancar();
|
|
23568
23710
|
}
|
|
23569
23711
|
let numeroCompleto;
|
|
@@ -24919,16 +25061,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24919
25061
|
const calango_1 = __importDefault(require("../../../tipos-de-simbolos/calango"));
|
|
24920
25062
|
exports.default = {
|
|
24921
25063
|
algoritmo: calango_1.default.ALGORITMO,
|
|
24922
|
-
|
|
24923
|
-
|
|
25064
|
+
ate: calango_1.default.ATE,
|
|
25065
|
+
caracter: calango_1.default.CARACTER,
|
|
25066
|
+
caso: calango_1.default.CASO,
|
|
25067
|
+
de: calango_1.default.DE,
|
|
25068
|
+
div: calango_1.default.DIVISAO_INTEIRA,
|
|
25069
|
+
escolha: calango_1.default.ESCOLHA,
|
|
25070
|
+
enquanto: calango_1.default.ENQUANTO,
|
|
25071
|
+
entao: calango_1.default.ENTAO,
|
|
24924
25072
|
escreva: calango_1.default.ESCREVA,
|
|
24925
25073
|
escreval: calango_1.default.ESCREVAL,
|
|
25074
|
+
faca: calango_1.default.FACA,
|
|
25075
|
+
falso: calango_1.default.FALSO,
|
|
25076
|
+
fimEnquanto: calango_1.default.FIM_ENQUANTO,
|
|
25077
|
+
fimEscolha: calango_1.default.FIM_ESCOLHA,
|
|
25078
|
+
fimFuncao: calango_1.default.FIM_FUNCAO,
|
|
25079
|
+
fimPara: calango_1.default.FIM_PARA,
|
|
25080
|
+
fimProcedimento: calango_1.default.FIM_PROCEDIMENTO,
|
|
25081
|
+
fimPrincipal: calango_1.default.FIM_PRINCIPAL,
|
|
25082
|
+
fimSe: calango_1.default.FIM_SE,
|
|
25083
|
+
outroCaso: calango_1.default.OUTRO_CASO,
|
|
25084
|
+
procedimento: calango_1.default.PROCEDIMENTO,
|
|
24926
25085
|
inteiro: calango_1.default.INTEIRO,
|
|
25086
|
+
funcao: calango_1.default.FUNCAO,
|
|
25087
|
+
interrompa: calango_1.default.INTERROMPA,
|
|
24927
25088
|
leia: calango_1.default.LEIA,
|
|
25089
|
+
logico: calango_1.default.LOGICO,
|
|
25090
|
+
mod: calango_1.default.MODULO,
|
|
25091
|
+
nao: calango_1.default.NEGACAO,
|
|
25092
|
+
para: calango_1.default.PARA,
|
|
25093
|
+
passo: calango_1.default.PASSO,
|
|
25094
|
+
principal: calango_1.default.PRINCIPAL,
|
|
25095
|
+
real: calango_1.default.REAL,
|
|
25096
|
+
retorna: calango_1.default.RETORNA,
|
|
24928
25097
|
se: calango_1.default.SE,
|
|
24929
|
-
entao: calango_1.default.ENTAO,
|
|
24930
25098
|
senao: calango_1.default.SENAO,
|
|
24931
|
-
|
|
25099
|
+
texto: calango_1.default.TIPO_TEXTO,
|
|
25100
|
+
verdadeiro: calango_1.default.VERDADEIRO,
|
|
24932
25101
|
};
|
|
24933
25102
|
|
|
24934
25103
|
},{"../../../tipos-de-simbolos/calango":220}],201:[function(require,module,exports){
|
|
@@ -26901,14 +27070,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26901
27070
|
exports.default = {
|
|
26902
27071
|
ADICAO: 'ADICAO',
|
|
26903
27072
|
ALGORITMO: 'ALGORITMO',
|
|
27073
|
+
CARACTER: 'CARACTER',
|
|
26904
27074
|
DIFERENTE: 'DIFERENTE',
|
|
26905
27075
|
DIVISAO: 'DIVISAO',
|
|
26906
27076
|
DIVISAO_INTEIRA: 'DIVISAO_INTEIRA',
|
|
26907
27077
|
E: 'E',
|
|
27078
|
+
ENQUANTO: 'ENQUANTO',
|
|
26908
27079
|
ENTAO: 'ENTAO',
|
|
26909
27080
|
ESCREVA: 'ESCREVA',
|
|
26910
27081
|
ESCREVAL: 'ESCREVAL',
|
|
26911
27082
|
EXPONENCIACAO: 'EXPONENCIACAO',
|
|
27083
|
+
FACA: 'FACA',
|
|
27084
|
+
FALSO: 'FALSO',
|
|
27085
|
+
ATE: 'ATE',
|
|
27086
|
+
CASO: 'CASO',
|
|
27087
|
+
COLCHETE_DIREITO: 'COLCHETE_DIREITO',
|
|
27088
|
+
COLCHETE_ESQUERDO: 'COLCHETE_ESQUERDO',
|
|
27089
|
+
DE: 'DE',
|
|
27090
|
+
DOIS_PONTOS: 'DOIS_PONTOS',
|
|
27091
|
+
ESCOLHA: 'ESCOLHA',
|
|
27092
|
+
FIM_ESCOLHA: 'FIM_ESCOLHA',
|
|
27093
|
+
FIM_FUNCAO: 'FIM_FUNCAO',
|
|
27094
|
+
FIM_PROCEDIMENTO: 'FIM_PROCEDIMENTO',
|
|
27095
|
+
FUNCAO: 'FUNCAO',
|
|
27096
|
+
FIM_ENQUANTO: 'FIM_ENQUANTO',
|
|
27097
|
+
FIM_PARA: 'FIM_PARA',
|
|
26912
27098
|
FIM_PRINCIPAL: 'FIM_PRINCIPAL',
|
|
26913
27099
|
FIM_SE: 'FIM_SE',
|
|
26914
27100
|
IDENTIFICADOR: 'IDENTIFICADOR',
|
|
@@ -26916,7 +27102,10 @@ exports.default = {
|
|
|
26916
27102
|
IGUAL_ATRIBUICAO: 'IGUAL_ATRIBUICAO',
|
|
26917
27103
|
IGUAL_IGUAL: 'IGUAL_IGUAL',
|
|
26918
27104
|
INTEIRO: 'INTEIRO',
|
|
27105
|
+
INTERROMPA: 'INTERROMPA',
|
|
26919
27106
|
LEIA: 'LEIA',
|
|
27107
|
+
LITERAL_CARACTER: 'LITERAL_CARACTER',
|
|
27108
|
+
LOGICO: 'LOGICO',
|
|
26920
27109
|
MAIOR: 'MAIOR',
|
|
26921
27110
|
MAIOR_IGUAL: 'MAIOR_IGUAL',
|
|
26922
27111
|
MENOR: 'MENOR',
|
|
@@ -26929,13 +27118,21 @@ exports.default = {
|
|
|
26929
27118
|
PARENTESE_DIREITO: 'PARENTESE_DIREITO',
|
|
26930
27119
|
PARENTESE_ESQUERDO: 'PARENTESE_ESQUERDO',
|
|
26931
27120
|
PRINCIPAL: 'PRINCIPAL',
|
|
27121
|
+
OUTRO_CASO: 'OUTRO_CASO',
|
|
27122
|
+
PARA: 'PARA',
|
|
27123
|
+
PROCEDIMENTO: 'PROCEDIMENTO',
|
|
27124
|
+
PASSO: 'PASSO',
|
|
26932
27125
|
PONTO: 'PONTO',
|
|
26933
27126
|
PONTO_E_VIRGULA: 'PONTO_E_VIRGULA',
|
|
26934
27127
|
QUEBRA_LINHA: 'QUEBRA_LINHA',
|
|
27128
|
+
REAL: 'REAL',
|
|
27129
|
+
RETORNA: 'RETORNA',
|
|
26935
27130
|
SE: 'SE',
|
|
26936
27131
|
SENAO: 'SENAO',
|
|
26937
27132
|
SUBTRACAO: 'SUBTRACAO',
|
|
26938
27133
|
TEXTO: 'TEXTO',
|
|
27134
|
+
TIPO_TEXTO: 'TIPO_TEXTO',
|
|
27135
|
+
VERDADEIRO: 'VERDADEIRO',
|
|
26939
27136
|
VIRGULA: 'VIRGULA',
|
|
26940
27137
|
};
|
|
26941
27138
|
|
|
@@ -40965,10 +41162,10 @@ class TradutorAssemblyRISCV {
|
|
|
40965
41162
|
Var: this.traduzirDeclaracaoVar.bind(this),
|
|
40966
41163
|
};
|
|
40967
41164
|
this.indentacao = 0;
|
|
40968
|
-
this.text = `
|
|
40969
|
-
.text
|
|
40970
|
-
.global _start
|
|
40971
|
-
|
|
41165
|
+
this.text = `
|
|
41166
|
+
.text
|
|
41167
|
+
.global _start
|
|
41168
|
+
|
|
40972
41169
|
_start:`;
|
|
40973
41170
|
}
|
|
40974
41171
|
gerarDigitoAleatorio() {
|
|
@@ -41035,9 +41232,9 @@ _start:`;
|
|
|
41035
41232
|
const reg = this.obterRegistrador();
|
|
41036
41233
|
this.text += `\n la ${reg}, ${nomeVar}`;
|
|
41037
41234
|
this.emitirCarga('a0', indice);
|
|
41038
|
-
this.text += `
|
|
41039
|
-
slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
|
|
41040
|
-
add ${reg}, ${reg}, a0
|
|
41235
|
+
this.text += `
|
|
41236
|
+
slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
|
|
41237
|
+
add ${reg}, ${reg}, a0
|
|
41041
41238
|
ld a0, 0(${reg})`;
|
|
41042
41239
|
this.liberarRegistrador(reg);
|
|
41043
41240
|
return 'a0';
|
|
@@ -41062,8 +41259,8 @@ _start:`;
|
|
|
41062
41259
|
const reg = this.obterRegistrador();
|
|
41063
41260
|
this.text += `\n la ${reg}, ${nomeVar}`;
|
|
41064
41261
|
this.emitirCarga('a1', indice);
|
|
41065
|
-
this.text += `
|
|
41066
|
-
slli a1, a1, 3 # multiplicar índice por 8
|
|
41262
|
+
this.text += `
|
|
41263
|
+
slli a1, a1, 3 # multiplicar índice por 8
|
|
41067
41264
|
add ${reg}, ${reg}, a1`;
|
|
41068
41265
|
this.emitirCarga('a1', valor);
|
|
41069
41266
|
this.text += `\n sd a1, 0(${reg})`;
|
|
@@ -41084,8 +41281,8 @@ _start:`;
|
|
|
41084
41281
|
this.variaveis.set(nomeVar, varLabel);
|
|
41085
41282
|
}
|
|
41086
41283
|
this.emitirCarga('a0', valor);
|
|
41087
|
-
this.text += `
|
|
41088
|
-
la a1, ${this.variaveis.get(nomeVar)}
|
|
41284
|
+
this.text += `
|
|
41285
|
+
la a1, ${this.variaveis.get(nomeVar)}
|
|
41089
41286
|
sd a0, 0(a1)`;
|
|
41090
41287
|
}
|
|
41091
41288
|
traduzirConstrutoBinario(construto) {
|
|
@@ -41170,18 +41367,18 @@ _start:`;
|
|
|
41170
41367
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
41171
41368
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
41172
41369
|
this.emitirCarga('a0', valor);
|
|
41173
|
-
this.text += `
|
|
41174
|
-
la a1, ${objeto}
|
|
41370
|
+
this.text += `
|
|
41371
|
+
la a1, ${objeto}
|
|
41175
41372
|
sd a0, 0(a1)`;
|
|
41176
41373
|
}
|
|
41177
41374
|
traduzirFuncaoConstruto(construto) {
|
|
41178
41375
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
41179
|
-
this.text += `
|
|
41180
|
-
|
|
41181
|
-
${labelFuncao}:
|
|
41182
|
-
addi sp, sp, -16
|
|
41183
|
-
sd ra, 8(sp)
|
|
41184
|
-
sd s0, 0(sp)
|
|
41376
|
+
this.text += `
|
|
41377
|
+
|
|
41378
|
+
${labelFuncao}:
|
|
41379
|
+
addi sp, sp, -16
|
|
41380
|
+
sd ra, 8(sp)
|
|
41381
|
+
sd s0, 0(sp)
|
|
41185
41382
|
addi s0, sp, 16`;
|
|
41186
41383
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
41187
41384
|
construto.corpo.forEach((declaracao) => {
|
|
@@ -41190,10 +41387,10 @@ ${labelFuncao}:
|
|
|
41190
41387
|
}
|
|
41191
41388
|
});
|
|
41192
41389
|
}
|
|
41193
|
-
this.text += `
|
|
41194
|
-
ld ra, 8(sp)
|
|
41195
|
-
ld s0, 0(sp)
|
|
41196
|
-
addi sp, sp, 16
|
|
41390
|
+
this.text += `
|
|
41391
|
+
ld ra, 8(sp)
|
|
41392
|
+
ld s0, 0(sp)
|
|
41393
|
+
addi sp, sp, 16
|
|
41197
41394
|
ret`;
|
|
41198
41395
|
}
|
|
41199
41396
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -41212,21 +41409,21 @@ ${labelFuncao}:
|
|
|
41212
41409
|
if (operador === 'e' || operador === '&&') {
|
|
41213
41410
|
this.text += `\n beqz a0, ${labelFim}`;
|
|
41214
41411
|
this.emitirCarga('a0', direita);
|
|
41215
|
-
this.text += `
|
|
41216
|
-
beqz a0, ${labelFim}
|
|
41217
|
-
${labelVerdadeiro}:
|
|
41218
|
-
li a0, 1
|
|
41412
|
+
this.text += `
|
|
41413
|
+
beqz a0, ${labelFim}
|
|
41414
|
+
${labelVerdadeiro}:
|
|
41415
|
+
li a0, 1
|
|
41219
41416
|
${labelFim}:`;
|
|
41220
41417
|
}
|
|
41221
41418
|
else if (operador === 'ou' || operador === '||') {
|
|
41222
41419
|
this.text += `\n bnez a0, ${labelVerdadeiro}`;
|
|
41223
41420
|
this.emitirCarga('a0', direita);
|
|
41224
|
-
this.text += `
|
|
41225
|
-
bnez a0, ${labelVerdadeiro}
|
|
41226
|
-
li a0, 0
|
|
41227
|
-
j ${labelFim}
|
|
41228
|
-
${labelVerdadeiro}:
|
|
41229
|
-
li a0, 1
|
|
41421
|
+
this.text += `
|
|
41422
|
+
bnez a0, ${labelVerdadeiro}
|
|
41423
|
+
li a0, 0
|
|
41424
|
+
j ${labelFim}
|
|
41425
|
+
${labelVerdadeiro}:
|
|
41426
|
+
li a0, 1
|
|
41230
41427
|
${labelFim}:`;
|
|
41231
41428
|
}
|
|
41232
41429
|
return 'a0';
|
|
@@ -41252,8 +41449,8 @@ ${labelFim}:`;
|
|
|
41252
41449
|
const nomeVar = (_a = construto.simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
41253
41450
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
41254
41451
|
const varLabel = this.variaveis.get(nomeVar);
|
|
41255
|
-
this.text += `
|
|
41256
|
-
la a0, ${varLabel}
|
|
41452
|
+
this.text += `
|
|
41453
|
+
la a0, ${varLabel}
|
|
41257
41454
|
ld a0, 0(a0)`;
|
|
41258
41455
|
return 'a0';
|
|
41259
41456
|
}
|
|
@@ -41269,8 +41466,8 @@ ${labelFim}:`;
|
|
|
41269
41466
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
41270
41467
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
41271
41468
|
this.emitirCarga('a0', valorTraduzido);
|
|
41272
|
-
this.text += `
|
|
41273
|
-
la a1, ${labelVetor}
|
|
41469
|
+
this.text += `
|
|
41470
|
+
la a1, ${labelVetor}
|
|
41274
41471
|
sd a0, ${index * 8}(a1)`;
|
|
41275
41472
|
}
|
|
41276
41473
|
});
|
|
@@ -41298,8 +41495,8 @@ ${labelFim}:`;
|
|
|
41298
41495
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
41299
41496
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
41300
41497
|
}
|
|
41301
|
-
this.text += `
|
|
41302
|
-
j ${labelInicio}
|
|
41498
|
+
this.text += `
|
|
41499
|
+
j ${labelInicio}
|
|
41303
41500
|
${labelFim}:`;
|
|
41304
41501
|
}
|
|
41305
41502
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -41320,8 +41517,8 @@ ${labelFim}:`;
|
|
|
41320
41517
|
}
|
|
41321
41518
|
});
|
|
41322
41519
|
}
|
|
41323
|
-
this.text += `
|
|
41324
|
-
j ${labelFim}
|
|
41520
|
+
this.text += `
|
|
41521
|
+
j ${labelFim}
|
|
41325
41522
|
${labelProximo}:`;
|
|
41326
41523
|
}
|
|
41327
41524
|
});
|
|
@@ -41362,21 +41559,21 @@ ${labelProximo}:`;
|
|
|
41362
41559
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
41363
41560
|
}
|
|
41364
41561
|
}
|
|
41365
|
-
this.text += `
|
|
41366
|
-
# Falhar com mensagem: ${mensagem}
|
|
41367
|
-
li a0, 1
|
|
41368
|
-
li a7, 93 # sys_exit
|
|
41562
|
+
this.text += `
|
|
41563
|
+
# Falhar com mensagem: ${mensagem}
|
|
41564
|
+
li a0, 1
|
|
41565
|
+
li a7, 93 # sys_exit
|
|
41369
41566
|
ecall`;
|
|
41370
41567
|
}
|
|
41371
41568
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
41372
41569
|
var _a;
|
|
41373
41570
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
41374
|
-
this.text += `
|
|
41375
|
-
|
|
41376
|
-
${nomeFuncao}:
|
|
41377
|
-
addi sp, sp, -16
|
|
41378
|
-
sd ra, 8(sp)
|
|
41379
|
-
sd s0, 0(sp)
|
|
41571
|
+
this.text += `
|
|
41572
|
+
|
|
41573
|
+
${nomeFuncao}:
|
|
41574
|
+
addi sp, sp, -16
|
|
41575
|
+
sd ra, 8(sp)
|
|
41576
|
+
sd s0, 0(sp)
|
|
41380
41577
|
addi s0, sp, 16`;
|
|
41381
41578
|
if (declaracao.funcao &&
|
|
41382
41579
|
declaracao.funcao.corpo &&
|
|
@@ -41387,10 +41584,10 @@ ${nomeFuncao}:
|
|
|
41387
41584
|
}
|
|
41388
41585
|
});
|
|
41389
41586
|
}
|
|
41390
|
-
this.text += `
|
|
41391
|
-
ld ra, 8(sp)
|
|
41392
|
-
ld s0, 0(sp)
|
|
41393
|
-
addi sp, sp, 16
|
|
41587
|
+
this.text += `
|
|
41588
|
+
ld ra, 8(sp)
|
|
41589
|
+
ld s0, 0(sp)
|
|
41590
|
+
addi sp, sp, 16
|
|
41394
41591
|
ret`;
|
|
41395
41592
|
}
|
|
41396
41593
|
traduzirDeclaracaoImportar(declaracao) {
|
|
@@ -41411,11 +41608,11 @@ ${nomeFuncao}:
|
|
|
41411
41608
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
41412
41609
|
this.variaveis.set(nomeVar, varLabel);
|
|
41413
41610
|
}
|
|
41414
|
-
this.text += `
|
|
41415
|
-
li a0, 0 # fd stdin
|
|
41416
|
-
la a1, ${this.variaveis.get(nomeVar)}
|
|
41417
|
-
li a2, 256
|
|
41418
|
-
li a7, 63 # sys_read
|
|
41611
|
+
this.text += `
|
|
41612
|
+
li a0, 0 # fd stdin
|
|
41613
|
+
la a1, ${this.variaveis.get(nomeVar)}
|
|
41614
|
+
li a2, 256
|
|
41615
|
+
li a7, 63 # sys_read
|
|
41419
41616
|
ecall`;
|
|
41420
41617
|
}
|
|
41421
41618
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -41446,8 +41643,8 @@ ${nomeFuncao}:
|
|
|
41446
41643
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
41447
41644
|
}
|
|
41448
41645
|
}
|
|
41449
|
-
this.text += `
|
|
41450
|
-
j ${labelInicio}
|
|
41646
|
+
this.text += `
|
|
41647
|
+
j ${labelInicio}
|
|
41451
41648
|
${labelFim}:`;
|
|
41452
41649
|
}
|
|
41453
41650
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -41459,17 +41656,17 @@ ${labelFim}:`;
|
|
|
41459
41656
|
tamanhoVetor = vetor.tamanho || 0;
|
|
41460
41657
|
}
|
|
41461
41658
|
// t0: contador; t1: limite (caller-saved, seguros aqui)
|
|
41462
|
-
this.text += `
|
|
41463
|
-
li t0, 0 # contador
|
|
41464
|
-
li t1, ${tamanhoVetor}
|
|
41465
|
-
${labelInicio}:
|
|
41659
|
+
this.text += `
|
|
41660
|
+
li t0, 0 # contador
|
|
41661
|
+
li t1, ${tamanhoVetor}
|
|
41662
|
+
${labelInicio}:
|
|
41466
41663
|
bge t0, t1, ${labelFim}`;
|
|
41467
41664
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
41468
41665
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
41469
41666
|
}
|
|
41470
|
-
this.text += `
|
|
41471
|
-
addi t0, t0, 1
|
|
41472
|
-
j ${labelInicio}
|
|
41667
|
+
this.text += `
|
|
41668
|
+
addi t0, t0, 1
|
|
41669
|
+
j ${labelInicio}
|
|
41473
41670
|
${labelFim}:`;
|
|
41474
41671
|
}
|
|
41475
41672
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
@@ -41477,10 +41674,10 @@ ${labelFim}:`;
|
|
|
41477
41674
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
41478
41675
|
this.emitirCarga('a0', valor);
|
|
41479
41676
|
}
|
|
41480
|
-
this.text += `
|
|
41481
|
-
ld ra, 8(sp)
|
|
41482
|
-
ld s0, 0(sp)
|
|
41483
|
-
addi sp, sp, 16
|
|
41677
|
+
this.text += `
|
|
41678
|
+
ld ra, 8(sp)
|
|
41679
|
+
ld s0, 0(sp)
|
|
41680
|
+
addi sp, sp, 16
|
|
41484
41681
|
ret`;
|
|
41485
41682
|
}
|
|
41486
41683
|
traduzirDeclaracaoSe(declaracao) {
|
|
@@ -41494,8 +41691,8 @@ ${labelFim}:`;
|
|
|
41494
41691
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
41495
41692
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
41496
41693
|
}
|
|
41497
|
-
this.text += `
|
|
41498
|
-
j ${labelFim}
|
|
41694
|
+
this.text += `
|
|
41695
|
+
j ${labelFim}
|
|
41499
41696
|
${labelSenao}:`;
|
|
41500
41697
|
if (declaracao.caminhoSenao &&
|
|
41501
41698
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
@@ -41544,8 +41741,8 @@ ${labelSenao}:`;
|
|
|
41544
41741
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
41545
41742
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
41546
41743
|
this.emitirCarga('a0', valor);
|
|
41547
|
-
this.text += `
|
|
41548
|
-
la a1, ${varLabel}
|
|
41744
|
+
this.text += `
|
|
41745
|
+
la a1, ${varLabel}
|
|
41549
41746
|
sd a0, 0(a1)`;
|
|
41550
41747
|
}
|
|
41551
41748
|
}
|
|
@@ -41567,17 +41764,17 @@ ${labelSenao}:`;
|
|
|
41567
41764
|
tamanhoString = String(stringValue.length);
|
|
41568
41765
|
}
|
|
41569
41766
|
// sys_write(fd=1, buf, count): a7=64, a0=fd, a1=buf, a2=count
|
|
41570
|
-
this.text += `
|
|
41571
|
-
la a1, ${nomeStringLiteral}
|
|
41572
|
-
li a2, ${tamanhoString}
|
|
41573
|
-
li a0, 1 # fd stdout
|
|
41574
|
-
li a7, 64 # sys_write
|
|
41767
|
+
this.text += `
|
|
41768
|
+
la a1, ${nomeStringLiteral}
|
|
41769
|
+
li a2, ${tamanhoString}
|
|
41770
|
+
li a0, 1 # fd stdout
|
|
41771
|
+
li a7, 64 # sys_write
|
|
41575
41772
|
ecall`;
|
|
41576
41773
|
}
|
|
41577
41774
|
saidaSistema() {
|
|
41578
|
-
this.text += `
|
|
41579
|
-
li a0, 0 # código de saída
|
|
41580
|
-
li a7, 93 # sys_exit
|
|
41775
|
+
this.text += `
|
|
41776
|
+
li a0, 0 # código de saída
|
|
41777
|
+
li a7, 93 # sys_exit
|
|
41581
41778
|
ecall`;
|
|
41582
41779
|
}
|
|
41583
41780
|
traduzir(declaracoes) {
|
|
@@ -43148,7 +43345,7 @@ class TradutorAssemblyScript {
|
|
|
43148
43345
|
let resultado = '';
|
|
43149
43346
|
this.indentacao += 4;
|
|
43150
43347
|
resultado += ' '.repeat(this.indentacao);
|
|
43151
|
-
for (let condicao of
|
|
43348
|
+
for (let condicao of caminho.condicoes || []) {
|
|
43152
43349
|
resultado +=
|
|
43153
43350
|
'case ' + this.dicionarioConstrutos[condicao.constructor.name](condicao) + ':\n';
|
|
43154
43351
|
resultado += ' '.repeat(this.indentacao);
|
|
@@ -48914,19 +49111,30 @@ class TradutorWebAssembly {
|
|
|
48914
49111
|
const dir = this.traduzirConstruto(construto.direita);
|
|
48915
49112
|
const op = construto.operador.lexema;
|
|
48916
49113
|
switch (op) {
|
|
48917
|
-
case '+':
|
|
48918
|
-
|
|
48919
|
-
case '
|
|
48920
|
-
|
|
48921
|
-
case '
|
|
48922
|
-
|
|
48923
|
-
case '
|
|
48924
|
-
|
|
48925
|
-
case '
|
|
49114
|
+
case '+':
|
|
49115
|
+
return `(i64.add ${esq} ${dir})`;
|
|
49116
|
+
case '-':
|
|
49117
|
+
return `(i64.sub ${esq} ${dir})`;
|
|
49118
|
+
case '*':
|
|
49119
|
+
return `(i64.mul ${esq} ${dir})`;
|
|
49120
|
+
case '/':
|
|
49121
|
+
return `(i64.div_s ${esq} ${dir})`;
|
|
49122
|
+
case '%':
|
|
49123
|
+
return `(i64.rem_s ${esq} ${dir})`;
|
|
49124
|
+
case '<':
|
|
49125
|
+
return `(i64.extend_i32_s (i64.lt_s ${esq} ${dir}))`;
|
|
49126
|
+
case '>':
|
|
49127
|
+
return `(i64.extend_i32_s (i64.gt_s ${esq} ${dir}))`;
|
|
49128
|
+
case '<=':
|
|
49129
|
+
return `(i64.extend_i32_s (i64.le_s ${esq} ${dir}))`;
|
|
49130
|
+
case '>=':
|
|
49131
|
+
return `(i64.extend_i32_s (i64.ge_s ${esq} ${dir}))`;
|
|
48926
49132
|
case '==':
|
|
48927
|
-
case '===':
|
|
49133
|
+
case '===':
|
|
49134
|
+
return `(i64.extend_i32_s (i64.eq ${esq} ${dir}))`;
|
|
48928
49135
|
case '!=':
|
|
48929
|
-
case '!==':
|
|
49136
|
+
case '!==':
|
|
49137
|
+
return `(i64.extend_i32_s (i64.ne ${esq} ${dir}))`;
|
|
48930
49138
|
default:
|
|
48931
49139
|
return `(i64.const 0) ;; operador não suportado: ${op}`;
|
|
48932
49140
|
}
|
|
@@ -49458,12 +49666,7 @@ class TradutorWebAssembly {
|
|
|
49458
49666
|
const { watLiteral } = this.escaparStringWat(s.conteudo);
|
|
49459
49667
|
return ` (data (i32.const ${s.deslocamento}) "${watLiteral}")`;
|
|
49460
49668
|
});
|
|
49461
|
-
const partes = [
|
|
49462
|
-
'(module',
|
|
49463
|
-
...linhasImports,
|
|
49464
|
-
'',
|
|
49465
|
-
linhaMemoria,
|
|
49466
|
-
];
|
|
49669
|
+
const partes = ['(module', ...linhasImports, '', linhaMemoria];
|
|
49467
49670
|
if (linhasDados.length > 0) {
|
|
49468
49671
|
partes.push('');
|
|
49469
49672
|
partes.push(...linhasDados);
|
|
@@ -49487,35 +49690,35 @@ class TradutorWebAssembly {
|
|
|
49487
49690
|
* Fornece os imports necessários (`delegua.escreva_texto`, `delegua.escreva_inteiro`).
|
|
49488
49691
|
*/
|
|
49489
49692
|
gerarArquivoHost() {
|
|
49490
|
-
return `// Gerado por Delégua -> WebAssembly
|
|
49491
|
-
// Uso: node delegua-host.mjs <arquivo.wasm>
|
|
49492
|
-
import { readFileSync } from 'fs';
|
|
49493
|
-
|
|
49494
|
-
const args = process.argv.slice(2);
|
|
49495
|
-
const wasmPath = args[0] ?? 'saida.wasm';
|
|
49496
|
-
|
|
49497
|
-
let memoryExport;
|
|
49498
|
-
|
|
49499
|
-
const importObject = {
|
|
49500
|
-
delegua: {
|
|
49501
|
-
/** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
|
|
49502
|
-
escreva_texto(ptr, len) {
|
|
49503
|
-
const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
|
|
49504
|
-
process.stdout.write(new TextDecoder('utf-8').decode(bytes));
|
|
49505
|
-
},
|
|
49506
|
-
/** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
|
|
49507
|
-
escreva_inteiro(valor) {
|
|
49508
|
-
process.stdout.write(String(valor));
|
|
49509
|
-
},
|
|
49510
|
-
}
|
|
49511
|
-
};
|
|
49512
|
-
|
|
49513
|
-
const wasmBuffer = readFileSync(wasmPath);
|
|
49514
|
-
const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
|
|
49515
|
-
memoryExport = instance.exports.memory;
|
|
49516
|
-
|
|
49517
|
-
const codigoSaida = Number(instance.exports.principal());
|
|
49518
|
-
process.exit(codigoSaida);
|
|
49693
|
+
return `// Gerado por Delégua -> WebAssembly
|
|
49694
|
+
// Uso: node delegua-host.mjs <arquivo.wasm>
|
|
49695
|
+
import { readFileSync } from 'fs';
|
|
49696
|
+
|
|
49697
|
+
const args = process.argv.slice(2);
|
|
49698
|
+
const wasmPath = args[0] ?? 'saida.wasm';
|
|
49699
|
+
|
|
49700
|
+
let memoryExport;
|
|
49701
|
+
|
|
49702
|
+
const importObject = {
|
|
49703
|
+
delegua: {
|
|
49704
|
+
/** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
|
|
49705
|
+
escreva_texto(ptr, len) {
|
|
49706
|
+
const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
|
|
49707
|
+
process.stdout.write(new TextDecoder('utf-8').decode(bytes));
|
|
49708
|
+
},
|
|
49709
|
+
/** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
|
|
49710
|
+
escreva_inteiro(valor) {
|
|
49711
|
+
process.stdout.write(String(valor));
|
|
49712
|
+
},
|
|
49713
|
+
}
|
|
49714
|
+
};
|
|
49715
|
+
|
|
49716
|
+
const wasmBuffer = readFileSync(wasmPath);
|
|
49717
|
+
const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
|
|
49718
|
+
memoryExport = instance.exports.memory;
|
|
49719
|
+
|
|
49720
|
+
const codigoSaida = Number(instance.exports.principal());
|
|
49721
|
+
process.exit(codigoSaida);
|
|
49519
49722
|
`;
|
|
49520
49723
|
}
|
|
49521
49724
|
}
|