@designliquido/delegua 1.23.1 → 1.23.3
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/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +54 -48
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +37 -20
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/bin/package.json +1 -1
- package/interpretador/interpretador.d.ts +4 -0
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +30 -20
- package/interpretador/interpretador.js.map +1 -1
- package/package.json +1 -1
- package/umd/delegua.js +120 -87
package/umd/delegua.js
CHANGED
|
@@ -2408,6 +2408,28 @@ const primitivas_dicionario_1 = __importDefault(require("../bibliotecas/primitiv
|
|
|
2408
2408
|
const primitivas_numero_1 = __importDefault(require("../bibliotecas/primitivas-numero"));
|
|
2409
2409
|
const primitivas_texto_1 = __importDefault(require("../bibliotecas/primitivas-texto"));
|
|
2410
2410
|
const primitivas_vetor_1 = __importDefault(require("../bibliotecas/primitivas-vetor"));
|
|
2411
|
+
// Constante usada em "declaracaoRetorna()"
|
|
2412
|
+
const simbolosInicioExpressao = new Set([
|
|
2413
|
+
delegua_2.default.CHAVE_ESQUERDA,
|
|
2414
|
+
delegua_2.default.COLCHETE_ESQUERDO,
|
|
2415
|
+
delegua_2.default.FALSO,
|
|
2416
|
+
delegua_2.default.FUNCAO,
|
|
2417
|
+
delegua_2.default.FUNÇÃO,
|
|
2418
|
+
delegua_2.default.IDENTIFICADOR,
|
|
2419
|
+
delegua_2.default.ISTO,
|
|
2420
|
+
delegua_2.default.NAO,
|
|
2421
|
+
delegua_2.default.NEGACAO,
|
|
2422
|
+
delegua_2.default.NUMERO,
|
|
2423
|
+
delegua_2.default.NULO,
|
|
2424
|
+
delegua_2.default.PARENTESE_ESQUERDO,
|
|
2425
|
+
delegua_2.default.SUPER,
|
|
2426
|
+
delegua_2.default.TEXTO,
|
|
2427
|
+
delegua_2.default.VERDADEIRO,
|
|
2428
|
+
delegua_2.default.ADICAO,
|
|
2429
|
+
delegua_2.default.SUBTRACAO,
|
|
2430
|
+
delegua_2.default.INCREMENTAR,
|
|
2431
|
+
delegua_2.default.DECREMENTAR
|
|
2432
|
+
]);
|
|
2411
2433
|
/**
|
|
2412
2434
|
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
2413
2435
|
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
@@ -3073,7 +3095,11 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3073
3095
|
return await this.resolverCadeiaChamadas(chamada);
|
|
3074
3096
|
case delegua_2.default.PONTO:
|
|
3075
3097
|
this.avancarEDevolverAnterior();
|
|
3076
|
-
this.
|
|
3098
|
+
const simboloAtual = this.simbolos[this.atual];
|
|
3099
|
+
if (!simboloAtual ||
|
|
3100
|
+
!/^[A-Za-z_$À-ÿ][A-Za-z0-9_$À-ÿ]*$/.test(simboloAtual.lexema)) {
|
|
3101
|
+
throw this.erro(simboloAtual, "Esperado nome do método ou propriedade após o '.'");
|
|
3102
|
+
}
|
|
3077
3103
|
const nome = this.avancarEDevolverAnterior();
|
|
3078
3104
|
let tipoInferido = expressaoAnterior.tipo;
|
|
3079
3105
|
// Se não for um dicionário anônimo (ou seja, ser variável ou constante com nome)
|
|
@@ -4013,24 +4039,9 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4013
4039
|
}
|
|
4014
4040
|
async declaracaoRetorna() {
|
|
4015
4041
|
const simboloChave = this.simbolos[this.atual - 1];
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
delegua_2.default.COLCHETE_ESQUERDO,
|
|
4020
|
-
delegua_2.default.FALSO,
|
|
4021
|
-
delegua_2.default.FUNCAO,
|
|
4022
|
-
delegua_2.default.FUNÇÃO,
|
|
4023
|
-
delegua_2.default.IDENTIFICADOR,
|
|
4024
|
-
delegua_2.default.ISTO,
|
|
4025
|
-
delegua_2.default.NAO,
|
|
4026
|
-
delegua_2.default.NEGACAO,
|
|
4027
|
-
delegua_2.default.NUMERO,
|
|
4028
|
-
delegua_2.default.NULO,
|
|
4029
|
-
delegua_2.default.PARENTESE_ESQUERDO,
|
|
4030
|
-
delegua_2.default.SUPER,
|
|
4031
|
-
delegua_2.default.TEXTO,
|
|
4032
|
-
delegua_2.default.VERDADEIRO,
|
|
4033
|
-
].includes(this.simbolos[this.atual].tipo)) {
|
|
4042
|
+
const simboloAtual = this.simbolos[this.atual];
|
|
4043
|
+
let valor;
|
|
4044
|
+
if (simboloAtual && simbolosInicioExpressao.has(simboloAtual.tipo)) {
|
|
4034
4045
|
valor = await this.expressao();
|
|
4035
4046
|
}
|
|
4036
4047
|
// Ponto-e-vírgula é opcional aqui.
|
|
@@ -4322,51 +4333,46 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4322
4333
|
*/
|
|
4323
4334
|
async declaracaoDeVariaveis() {
|
|
4324
4335
|
const simboloVariavel = this.simboloAnterior();
|
|
4325
|
-
const identificadores = [];
|
|
4326
|
-
const retorno = [];
|
|
4327
|
-
let tipo = 'qualquer';
|
|
4328
4336
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
4329
4337
|
return await this.declaracaoDesestruturacaoVariavel();
|
|
4330
4338
|
}
|
|
4339
|
+
const identificadores = [];
|
|
4331
4340
|
do {
|
|
4332
4341
|
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
4333
4342
|
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
4343
|
+
let tipo = 'qualquer';
|
|
4334
4344
|
let tipoExplicito = false;
|
|
4335
4345
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
4336
4346
|
tipo = this.verificarDefinicaoTipoAtual();
|
|
4337
4347
|
tipoExplicito = true;
|
|
4338
4348
|
this.avancarEDevolverAnterior();
|
|
4339
4349
|
}
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4350
|
+
const retorno = [];
|
|
4351
|
+
const decoradores = Array.from(this.pilhaDecoradores);
|
|
4352
|
+
const temAtribuicao = this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL, delegua_2.default.SETA_ESQUERDA);
|
|
4353
|
+
if (!temAtribuicao) {
|
|
4354
|
+
for (const identificador of identificadores) {
|
|
4343
4355
|
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
4344
|
-
retorno.push(new declaracoes_1.Var(identificador, undefined, tipo, tipoExplicito,
|
|
4356
|
+
retorno.push(new declaracoes_1.Var(identificador, undefined, tipo, tipoExplicito, decoradores));
|
|
4345
4357
|
}
|
|
4346
|
-
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
4347
|
-
this.pilhaDecoradores = [];
|
|
4348
|
-
return retorno;
|
|
4349
4358
|
}
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
for (let [indice, identificador] of identificadores.entries()) {
|
|
4358
|
-
const tipoOriginal = tipo; // Preserva o tipo antes da inferência
|
|
4359
|
-
tipo =
|
|
4360
|
-
this.logicaComumInferenciaTiposVariaveisEConstantes(inicializadores[indice], tipo) ?? tipo;
|
|
4361
|
-
if (tipo !== 'dicionário') {
|
|
4362
|
-
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
4359
|
+
else {
|
|
4360
|
+
const inicializadores = [];
|
|
4361
|
+
do {
|
|
4362
|
+
inicializadores.push(await this.expressao());
|
|
4363
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
4364
|
+
if (identificadores.length !== inicializadores.length) {
|
|
4365
|
+
throw this.erro(simboloVariavel, 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
4363
4366
|
}
|
|
4364
|
-
|
|
4365
|
-
const
|
|
4366
|
-
this.
|
|
4367
|
+
for (let [indice, identificador] of identificadores.entries()) {
|
|
4368
|
+
const inicializador = inicializadores[indice];
|
|
4369
|
+
const tipoInferido = this.logicaComumInferenciaTiposVariaveisEConstantes(inicializador, tipo) ?? tipo;
|
|
4370
|
+
const informacaoSintatica = tipo === 'dicionário'
|
|
4371
|
+
? this.resolverInformacaoElementoSintaticoDeDicionario(inicializador)
|
|
4372
|
+
: new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipoInferido);
|
|
4373
|
+
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, informacaoSintatica);
|
|
4374
|
+
retorno.push(new declaracoes_1.Var(identificador, inicializador, tipoInferido, tipoExplicito, decoradores, tipo));
|
|
4367
4375
|
}
|
|
4368
|
-
retorno.push(new declaracoes_1.Var(identificador, inicializadores[indice], tipo, tipoExplicito, Array.from(this.pilhaDecoradores), tipoOriginal // Passa o tipo original para o construtor
|
|
4369
|
-
));
|
|
4370
4376
|
}
|
|
4371
4377
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
4372
4378
|
this.pilhaDecoradores = [];
|
|
@@ -6364,9 +6370,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
6364
6370
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Primitiva '${entidadeChamada.simbolo.lexema}' não existe.`);
|
|
6365
6371
|
}
|
|
6366
6372
|
logicaComumInferenciaTiposVariaveisEConstantes(inicializador, tipoPrevio) {
|
|
6367
|
-
if (tipoPrevio !== 'qualquer')
|
|
6373
|
+
if (tipoPrevio !== 'qualquer')
|
|
6368
6374
|
return tipoPrevio;
|
|
6369
|
-
}
|
|
6370
6375
|
switch (inicializador.constructor) {
|
|
6371
6376
|
case construtos_1.AcessoIndiceVariavel:
|
|
6372
6377
|
const entidadeChamadaAcessoIndiceVariavel = inicializador
|
|
@@ -6399,7 +6404,16 @@ class AvaliadorSintaticoPitugues {
|
|
|
6399
6404
|
return entidadeChamadaReferenciaFuncao.tipo;
|
|
6400
6405
|
case construtos_1.Variavel:
|
|
6401
6406
|
const entidadeChamadaVariavel = entidadeChamadaChamada;
|
|
6402
|
-
|
|
6407
|
+
const tipoBruto = entidadeChamadaVariavel.tipo;
|
|
6408
|
+
if (tipoBruto &&
|
|
6409
|
+
tipoBruto.startsWith('função<') &&
|
|
6410
|
+
tipoBruto.endsWith('>')) {
|
|
6411
|
+
return tipoBruto.substring(7, tipoBruto.length - 1);
|
|
6412
|
+
}
|
|
6413
|
+
else if (tipoBruto === 'função') {
|
|
6414
|
+
return 'qualquer';
|
|
6415
|
+
}
|
|
6416
|
+
return tipoBruto;
|
|
6403
6417
|
}
|
|
6404
6418
|
break;
|
|
6405
6419
|
case construtos_1.FuncaoConstruto:
|
|
@@ -6579,15 +6593,13 @@ class AvaliadorSintaticoPitugues {
|
|
|
6579
6593
|
const qtdIdentificadores = identificadores.length;
|
|
6580
6594
|
const qtdValores = inicializadores.length;
|
|
6581
6595
|
const ehDesempacotamento = qtdIdentificadores > 1 && qtdValores === 1;
|
|
6582
|
-
if (indexResto > -1) {
|
|
6583
|
-
if (
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
6587
|
-
}
|
|
6596
|
+
if (indexResto > -1 && qtdValores < qtdIdentificadores - 1) {
|
|
6597
|
+
if (!ehDesempacotamento ||
|
|
6598
|
+
(ehDesempacotamento && inicializadores[0] instanceof construtos_1.Literal)) {
|
|
6599
|
+
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
6588
6600
|
}
|
|
6589
6601
|
}
|
|
6590
|
-
else {
|
|
6602
|
+
else if (indexResto === -1) {
|
|
6591
6603
|
if (!ehDesempacotamento && qtdIdentificadores !== qtdValores) {
|
|
6592
6604
|
throw this.erro(this.simboloAnterior(), 'Quantidade de inicializadores à esquerda do igual é diferente da quantidade de identificadores à direita.');
|
|
6593
6605
|
}
|
|
@@ -6600,41 +6612,52 @@ class AvaliadorSintaticoPitugues {
|
|
|
6600
6612
|
}
|
|
6601
6613
|
const retorno = [];
|
|
6602
6614
|
let origemParaAtribuicao = inicializadores[0];
|
|
6603
|
-
// Injeção de
|
|
6615
|
+
// Injeção de código para variáveis temporárias
|
|
6604
6616
|
if (ehDesempacotamento && !(inicializadores[0] instanceof construtos_1.Vetor)) {
|
|
6605
6617
|
const linha = identificadores[0].linha;
|
|
6606
|
-
// Cria variável temporária para evitar reavaliar a expressão original múltiplas vezes
|
|
6607
6618
|
const nomeVarTemp = `__temp_desempacotamento_${new Date().getTime()}_${Math.floor(Math.random() * 1000)}`;
|
|
6608
6619
|
const simboloVarTemp = new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR, nomeVarTemp, null, linha, -1);
|
|
6609
6620
|
retorno.push(new declaracoes_1.Var(simboloVarTemp, inicializadores[0], 'qualquer[]'));
|
|
6610
6621
|
origemParaAtribuicao = new construtos_1.Variavel(this.hashArquivo, simboloVarTemp);
|
|
6611
|
-
// Injeta validação de tamanho se não houver operador de resto
|
|
6612
6622
|
if (indexResto === -1) {
|
|
6613
6623
|
retorno.push(this.construirValidacaoDesempacotamento(identificadores[0], origemParaAtribuicao, qtdIdentificadores));
|
|
6614
6624
|
}
|
|
6615
6625
|
}
|
|
6616
|
-
let cursorValores = 0;
|
|
6617
6626
|
const qtdParaResto = qtdValores - (qtdIdentificadores - 1);
|
|
6618
|
-
|
|
6627
|
+
const elementosAposResto = qtdIdentificadores - 1 - indexResto;
|
|
6628
|
+
let cursorValores = 0;
|
|
6629
|
+
let cursorDesempacotamento = 0;
|
|
6630
|
+
for (let i = 0; i < qtdIdentificadores; i++) {
|
|
6619
6631
|
const identificador = identificadores[i];
|
|
6620
6632
|
let inicializador;
|
|
6621
6633
|
let tipo = 'qualquer';
|
|
6622
6634
|
if (i === indexResto) {
|
|
6623
|
-
|
|
6635
|
+
let valoresResto;
|
|
6636
|
+
if (ehDesempacotamento && inicializadores[0] instanceof construtos_1.Vetor) {
|
|
6637
|
+
const vetorLiteral = inicializadores[0];
|
|
6638
|
+
valoresResto = vetorLiteral.valores.slice(cursorDesempacotamento, vetorLiteral.valores.length - elementosAposResto);
|
|
6639
|
+
cursorDesempacotamento += valoresResto.length;
|
|
6640
|
+
}
|
|
6641
|
+
else {
|
|
6642
|
+
valoresResto = inicializadores.slice(cursorValores, cursorValores + qtdParaResto);
|
|
6643
|
+
cursorValores += qtdParaResto;
|
|
6644
|
+
}
|
|
6624
6645
|
let tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(valoresResto);
|
|
6625
|
-
if (!tipoInferido.endsWith('[]'))
|
|
6646
|
+
if (!tipoInferido.endsWith('[]')) {
|
|
6626
6647
|
tipoInferido = `${tipoInferido}[]`;
|
|
6648
|
+
}
|
|
6627
6649
|
inicializador = new construtos_1.Vetor(identificador.hashArquivo, identificador.linha, valoresResto, tipoInferido);
|
|
6628
6650
|
tipo = tipoInferido;
|
|
6629
|
-
cursorValores += qtdParaResto;
|
|
6630
6651
|
}
|
|
6631
6652
|
else if (ehDesempacotamento) {
|
|
6632
6653
|
if (inicializadores[0] instanceof construtos_1.Vetor) {
|
|
6633
|
-
|
|
6654
|
+
const vetorLiteral = inicializadores[0];
|
|
6655
|
+
inicializador = vetorLiteral.valores[cursorDesempacotamento];
|
|
6634
6656
|
}
|
|
6635
6657
|
else {
|
|
6636
6658
|
inicializador = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, origemParaAtribuicao, new construtos_1.Literal(this.hashArquivo, identificador.linha, i, 'número'), new lexador_1.Simbolo(pitugues_2.default.COLCHETE_DIREITO, ']', null, identificador.linha, -1));
|
|
6637
6659
|
}
|
|
6660
|
+
cursorDesempacotamento++;
|
|
6638
6661
|
}
|
|
6639
6662
|
else {
|
|
6640
6663
|
inicializador = inicializadores[cursorValores];
|
|
@@ -6924,7 +6947,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6924
6947
|
expressao = await this.finalizarChamada(expressao);
|
|
6925
6948
|
}
|
|
6926
6949
|
else if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.PONTO)) {
|
|
6927
|
-
const nome = this.consumir(pitugues_2.default.IDENTIFICADOR, "Esperado nome do método após '.'
|
|
6950
|
+
const nome = this.consumir(pitugues_2.default.IDENTIFICADOR, "Esperado nome do método ou propriedade após o '.'");
|
|
6928
6951
|
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
6929
6952
|
}
|
|
6930
6953
|
else if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.COLCHETE_ESQUERDO)) {
|
|
@@ -24125,8 +24148,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24125
24148
|
});
|
|
24126
24149
|
}
|
|
24127
24150
|
async logicaComumExecucaoEnquanto(enquanto, acumularRetornos) {
|
|
24128
|
-
let retornoExecucao = undefined;
|
|
24129
24151
|
const retornos = [];
|
|
24152
|
+
let retornoExecucao = undefined;
|
|
24153
|
+
let iteracoes = 0;
|
|
24130
24154
|
while ((acumularRetornos ||
|
|
24131
24155
|
!(retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.Quebra)) &&
|
|
24132
24156
|
this.eVerdadeiro(await this.avaliar(enquanto.condicao))) {
|
|
@@ -24134,6 +24158,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24134
24158
|
if (this.funcaoVerificarIteracao) {
|
|
24135
24159
|
await this.funcaoVerificarIteracao();
|
|
24136
24160
|
}
|
|
24161
|
+
await this.cederControle(++iteracoes);
|
|
24137
24162
|
retornoExecucao = await this.executar(enquanto.corpo);
|
|
24138
24163
|
if (retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.SustarQuebra) {
|
|
24139
24164
|
if (acumularRetornos) {
|
|
@@ -24172,13 +24197,15 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24172
24197
|
return this.logicaComumExecucaoEnquanto(declaracao, false);
|
|
24173
24198
|
}
|
|
24174
24199
|
async logicaComumExecucaoFazer(fazer, acumularRetornos) {
|
|
24175
|
-
let retornoExecucao = undefined;
|
|
24176
24200
|
const retornos = [];
|
|
24201
|
+
let retornoExecucao = undefined;
|
|
24202
|
+
let iteracoes = 0;
|
|
24177
24203
|
do {
|
|
24178
24204
|
try {
|
|
24179
24205
|
if (this.funcaoVerificarIteracao) {
|
|
24180
24206
|
await this.funcaoVerificarIteracao();
|
|
24181
24207
|
}
|
|
24208
|
+
await this.cederControle(++iteracoes);
|
|
24182
24209
|
retornoExecucao = await this.executar(fazer.caminhoFazer);
|
|
24183
24210
|
if (retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.SustarQuebra) {
|
|
24184
24211
|
if (acumularRetornos) {
|
|
@@ -24224,8 +24251,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24224
24251
|
if (declaracaoInicializador !== null && declaracaoInicializador !== undefined) {
|
|
24225
24252
|
await this.avaliar(declaracaoInicializador);
|
|
24226
24253
|
}
|
|
24227
|
-
let retornoExecucao = undefined;
|
|
24228
24254
|
const retornos = [];
|
|
24255
|
+
let retornoExecucao = undefined;
|
|
24256
|
+
let iteracoes = 0;
|
|
24229
24257
|
while (acumularRetornos ||
|
|
24230
24258
|
!(retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.Quebra)) {
|
|
24231
24259
|
if (para.condicao !== null && !this.eVerdadeiro(await this.avaliar(para.condicao))) {
|
|
@@ -24234,6 +24262,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24234
24262
|
if (this.funcaoVerificarIteracao) {
|
|
24235
24263
|
await this.funcaoVerificarIteracao();
|
|
24236
24264
|
}
|
|
24265
|
+
await this.cederControle(++iteracoes);
|
|
24237
24266
|
retornoExecucao = await this.executar(para.corpo);
|
|
24238
24267
|
if (retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.SustarQuebra) {
|
|
24239
24268
|
if (acumularRetornos) {
|
|
@@ -24265,6 +24294,24 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24265
24294
|
async visitarDeclaracaoPara(declaracao) {
|
|
24266
24295
|
return this.logicaComumExecucaoPara(declaracao, false);
|
|
24267
24296
|
}
|
|
24297
|
+
/**
|
|
24298
|
+
* Define a variável de iteração de um laço 'para cada' (ou compreensão de lista) SEM coerção de tipo. A iteração sempre preserva o valor original do elemento, independentemente do tipo inferido para a variável.
|
|
24299
|
+
*/
|
|
24300
|
+
definirVariavelIteracao(variavelIteracao, valorElemento) {
|
|
24301
|
+
if (variavelIteracao instanceof construtos_1.Variavel) {
|
|
24302
|
+
this.pilhaEscoposExecucao.definirVariavel(variavelIteracao.simbolo.lexema, valorElemento, 'qualquer');
|
|
24303
|
+
}
|
|
24304
|
+
else if (variavelIteracao instanceof construtos_1.Dupla) {
|
|
24305
|
+
const nomePrimeiro = variavelIteracao.primeiro?.valor?.toString?.() ?? variavelIteracao.primeiro?.lexema;
|
|
24306
|
+
const nomeSegundo = variavelIteracao.segundo?.valor?.toString?.() ?? variavelIteracao.segundo?.lexema;
|
|
24307
|
+
if (nomePrimeiro) {
|
|
24308
|
+
this.pilhaEscoposExecucao.definirVariavel(nomePrimeiro, valorElemento.primeiro?.valor ?? valorElemento.primeiro, 'qualquer');
|
|
24309
|
+
}
|
|
24310
|
+
if (nomeSegundo) {
|
|
24311
|
+
this.pilhaEscoposExecucao.definirVariavel(nomeSegundo, valorElemento.segundo?.valor ?? valorElemento.segundo, 'qualquer');
|
|
24312
|
+
}
|
|
24313
|
+
}
|
|
24314
|
+
}
|
|
24268
24315
|
async logicaComumExecucaoParaCada(paraCada, acumularRetornos) {
|
|
24269
24316
|
let retornoExecucao = undefined;
|
|
24270
24317
|
// Posição atual precisa ser reiniciada, pois pode estar dentro de outro
|
|
@@ -24285,6 +24332,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24285
24332
|
return Promise.reject("Variável ou literal provida em instrução 'para cada' não é um vetor.");
|
|
24286
24333
|
}
|
|
24287
24334
|
const retornos = [];
|
|
24335
|
+
let iteracoes = 0;
|
|
24288
24336
|
while ((acumularRetornos ||
|
|
24289
24337
|
!(retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.Quebra)) &&
|
|
24290
24338
|
paraCada.posicaoAtual < valorVetorOuDicionarioResolvido.length) {
|
|
@@ -24292,23 +24340,8 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24292
24340
|
if (this.funcaoVerificarIteracao) {
|
|
24293
24341
|
await this.funcaoVerificarIteracao();
|
|
24294
24342
|
}
|
|
24295
|
-
|
|
24296
|
-
|
|
24297
|
-
}
|
|
24298
|
-
if (paraCada.variavelIteracao instanceof construtos_1.Dupla) {
|
|
24299
|
-
const valorComoDupla = valorVetorOuDicionarioResolvido[paraCada.posicaoAtual];
|
|
24300
|
-
const nomesVariaveis = await Promise.all([
|
|
24301
|
-
this.avaliar(paraCada.variavelIteracao.primeiro),
|
|
24302
|
-
this.avaliar(paraCada.variavelIteracao.segundo),
|
|
24303
|
-
]);
|
|
24304
|
-
const valoresDupla = await Promise.all([
|
|
24305
|
-
this.avaliar(valorComoDupla.primeiro),
|
|
24306
|
-
this.avaliar(valorComoDupla.segundo),
|
|
24307
|
-
]);
|
|
24308
|
-
// nomesVariaveis são strings (nomes das variáveis)
|
|
24309
|
-
this.pilhaEscoposExecucao.definirVariavel(String(nomesVariaveis[0]), valoresDupla[0]);
|
|
24310
|
-
this.pilhaEscoposExecucao.definirVariavel(String(nomesVariaveis[1]), valoresDupla[1]);
|
|
24311
|
-
}
|
|
24343
|
+
await this.cederControle(++iteracoes);
|
|
24344
|
+
this.definirVariavelIteracao(paraCada.variavelIteracao, valorVetorOuDicionarioResolvido[paraCada.posicaoAtual]);
|
|
24312
24345
|
retornoExecucao = await this.executar(paraCada.corpo);
|
|
24313
24346
|
if (retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.SustarQuebra) {
|
|
24314
24347
|
if (acumularRetornos) {
|