@designliquido/delegua 0.8.1 → 0.9.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/bin/package.json +1 -1
  2. package/fontes/avaliador-sintatico/avaliador-sintatico-base.d.ts +2 -1
  3. package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +3 -0
  4. package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
  5. package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +2 -1
  6. package/fontes/avaliador-sintatico/avaliador-sintatico.js +14 -0
  7. package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
  8. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +2 -1
  9. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +3 -0
  10. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
  11. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +2 -1
  12. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +12 -0
  13. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
  14. package/fontes/bibliotecas/biblioteca-global.js +351 -177
  15. package/fontes/bibliotecas/biblioteca-global.js.map +1 -1
  16. package/fontes/construtos/acesso-indice-variavel.d.ts +1 -1
  17. package/fontes/construtos/acesso-indice-variavel.js +41 -1
  18. package/fontes/construtos/acesso-indice-variavel.js.map +1 -1
  19. package/fontes/construtos/acesso-metodo.d.ts +1 -1
  20. package/fontes/construtos/acesso-metodo.js +41 -1
  21. package/fontes/construtos/acesso-metodo.js.map +1 -1
  22. package/fontes/construtos/agrupamento.d.ts +1 -1
  23. package/fontes/construtos/agrupamento.js +41 -1
  24. package/fontes/construtos/agrupamento.js.map +1 -1
  25. package/fontes/construtos/atribuicao-sobrescrita.d.ts +2 -1
  26. package/fontes/construtos/atribuicao-sobrescrita.js +41 -1
  27. package/fontes/construtos/atribuicao-sobrescrita.js.map +1 -1
  28. package/fontes/construtos/atribuir.d.ts +1 -1
  29. package/fontes/construtos/atribuir.js +41 -1
  30. package/fontes/construtos/atribuir.js.map +1 -1
  31. package/fontes/construtos/binario.d.ts +1 -1
  32. package/fontes/construtos/binario.js +41 -1
  33. package/fontes/construtos/binario.js.map +1 -1
  34. package/fontes/construtos/chamada.d.ts +1 -1
  35. package/fontes/construtos/chamada.js +41 -1
  36. package/fontes/construtos/chamada.js.map +1 -1
  37. package/fontes/construtos/conjunto.d.ts +2 -1
  38. package/fontes/construtos/conjunto.js +41 -1
  39. package/fontes/construtos/conjunto.js.map +1 -1
  40. package/fontes/construtos/construto.d.ts +1 -1
  41. package/fontes/construtos/dicionario.d.ts +2 -1
  42. package/fontes/construtos/dicionario.js +41 -1
  43. package/fontes/construtos/dicionario.js.map +1 -1
  44. package/fontes/construtos/funcao.d.ts +1 -1
  45. package/fontes/construtos/funcao.js +41 -1
  46. package/fontes/construtos/funcao.js.map +1 -1
  47. package/fontes/construtos/isto.d.ts +2 -1
  48. package/fontes/construtos/isto.js +41 -1
  49. package/fontes/construtos/isto.js.map +1 -1
  50. package/fontes/construtos/literal.d.ts +1 -1
  51. package/fontes/construtos/literal.js +41 -1
  52. package/fontes/construtos/literal.js.map +1 -1
  53. package/fontes/construtos/logico.d.ts +2 -1
  54. package/fontes/construtos/logico.js +41 -1
  55. package/fontes/construtos/logico.js.map +1 -1
  56. package/fontes/construtos/super.d.ts +2 -2
  57. package/fontes/construtos/super.js +41 -1
  58. package/fontes/construtos/super.js.map +1 -1
  59. package/fontes/construtos/unario.d.ts +2 -1
  60. package/fontes/construtos/unario.js +41 -1
  61. package/fontes/construtos/unario.js.map +1 -1
  62. package/fontes/construtos/variavel.d.ts +1 -1
  63. package/fontes/construtos/variavel.js +41 -1
  64. package/fontes/construtos/variavel.js.map +1 -1
  65. package/fontes/construtos/vetor.d.ts +2 -1
  66. package/fontes/construtos/vetor.js +41 -1
  67. package/fontes/construtos/vetor.js.map +1 -1
  68. package/fontes/declaracoes/bloco.d.ts +1 -1
  69. package/fontes/declaracoes/bloco.js +41 -1
  70. package/fontes/declaracoes/bloco.js.map +1 -1
  71. package/fontes/declaracoes/classe.d.ts +2 -2
  72. package/fontes/declaracoes/classe.js +41 -1
  73. package/fontes/declaracoes/classe.js.map +1 -1
  74. package/fontes/declaracoes/continua.d.ts +2 -2
  75. package/fontes/declaracoes/continua.js +41 -1
  76. package/fontes/declaracoes/continua.js.map +1 -1
  77. package/fontes/declaracoes/declaracao.d.ts +2 -1
  78. package/fontes/declaracoes/declaracao.js +41 -1
  79. package/fontes/declaracoes/declaracao.js.map +1 -1
  80. package/fontes/declaracoes/enquanto.d.ts +2 -1
  81. package/fontes/declaracoes/enquanto.js +41 -1
  82. package/fontes/declaracoes/enquanto.js.map +1 -1
  83. package/fontes/declaracoes/escolha.d.ts +2 -1
  84. package/fontes/declaracoes/escolha.js +41 -1
  85. package/fontes/declaracoes/escolha.js.map +1 -1
  86. package/fontes/declaracoes/escreva.d.ts +1 -1
  87. package/fontes/declaracoes/escreva.js +41 -1
  88. package/fontes/declaracoes/escreva.js.map +1 -1
  89. package/fontes/declaracoes/expressao.d.ts +1 -1
  90. package/fontes/declaracoes/expressao.js +41 -1
  91. package/fontes/declaracoes/expressao.js.map +1 -1
  92. package/fontes/declaracoes/fazer.d.ts +2 -1
  93. package/fontes/declaracoes/fazer.js +41 -1
  94. package/fontes/declaracoes/fazer.js.map +1 -1
  95. package/fontes/declaracoes/funcao.d.ts +1 -1
  96. package/fontes/declaracoes/funcao.js +41 -1
  97. package/fontes/declaracoes/funcao.js.map +1 -1
  98. package/fontes/declaracoes/importar.d.ts +2 -1
  99. package/fontes/declaracoes/importar.js +41 -1
  100. package/fontes/declaracoes/importar.js.map +1 -1
  101. package/fontes/declaracoes/leia.d.ts +1 -1
  102. package/fontes/declaracoes/leia.js +44 -1
  103. package/fontes/declaracoes/leia.js.map +1 -1
  104. package/fontes/declaracoes/para.d.ts +2 -1
  105. package/fontes/declaracoes/para.js +41 -1
  106. package/fontes/declaracoes/para.js.map +1 -1
  107. package/fontes/declaracoes/retorna.d.ts +1 -1
  108. package/fontes/declaracoes/retorna.js +41 -1
  109. package/fontes/declaracoes/retorna.js.map +1 -1
  110. package/fontes/declaracoes/se.d.ts +1 -1
  111. package/fontes/declaracoes/se.js +41 -1
  112. package/fontes/declaracoes/se.js.map +1 -1
  113. package/fontes/declaracoes/sustar.d.ts +1 -1
  114. package/fontes/declaracoes/sustar.js +41 -1
  115. package/fontes/declaracoes/sustar.js.map +1 -1
  116. package/fontes/declaracoes/tente.d.ts +1 -1
  117. package/fontes/declaracoes/tente.js +41 -1
  118. package/fontes/declaracoes/tente.js.map +1 -1
  119. package/fontes/declaracoes/var.d.ts +1 -1
  120. package/fontes/declaracoes/var.js +41 -1
  121. package/fontes/declaracoes/var.js.map +1 -1
  122. package/fontes/delegua.d.ts +3 -3
  123. package/fontes/delegua.js +136 -61
  124. package/fontes/delegua.js.map +1 -1
  125. package/fontes/depuracao/servidor-depuracao.d.ts +4 -4
  126. package/fontes/depuracao/servidor-depuracao.js +121 -47
  127. package/fontes/depuracao/servidor-depuracao.js.map +1 -1
  128. package/fontes/estruturas/funcao-padrao.d.ts +1 -1
  129. package/fontes/estruturas/funcao-padrao.js +46 -2
  130. package/fontes/estruturas/funcao-padrao.js.map +1 -1
  131. package/fontes/estruturas/funcao.d.ts +1 -1
  132. package/fontes/estruturas/funcao.js +74 -28
  133. package/fontes/estruturas/funcao.js.map +1 -1
  134. package/fontes/interfaces/avaliador-sintatico-interface.d.ts +5 -4
  135. package/fontes/interfaces/delegua-interface.d.ts +2 -2
  136. package/fontes/interfaces/interpretador-com-depuracao-interface.d.ts +3 -4
  137. package/fontes/interfaces/interpretador-interface.d.ts +6 -5
  138. package/fontes/interpretador/dialetos/egua-classico.d.ts +31 -30
  139. package/fontes/interpretador/dialetos/egua-classico.js +906 -470
  140. package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
  141. package/fontes/interpretador/interpretador-com-depuracao.d.ts +6 -6
  142. package/fontes/interpretador/interpretador-com-depuracao.js +280 -155
  143. package/fontes/interpretador/interpretador-com-depuracao.js.map +1 -1
  144. package/fontes/interpretador/interpretador.d.ts +43 -34
  145. package/fontes/interpretador/interpretador.js +1045 -535
  146. package/fontes/interpretador/interpretador.js.map +1 -1
  147. package/fontes/lexador/lexador.js +2 -2
  148. package/fontes/lexador/lexador.js.map +1 -1
  149. package/fontes/lexador/palavras-reservadas.d.ts +22 -21
  150. package/fontes/lexador/palavras-reservadas.js +22 -21
  151. package/fontes/lexador/palavras-reservadas.js.map +1 -1
  152. package/fontes/resolvedor/dialetos/egua-classico.d.ts +25 -3
  153. package/fontes/resolvedor/dialetos/egua-classico.js +40 -0
  154. package/fontes/resolvedor/dialetos/egua-classico.js.map +1 -1
  155. package/fontes/tipos-de-simbolos/delegua.d.ts +2 -1
  156. package/fontes/tipos-de-simbolos/delegua.js +2 -1
  157. package/fontes/tipos-de-simbolos/delegua.js.map +1 -1
  158. package/fontes/tipos-de-simbolos/eguap.d.ts +1 -0
  159. package/fontes/tipos-de-simbolos/eguap.js +1 -0
  160. package/fontes/tipos-de-simbolos/eguap.js.map +1 -1
  161. package/package.json +1 -1
  162. package/testes/biblioteca-global.test.js +424 -181
  163. package/testes/biblioteca-global.test.js.map +1 -1
  164. package/testes/egua-classico/interpretador.test.js +379 -163
  165. package/testes/egua-classico/interpretador.test.js.map +1 -1
  166. package/testes/eguap/interpretador.test.js +388 -172
  167. package/testes/eguap/interpretador.test.js.map +1 -1
  168. package/testes/interpretador.test.js +876 -399
  169. package/testes/interpretador.test.js.map +1 -1
@@ -22,12 +22,49 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
25
61
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
62
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
63
  };
28
64
  Object.defineProperty(exports, "__esModule", { value: true });
29
65
  exports.Interpretador = void 0;
30
66
  var caminho = __importStar(require("path"));
67
+ var readline = __importStar(require("readline"));
31
68
  var browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
32
69
  var delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
33
70
  var espaco_variaveis_1 = require("../espaco-variaveis");
@@ -48,13 +85,20 @@ var primitivas_vetor_1 = __importDefault(require("../bibliotecas/primitivas-veto
48
85
  var Interpretador = /** @class */ (function () {
49
86
  function Interpretador(importador, diretorioBase, performance, funcaoDeRetorno) {
50
87
  if (performance === void 0) { performance = false; }
88
+ if (funcaoDeRetorno === void 0) { funcaoDeRetorno = null; }
51
89
  this.funcaoDeRetorno = null;
90
+ this.interfaceDeEntrada = null;
52
91
  this.resultadoInterpretador = [];
53
92
  this.regexInterpolacao = /\$\{([a-z_][\w]*)\}/gi;
54
93
  this.importador = importador;
55
94
  this.diretorioBase = diretorioBase;
56
95
  this.performance = performance;
57
96
  this.funcaoDeRetorno = funcaoDeRetorno || console.log;
97
+ this.interfaceDeEntrada = readline.createInterface({
98
+ input: process.stdin,
99
+ output: process.stdout,
100
+ prompt: '\n> ',
101
+ });
58
102
  this.erros = [];
59
103
  this.declaracoes = [];
60
104
  this.pilhaEscoposExecucao = new pilha_escopos_execucao_1.PilhaEscoposExecucao();
@@ -69,10 +113,22 @@ var Interpretador = /** @class */ (function () {
69
113
  /**
70
114
  * Execução da leitura de valores da entrada configurada no
71
115
  * início da aplicação.
72
- * @param expressao
116
+ * @param expressao Expressão do tipo Leia
117
+ * @returns Promise com o resultado da leitura.
73
118
  */
74
119
  Interpretador.prototype.visitarExpressaoLeia = function (expressao) {
75
- throw new Error('Método não implementado.');
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var mensagem;
122
+ var _this = this;
123
+ return __generator(this, function (_a) {
124
+ mensagem = expressao.argumentos && expressao.argumentos[0] ? expressao.argumentos[0].valor : '';
125
+ return [2 /*return*/, new Promise(function (resolucao) {
126
+ return _this.interfaceDeEntrada.question(mensagem, function (resposta) {
127
+ resolucao(resposta);
128
+ });
129
+ })];
130
+ });
131
+ });
76
132
  };
77
133
  /**
78
134
  * Retira a interpolação de um texto.
@@ -119,10 +175,24 @@ var Interpretador = /** @class */ (function () {
119
175
  return expressao.valor;
120
176
  };
121
177
  Interpretador.prototype.avaliar = function (expressao) {
122
- return expressao.aceitar(this);
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0: return [4 /*yield*/, expressao.aceitar(this)];
182
+ case 1: return [2 /*return*/, _a.sent()];
183
+ }
184
+ });
185
+ });
123
186
  };
124
187
  Interpretador.prototype.visitarExpressaoAgrupamento = function (expressao) {
125
- return this.avaliar(expressao.expressao);
188
+ return __awaiter(this, void 0, void 0, function () {
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, this.avaliar(expressao.expressao)];
192
+ case 1: return [2 /*return*/, _a.sent()];
193
+ }
194
+ });
195
+ });
126
196
  };
127
197
  Interpretador.prototype.eVerdadeiro = function (objeto) {
128
198
  if (objeto === null)
@@ -132,22 +202,34 @@ var Interpretador = /** @class */ (function () {
132
202
  return true;
133
203
  };
134
204
  Interpretador.prototype.verificarOperandoNumero = function (operador, operando) {
135
- if (typeof operando === 'number')
205
+ if (typeof operando === 'number' || operando.tipo === 'número')
136
206
  return;
137
- throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', operador.linha);
207
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', Number(operador.linha));
138
208
  };
139
209
  Interpretador.prototype.visitarExpressaoUnaria = function (expressao) {
140
- var direita = this.avaliar(expressao.direita);
141
- switch (expressao.operador.tipo) {
142
- case delegua_1.default.SUBTRACAO:
143
- this.verificarOperandoNumero(expressao.operador, direita);
144
- return -direita;
145
- case delegua_1.default.NEGACAO:
146
- return !this.eVerdadeiro(direita);
147
- case delegua_1.default.BIT_NOT:
148
- return ~direita;
149
- }
150
- return null;
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ var direita, valor;
212
+ return __generator(this, function (_a) {
213
+ switch (_a.label) {
214
+ case 0: return [4 /*yield*/, this.avaliar(expressao.direita)];
215
+ case 1:
216
+ direita = _a.sent();
217
+ valor = direita.hasOwnProperty('valor') ?
218
+ direita.valor :
219
+ direita;
220
+ switch (expressao.operador.tipo) {
221
+ case delegua_1.default.SUBTRACAO:
222
+ this.verificarOperandoNumero(expressao.operador, valor);
223
+ return [2 /*return*/, -valor];
224
+ case delegua_1.default.NEGACAO:
225
+ return [2 /*return*/, !this.eVerdadeiro(valor)];
226
+ case delegua_1.default.BIT_NOT:
227
+ return [2 /*return*/, ~valor];
228
+ }
229
+ return [2 /*return*/, null];
230
+ }
231
+ });
232
+ });
151
233
  };
152
234
  Interpretador.prototype.eIgual = function (esquerda, direita) {
153
235
  if (esquerda === null && direita === null)
@@ -189,80 +271,98 @@ var Interpretador = /** @class */ (function () {
189
271
  throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
190
272
  };
191
273
  Interpretador.prototype.visitarExpressaoBinaria = function (expressao) {
192
- var esquerda = this.avaliar(expressao.esquerda);
193
- var direita = this.avaliar(expressao.direita);
194
- var valorEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('valor'))
195
- ? esquerda.valor
196
- : esquerda;
197
- var valorDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('valor'))
198
- ? direita.valor
199
- : direita;
200
- var tipoEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('tipo'))
201
- ? esquerda.tipo
202
- : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
203
- var tipoDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('tipo'))
204
- ? direita.tipo
205
- : (0, inferenciador_1.inferirTipoVariavel)(direita);
206
- switch (expressao.operador.tipo) {
207
- case delegua_1.default.EXPONENCIACAO:
208
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
209
- return Math.pow(valorEsquerdo, valorDireito);
210
- case delegua_1.default.MAIOR:
211
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
212
- return Number(valorEsquerdo) > Number(valorDireito);
213
- case delegua_1.default.MAIOR_IGUAL:
214
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
215
- return Number(valorEsquerdo) >= Number(valorDireito);
216
- case delegua_1.default.MENOR:
217
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
218
- return Number(valorEsquerdo) < Number(valorDireito);
219
- case delegua_1.default.MENOR_IGUAL:
220
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
221
- return Number(valorEsquerdo) <= Number(valorDireito);
222
- case delegua_1.default.SUBTRACAO:
223
- case delegua_1.default.MENOS_IGUAL:
224
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
225
- return Number(valorEsquerdo) - Number(valorDireito);
226
- case delegua_1.default.ADICAO:
227
- case delegua_1.default.MAIS_IGUAL:
228
- if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
229
- return Number(valorEsquerdo) + Number(valorDireito);
230
- }
231
- else {
232
- return String(valorEsquerdo) + String(valorDireito);
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ var esquerda, direita, valorEsquerdo, valorDireito, tipoEsquerdo, tipoDireito, erro_1;
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0:
279
+ _a.trys.push([0, 3, , 4]);
280
+ return [4 /*yield*/, this.avaliar(expressao.esquerda)];
281
+ case 1:
282
+ esquerda = _a.sent();
283
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
284
+ case 2:
285
+ direita = _a.sent();
286
+ valorEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('valor'))
287
+ ? esquerda.valor
288
+ : esquerda;
289
+ valorDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('valor'))
290
+ ? direita.valor
291
+ : direita;
292
+ tipoEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('tipo'))
293
+ ? esquerda.tipo
294
+ : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
295
+ tipoDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('tipo'))
296
+ ? direita.tipo
297
+ : (0, inferenciador_1.inferirTipoVariavel)(direita);
298
+ switch (expressao.operador.tipo) {
299
+ case delegua_1.default.EXPONENCIACAO:
300
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
301
+ return [2 /*return*/, Math.pow(valorEsquerdo, valorDireito)];
302
+ case delegua_1.default.MAIOR:
303
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
304
+ return [2 /*return*/, Number(valorEsquerdo) > Number(valorDireito)];
305
+ case delegua_1.default.MAIOR_IGUAL:
306
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
307
+ return [2 /*return*/, Number(valorEsquerdo) >= Number(valorDireito)];
308
+ case delegua_1.default.MENOR:
309
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
310
+ return [2 /*return*/, Number(valorEsquerdo) < Number(valorDireito)];
311
+ case delegua_1.default.MENOR_IGUAL:
312
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
313
+ return [2 /*return*/, Number(valorEsquerdo) <= Number(valorDireito)];
314
+ case delegua_1.default.SUBTRACAO:
315
+ case delegua_1.default.MENOS_IGUAL:
316
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
317
+ return [2 /*return*/, Number(valorEsquerdo) - Number(valorDireito)];
318
+ case delegua_1.default.ADICAO:
319
+ case delegua_1.default.MAIS_IGUAL:
320
+ if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
321
+ return [2 /*return*/, Number(valorEsquerdo) + Number(valorDireito)];
322
+ }
323
+ else {
324
+ return [2 /*return*/, String(valorEsquerdo) + String(valorDireito)];
325
+ }
326
+ case delegua_1.default.DIVISAO:
327
+ case delegua_1.default.DIVISAO_IGUAL:
328
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
329
+ return [2 /*return*/, Number(valorEsquerdo) / Number(valorDireito)];
330
+ case delegua_1.default.MULTIPLICACAO:
331
+ case delegua_1.default.MULTIPLICACAO_IGUAL:
332
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
333
+ return [2 /*return*/, Number(valorEsquerdo) * Number(valorDireito)];
334
+ case delegua_1.default.MODULO:
335
+ case delegua_1.default.MODULO_IGUAL:
336
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
337
+ return [2 /*return*/, Number(valorEsquerdo) % Number(valorDireito)];
338
+ case delegua_1.default.BIT_AND:
339
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
340
+ return [2 /*return*/, Number(valorEsquerdo) & Number(valorDireito)];
341
+ case delegua_1.default.BIT_XOR:
342
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
343
+ return [2 /*return*/, Number(valorEsquerdo) ^ Number(valorDireito)];
344
+ case delegua_1.default.BIT_OR:
345
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
346
+ return [2 /*return*/, Number(valorEsquerdo) | Number(valorDireito)];
347
+ case delegua_1.default.MENOR_MENOR:
348
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
349
+ return [2 /*return*/, Number(valorEsquerdo) << Number(valorDireito)];
350
+ case delegua_1.default.MAIOR_MAIOR:
351
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
352
+ return [2 /*return*/, Number(valorEsquerdo) >> Number(valorDireito)];
353
+ case delegua_1.default.DIFERENTE:
354
+ return [2 /*return*/, !this.eIgual(valorEsquerdo, valorDireito)];
355
+ case delegua_1.default.IGUAL_IGUAL:
356
+ return [2 /*return*/, this.eIgual(valorEsquerdo, valorDireito)];
357
+ }
358
+ return [3 /*break*/, 4];
359
+ case 3:
360
+ erro_1 = _a.sent();
361
+ return [2 /*return*/, Promise.reject(erro_1)];
362
+ case 4: return [2 /*return*/];
233
363
  }
234
- case delegua_1.default.DIVISAO:
235
- case delegua_1.default.DIVISAO_IGUAL:
236
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
237
- return Number(valorEsquerdo) / Number(valorDireito);
238
- case delegua_1.default.MULTIPLICACAO:
239
- case delegua_1.default.MULTIPLICACAO_IGUAL:
240
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
241
- return Number(valorEsquerdo) * Number(valorDireito);
242
- case delegua_1.default.MODULO:
243
- case delegua_1.default.MODULO_IGUAL:
244
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
245
- return Number(valorEsquerdo) % Number(valorDireito);
246
- case delegua_1.default.BIT_AND:
247
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
248
- return Number(valorEsquerdo) & Number(valorDireito);
249
- case delegua_1.default.BIT_XOR:
250
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
251
- return Number(valorEsquerdo) ^ Number(valorDireito);
252
- case delegua_1.default.BIT_OR:
253
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
254
- return Number(valorEsquerdo) | Number(valorDireito);
255
- case delegua_1.default.MENOR_MENOR:
256
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
257
- return Number(valorEsquerdo) << Number(valorDireito);
258
- case delegua_1.default.MAIOR_MAIOR:
259
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
260
- return Number(valorEsquerdo) >> Number(valorDireito);
261
- case delegua_1.default.DIFERENTE:
262
- return !this.eIgual(valorEsquerdo, valorDireito);
263
- case delegua_1.default.IGUAL_IGUAL:
264
- return this.eIgual(valorEsquerdo, valorDireito);
265
- }
364
+ });
365
+ });
266
366
  };
267
367
  /**
268
368
  * Executa uma chamada de função, método ou classe.
@@ -270,65 +370,99 @@ var Interpretador = /** @class */ (function () {
270
370
  * @returns O resultado da chamada.
271
371
  */
272
372
  Interpretador.prototype.visitarExpressaoDeChamada = function (expressao) {
273
- var variavelEntidadeChamada = this.avaliar(expressao.entidadeChamada);
274
- var entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
275
- ? variavelEntidadeChamada.valor
276
- : variavelEntidadeChamada;
277
- var argumentos = [];
278
- for (var i = 0; i < expressao.argumentos.length; i++) {
279
- argumentos.push(this.avaliar(expressao.argumentos[i]));
280
- }
281
- if (!(entidadeChamada instanceof estruturas_1.Chamavel)) {
282
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
283
- }
284
- if (entidadeChamada instanceof metodo_primitiva_1.MetodoPrimitiva) {
285
- var argumentosResolvidos = [];
286
- for (var _i = 0, _a = expressao.argumentos; _i < _a.length; _i++) {
287
- var argumento = _a[_i];
288
- var valorResolvido = this.avaliar(argumento);
289
- argumentosResolvidos.push(valorResolvido.hasOwnProperty('valor')
290
- ? valorResolvido.valor
291
- : valorResolvido);
292
- }
293
- return entidadeChamada.chamar(argumentosResolvidos);
294
- }
295
- var parametros;
296
- if (entidadeChamada instanceof estruturas_1.DeleguaFuncao) {
297
- parametros = entidadeChamada.declaracao.parametros;
298
- }
299
- else if (entidadeChamada instanceof estruturas_1.DeleguaClasse) {
300
- parametros = entidadeChamada.metodos.inicializacao
301
- ? entidadeChamada.metodos.inicializacao.declaracao.parametros
302
- : [];
303
- }
304
- else {
305
- parametros = [];
306
- }
307
- // Completar os parâmetros não preenchidos com nulos.
308
- if (argumentos.length < entidadeChamada.aridade()) {
309
- var diferenca = entidadeChamada.aridade() - argumentos.length;
310
- for (var i = 0; i < diferenca; i++) {
311
- argumentos.push(null);
312
- }
313
- }
314
- else {
315
- if (parametros &&
316
- parametros.length > 0 &&
317
- parametros[parametros.length - 1].tipo === 'estrela') {
318
- var novosArgumentos = argumentos.slice(0, parametros.length - 1);
319
- novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
320
- argumentos = novosArgumentos;
321
- }
322
- }
323
- if (entidadeChamada instanceof estruturas_1.FuncaoPadrao) {
324
- try {
325
- return entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome);
326
- }
327
- catch (erro) {
328
- this.erros.push(erro);
329
- }
330
- }
331
- return entidadeChamada.chamar(this, argumentos);
373
+ return __awaiter(this, void 0, void 0, function () {
374
+ var variavelEntidadeChamada, entidadeChamada, argumentos, i, _a, _b, argumentosResolvidos, _i, _c, argumento, valorResolvido, parametros, diferenca, i, novosArgumentos, erro_2;
375
+ return __generator(this, function (_d) {
376
+ switch (_d.label) {
377
+ case 0:
378
+ _d.trys.push([0, 11, , 12]);
379
+ return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
380
+ case 1:
381
+ variavelEntidadeChamada = _d.sent();
382
+ entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
383
+ ? variavelEntidadeChamada.valor
384
+ : variavelEntidadeChamada;
385
+ argumentos = [];
386
+ i = 0;
387
+ _d.label = 2;
388
+ case 2:
389
+ if (!(i < expressao.argumentos.length)) return [3 /*break*/, 5];
390
+ _b = (_a = argumentos).push;
391
+ return [4 /*yield*/, this.avaliar(expressao.argumentos[i])];
392
+ case 3:
393
+ _b.apply(_a, [_d.sent()]);
394
+ _d.label = 4;
395
+ case 4:
396
+ i++;
397
+ return [3 /*break*/, 2];
398
+ case 5:
399
+ if (!(entidadeChamada instanceof estruturas_1.Chamavel)) {
400
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
401
+ }
402
+ if (!(entidadeChamada instanceof metodo_primitiva_1.MetodoPrimitiva)) return [3 /*break*/, 10];
403
+ argumentosResolvidos = [];
404
+ _i = 0, _c = expressao.argumentos;
405
+ _d.label = 6;
406
+ case 6:
407
+ if (!(_i < _c.length)) return [3 /*break*/, 9];
408
+ argumento = _c[_i];
409
+ return [4 /*yield*/, this.avaliar(argumento)];
410
+ case 7:
411
+ valorResolvido = _d.sent();
412
+ argumentosResolvidos.push(valorResolvido.hasOwnProperty('valor')
413
+ ? valorResolvido.valor
414
+ : valorResolvido);
415
+ _d.label = 8;
416
+ case 8:
417
+ _i++;
418
+ return [3 /*break*/, 6];
419
+ case 9: return [2 /*return*/, entidadeChamada.chamar(argumentosResolvidos)];
420
+ case 10:
421
+ parametros = void 0;
422
+ if (entidadeChamada instanceof estruturas_1.DeleguaFuncao) {
423
+ parametros = entidadeChamada.declaracao.parametros;
424
+ }
425
+ else if (entidadeChamada instanceof estruturas_1.DeleguaClasse) {
426
+ parametros = entidadeChamada.metodos.inicializacao
427
+ ? entidadeChamada.metodos.inicializacao.declaracao.parametros
428
+ : [];
429
+ }
430
+ else {
431
+ parametros = [];
432
+ }
433
+ // Completar os parâmetros não preenchidos com nulos.
434
+ if (argumentos.length < entidadeChamada.aridade()) {
435
+ diferenca = entidadeChamada.aridade() - argumentos.length;
436
+ for (i = 0; i < diferenca; i++) {
437
+ argumentos.push(null);
438
+ }
439
+ }
440
+ else {
441
+ if (parametros &&
442
+ parametros.length > 0 &&
443
+ parametros[parametros.length - 1].tipo === 'estrela') {
444
+ novosArgumentos = argumentos.slice(0, parametros.length - 1);
445
+ novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
446
+ argumentos = novosArgumentos;
447
+ }
448
+ }
449
+ if (entidadeChamada instanceof estruturas_1.FuncaoPadrao) {
450
+ try {
451
+ return [2 /*return*/, entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome)];
452
+ }
453
+ catch (erro) {
454
+ this.erros.push(erro);
455
+ }
456
+ }
457
+ return [2 /*return*/, entidadeChamada.chamar(this, argumentos)];
458
+ case 11:
459
+ erro_2 = _d.sent();
460
+ console.log(erro_2);
461
+ return [3 /*break*/, 12];
462
+ case 12: return [2 /*return*/];
463
+ }
464
+ });
465
+ });
332
466
  };
333
467
  /**
334
468
  * Execução de uma expressão de atribuição.
@@ -336,9 +470,18 @@ var Interpretador = /** @class */ (function () {
336
470
  * @returns O valor atribuído.
337
471
  */
338
472
  Interpretador.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
339
- var valor = this.avaliar(expressao.valor);
340
- this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
341
- return valor;
473
+ return __awaiter(this, void 0, void 0, function () {
474
+ var valor;
475
+ return __generator(this, function (_a) {
476
+ switch (_a.label) {
477
+ case 0: return [4 /*yield*/, this.avaliar(expressao.valor)];
478
+ case 1:
479
+ valor = _a.sent();
480
+ this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
481
+ return [2 /*return*/, valor];
482
+ }
483
+ });
484
+ });
342
485
  };
343
486
  Interpretador.prototype.procurarVariavel = function (simbolo) {
344
487
  return this.pilhaEscoposExecucao.obterVariavel(simbolo);
@@ -347,33 +490,53 @@ var Interpretador = /** @class */ (function () {
347
490
  return this.procurarVariavel(expressao.simbolo);
348
491
  };
349
492
  Interpretador.prototype.visitarDeclaracaoDeExpressao = function (declaracao) {
350
- return this.avaliar(declaracao.expressao);
493
+ return __awaiter(this, void 0, void 0, function () {
494
+ return __generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.expressao)];
497
+ case 1: return [2 /*return*/, _a.sent()];
498
+ }
499
+ });
500
+ });
351
501
  };
352
502
  Interpretador.prototype.visitarExpressaoLogica = function (expressao) {
353
- var esquerda = this.avaliar(expressao.esquerda);
354
- if (expressao.operador.tipo === delegua_1.default.EM) {
355
- var direita = this.avaliar(expressao.direita);
356
- if (Array.isArray(direita) || typeof direita === 'string') {
357
- return direita.includes(esquerda);
358
- }
359
- else if (direita.constructor === Object) {
360
- return esquerda in direita;
361
- }
362
- else {
363
- throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
364
- }
365
- }
366
- // se um estado for verdadeiro, retorna verdadeiro
367
- if (expressao.operador.tipo === delegua_1.default.OU) {
368
- if (this.eVerdadeiro(esquerda))
369
- return esquerda;
370
- }
371
- // se um estado for falso, retorna falso
372
- if (expressao.operador.tipo === delegua_1.default.E) {
373
- if (!this.eVerdadeiro(esquerda))
374
- return esquerda;
375
- }
376
- return this.avaliar(expressao.direita);
503
+ return __awaiter(this, void 0, void 0, function () {
504
+ var esquerda, direita;
505
+ return __generator(this, function (_a) {
506
+ switch (_a.label) {
507
+ case 0: return [4 /*yield*/, this.avaliar(expressao.esquerda)];
508
+ case 1:
509
+ esquerda = _a.sent();
510
+ if (!(expressao.operador.tipo === delegua_1.default.EM)) return [3 /*break*/, 3];
511
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
512
+ case 2:
513
+ direita = _a.sent();
514
+ if (Array.isArray(direita) || typeof direita === 'string') {
515
+ return [2 /*return*/, direita.includes(esquerda)];
516
+ }
517
+ else if (direita.constructor === Object) {
518
+ return [2 /*return*/, esquerda in direita];
519
+ }
520
+ else {
521
+ throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
522
+ }
523
+ _a.label = 3;
524
+ case 3:
525
+ // se um estado for verdadeiro, retorna verdadeiro
526
+ if (expressao.operador.tipo === delegua_1.default.OU) {
527
+ if (this.eVerdadeiro(esquerda))
528
+ return [2 /*return*/, esquerda];
529
+ }
530
+ // se um estado for falso, retorna falso
531
+ if (expressao.operador.tipo === delegua_1.default.E) {
532
+ if (!this.eVerdadeiro(esquerda))
533
+ return [2 /*return*/, esquerda];
534
+ }
535
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
536
+ case 4: return [2 /*return*/, _a.sent()];
537
+ }
538
+ });
539
+ });
377
540
  };
378
541
  /**
379
542
  * Executa uma expressão Se, que tem uma condição, pode ter um bloco
@@ -382,146 +545,288 @@ var Interpretador = /** @class */ (function () {
382
545
  * @returns O resultado da avaliação do bloco cuja condição é verdadeira.
383
546
  */
384
547
  Interpretador.prototype.visitarExpressaoSe = function (declaracao) {
385
- if (this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
386
- return this.executar(declaracao.caminhoEntao);
387
- }
388
- for (var i = 0; i < declaracao.caminhosSeSenao.length; i++) {
389
- var atual = declaracao.caminhosSeSenao[i];
390
- if (this.eVerdadeiro(this.avaliar(atual.condicao))) {
391
- return this.executar(atual.caminho);
392
- }
393
- }
394
- if (declaracao.caminhoSenao !== null) {
395
- return this.executar(declaracao.caminhoSenao);
396
- }
397
- return null;
548
+ return __awaiter(this, void 0, void 0, function () {
549
+ var _a, i, atual, _b;
550
+ return __generator(this, function (_c) {
551
+ switch (_c.label) {
552
+ case 0:
553
+ _a = this.eVerdadeiro;
554
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
555
+ case 1:
556
+ if (!_a.apply(this, [_c.sent()])) return [3 /*break*/, 3];
557
+ return [4 /*yield*/, this.executar(declaracao.caminhoEntao)];
558
+ case 2: return [2 /*return*/, _c.sent()];
559
+ case 3:
560
+ i = 0;
561
+ _c.label = 4;
562
+ case 4:
563
+ if (!(i < declaracao.caminhosSeSenao.length)) return [3 /*break*/, 8];
564
+ atual = declaracao.caminhosSeSenao[i];
565
+ _b = this.eVerdadeiro;
566
+ return [4 /*yield*/, this.avaliar(atual.condicao)];
567
+ case 5:
568
+ if (!_b.apply(this, [_c.sent()])) return [3 /*break*/, 7];
569
+ return [4 /*yield*/, this.executar(atual.caminho)];
570
+ case 6: return [2 /*return*/, _c.sent()];
571
+ case 7:
572
+ i++;
573
+ return [3 /*break*/, 4];
574
+ case 8:
575
+ if (!(declaracao.caminhoSenao !== null)) return [3 /*break*/, 10];
576
+ return [4 /*yield*/, this.executar(declaracao.caminhoSenao)];
577
+ case 9: return [2 /*return*/, _c.sent()];
578
+ case 10: return [2 /*return*/, null];
579
+ }
580
+ });
581
+ });
398
582
  };
399
583
  Interpretador.prototype.visitarExpressaoPara = function (declaracao) {
400
- if (declaracao.inicializador !== null) {
401
- this.avaliar(declaracao.inicializador);
402
- }
403
- var retornoExecucao;
404
- while (!(retornoExecucao instanceof quebras_1.Quebra)) {
405
- if (declaracao.condicao !== null &&
406
- !this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
407
- break;
408
- }
409
- try {
410
- retornoExecucao = this.executar(declaracao.corpo);
411
- }
412
- catch (erro) {
413
- throw erro;
414
- }
415
- if (declaracao.incrementar !== null) {
416
- this.avaliar(declaracao.incrementar);
417
- }
418
- }
419
- return null;
584
+ return __awaiter(this, void 0, void 0, function () {
585
+ var retornoExecucao, _a, _b, erro_3;
586
+ return __generator(this, function (_c) {
587
+ switch (_c.label) {
588
+ case 0:
589
+ if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
590
+ return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
591
+ case 1:
592
+ _c.sent();
593
+ _c.label = 2;
594
+ case 2:
595
+ if (!!(retornoExecucao instanceof quebras_1.Quebra)) return [3 /*break*/, 11];
596
+ _a = declaracao.condicao !== null;
597
+ if (!_a) return [3 /*break*/, 4];
598
+ _b = this.eVerdadeiro;
599
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
600
+ case 3:
601
+ _a = !_b.apply(this, [_c.sent()]);
602
+ _c.label = 4;
603
+ case 4:
604
+ if (_a) {
605
+ return [3 /*break*/, 11];
606
+ }
607
+ _c.label = 5;
608
+ case 5:
609
+ _c.trys.push([5, 7, , 8]);
610
+ return [4 /*yield*/, this.executar(declaracao.corpo)];
611
+ case 6:
612
+ retornoExecucao = _c.sent();
613
+ return [3 /*break*/, 8];
614
+ case 7:
615
+ erro_3 = _c.sent();
616
+ throw erro_3;
617
+ case 8:
618
+ if (!(declaracao.incrementar !== null)) return [3 /*break*/, 10];
619
+ return [4 /*yield*/, this.avaliar(declaracao.incrementar)];
620
+ case 9:
621
+ _c.sent();
622
+ _c.label = 10;
623
+ case 10: return [3 /*break*/, 2];
624
+ case 11: return [2 /*return*/, null];
625
+ }
626
+ });
627
+ });
420
628
  };
421
629
  Interpretador.prototype.visitarExpressaoFazer = function (declaracao) {
422
- var retornoExecucao;
423
- do {
424
- try {
425
- retornoExecucao = this.executar(declaracao.caminhoFazer);
426
- }
427
- catch (erro) {
428
- throw erro;
429
- }
430
- } while (!(retornoExecucao instanceof quebras_1.Quebra) &&
431
- this.eVerdadeiro(this.avaliar(declaracao.condicaoEnquanto)));
630
+ return __awaiter(this, void 0, void 0, function () {
631
+ var retornoExecucao, erro_4, _a, _b;
632
+ return __generator(this, function (_c) {
633
+ switch (_c.label) {
634
+ case 0:
635
+ _c.trys.push([0, 2, , 3]);
636
+ return [4 /*yield*/, this.executar(declaracao.caminhoFazer)];
637
+ case 1:
638
+ retornoExecucao = _c.sent();
639
+ return [3 /*break*/, 3];
640
+ case 2:
641
+ erro_4 = _c.sent();
642
+ throw erro_4;
643
+ case 3:
644
+ _a = !(retornoExecucao instanceof quebras_1.Quebra);
645
+ if (!_a) return [3 /*break*/, 5];
646
+ _b = this.eVerdadeiro;
647
+ return [4 /*yield*/, this.avaliar(declaracao.condicaoEnquanto)];
648
+ case 4:
649
+ _a = _b.apply(this, [_c.sent()]);
650
+ _c.label = 5;
651
+ case 5:
652
+ if (_a) return [3 /*break*/, 0];
653
+ _c.label = 6;
654
+ case 6: return [2 /*return*/];
655
+ }
656
+ });
657
+ });
432
658
  };
433
659
  Interpretador.prototype.visitarExpressaoEscolha = function (declaracao) {
434
- var condicaoEscolha = this.avaliar(declaracao.identificadorOuLiteral);
435
- var caminhos = declaracao.caminhos;
436
- var caminhoPadrao = declaracao.caminhoPadrao;
437
- var encontrado = false;
438
- try {
439
- for (var i = 0; i < caminhos.length; i++) {
440
- var caminho_1 = caminhos[i];
441
- for (var j = 0; j < caminho_1.condicoes.length; j++) {
442
- if (this.avaliar(caminho_1.condicoes[j]) === condicaoEscolha) {
660
+ return __awaiter(this, void 0, void 0, function () {
661
+ var condicaoEscolha, caminhos, caminhoPadrao, encontrado, i, caminho_1, j, erro_5, erro_6;
662
+ return __generator(this, function (_a) {
663
+ switch (_a.label) {
664
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.identificadorOuLiteral)];
665
+ case 1:
666
+ condicaoEscolha = _a.sent();
667
+ caminhos = declaracao.caminhos;
668
+ caminhoPadrao = declaracao.caminhoPadrao;
669
+ encontrado = false;
670
+ _a.label = 2;
671
+ case 2:
672
+ _a.trys.push([2, 14, , 15]);
673
+ i = 0;
674
+ _a.label = 3;
675
+ case 3:
676
+ if (!(i < caminhos.length)) return [3 /*break*/, 11];
677
+ caminho_1 = caminhos[i];
678
+ j = 0;
679
+ _a.label = 4;
680
+ case 4:
681
+ if (!(j < caminho_1.condicoes.length)) return [3 /*break*/, 10];
682
+ return [4 /*yield*/, this.avaliar(caminho_1.condicoes[j])];
683
+ case 5:
684
+ if (!((_a.sent()) === condicaoEscolha)) return [3 /*break*/, 9];
443
685
  encontrado = true;
444
- try {
445
- this.executarBloco(caminho_1.declaracoes);
446
- }
447
- catch (erro) {
448
- throw erro;
449
- }
450
- }
686
+ _a.label = 6;
687
+ case 6:
688
+ _a.trys.push([6, 8, , 9]);
689
+ return [4 /*yield*/, this.executarBloco(caminho_1.declaracoes)];
690
+ case 7:
691
+ _a.sent();
692
+ return [3 /*break*/, 9];
693
+ case 8:
694
+ erro_5 = _a.sent();
695
+ throw erro_5;
696
+ case 9:
697
+ j++;
698
+ return [3 /*break*/, 4];
699
+ case 10:
700
+ i++;
701
+ return [3 /*break*/, 3];
702
+ case 11:
703
+ if (!(caminhoPadrao !== null && encontrado === false)) return [3 /*break*/, 13];
704
+ return [4 /*yield*/, this.executarBloco(caminhoPadrao.declaracoes)];
705
+ case 12:
706
+ _a.sent();
707
+ _a.label = 13;
708
+ case 13: return [3 /*break*/, 15];
709
+ case 14:
710
+ erro_6 = _a.sent();
711
+ throw erro_6;
712
+ case 15: return [2 /*return*/];
451
713
  }
452
- }
453
- if (caminhoPadrao !== null && encontrado === false) {
454
- this.executarBloco(caminhoPadrao.declaracoes);
455
- }
456
- }
457
- catch (erro) {
458
- throw erro;
459
- }
714
+ });
715
+ });
460
716
  };
461
717
  Interpretador.prototype.visitarExpressaoTente = function (declaracao) {
462
- try {
463
- var sucesso = true;
464
- try {
465
- this.executarBloco(declaracao.caminhoTente);
466
- }
467
- catch (erro) {
468
- sucesso = false;
469
- if (declaracao.caminhoPegue !== null) {
470
- this.executarBloco(declaracao.caminhoPegue);
471
- }
472
- else {
473
- this.erros.push(erro);
718
+ return __awaiter(this, void 0, void 0, function () {
719
+ var sucesso, erro_7;
720
+ return __generator(this, function (_a) {
721
+ switch (_a.label) {
722
+ case 0:
723
+ _a.trys.push([0, , 10, 13]);
724
+ sucesso = true;
725
+ _a.label = 1;
726
+ case 1:
727
+ _a.trys.push([1, 3, , 7]);
728
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoTente)];
729
+ case 2:
730
+ _a.sent();
731
+ return [3 /*break*/, 7];
732
+ case 3:
733
+ erro_7 = _a.sent();
734
+ sucesso = false;
735
+ if (!(declaracao.caminhoPegue !== null)) return [3 /*break*/, 5];
736
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoPegue)];
737
+ case 4:
738
+ _a.sent();
739
+ return [3 /*break*/, 6];
740
+ case 5:
741
+ this.erros.push(erro_7);
742
+ _a.label = 6;
743
+ case 6: return [3 /*break*/, 7];
744
+ case 7:
745
+ if (!(sucesso && declaracao.caminhoSenao !== null)) return [3 /*break*/, 9];
746
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoSenao)];
747
+ case 8:
748
+ _a.sent();
749
+ _a.label = 9;
750
+ case 9: return [3 /*break*/, 13];
751
+ case 10:
752
+ if (!(declaracao.caminhoFinalmente !== null)) return [3 /*break*/, 12];
753
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoFinalmente)];
754
+ case 11:
755
+ _a.sent();
756
+ _a.label = 12;
757
+ case 12: return [7 /*endfinally*/];
758
+ case 13: return [2 /*return*/];
474
759
  }
475
- }
476
- if (sucesso && declaracao.caminhoSenao !== null) {
477
- this.executarBloco(declaracao.caminhoSenao);
478
- }
479
- }
480
- finally {
481
- if (declaracao.caminhoFinalmente !== null)
482
- this.executarBloco(declaracao.caminhoFinalmente);
483
- }
760
+ });
761
+ });
484
762
  };
485
763
  Interpretador.prototype.visitarExpressaoEnquanto = function (declaracao) {
486
- var retornoExecucao;
487
- while (!(retornoExecucao instanceof quebras_1.Quebra) &&
488
- this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
489
- try {
490
- retornoExecucao = this.executar(declaracao.corpo);
491
- }
492
- catch (erro) {
493
- throw erro;
494
- }
495
- }
496
- return null;
764
+ return __awaiter(this, void 0, void 0, function () {
765
+ var retornoExecucao, _a, _b, erro_8;
766
+ return __generator(this, function (_c) {
767
+ switch (_c.label) {
768
+ case 0:
769
+ _a = !(retornoExecucao instanceof quebras_1.Quebra);
770
+ if (!_a) return [3 /*break*/, 2];
771
+ _b = this.eVerdadeiro;
772
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
773
+ case 1:
774
+ _a = _b.apply(this, [_c.sent()]);
775
+ _c.label = 2;
776
+ case 2:
777
+ if (!_a) return [3 /*break*/, 7];
778
+ _c.label = 3;
779
+ case 3:
780
+ _c.trys.push([3, 5, , 6]);
781
+ return [4 /*yield*/, this.executar(declaracao.corpo)];
782
+ case 4:
783
+ retornoExecucao = _c.sent();
784
+ return [3 /*break*/, 6];
785
+ case 5:
786
+ erro_8 = _c.sent();
787
+ throw erro_8;
788
+ case 6: return [3 /*break*/, 0];
789
+ case 7: return [2 /*return*/, null];
790
+ }
791
+ });
792
+ });
497
793
  };
498
794
  Interpretador.prototype.visitarExpressaoImportar = function (declaracao) {
499
- var caminhoRelativo = this.avaliar(declaracao.caminho);
500
- var caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
501
- var nomeArquivo = caminho.basename(caminhoTotal);
502
- if (!caminhoTotal.endsWith('.egua') &&
503
- !caminhoTotal.endsWith('.delegua')) {
504
- try {
505
- return (0, importar_biblioteca_1.default)(caminhoRelativo);
506
- }
507
- catch (erro) {
508
- this.erros.push(erro);
509
- return null;
510
- }
511
- }
512
- var conteudoImportacao = this.importador.importar(caminhoRelativo);
513
- var retornoInterpretador = this.interpretar(conteudoImportacao.retornoAvaliadorSintatico.declaracoes, true);
514
- var funcoesChamaveis = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
515
- var eDicionario = function (objeto) { return objeto.constructor === Object; };
516
- if (eDicionario(funcoesChamaveis)) {
517
- var novoModulo = new estruturas_1.DeleguaModulo();
518
- var chaves = Object.keys(funcoesChamaveis);
519
- for (var i = 0; i < chaves.length; i++) {
520
- novoModulo.componentes[chaves[i]] = funcoesChamaveis[chaves[i]];
521
- }
522
- return novoModulo;
523
- }
524
- return funcoesChamaveis;
795
+ return __awaiter(this, void 0, void 0, function () {
796
+ var caminhoRelativo, caminhoTotal, nomeArquivo, conteudoImportacao, retornoInterpretador, funcoesChamaveis, eDicionario, novoModulo, chaves, i;
797
+ return __generator(this, function (_a) {
798
+ switch (_a.label) {
799
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.caminho)];
800
+ case 1:
801
+ caminhoRelativo = _a.sent();
802
+ caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
803
+ nomeArquivo = caminho.basename(caminhoTotal);
804
+ if (!caminhoTotal.endsWith('.egua') &&
805
+ !caminhoTotal.endsWith('.delegua')) {
806
+ try {
807
+ return [2 /*return*/, (0, importar_biblioteca_1.default)(caminhoRelativo)];
808
+ }
809
+ catch (erro) {
810
+ this.erros.push(erro);
811
+ return [2 /*return*/, null];
812
+ }
813
+ }
814
+ conteudoImportacao = this.importador.importar(caminhoRelativo);
815
+ retornoInterpretador = this.interpretar(conteudoImportacao.retornoAvaliadorSintatico.declaracoes, true);
816
+ funcoesChamaveis = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
817
+ eDicionario = function (objeto) { return objeto.constructor === Object; };
818
+ if (eDicionario(funcoesChamaveis)) {
819
+ novoModulo = new estruturas_1.DeleguaModulo();
820
+ chaves = Object.keys(funcoesChamaveis);
821
+ for (i = 0; i < chaves.length; i++) {
822
+ novoModulo.componentes[chaves[i]] = funcoesChamaveis[chaves[i]];
823
+ }
824
+ return [2 /*return*/, novoModulo];
825
+ }
826
+ return [2 /*return*/, funcoesChamaveis];
827
+ }
828
+ });
829
+ });
525
830
  };
526
831
  /**
527
832
  * Execução de uma escrita na saída configurada, que pode ser `console` (padrão) ou
@@ -530,24 +835,42 @@ var Interpretador = /** @class */ (function () {
530
835
  * @returns Sempre nulo, por convenção de visita.
531
836
  */
532
837
  Interpretador.prototype.visitarExpressaoEscreva = function (declaracao) {
533
- try {
534
- var valor = void 0;
535
- for (var _i = 0, _a = declaracao.argumentos; _i < _a.length; _i++) {
536
- var argumento = _a[_i];
537
- var resultadoAvaliacao = this.avaliar(argumento);
538
- valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor'))
539
- ? resultadoAvaliacao.valor
540
- : resultadoAvaliacao;
541
- }
542
- var formatoTexto = this.paraTexto(valor);
543
- // Por enquanto `escreva` não devolve resultado no interpretador.
544
- // this.resultadoInterpretador.push(formatoTexto);
545
- this.funcaoDeRetorno(formatoTexto);
546
- return null;
547
- }
548
- catch (erro) {
549
- this.erros.push(erro);
550
- }
838
+ return __awaiter(this, void 0, void 0, function () {
839
+ var valor, _i, _a, argumento, resultadoAvaliacao, formatoTexto, erro_9;
840
+ return __generator(this, function (_b) {
841
+ switch (_b.label) {
842
+ case 0:
843
+ _b.trys.push([0, 5, , 6]);
844
+ valor = void 0;
845
+ _i = 0, _a = declaracao.argumentos;
846
+ _b.label = 1;
847
+ case 1:
848
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
849
+ argumento = _a[_i];
850
+ return [4 /*yield*/, this.avaliar(argumento)];
851
+ case 2:
852
+ resultadoAvaliacao = _b.sent();
853
+ valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor'))
854
+ ? resultadoAvaliacao.valor
855
+ : resultadoAvaliacao;
856
+ _b.label = 3;
857
+ case 3:
858
+ _i++;
859
+ return [3 /*break*/, 1];
860
+ case 4:
861
+ formatoTexto = this.paraTexto(valor);
862
+ // Por enquanto `escreva` não devolve resultado no interpretador.
863
+ // this.resultadoInterpretador.push(formatoTexto);
864
+ this.funcaoDeRetorno(formatoTexto);
865
+ return [2 /*return*/, null];
866
+ case 5:
867
+ erro_9 = _b.sent();
868
+ this.erros.push(erro_9);
869
+ return [3 /*break*/, 6];
870
+ case 6: return [2 /*return*/];
871
+ }
872
+ });
873
+ });
551
874
  };
552
875
  /**
553
876
  * Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
@@ -559,20 +882,37 @@ var Interpretador = /** @class */ (function () {
559
882
  * @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
560
883
  */
561
884
  Interpretador.prototype.executarBloco = function (declaracoes, ambiente) {
562
- var escopoExecucao = {
563
- declaracoes: declaracoes,
564
- declaracaoAtual: 0,
565
- ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
566
- };
567
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
568
- var retornoUltimoEscopo = this.executarUltimoEscopo();
569
- if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
570
- throw retornoUltimoEscopo;
571
- }
572
- return retornoUltimoEscopo;
885
+ return __awaiter(this, void 0, void 0, function () {
886
+ var escopoExecucao, retornoUltimoEscopo;
887
+ return __generator(this, function (_a) {
888
+ switch (_a.label) {
889
+ case 0:
890
+ escopoExecucao = {
891
+ declaracoes: declaracoes,
892
+ declaracaoAtual: 0,
893
+ ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
894
+ };
895
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
896
+ return [4 /*yield*/, this.executarUltimoEscopo()];
897
+ case 1:
898
+ retornoUltimoEscopo = _a.sent();
899
+ if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
900
+ throw retornoUltimoEscopo;
901
+ }
902
+ return [2 /*return*/, retornoUltimoEscopo];
903
+ }
904
+ });
905
+ });
573
906
  };
574
907
  Interpretador.prototype.visitarExpressaoBloco = function (declaracao) {
575
- return this.executarBloco(declaracao.declaracoes);
908
+ return __awaiter(this, void 0, void 0, function () {
909
+ return __generator(this, function (_a) {
910
+ switch (_a.label) {
911
+ case 0: return [4 /*yield*/, this.executarBloco(declaracao.declaracoes)];
912
+ case 1: return [2 /*return*/, _a.sent()];
913
+ }
914
+ });
915
+ });
576
916
  };
577
917
  /**
578
918
  * Executa expressão de definição de variável.
@@ -580,14 +920,25 @@ var Interpretador = /** @class */ (function () {
580
920
  * @returns Sempre retorna nulo.
581
921
  */
582
922
  Interpretador.prototype.visitarExpressaoVar = function (declaracao) {
583
- var valorOuOutraVariavel = null;
584
- if (declaracao.inicializador !== null) {
585
- valorOuOutraVariavel = this.avaliar(declaracao.inicializador);
586
- }
587
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
588
- ? valorOuOutraVariavel.valor
589
- : valorOuOutraVariavel);
590
- return null;
923
+ return __awaiter(this, void 0, void 0, function () {
924
+ var valorOuOutraVariavel;
925
+ return __generator(this, function (_a) {
926
+ switch (_a.label) {
927
+ case 0:
928
+ valorOuOutraVariavel = null;
929
+ if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
930
+ return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
931
+ case 1:
932
+ valorOuOutraVariavel = _a.sent();
933
+ _a.label = 2;
934
+ case 2:
935
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
936
+ ? valorOuOutraVariavel.valor
937
+ : valorOuOutraVariavel);
938
+ return [2 /*return*/, null];
939
+ }
940
+ });
941
+ });
591
942
  };
592
943
  Interpretador.prototype.visitarExpressaoContinua = function (declaracao) {
593
944
  return new quebras_1.ContinuarQuebra();
@@ -596,100 +947,150 @@ var Interpretador = /** @class */ (function () {
596
947
  return new quebras_1.SustarQuebra();
597
948
  };
598
949
  Interpretador.prototype.visitarExpressaoRetornar = function (declaracao) {
599
- var valor = null;
600
- if (declaracao.valor != null)
601
- valor = this.avaliar(declaracao.valor);
602
- return new quebras_1.RetornoQuebra(valor);
950
+ return __awaiter(this, void 0, void 0, function () {
951
+ var valor;
952
+ return __generator(this, function (_a) {
953
+ switch (_a.label) {
954
+ case 0:
955
+ valor = null;
956
+ if (!(declaracao.valor != null)) return [3 /*break*/, 2];
957
+ return [4 /*yield*/, this.avaliar(declaracao.valor)];
958
+ case 1:
959
+ valor = _a.sent();
960
+ _a.label = 2;
961
+ case 2: return [2 /*return*/, new quebras_1.RetornoQuebra(valor)];
962
+ }
963
+ });
964
+ });
603
965
  };
604
966
  Interpretador.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
605
967
  return new estruturas_1.DeleguaFuncao(null, expressao);
606
968
  };
607
969
  Interpretador.prototype.visitarExpressaoAtribuicaoSobrescrita = function (expressao) {
608
- var objeto = this.avaliar(expressao.objeto);
609
- var indice = this.avaliar(expressao.indice);
610
- var valor = this.avaliar(expressao.valor);
611
- if (Array.isArray(objeto)) {
612
- if (indice < 0 && objeto.length !== 0) {
613
- while (indice < 0) {
614
- indice += objeto.length;
970
+ return __awaiter(this, void 0, void 0, function () {
971
+ var promises, objeto, indice, valor;
972
+ return __generator(this, function (_a) {
973
+ switch (_a.label) {
974
+ case 0: return [4 /*yield*/, Promise.all([
975
+ this.avaliar(expressao.objeto),
976
+ this.avaliar(expressao.indice),
977
+ this.avaliar(expressao.valor)
978
+ ])];
979
+ case 1:
980
+ promises = _a.sent();
981
+ objeto = promises[0];
982
+ indice = promises[1];
983
+ valor = promises[2];
984
+ if (Array.isArray(objeto)) {
985
+ if (indice < 0 && objeto.length !== 0) {
986
+ while (indice < 0) {
987
+ indice += objeto.length;
988
+ }
989
+ }
990
+ while (objeto.length < indice) {
991
+ objeto.push(null);
992
+ }
993
+ objeto[indice] = valor;
994
+ }
995
+ else if (objeto.constructor === Object ||
996
+ objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
997
+ objeto instanceof estruturas_1.DeleguaFuncao ||
998
+ objeto instanceof estruturas_1.DeleguaClasse ||
999
+ objeto instanceof estruturas_1.DeleguaModulo) {
1000
+ objeto[indice] = valor;
1001
+ }
1002
+ else {
1003
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
1004
+ }
1005
+ return [2 /*return*/];
615
1006
  }
616
- }
617
- while (objeto.length < indice) {
618
- objeto.push(null);
619
- }
620
- objeto[indice] = valor;
621
- }
622
- else if (objeto.constructor === Object ||
623
- objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
624
- objeto instanceof estruturas_1.DeleguaFuncao ||
625
- objeto instanceof estruturas_1.DeleguaClasse ||
626
- objeto instanceof estruturas_1.DeleguaModulo) {
627
- objeto[indice] = valor;
628
- }
629
- else {
630
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
631
- }
1007
+ });
1008
+ });
632
1009
  };
633
1010
  Interpretador.prototype.visitarExpressaoAcessoIndiceVariavel = function (expressao) {
634
- var variavelObjeto = this.avaliar(expressao.entidadeChamada);
635
- var objeto = variavelObjeto.hasOwnProperty('valor')
636
- ? variavelObjeto.valor
637
- : variavelObjeto;
638
- var indice = this.avaliar(expressao.indice);
639
- var valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
640
- if (Array.isArray(objeto)) {
641
- if (!Number.isInteger(valorIndice)) {
642
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
643
- }
644
- if (valorIndice < 0 && objeto.length !== 0) {
645
- while (valorIndice < 0) {
646
- valorIndice += objeto.length;
647
- }
648
- }
649
- if (valorIndice >= objeto.length) {
650
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
651
- }
652
- return objeto[valorIndice];
653
- }
654
- else if (objeto.constructor === Object ||
655
- objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
656
- objeto instanceof estruturas_1.DeleguaFuncao ||
657
- objeto instanceof estruturas_1.DeleguaClasse ||
658
- objeto instanceof estruturas_1.DeleguaModulo) {
659
- return objeto[valorIndice] || null;
660
- }
661
- else if (typeof objeto === 'string') {
662
- if (!Number.isInteger(valorIndice)) {
663
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
664
- }
665
- if (valorIndice < 0 && objeto.length !== 0) {
666
- while (valorIndice < 0) {
667
- valorIndice += objeto.length;
1011
+ return __awaiter(this, void 0, void 0, function () {
1012
+ var variavelObjeto, objeto, indice, valorIndice;
1013
+ return __generator(this, function (_a) {
1014
+ switch (_a.label) {
1015
+ case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
1016
+ case 1:
1017
+ variavelObjeto = _a.sent();
1018
+ objeto = variavelObjeto.hasOwnProperty('valor')
1019
+ ? variavelObjeto.valor
1020
+ : variavelObjeto;
1021
+ return [4 /*yield*/, this.avaliar(expressao.indice)];
1022
+ case 2:
1023
+ indice = _a.sent();
1024
+ valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
1025
+ if (Array.isArray(objeto)) {
1026
+ if (!Number.isInteger(valorIndice)) {
1027
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
1028
+ }
1029
+ if (valorIndice < 0 && objeto.length !== 0) {
1030
+ while (valorIndice < 0) {
1031
+ valorIndice += objeto.length;
1032
+ }
1033
+ }
1034
+ if (valorIndice >= objeto.length) {
1035
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
1036
+ }
1037
+ return [2 /*return*/, objeto[valorIndice]];
1038
+ }
1039
+ else if (objeto.constructor === Object ||
1040
+ objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
1041
+ objeto instanceof estruturas_1.DeleguaFuncao ||
1042
+ objeto instanceof estruturas_1.DeleguaClasse ||
1043
+ objeto instanceof estruturas_1.DeleguaModulo) {
1044
+ return [2 /*return*/, objeto[valorIndice] || null];
1045
+ }
1046
+ else if (typeof objeto === 'string') {
1047
+ if (!Number.isInteger(valorIndice)) {
1048
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
1049
+ }
1050
+ if (valorIndice < 0 && objeto.length !== 0) {
1051
+ while (valorIndice < 0) {
1052
+ valorIndice += objeto.length;
1053
+ }
1054
+ }
1055
+ if (valorIndice >= objeto.length) {
1056
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
1057
+ }
1058
+ return [2 /*return*/, objeto.charAt(valorIndice)];
1059
+ }
1060
+ else {
1061
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
1062
+ }
1063
+ return [2 /*return*/];
668
1064
  }
669
- }
670
- if (valorIndice >= objeto.length) {
671
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
672
- }
673
- return objeto.charAt(valorIndice);
674
- }
675
- else {
676
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
677
- }
1065
+ });
1066
+ });
678
1067
  };
679
1068
  Interpretador.prototype.visitarExpressaoDefinir = function (expressao) {
680
- var objeto = this.avaliar(expressao.objeto);
681
- if (!(objeto instanceof estruturas_1.ObjetoDeleguaClasse) &&
682
- objeto.constructor !== Object) {
683
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
684
- }
685
- var valor = this.avaliar(expressao.valor);
686
- if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
687
- objeto.set(expressao.nome, valor);
688
- return valor;
689
- }
690
- else if (objeto.constructor === Object) {
691
- objeto[expressao.simbolo.lexema] = valor;
692
- }
1069
+ return __awaiter(this, void 0, void 0, function () {
1070
+ var objeto, valor;
1071
+ return __generator(this, function (_a) {
1072
+ switch (_a.label) {
1073
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
1074
+ case 1:
1075
+ objeto = _a.sent();
1076
+ if (!(objeto instanceof estruturas_1.ObjetoDeleguaClasse) &&
1077
+ objeto.constructor !== Object) {
1078
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
1079
+ }
1080
+ return [4 /*yield*/, this.avaliar(expressao.valor)];
1081
+ case 2:
1082
+ valor = _a.sent();
1083
+ if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
1084
+ objeto.set(expressao.nome, valor);
1085
+ return [2 /*return*/, valor];
1086
+ }
1087
+ else if (objeto.constructor === Object) {
1088
+ objeto[expressao.simbolo.lexema] = valor;
1089
+ }
1090
+ return [2 /*return*/];
1091
+ }
1092
+ });
1093
+ });
693
1094
  };
694
1095
  Interpretador.prototype.visitarExpressaoFuncao = function (declaracao) {
695
1096
  var funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
@@ -701,33 +1102,44 @@ var Interpretador = /** @class */ (function () {
701
1102
  * @returns Sempre retorna nulo, por ser requerido pelo contrato de visita.
702
1103
  */
703
1104
  Interpretador.prototype.visitarExpressaoClasse = function (declaracao) {
704
- var superClasse = null;
705
- if (declaracao.superClasse !== null) {
706
- var variavelSuperClasse = this.avaliar(declaracao.superClasse);
707
- superClasse = variavelSuperClasse.valor;
708
- if (!(superClasse instanceof estruturas_1.DeleguaClasse)) {
709
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
710
- }
711
- }
712
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
713
- if (declaracao.superClasse !== null) {
714
- this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
715
- }
716
- var metodos = {};
717
- var definirMetodos = declaracao.metodos;
718
- for (var i = 0; i < declaracao.metodos.length; i++) {
719
- var metodoAtual = definirMetodos[i];
720
- var eInicializador = metodoAtual.simbolo.lexema === 'construtor';
721
- var funcao = new estruturas_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
722
- metodos[metodoAtual.simbolo.lexema] = funcao;
723
- }
724
- var deleguaClasse = new estruturas_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
725
- // TODO: Recolocar isso se for necessário.
726
- /* if (superClasse !== null) {
727
- this.ambiente = this.ambiente.enclosing;
728
- } */
729
- this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
730
- return null;
1105
+ return __awaiter(this, void 0, void 0, function () {
1106
+ var superClasse, variavelSuperClasse, metodos, definirMetodos, i, metodoAtual, eInicializador, funcao, deleguaClasse;
1107
+ return __generator(this, function (_a) {
1108
+ switch (_a.label) {
1109
+ case 0:
1110
+ superClasse = null;
1111
+ if (!(declaracao.superClasse !== null)) return [3 /*break*/, 2];
1112
+ return [4 /*yield*/, this.avaliar(declaracao.superClasse)];
1113
+ case 1:
1114
+ variavelSuperClasse = _a.sent();
1115
+ superClasse = variavelSuperClasse.valor;
1116
+ if (!(superClasse instanceof estruturas_1.DeleguaClasse)) {
1117
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
1118
+ }
1119
+ _a.label = 2;
1120
+ case 2:
1121
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
1122
+ if (declaracao.superClasse !== null) {
1123
+ this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
1124
+ }
1125
+ metodos = {};
1126
+ definirMetodos = declaracao.metodos;
1127
+ for (i = 0; i < declaracao.metodos.length; i++) {
1128
+ metodoAtual = definirMetodos[i];
1129
+ eInicializador = metodoAtual.simbolo.lexema === 'construtor';
1130
+ funcao = new estruturas_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
1131
+ metodos[metodoAtual.simbolo.lexema] = funcao;
1132
+ }
1133
+ deleguaClasse = new estruturas_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
1134
+ // TODO: Recolocar isso se for necessário.
1135
+ /* if (superClasse !== null) {
1136
+ this.ambiente = this.ambiente.enclosing;
1137
+ } */
1138
+ this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
1139
+ return [2 /*return*/, null];
1140
+ }
1141
+ });
1142
+ });
731
1143
  };
732
1144
  /**
733
1145
  * Executa um acesso a método, normalmente de um objeto de classe.
@@ -735,49 +1147,95 @@ var Interpretador = /** @class */ (function () {
735
1147
  * @returns O resultado da execução.
736
1148
  */
737
1149
  Interpretador.prototype.visitarExpressaoAcessoMetodo = function (expressao) {
738
- var variavelObjeto = this.avaliar(expressao.objeto);
739
- var objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
740
- if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
741
- return objeto.get(expressao.simbolo) || null;
742
- }
743
- if (objeto.constructor === Object) {
744
- return objeto[expressao.simbolo.lexema] || null;
745
- }
746
- if (objeto instanceof estruturas_1.DeleguaModulo) {
747
- return objeto.componentes[expressao.simbolo.lexema] || null;
748
- }
749
- switch (variavelObjeto.tipo) {
750
- case 'texto':
751
- var metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema];
752
- if (metodoDePrimitivaTexto) {
753
- return new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaTexto);
754
- }
755
- break;
756
- case 'vetor':
757
- var metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema];
758
- if (metodoDePrimitivaVetor) {
759
- return new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaVetor);
1150
+ return __awaiter(this, void 0, void 0, function () {
1151
+ var variavelObjeto, objeto, metodoDePrimitivaTexto, metodoDePrimitivaVetor;
1152
+ return __generator(this, function (_a) {
1153
+ switch (_a.label) {
1154
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
1155
+ case 1:
1156
+ variavelObjeto = _a.sent();
1157
+ objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
1158
+ if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
1159
+ return [2 /*return*/, objeto.get(expressao.simbolo) || null];
1160
+ }
1161
+ if (objeto.constructor === Object) {
1162
+ return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
1163
+ }
1164
+ if (objeto instanceof estruturas_1.DeleguaModulo) {
1165
+ return [2 /*return*/, objeto.componentes[expressao.simbolo.lexema] || null];
1166
+ }
1167
+ switch (variavelObjeto.tipo) {
1168
+ case 'texto':
1169
+ metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema];
1170
+ if (metodoDePrimitivaTexto) {
1171
+ return [2 /*return*/, new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaTexto)];
1172
+ }
1173
+ break;
1174
+ case 'vetor':
1175
+ metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema];
1176
+ if (metodoDePrimitivaVetor) {
1177
+ return [2 /*return*/, new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaVetor)];
1178
+ }
1179
+ break;
1180
+ }
1181
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
760
1182
  }
761
- break;
762
- }
763
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
1183
+ });
1184
+ });
764
1185
  };
765
1186
  Interpretador.prototype.visitarExpressaoIsto = function (expressao) {
766
1187
  return this.procurarVariavel(expressao.palavraChave);
767
1188
  };
768
1189
  Interpretador.prototype.visitarExpressaoDicionario = function (expressao) {
769
- var dicionario = {};
770
- for (var i = 0; i < expressao.chaves.length; i++) {
771
- dicionario[this.avaliar(expressao.chaves[i])] = this.avaliar(expressao.valores[i]);
772
- }
773
- return dicionario;
1190
+ return __awaiter(this, void 0, void 0, function () {
1191
+ var dicionario, i, promises;
1192
+ return __generator(this, function (_a) {
1193
+ switch (_a.label) {
1194
+ case 0:
1195
+ dicionario = {};
1196
+ i = 0;
1197
+ _a.label = 1;
1198
+ case 1:
1199
+ if (!(i < expressao.chaves.length)) return [3 /*break*/, 4];
1200
+ return [4 /*yield*/, Promise.all([
1201
+ this.avaliar(expressao.chaves[i]),
1202
+ this.avaliar(expressao.valores[i])
1203
+ ])];
1204
+ case 2:
1205
+ promises = _a.sent();
1206
+ dicionario[promises[0]] = promises[1];
1207
+ _a.label = 3;
1208
+ case 3:
1209
+ i++;
1210
+ return [3 /*break*/, 1];
1211
+ case 4: return [2 /*return*/, dicionario];
1212
+ }
1213
+ });
1214
+ });
774
1215
  };
775
1216
  Interpretador.prototype.visitarExpressaoVetor = function (expressao) {
776
- var valores = [];
777
- for (var i = 0; i < expressao.valores.length; i++) {
778
- valores.push(this.avaliar(expressao.valores[i]));
779
- }
780
- return valores;
1217
+ return __awaiter(this, void 0, void 0, function () {
1218
+ var valores, i, _a, _b;
1219
+ return __generator(this, function (_c) {
1220
+ switch (_c.label) {
1221
+ case 0:
1222
+ valores = [];
1223
+ i = 0;
1224
+ _c.label = 1;
1225
+ case 1:
1226
+ if (!(i < expressao.valores.length)) return [3 /*break*/, 4];
1227
+ _b = (_a = valores).push;
1228
+ return [4 /*yield*/, this.avaliar(expressao.valores[i])];
1229
+ case 2:
1230
+ _b.apply(_a, [_c.sent()]);
1231
+ _c.label = 3;
1232
+ case 3:
1233
+ i++;
1234
+ return [3 /*break*/, 1];
1235
+ case 4: return [2 /*return*/, valores];
1236
+ }
1237
+ });
1238
+ });
781
1239
  };
782
1240
  // TODO: Após remoção do Resolvedor, simular casos que usem 'super' e 'isto'.
783
1241
  Interpretador.prototype.visitarExpressaoSuper = function (expressao) {
@@ -818,14 +1276,23 @@ var Interpretador = /** @class */ (function () {
818
1276
  */
819
1277
  Interpretador.prototype.executar = function (declaracao, mostrarResultado) {
820
1278
  if (mostrarResultado === void 0) { mostrarResultado = false; }
821
- var resultado = declaracao.aceitar(this);
822
- if (mostrarResultado) {
823
- this.funcaoDeRetorno(this.paraTexto(resultado));
824
- }
825
- if (resultado || typeof resultado === 'boolean') {
826
- this.resultadoInterpretador.push(this.paraTexto(resultado));
827
- }
828
- return resultado;
1279
+ return __awaiter(this, void 0, void 0, function () {
1280
+ var resultado;
1281
+ return __generator(this, function (_a) {
1282
+ switch (_a.label) {
1283
+ case 0: return [4 /*yield*/, declaracao.aceitar(this)];
1284
+ case 1:
1285
+ resultado = _a.sent();
1286
+ if (mostrarResultado) {
1287
+ this.funcaoDeRetorno(this.paraTexto(resultado));
1288
+ }
1289
+ if (resultado || typeof resultado === 'boolean') {
1290
+ this.resultadoInterpretador.push(this.paraTexto(resultado));
1291
+ }
1292
+ return [2 /*return*/, resultado];
1293
+ }
1294
+ });
1295
+ });
829
1296
  };
830
1297
  /**
831
1298
  * Executa o último escopo empilhado no topo na pilha de escopos do interpretador.
@@ -839,25 +1306,42 @@ var Interpretador = /** @class */ (function () {
839
1306
  */
840
1307
  Interpretador.prototype.executarUltimoEscopo = function (manterAmbiente) {
841
1308
  if (manterAmbiente === void 0) { manterAmbiente = false; }
842
- var ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
843
- try {
844
- var retornoExecucao = void 0;
845
- for (; !(retornoExecucao instanceof quebras_1.Quebra) &&
846
- ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
847
- retornoExecucao = this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
848
- }
849
- return retornoExecucao;
850
- }
851
- catch (erro) {
852
- return erro;
853
- }
854
- finally {
855
- this.pilhaEscoposExecucao.removerUltimo();
856
- if (manterAmbiente) {
857
- var escopoAnterior = this.pilhaEscoposExecucao.topoDaPilha();
858
- escopoAnterior.ambiente.valores = Object.assign(escopoAnterior.ambiente.valores, ultimoEscopo.ambiente.valores);
859
- }
860
- }
1309
+ return __awaiter(this, void 0, void 0, function () {
1310
+ var ultimoEscopo, retornoExecucao, erro_10, escopoAnterior;
1311
+ return __generator(this, function (_a) {
1312
+ switch (_a.label) {
1313
+ case 0:
1314
+ ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
1315
+ _a.label = 1;
1316
+ case 1:
1317
+ _a.trys.push([1, 6, 7, 8]);
1318
+ retornoExecucao = void 0;
1319
+ _a.label = 2;
1320
+ case 2:
1321
+ if (!(!(retornoExecucao instanceof quebras_1.Quebra) &&
1322
+ ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length)) return [3 /*break*/, 5];
1323
+ return [4 /*yield*/, this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual])];
1324
+ case 3:
1325
+ retornoExecucao = _a.sent();
1326
+ _a.label = 4;
1327
+ case 4:
1328
+ ultimoEscopo.declaracaoAtual++;
1329
+ return [3 /*break*/, 2];
1330
+ case 5: return [2 /*return*/, retornoExecucao];
1331
+ case 6:
1332
+ erro_10 = _a.sent();
1333
+ return [2 /*return*/, Promise.reject(erro_10)];
1334
+ case 7:
1335
+ this.pilhaEscoposExecucao.removerUltimo();
1336
+ if (manterAmbiente) {
1337
+ escopoAnterior = this.pilhaEscoposExecucao.topoDaPilha();
1338
+ escopoAnterior.ambiente.valores = Object.assign(escopoAnterior.ambiente.valores, ultimoEscopo.ambiente.valores);
1339
+ }
1340
+ return [7 /*endfinally*/];
1341
+ case 8: return [2 /*return*/];
1342
+ }
1343
+ });
1344
+ });
861
1345
  };
862
1346
  /**
863
1347
  * Interpretação sem depurador, com medição de performance.
@@ -869,29 +1353,55 @@ var Interpretador = /** @class */ (function () {
869
1353
  */
870
1354
  Interpretador.prototype.interpretar = function (declaracoes, manterAmbiente) {
871
1355
  if (manterAmbiente === void 0) { manterAmbiente = false; }
872
- this.erros = [];
873
- var escopoExecucao = {
874
- declaracoes: declaracoes,
875
- declaracaoAtual: 0,
876
- ambiente: new espaco_variaveis_1.EspacoVariaveis(),
877
- };
878
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
879
- var inicioInterpretacao = (0, browser_process_hrtime_1.default)();
880
- try {
881
- this.executarUltimoEscopo(manterAmbiente);
882
- }
883
- finally {
884
- if (this.performance) {
885
- var deltaInterpretacao = (0, browser_process_hrtime_1.default)(inicioInterpretacao);
886
- console.log("[Interpretador] Tempo para interpreta\u00E7ao: ".concat(deltaInterpretacao[0] * 1e9 + deltaInterpretacao[1], "ns"));
887
- }
888
- var retorno = {
889
- erros: this.erros,
890
- resultado: this.resultadoInterpretador,
891
- };
892
- this.resultadoInterpretador = [];
893
- return retorno;
894
- }
1356
+ return __awaiter(this, void 0, void 0, function () {
1357
+ var escopoExecucao, inicioInterpretacao, retornoOuErro, erro_11, deltaInterpretacao, retorno;
1358
+ return __generator(this, function (_a) {
1359
+ switch (_a.label) {
1360
+ case 0:
1361
+ this.erros = [];
1362
+ escopoExecucao = {
1363
+ declaracoes: declaracoes,
1364
+ declaracaoAtual: 0,
1365
+ ambiente: new espaco_variaveis_1.EspacoVariaveis(),
1366
+ };
1367
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
1368
+ inicioInterpretacao = (0, browser_process_hrtime_1.default)();
1369
+ _a.label = 1;
1370
+ case 1:
1371
+ _a.trys.push([1, 3, 4, 5]);
1372
+ return [4 /*yield*/, this.executarUltimoEscopo(manterAmbiente)];
1373
+ case 2:
1374
+ retornoOuErro = _a.sent();
1375
+ if (retornoOuErro instanceof excecoes_1.ErroEmTempoDeExecucao) {
1376
+ this.erros.push(retornoOuErro);
1377
+ }
1378
+ return [3 /*break*/, 5];
1379
+ case 3:
1380
+ erro_11 = _a.sent();
1381
+ this.erros.push(erro_11);
1382
+ return [3 /*break*/, 5];
1383
+ case 4:
1384
+ if (this.performance) {
1385
+ deltaInterpretacao = (0, browser_process_hrtime_1.default)(inicioInterpretacao);
1386
+ console.log("[Interpretador] Tempo para interpreta\u00E7ao: ".concat(deltaInterpretacao[0] * 1e9 + deltaInterpretacao[1], "ns"));
1387
+ }
1388
+ retorno = {
1389
+ erros: this.erros,
1390
+ resultado: this.resultadoInterpretador,
1391
+ };
1392
+ this.resultadoInterpretador = [];
1393
+ return [2 /*return*/, retorno];
1394
+ case 5: return [2 /*return*/];
1395
+ }
1396
+ });
1397
+ });
1398
+ };
1399
+ /**
1400
+ * Procedimento de finalização de execução, normalmente solicitado pelo
1401
+ * núcleo da linguagem.
1402
+ */
1403
+ Interpretador.prototype.finalizacao = function () {
1404
+ this.interfaceDeEntrada.close();
895
1405
  };
896
1406
  return Interpretador;
897
1407
  }());