@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,6 +22,42 @@ 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
  };
@@ -84,23 +120,35 @@ var InterpretadorEguaClassico = /** @class */ (function () {
84
120
  return Boolean(objeto);
85
121
  return true;
86
122
  };
87
- InterpretadorEguaClassico.prototype.verificarOperandoNumero = function (operador, operand) {
88
- if (typeof operand === 'number')
123
+ InterpretadorEguaClassico.prototype.verificarOperandoNumero = function (operador, operando) {
124
+ if (typeof operando === 'number' || operando.tipo === 'número')
89
125
  return;
90
126
  throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operador precisa ser um número.', operador.linha);
91
127
  };
92
128
  InterpretadorEguaClassico.prototype.visitarExpressaoUnaria = function (expr) {
93
- var direita = this.avaliar(expr.direita);
94
- switch (expr.operador.tipo) {
95
- case delegua_1.default.SUBTRACAO:
96
- this.verificarOperandoNumero(expr.operador, direita);
97
- return -direita;
98
- case delegua_1.default.NEGACAO:
99
- return !this.eVerdadeiro(direita);
100
- case delegua_1.default.BIT_NOT:
101
- return ~direita;
102
- }
103
- return null;
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var direita, valor;
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0: return [4 /*yield*/, this.avaliar(expr.direita)];
134
+ case 1:
135
+ direita = _a.sent();
136
+ valor = direita.hasOwnProperty('valor') ?
137
+ direita.valor :
138
+ direita;
139
+ switch (expr.operador.tipo) {
140
+ case delegua_1.default.SUBTRACAO:
141
+ this.verificarOperandoNumero(expr.operador, valor);
142
+ return [2 /*return*/, -valor];
143
+ case delegua_1.default.NEGACAO:
144
+ return [2 /*return*/, !this.eVerdadeiro(valor)];
145
+ case delegua_1.default.BIT_NOT:
146
+ return [2 /*return*/, ~valor];
147
+ }
148
+ return [2 /*return*/, null];
149
+ }
150
+ });
151
+ });
104
152
  };
105
153
  InterpretadorEguaClassico.prototype.eIgual = function (esquerda, direita) {
106
154
  if (esquerda.tipo) {
@@ -134,128 +182,172 @@ var InterpretadorEguaClassico = /** @class */ (function () {
134
182
  throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
135
183
  };
136
184
  InterpretadorEguaClassico.prototype.visitarExpressaoBinaria = function (expressao) {
137
- var esquerda = this.avaliar(expressao.esquerda);
138
- var direita = this.avaliar(expressao.direita);
139
- var valorEsquerdo = esquerda.hasOwnProperty('valor')
140
- ? esquerda.valor
141
- : esquerda;
142
- var valorDireito = direita.hasOwnProperty('valor')
143
- ? direita.valor
144
- : direita;
145
- var tipoEsquerdo = esquerda.hasOwnProperty('tipo')
146
- ? esquerda.tipo
147
- : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
148
- var tipoDireito = direita.hasOwnProperty('tipo')
149
- ? direita.tipo
150
- : (0, inferenciador_1.inferirTipoVariavel)(direita);
151
- switch (expressao.operador.tipo) {
152
- case delegua_1.default.EXPONENCIACAO:
153
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
154
- return Math.pow(valorEsquerdo, valorDireito);
155
- case delegua_1.default.MAIOR:
156
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
157
- return Number(valorEsquerdo) > Number(valorDireito);
158
- case delegua_1.default.MAIOR_IGUAL:
159
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
160
- return Number(valorEsquerdo) >= Number(valorDireito);
161
- case delegua_1.default.MENOR:
162
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
163
- return Number(valorEsquerdo) < Number(valorDireito);
164
- case delegua_1.default.MENOR_IGUAL:
165
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
166
- return Number(valorEsquerdo) <= Number(valorDireito);
167
- case delegua_1.default.SUBTRACAO:
168
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
169
- return Number(valorEsquerdo) - Number(valorDireito);
170
- case delegua_1.default.ADICAO:
171
- if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
172
- return Number(esquerda) + Number(direita);
173
- }
174
- else if (tipoEsquerdo === 'texto' &&
175
- tipoDireito === 'texto') {
176
- return String(esquerda) + String(direita);
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var esquerda, direita, valorEsquerdo, valorDireito, tipoEsquerdo, tipoDireito, erro_1;
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0:
190
+ _a.trys.push([0, 3, , 4]);
191
+ return [4 /*yield*/, this.avaliar(expressao.esquerda)];
192
+ case 1:
193
+ esquerda = _a.sent();
194
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
195
+ case 2:
196
+ direita = _a.sent();
197
+ valorEsquerdo = esquerda.hasOwnProperty('valor')
198
+ ? esquerda.valor
199
+ : esquerda;
200
+ valorDireito = direita.hasOwnProperty('valor')
201
+ ? direita.valor
202
+ : direita;
203
+ tipoEsquerdo = esquerda.hasOwnProperty('tipo')
204
+ ? esquerda.tipo
205
+ : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
206
+ tipoDireito = direita.hasOwnProperty('tipo')
207
+ ? direita.tipo
208
+ : (0, inferenciador_1.inferirTipoVariavel)(direita);
209
+ switch (expressao.operador.tipo) {
210
+ case delegua_1.default.EXPONENCIACAO:
211
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
212
+ return [2 /*return*/, Math.pow(valorEsquerdo, valorDireito)];
213
+ case delegua_1.default.MAIOR:
214
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
215
+ return [2 /*return*/, Number(valorEsquerdo) > Number(valorDireito)];
216
+ case delegua_1.default.MAIOR_IGUAL:
217
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
218
+ return [2 /*return*/, Number(valorEsquerdo) >= Number(valorDireito)];
219
+ case delegua_1.default.MENOR:
220
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
221
+ return [2 /*return*/, Number(valorEsquerdo) < Number(valorDireito)];
222
+ case delegua_1.default.MENOR_IGUAL:
223
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
224
+ return [2 /*return*/, Number(valorEsquerdo) <= Number(valorDireito)];
225
+ case delegua_1.default.SUBTRACAO:
226
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
227
+ return [2 /*return*/, Number(valorEsquerdo) - Number(valorDireito)];
228
+ case delegua_1.default.ADICAO:
229
+ if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
230
+ return [2 /*return*/, Number(esquerda) + Number(direita)];
231
+ }
232
+ else if (tipoEsquerdo === 'texto' &&
233
+ tipoDireito === 'texto') {
234
+ return [2 /*return*/, String(esquerda) + String(direita)];
235
+ }
236
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
237
+ case delegua_1.default.DIVISAO:
238
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
239
+ return [2 /*return*/, Number(valorEsquerdo) / Number(valorDireito)];
240
+ case delegua_1.default.MULTIPLICACAO:
241
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
242
+ return [2 /*return*/, Number(valorEsquerdo) * Number(valorDireito)];
243
+ case delegua_1.default.MODULO:
244
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
245
+ return [2 /*return*/, Number(valorEsquerdo) % Number(valorDireito)];
246
+ case delegua_1.default.BIT_AND:
247
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
248
+ return [2 /*return*/, Number(valorEsquerdo) & Number(valorDireito)];
249
+ case delegua_1.default.BIT_XOR:
250
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
251
+ return [2 /*return*/, Number(valorEsquerdo) ^ Number(valorDireito)];
252
+ case delegua_1.default.BIT_OR:
253
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
254
+ return [2 /*return*/, Number(valorEsquerdo) | Number(valorDireito)];
255
+ case delegua_1.default.MENOR_MENOR:
256
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
257
+ return [2 /*return*/, Number(valorEsquerdo) << Number(valorDireito)];
258
+ case delegua_1.default.MAIOR_MAIOR:
259
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
260
+ return [2 /*return*/, Number(valorEsquerdo) >> Number(valorDireito)];
261
+ case delegua_1.default.DIFERENTE:
262
+ return [2 /*return*/, !this.eIgual(valorEsquerdo, valorDireito)];
263
+ case delegua_1.default.IGUAL_IGUAL:
264
+ return [2 /*return*/, this.eIgual(valorEsquerdo, valorDireito)];
265
+ }
266
+ return [2 /*return*/, null];
267
+ case 3:
268
+ erro_1 = _a.sent();
269
+ return [2 /*return*/, Promise.reject(erro_1)];
270
+ case 4: return [2 /*return*/];
177
271
  }
178
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
179
- case delegua_1.default.DIVISAO:
180
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
181
- return Number(valorEsquerdo) / Number(valorDireito);
182
- case delegua_1.default.MULTIPLICACAO:
183
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
184
- return Number(valorEsquerdo) * Number(valorDireito);
185
- case delegua_1.default.MODULO:
186
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
187
- return Number(valorEsquerdo) % Number(valorDireito);
188
- case delegua_1.default.BIT_AND:
189
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
190
- return Number(valorEsquerdo) & Number(valorDireito);
191
- case delegua_1.default.BIT_XOR:
192
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
193
- return Number(valorEsquerdo) ^ Number(valorDireito);
194
- case delegua_1.default.BIT_OR:
195
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
196
- return Number(valorEsquerdo) | Number(valorDireito);
197
- case delegua_1.default.MENOR_MENOR:
198
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
199
- return Number(valorEsquerdo) << Number(valorDireito);
200
- case delegua_1.default.MAIOR_MAIOR:
201
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
202
- return Number(valorEsquerdo) >> Number(valorDireito);
203
- case delegua_1.default.DIFERENTE:
204
- return !this.eIgual(valorEsquerdo, valorDireito);
205
- case delegua_1.default.IGUAL_IGUAL:
206
- return this.eIgual(valorEsquerdo, valorDireito);
207
- }
208
- return null;
272
+ });
273
+ });
209
274
  };
210
275
  InterpretadorEguaClassico.prototype.visitarExpressaoDeChamada = function (expressao) {
211
- var variavelEntidadeChamada = this.avaliar(expressao.entidadeChamada);
212
- var entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
213
- ? variavelEntidadeChamada.valor
214
- : variavelEntidadeChamada;
215
- var argumentos = [];
216
- for (var i = 0; i < expressao.argumentos.length; i++) {
217
- argumentos.push(this.avaliar(expressao.argumentos[i]));
218
- }
219
- if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
220
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
221
- }
222
- var parametros;
223
- if (entidadeChamada instanceof funcao_1.DeleguaFuncao) {
224
- parametros = entidadeChamada.declaracao.parametros;
225
- }
226
- else if (entidadeChamada instanceof delegua_classe_1.DeleguaClasse) {
227
- parametros = entidadeChamada.metodos.inicializacao
228
- ? entidadeChamada.metodos.inicializacao.declaracao.parametros
229
- : [];
230
- }
231
- else {
232
- parametros = [];
233
- }
234
- // Isso aqui completa os parâmetros não preenchidos com nulos.
235
- if (argumentos.length < entidadeChamada.aridade()) {
236
- var diferenca = entidadeChamada.aridade() - argumentos.length;
237
- for (var i = 0; i < diferenca; i++) {
238
- argumentos.push(null);
239
- }
240
- }
241
- else {
242
- if (parametros &&
243
- parametros.length > 0 &&
244
- parametros[parametros.length - 1]['tipo'] === 'estrela') {
245
- var novosArgumentos = argumentos.slice(0, parametros.length - 1);
246
- novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
247
- argumentos = novosArgumentos;
248
- }
249
- }
250
- if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
251
- return entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome);
252
- }
253
- return entidadeChamada.chamar(this, argumentos);
276
+ return __awaiter(this, void 0, void 0, function () {
277
+ var variavelEntidadeChamada, entidadeChamada, argumentos, i, _a, _b, parametros, diferenca, i, novosArgumentos;
278
+ return __generator(this, function (_c) {
279
+ switch (_c.label) {
280
+ case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
281
+ case 1:
282
+ variavelEntidadeChamada = _c.sent();
283
+ entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
284
+ ? variavelEntidadeChamada.valor
285
+ : variavelEntidadeChamada;
286
+ argumentos = [];
287
+ i = 0;
288
+ _c.label = 2;
289
+ case 2:
290
+ if (!(i < expressao.argumentos.length)) return [3 /*break*/, 5];
291
+ _b = (_a = argumentos).push;
292
+ return [4 /*yield*/, this.avaliar(expressao.argumentos[i])];
293
+ case 3:
294
+ _b.apply(_a, [_c.sent()]);
295
+ _c.label = 4;
296
+ case 4:
297
+ i++;
298
+ return [3 /*break*/, 2];
299
+ case 5:
300
+ if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
301
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
302
+ }
303
+ if (entidadeChamada instanceof funcao_1.DeleguaFuncao) {
304
+ parametros = entidadeChamada.declaracao.parametros;
305
+ }
306
+ else if (entidadeChamada instanceof delegua_classe_1.DeleguaClasse) {
307
+ parametros = entidadeChamada.metodos.inicializacao
308
+ ? entidadeChamada.metodos.inicializacao.declaracao.parametros
309
+ : [];
310
+ }
311
+ else {
312
+ parametros = [];
313
+ }
314
+ // Isso aqui completa os parâmetros não preenchidos com nulos.
315
+ if (argumentos.length < entidadeChamada.aridade()) {
316
+ diferenca = entidadeChamada.aridade() - argumentos.length;
317
+ for (i = 0; i < diferenca; i++) {
318
+ argumentos.push(null);
319
+ }
320
+ }
321
+ else {
322
+ if (parametros &&
323
+ parametros.length > 0 &&
324
+ parametros[parametros.length - 1]['tipo'] === 'estrela') {
325
+ novosArgumentos = argumentos.slice(0, parametros.length - 1);
326
+ novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
327
+ argumentos = novosArgumentos;
328
+ }
329
+ }
330
+ if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
331
+ return [2 /*return*/, entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome)];
332
+ }
333
+ return [2 /*return*/, entidadeChamada.chamar(this, argumentos)];
334
+ }
335
+ });
336
+ });
254
337
  };
255
338
  InterpretadorEguaClassico.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
256
- var valor = this.avaliar(expressao.valor);
257
- this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
258
- return valor;
339
+ return __awaiter(this, void 0, void 0, function () {
340
+ var valor;
341
+ return __generator(this, function (_a) {
342
+ switch (_a.label) {
343
+ case 0: return [4 /*yield*/, this.avaliar(expressao.valor)];
344
+ case 1:
345
+ valor = _a.sent();
346
+ this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
347
+ return [2 /*return*/, valor];
348
+ }
349
+ });
350
+ });
259
351
  };
260
352
  InterpretadorEguaClassico.prototype.procurarVariavel = function (simbolo, expressao) {
261
353
  return this.pilhaEscoposExecucao.obterVariavel(simbolo);
@@ -264,187 +356,360 @@ var InterpretadorEguaClassico = /** @class */ (function () {
264
356
  return this.procurarVariavel(expressao.simbolo, expressao);
265
357
  };
266
358
  InterpretadorEguaClassico.prototype.visitarDeclaracaoDeExpressao = function (declaracao) {
267
- return this.avaliar(declaracao.expressao);
359
+ return __awaiter(this, void 0, void 0, function () {
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.expressao)];
363
+ case 1: return [2 /*return*/, _a.sent()];
364
+ }
365
+ });
366
+ });
268
367
  };
269
368
  InterpretadorEguaClassico.prototype.visitarExpressaoLogica = function (expressao) {
270
- var esquerda = this.avaliar(expressao.esquerda);
271
- if (expressao.operador.tipo === delegua_1.default.EM) {
272
- var direita = this.avaliar(expressao.direita);
273
- if (Array.isArray(direita) || typeof direita === 'string') {
274
- return direita.includes(esquerda);
275
- }
276
- else if (direita.constructor === Object) {
277
- return esquerda in direita;
278
- }
279
- else {
280
- throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
281
- }
282
- }
283
- // se um estado for verdadeiro, retorna verdadeiro
284
- if (expressao.operador.tipo === delegua_1.default.OU) {
285
- if (this.eVerdadeiro(esquerda))
286
- return esquerda;
287
- }
288
- // se um estado for falso, retorna falso
289
- if (expressao.operador.tipo === delegua_1.default.E) {
290
- if (!this.eVerdadeiro(esquerda))
291
- return esquerda;
292
- }
293
- return this.avaliar(expressao.direita);
369
+ return __awaiter(this, void 0, void 0, function () {
370
+ var esquerda, direita;
371
+ return __generator(this, function (_a) {
372
+ switch (_a.label) {
373
+ case 0: return [4 /*yield*/, this.avaliar(expressao.esquerda)];
374
+ case 1:
375
+ esquerda = _a.sent();
376
+ if (!(expressao.operador.tipo === delegua_1.default.EM)) return [3 /*break*/, 3];
377
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
378
+ case 2:
379
+ direita = _a.sent();
380
+ if (Array.isArray(direita) || typeof direita === 'string') {
381
+ return [2 /*return*/, direita.includes(esquerda)];
382
+ }
383
+ else if (direita.constructor === Object) {
384
+ return [2 /*return*/, esquerda in direita];
385
+ }
386
+ else {
387
+ throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
388
+ }
389
+ _a.label = 3;
390
+ case 3:
391
+ // se um estado for verdadeiro, retorna verdadeiro
392
+ if (expressao.operador.tipo === delegua_1.default.OU) {
393
+ if (this.eVerdadeiro(esquerda))
394
+ return [2 /*return*/, esquerda];
395
+ }
396
+ // se um estado for falso, retorna falso
397
+ if (expressao.operador.tipo === delegua_1.default.E) {
398
+ if (!this.eVerdadeiro(esquerda))
399
+ return [2 /*return*/, esquerda];
400
+ }
401
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
402
+ case 4: return [2 /*return*/, _a.sent()];
403
+ }
404
+ });
405
+ });
294
406
  };
295
407
  InterpretadorEguaClassico.prototype.visitarExpressaoSe = function (declaracao) {
296
- if (this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
297
- return this.executar(declaracao.caminhoEntao);
298
- }
299
- for (var i = 0; i < declaracao.caminhosSeSenao.length; i++) {
300
- var atual = declaracao.caminhosSeSenao[i];
301
- if (this.eVerdadeiro(this.avaliar(atual.condicao))) {
302
- return this.executar(atual.caminho);
303
- }
304
- }
305
- if (declaracao.caminhoSenao !== null) {
306
- return this.executar(declaracao.caminhoSenao);
307
- }
308
- return null;
408
+ return __awaiter(this, void 0, void 0, function () {
409
+ var _a, i, atual, _b;
410
+ return __generator(this, function (_c) {
411
+ switch (_c.label) {
412
+ case 0:
413
+ _a = this.eVerdadeiro;
414
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
415
+ case 1:
416
+ if (!_a.apply(this, [_c.sent()])) return [3 /*break*/, 3];
417
+ return [4 /*yield*/, this.executar(declaracao.caminhoEntao)];
418
+ case 2: return [2 /*return*/, _c.sent()];
419
+ case 3:
420
+ i = 0;
421
+ _c.label = 4;
422
+ case 4:
423
+ if (!(i < declaracao.caminhosSeSenao.length)) return [3 /*break*/, 8];
424
+ atual = declaracao.caminhosSeSenao[i];
425
+ _b = this.eVerdadeiro;
426
+ return [4 /*yield*/, this.avaliar(atual.condicao)];
427
+ case 5:
428
+ if (!_b.apply(this, [_c.sent()])) return [3 /*break*/, 7];
429
+ return [4 /*yield*/, this.executar(atual.caminho)];
430
+ case 6: return [2 /*return*/, _c.sent()];
431
+ case 7:
432
+ i++;
433
+ return [3 /*break*/, 4];
434
+ case 8:
435
+ if (!(declaracao.caminhoSenao !== null)) return [3 /*break*/, 10];
436
+ return [4 /*yield*/, this.executar(declaracao.caminhoSenao)];
437
+ case 9: return [2 /*return*/, _c.sent()];
438
+ case 10: return [2 /*return*/, null];
439
+ }
440
+ });
441
+ });
309
442
  };
310
443
  InterpretadorEguaClassico.prototype.visitarExpressaoPara = function (declaracao) {
311
- if (declaracao.inicializador !== null) {
312
- this.avaliar(declaracao.inicializador);
313
- }
314
- while (true) {
315
- if (declaracao.condicao !== null) {
316
- if (!this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
317
- break;
444
+ return __awaiter(this, void 0, void 0, function () {
445
+ var _a, erro_2;
446
+ return __generator(this, function (_b) {
447
+ switch (_b.label) {
448
+ case 0:
449
+ if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
450
+ return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
451
+ case 1:
452
+ _b.sent();
453
+ _b.label = 2;
454
+ case 2:
455
+ if (!true) return [3 /*break*/, 10];
456
+ if (!(declaracao.condicao !== null)) return [3 /*break*/, 4];
457
+ _a = this.eVerdadeiro;
458
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
459
+ case 3:
460
+ if (!_a.apply(this, [_b.sent()])) {
461
+ return [3 /*break*/, 10];
462
+ }
463
+ _b.label = 4;
464
+ case 4:
465
+ _b.trys.push([4, 6, , 7]);
466
+ return [4 /*yield*/, this.executar(declaracao.corpo)];
467
+ case 5:
468
+ _b.sent();
469
+ return [3 /*break*/, 7];
470
+ case 6:
471
+ erro_2 = _b.sent();
472
+ throw erro_2;
473
+ case 7:
474
+ if (!(declaracao.incrementar !== null)) return [3 /*break*/, 9];
475
+ return [4 /*yield*/, this.avaliar(declaracao.incrementar)];
476
+ case 8:
477
+ _b.sent();
478
+ _b.label = 9;
479
+ case 9: return [3 /*break*/, 2];
480
+ case 10: return [2 /*return*/, null];
318
481
  }
319
- }
320
- try {
321
- this.executar(declaracao.corpo);
322
- }
323
- catch (erro) {
324
- throw erro;
325
- }
326
- if (declaracao.incrementar !== null) {
327
- this.avaliar(declaracao.incrementar);
328
- }
329
- }
330
- return null;
482
+ });
483
+ });
331
484
  };
332
485
  InterpretadorEguaClassico.prototype.visitarExpressaoFazer = function (declaracao) {
333
- do {
334
- try {
335
- this.executar(declaracao.caminhoFazer);
336
- }
337
- catch (erro) {
338
- throw erro;
339
- }
340
- } while (this.eVerdadeiro(this.avaliar(declaracao.condicaoEnquanto)));
486
+ return __awaiter(this, void 0, void 0, function () {
487
+ var erro_3, _a;
488
+ return __generator(this, function (_b) {
489
+ switch (_b.label) {
490
+ case 0:
491
+ _b.trys.push([0, 2, , 3]);
492
+ return [4 /*yield*/, this.executar(declaracao.caminhoFazer)];
493
+ case 1:
494
+ _b.sent();
495
+ return [3 /*break*/, 3];
496
+ case 2:
497
+ erro_3 = _b.sent();
498
+ throw erro_3;
499
+ case 3:
500
+ _a = this.eVerdadeiro;
501
+ return [4 /*yield*/, this.avaliar(declaracao.condicaoEnquanto)];
502
+ case 4:
503
+ if (_a.apply(this, [_b.sent()])) return [3 /*break*/, 0];
504
+ _b.label = 5;
505
+ case 5: return [2 /*return*/];
506
+ }
507
+ });
508
+ });
341
509
  };
342
510
  InterpretadorEguaClassico.prototype.visitarExpressaoEscolha = function (declaracao) {
343
- var condicaoEscolha = this.avaliar(declaracao.identificadorOuLiteral);
344
- var caminhos = declaracao.caminhos;
345
- var caminhoPadrao = declaracao.caminhoPadrao;
346
- var encontrado = false;
347
- try {
348
- for (var i = 0; i < caminhos.length; i++) {
349
- var caminho_1 = caminhos[i];
350
- for (var j = 0; j < caminho_1.condicoes.length; j++) {
351
- if (this.avaliar(caminho_1.condicoes[j]) === condicaoEscolha) {
511
+ return __awaiter(this, void 0, void 0, function () {
512
+ var condicaoEscolha, caminhos, caminhoPadrao, encontrado, i, caminho_1, j, k, erro_4, i, erro_5;
513
+ return __generator(this, function (_a) {
514
+ switch (_a.label) {
515
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.identificadorOuLiteral)];
516
+ case 1:
517
+ condicaoEscolha = _a.sent();
518
+ caminhos = declaracao.caminhos;
519
+ caminhoPadrao = declaracao.caminhoPadrao;
520
+ encontrado = false;
521
+ _a.label = 2;
522
+ case 2:
523
+ _a.trys.push([2, 19, , 20]);
524
+ i = 0;
525
+ _a.label = 3;
526
+ case 3:
527
+ if (!(i < caminhos.length)) return [3 /*break*/, 14];
528
+ caminho_1 = caminhos[i];
529
+ j = 0;
530
+ _a.label = 4;
531
+ case 4:
532
+ if (!(j < caminho_1.condicoes.length)) return [3 /*break*/, 13];
533
+ return [4 /*yield*/, this.avaliar(caminho_1.condicoes[j])];
534
+ case 5:
535
+ if (!((_a.sent()) === condicaoEscolha)) return [3 /*break*/, 12];
352
536
  encontrado = true;
353
- try {
354
- for (var k = 0; k < caminho_1.declaracoes.length; k++) {
355
- this.executar(caminho_1.declaracoes[k]);
356
- }
357
- }
358
- catch (erro) {
359
- throw erro;
360
- }
361
- }
537
+ _a.label = 6;
538
+ case 6:
539
+ _a.trys.push([6, 11, , 12]);
540
+ k = 0;
541
+ _a.label = 7;
542
+ case 7:
543
+ if (!(k < caminho_1.declaracoes.length)) return [3 /*break*/, 10];
544
+ return [4 /*yield*/, this.executar(caminho_1.declaracoes[k])];
545
+ case 8:
546
+ _a.sent();
547
+ _a.label = 9;
548
+ case 9:
549
+ k++;
550
+ return [3 /*break*/, 7];
551
+ case 10: return [3 /*break*/, 12];
552
+ case 11:
553
+ erro_4 = _a.sent();
554
+ throw erro_4;
555
+ case 12:
556
+ j++;
557
+ return [3 /*break*/, 4];
558
+ case 13:
559
+ i++;
560
+ return [3 /*break*/, 3];
561
+ case 14:
562
+ if (!(caminhoPadrao !== null && encontrado === false)) return [3 /*break*/, 18];
563
+ i = 0;
564
+ _a.label = 15;
565
+ case 15:
566
+ if (!(i < caminhoPadrao.declaracoes.length)) return [3 /*break*/, 18];
567
+ return [4 /*yield*/, this.executar(caminhoPadrao['declaracoes'][i])];
568
+ case 16:
569
+ _a.sent();
570
+ _a.label = 17;
571
+ case 17:
572
+ i++;
573
+ return [3 /*break*/, 15];
574
+ case 18: return [3 /*break*/, 20];
575
+ case 19:
576
+ erro_5 = _a.sent();
577
+ throw erro_5;
578
+ case 20: return [2 /*return*/];
362
579
  }
363
- }
364
- if (caminhoPadrao !== null && encontrado === false) {
365
- for (var i = 0; i < caminhoPadrao.declaracoes.length; i++) {
366
- this.executar(caminhoPadrao['declaracoes'][i]);
367
- }
368
- }
369
- }
370
- catch (erro) {
371
- throw erro;
372
- }
580
+ });
581
+ });
373
582
  };
374
583
  InterpretadorEguaClassico.prototype.visitarExpressaoTente = function (declaracao) {
375
- try {
376
- var sucesso = true;
377
- try {
378
- this.executarBloco(declaracao.caminhoTente);
379
- }
380
- catch (erro) {
381
- sucesso = false;
382
- if (declaracao.caminhoPegue !== null) {
383
- this.executarBloco(declaracao.caminhoPegue);
584
+ return __awaiter(this, void 0, void 0, function () {
585
+ var sucesso, erro_6;
586
+ return __generator(this, function (_a) {
587
+ switch (_a.label) {
588
+ case 0:
589
+ _a.trys.push([0, , 10, 13]);
590
+ sucesso = true;
591
+ _a.label = 1;
592
+ case 1:
593
+ _a.trys.push([1, 3, , 7]);
594
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoTente)];
595
+ case 2:
596
+ _a.sent();
597
+ return [3 /*break*/, 7];
598
+ case 3:
599
+ erro_6 = _a.sent();
600
+ sucesso = false;
601
+ if (!(declaracao.caminhoPegue !== null)) return [3 /*break*/, 5];
602
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoPegue)];
603
+ case 4:
604
+ _a.sent();
605
+ return [3 /*break*/, 6];
606
+ case 5:
607
+ this.erros.push(erro_6);
608
+ _a.label = 6;
609
+ case 6: return [3 /*break*/, 7];
610
+ case 7:
611
+ if (!(sucesso && declaracao.caminhoSenao !== null)) return [3 /*break*/, 9];
612
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoSenao)];
613
+ case 8:
614
+ _a.sent();
615
+ _a.label = 9;
616
+ case 9: return [3 /*break*/, 13];
617
+ case 10:
618
+ if (!(declaracao.caminhoFinalmente !== null)) return [3 /*break*/, 12];
619
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoFinalmente)];
620
+ case 11:
621
+ _a.sent();
622
+ _a.label = 12;
623
+ case 12: return [7 /*endfinally*/];
624
+ case 13: return [2 /*return*/];
384
625
  }
385
- else {
386
- this.erros.push(erro);
387
- }
388
- }
389
- if (sucesso && declaracao.caminhoSenao !== null) {
390
- this.executarBloco(declaracao.caminhoSenao);
391
- }
392
- }
393
- finally {
394
- if (declaracao.caminhoFinalmente !== null)
395
- this.executarBloco(declaracao.caminhoFinalmente);
396
- }
626
+ });
627
+ });
397
628
  };
398
629
  InterpretadorEguaClassico.prototype.visitarExpressaoEnquanto = function (declaracao) {
399
- while (this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
400
- try {
401
- this.executar(declaracao.corpo);
402
- }
403
- catch (erro) {
404
- throw erro;
405
- }
406
- }
407
- return null;
630
+ return __awaiter(this, void 0, void 0, function () {
631
+ var _a, erro_7;
632
+ return __generator(this, function (_b) {
633
+ switch (_b.label) {
634
+ case 0:
635
+ _a = this.eVerdadeiro;
636
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
637
+ case 1:
638
+ if (!_a.apply(this, [_b.sent()])) return [3 /*break*/, 6];
639
+ _b.label = 2;
640
+ case 2:
641
+ _b.trys.push([2, 4, , 5]);
642
+ return [4 /*yield*/, this.executar(declaracao.corpo)];
643
+ case 3:
644
+ _b.sent();
645
+ return [3 /*break*/, 5];
646
+ case 4:
647
+ erro_7 = _b.sent();
648
+ throw erro_7;
649
+ case 5: return [3 /*break*/, 0];
650
+ case 6: return [2 /*return*/, null];
651
+ }
652
+ });
653
+ });
408
654
  };
409
655
  InterpretadorEguaClassico.prototype.visitarExpressaoImportar = function (declaracao) {
410
- var caminhoRelativo = this.avaliar(declaracao.caminho);
411
- var caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
412
- // const nomeArquivo = caminho.basename(caminhoTotal);
413
- var dados = (0, importar_biblioteca_1.default)(caminhoRelativo);
414
- if (dados)
415
- return dados;
416
- try {
417
- if (!fs.existsSync(caminhoTotal)) {
418
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível encontrar arquivo importado.', declaracao.linha);
419
- }
420
- }
421
- catch (erro) {
422
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível ler o arquivo.', declaracao.linha);
423
- }
424
- dados = fs.readFileSync(caminhoTotal).toString();
425
- var delegua = new delegua_2.Delegua(this.Delegua.dialeto, false);
426
- delegua.executar(dados);
427
- var exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
428
- var eDicionario = function (objeto) { return objeto.constructor === Object; };
429
- if (eDicionario(exportar)) {
430
- var novoModulo = new modulo_1.DeleguaModulo();
431
- var chaves = Object.keys(exportar);
432
- for (var i = 0; i < chaves.length; i++) {
433
- novoModulo[chaves[i]] = exportar[chaves[i]];
434
- }
435
- return novoModulo;
436
- }
437
- return exportar;
656
+ return __awaiter(this, void 0, void 0, function () {
657
+ var caminhoRelativo, caminhoTotal, dados, delegua, exportar, eDicionario, novoModulo, chaves, i;
658
+ return __generator(this, function (_a) {
659
+ switch (_a.label) {
660
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.caminho)];
661
+ case 1:
662
+ caminhoRelativo = _a.sent();
663
+ caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
664
+ dados = (0, importar_biblioteca_1.default)(caminhoRelativo);
665
+ if (dados)
666
+ return [2 /*return*/, dados];
667
+ try {
668
+ if (!fs.existsSync(caminhoTotal)) {
669
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível encontrar arquivo importado.', declaracao.linha);
670
+ }
671
+ }
672
+ catch (erro) {
673
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível ler o arquivo.', declaracao.linha);
674
+ }
675
+ dados = fs.readFileSync(caminhoTotal).toString();
676
+ delegua = new delegua_2.Delegua(this.Delegua.dialeto, false);
677
+ delegua.executar(dados);
678
+ exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
679
+ eDicionario = function (objeto) { return objeto.constructor === Object; };
680
+ if (eDicionario(exportar)) {
681
+ novoModulo = new modulo_1.DeleguaModulo();
682
+ chaves = Object.keys(exportar);
683
+ for (i = 0; i < chaves.length; i++) {
684
+ novoModulo[chaves[i]] = exportar[chaves[i]];
685
+ }
686
+ return [2 /*return*/, novoModulo];
687
+ }
688
+ return [2 /*return*/, exportar];
689
+ }
690
+ });
691
+ });
438
692
  };
439
693
  InterpretadorEguaClassico.prototype.visitarExpressaoEscreva = function (declaracao) {
440
- try {
441
- var valor = this.avaliar(declaracao.argumentos[0]);
442
- console.log(this.paraTexto(valor));
443
- return null;
444
- }
445
- catch (erro) {
446
- this.erros.push(erro);
447
- }
694
+ return __awaiter(this, void 0, void 0, function () {
695
+ var valor, erro_8;
696
+ return __generator(this, function (_a) {
697
+ switch (_a.label) {
698
+ case 0:
699
+ _a.trys.push([0, 2, , 3]);
700
+ return [4 /*yield*/, this.avaliar(declaracao.argumentos[0])];
701
+ case 1:
702
+ valor = _a.sent();
703
+ console.log(this.paraTexto(valor));
704
+ return [2 /*return*/, null];
705
+ case 2:
706
+ erro_8 = _a.sent();
707
+ this.erros.push(erro_8);
708
+ return [3 /*break*/, 3];
709
+ case 3: return [2 /*return*/];
710
+ }
711
+ });
712
+ });
448
713
  };
449
714
  /**
450
715
  * Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
@@ -457,20 +722,37 @@ var InterpretadorEguaClassico = /** @class */ (function () {
457
722
  * @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
458
723
  */
459
724
  InterpretadorEguaClassico.prototype.executarBloco = function (declaracoes, ambiente) {
460
- var escopoExecucao = {
461
- declaracoes: declaracoes,
462
- declaracaoAtual: 0,
463
- ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
464
- };
465
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
466
- var retornoUltimoEscopo = this.executarUltimoEscopo();
467
- if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
468
- throw retornoUltimoEscopo;
469
- }
470
- return retornoUltimoEscopo;
725
+ return __awaiter(this, void 0, void 0, function () {
726
+ var escopoExecucao, retornoUltimoEscopo;
727
+ return __generator(this, function (_a) {
728
+ switch (_a.label) {
729
+ case 0:
730
+ escopoExecucao = {
731
+ declaracoes: declaracoes,
732
+ declaracaoAtual: 0,
733
+ ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
734
+ };
735
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
736
+ return [4 /*yield*/, this.executarUltimoEscopo()];
737
+ case 1:
738
+ retornoUltimoEscopo = _a.sent();
739
+ if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
740
+ throw retornoUltimoEscopo;
741
+ }
742
+ return [2 /*return*/, retornoUltimoEscopo];
743
+ }
744
+ });
745
+ });
471
746
  };
472
747
  InterpretadorEguaClassico.prototype.visitarExpressaoBloco = function (declaracao) {
473
- return this.executarBloco(declaracao.declaracoes);
748
+ return __awaiter(this, void 0, void 0, function () {
749
+ return __generator(this, function (_a) {
750
+ switch (_a.label) {
751
+ case 0: return [4 /*yield*/, this.executarBloco(declaracao.declaracoes)];
752
+ case 1: return [2 /*return*/, _a.sent()];
753
+ }
754
+ });
755
+ });
474
756
  };
475
757
  /**
476
758
  * Executa expressão de definição de variável.
@@ -478,14 +760,25 @@ var InterpretadorEguaClassico = /** @class */ (function () {
478
760
  * @returns Sempre retorna nulo.
479
761
  */
480
762
  InterpretadorEguaClassico.prototype.visitarExpressaoVar = function (declaracao) {
481
- var valorOuOutraVariavel = null;
482
- if (declaracao.inicializador !== null) {
483
- valorOuOutraVariavel = this.avaliar(declaracao.inicializador);
484
- }
485
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
486
- ? valorOuOutraVariavel.valor
487
- : valorOuOutraVariavel);
488
- return null;
763
+ return __awaiter(this, void 0, void 0, function () {
764
+ var valorOuOutraVariavel;
765
+ return __generator(this, function (_a) {
766
+ switch (_a.label) {
767
+ case 0:
768
+ valorOuOutraVariavel = null;
769
+ if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
770
+ return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
771
+ case 1:
772
+ valorOuOutraVariavel = _a.sent();
773
+ _a.label = 2;
774
+ case 2:
775
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
776
+ ? valorOuOutraVariavel.valor
777
+ : valorOuOutraVariavel);
778
+ return [2 /*return*/, null];
779
+ }
780
+ });
781
+ });
489
782
  };
490
783
  InterpretadorEguaClassico.prototype.visitarExpressaoContinua = function (declaracao) {
491
784
  return new quebras_1.ContinuarQuebra();
@@ -494,164 +787,270 @@ var InterpretadorEguaClassico = /** @class */ (function () {
494
787
  return new quebras_1.SustarQuebra();
495
788
  };
496
789
  InterpretadorEguaClassico.prototype.visitarExpressaoRetornar = function (declaracao) {
497
- var valor = null;
498
- if (declaracao.valor != null)
499
- valor = this.avaliar(declaracao.valor);
500
- return new quebras_1.RetornoQuebra(valor);
790
+ return __awaiter(this, void 0, void 0, function () {
791
+ var valor;
792
+ return __generator(this, function (_a) {
793
+ switch (_a.label) {
794
+ case 0:
795
+ valor = null;
796
+ if (!(declaracao.valor != null)) return [3 /*break*/, 2];
797
+ return [4 /*yield*/, this.avaliar(declaracao.valor)];
798
+ case 1:
799
+ valor = _a.sent();
800
+ _a.label = 2;
801
+ case 2: return [2 /*return*/, new quebras_1.RetornoQuebra(valor)];
802
+ }
803
+ });
804
+ });
501
805
  };
502
806
  InterpretadorEguaClassico.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
503
807
  return new funcao_1.DeleguaFuncao(null, expressao);
504
808
  };
505
809
  InterpretadorEguaClassico.prototype.visitarExpressaoAtribuicaoSobrescrita = function (expressao) {
506
- var objeto = this.avaliar(expressao.objeto);
507
- var indice = this.avaliar(expressao.indice);
508
- var valor = this.avaliar(expressao.valor);
509
- if (Array.isArray(objeto)) {
510
- if (indice < 0 && objeto.length !== 0) {
511
- while (indice < 0) {
512
- indice += objeto.length;
810
+ return __awaiter(this, void 0, void 0, function () {
811
+ var objeto, indice, valor;
812
+ return __generator(this, function (_a) {
813
+ switch (_a.label) {
814
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
815
+ case 1:
816
+ objeto = _a.sent();
817
+ return [4 /*yield*/, this.avaliar(expressao.indice)];
818
+ case 2:
819
+ indice = _a.sent();
820
+ return [4 /*yield*/, this.avaliar(expressao.valor)];
821
+ case 3:
822
+ valor = _a.sent();
823
+ if (Array.isArray(objeto)) {
824
+ if (indice < 0 && objeto.length !== 0) {
825
+ while (indice < 0) {
826
+ indice += objeto.length;
827
+ }
828
+ }
829
+ while (objeto.length < indice) {
830
+ objeto.push(null);
831
+ }
832
+ objeto[indice] = valor;
833
+ }
834
+ else if (objeto.constructor === Object ||
835
+ objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
836
+ objeto instanceof funcao_1.DeleguaFuncao ||
837
+ objeto instanceof delegua_classe_1.DeleguaClasse ||
838
+ objeto instanceof modulo_1.DeleguaModulo) {
839
+ objeto[indice] = valor;
840
+ }
841
+ else {
842
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
843
+ }
844
+ return [2 /*return*/];
513
845
  }
514
- }
515
- while (objeto.length < indice) {
516
- objeto.push(null);
517
- }
518
- objeto[indice] = valor;
519
- }
520
- else if (objeto.constructor === Object ||
521
- objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
522
- objeto instanceof funcao_1.DeleguaFuncao ||
523
- objeto instanceof delegua_classe_1.DeleguaClasse ||
524
- objeto instanceof modulo_1.DeleguaModulo) {
525
- objeto[indice] = valor;
526
- }
527
- else {
528
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
529
- }
846
+ });
847
+ });
530
848
  };
531
849
  InterpretadorEguaClassico.prototype.visitarExpressaoAcessoIndiceVariavel = function (expressao) {
532
- var variavelObjeto = this.avaliar(expressao.entidadeChamada);
533
- var objeto = variavelObjeto.hasOwnProperty('valor')
534
- ? variavelObjeto.valor
535
- : variavelObjeto;
536
- var indice = this.avaliar(expressao.indice);
537
- var valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
538
- if (Array.isArray(objeto)) {
539
- if (!Number.isInteger(valorIndice)) {
540
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
541
- }
542
- if (indice < 0 && objeto.length !== 0) {
543
- while (indice < 0) {
544
- indice += objeto.length;
545
- }
546
- }
547
- if (indice >= objeto.length) {
548
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
549
- }
550
- return objeto[indice];
551
- }
552
- else if (objeto.constructor === Object ||
553
- objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
554
- objeto instanceof funcao_1.DeleguaFuncao ||
555
- objeto instanceof delegua_classe_1.DeleguaClasse ||
556
- objeto instanceof modulo_1.DeleguaModulo) {
557
- return objeto[indice] || null;
558
- }
559
- else if (typeof objeto === 'string') {
560
- if (!Number.isInteger(indice)) {
561
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
562
- }
563
- if (indice < 0 && objeto.length !== 0) {
564
- while (indice < 0) {
565
- indice += objeto.length;
850
+ return __awaiter(this, void 0, void 0, function () {
851
+ var variavelObjeto, objeto, indice, valorIndice;
852
+ return __generator(this, function (_a) {
853
+ switch (_a.label) {
854
+ case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
855
+ case 1:
856
+ variavelObjeto = _a.sent();
857
+ objeto = variavelObjeto.hasOwnProperty('valor')
858
+ ? variavelObjeto.valor
859
+ : variavelObjeto;
860
+ return [4 /*yield*/, this.avaliar(expressao.indice)];
861
+ case 2:
862
+ indice = _a.sent();
863
+ valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
864
+ if (Array.isArray(objeto)) {
865
+ if (!Number.isInteger(valorIndice)) {
866
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
867
+ }
868
+ if (indice < 0 && objeto.length !== 0) {
869
+ while (indice < 0) {
870
+ indice += objeto.length;
871
+ }
872
+ }
873
+ if (indice >= objeto.length) {
874
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
875
+ }
876
+ return [2 /*return*/, objeto[indice]];
877
+ }
878
+ else if (objeto.constructor === Object ||
879
+ objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
880
+ objeto instanceof funcao_1.DeleguaFuncao ||
881
+ objeto instanceof delegua_classe_1.DeleguaClasse ||
882
+ objeto instanceof modulo_1.DeleguaModulo) {
883
+ return [2 /*return*/, objeto[indice] || null];
884
+ }
885
+ else if (typeof objeto === 'string') {
886
+ if (!Number.isInteger(indice)) {
887
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
888
+ }
889
+ if (indice < 0 && objeto.length !== 0) {
890
+ while (indice < 0) {
891
+ indice += objeto.length;
892
+ }
893
+ }
894
+ if (indice >= objeto.length) {
895
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
896
+ }
897
+ return [2 /*return*/, objeto.charAt(indice)];
898
+ }
899
+ else {
900
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
901
+ }
902
+ return [2 /*return*/];
566
903
  }
567
- }
568
- if (indice >= objeto.length) {
569
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
570
- }
571
- return objeto.charAt(indice);
572
- }
573
- else {
574
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
575
- }
904
+ });
905
+ });
576
906
  };
577
907
  InterpretadorEguaClassico.prototype.visitarExpressaoDefinir = function (expressao) {
578
- var objeto = this.avaliar(expressao.objeto);
579
- if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) &&
580
- objeto.constructor !== Object) {
581
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
582
- }
583
- var valor = this.avaliar(expressao.valor);
584
- if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
585
- objeto.set(expressao.nome, valor);
586
- return valor;
587
- }
588
- else if (objeto.constructor === Object) {
589
- objeto[expressao.simbolo.lexema] = valor;
590
- }
908
+ return __awaiter(this, void 0, void 0, function () {
909
+ var objeto, valor;
910
+ return __generator(this, function (_a) {
911
+ switch (_a.label) {
912
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
913
+ case 1:
914
+ objeto = _a.sent();
915
+ if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) &&
916
+ objeto.constructor !== Object) {
917
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
918
+ }
919
+ return [4 /*yield*/, this.avaliar(expressao.valor)];
920
+ case 2:
921
+ valor = _a.sent();
922
+ if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
923
+ objeto.set(expressao.nome, valor);
924
+ return [2 /*return*/, valor];
925
+ }
926
+ else if (objeto.constructor === Object) {
927
+ objeto[expressao.simbolo.lexema] = valor;
928
+ }
929
+ return [2 /*return*/];
930
+ }
931
+ });
932
+ });
591
933
  };
592
934
  InterpretadorEguaClassico.prototype.visitarExpressaoFuncao = function (declaracao) {
593
935
  var funcao = new funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
594
936
  this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
595
937
  };
596
938
  InterpretadorEguaClassico.prototype.visitarExpressaoClasse = function (declaracao) {
597
- var superClasse = null;
598
- if (declaracao.superClasse !== null) {
599
- var variavelSuperClasse = this.avaliar(declaracao.superClasse);
600
- superClasse = variavelSuperClasse.valor;
601
- if (!(superClasse instanceof delegua_classe_1.DeleguaClasse)) {
602
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
603
- }
604
- }
605
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
606
- if (declaracao.superClasse !== null) {
607
- this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
608
- }
609
- var metodos = {};
610
- var definirMetodos = declaracao.metodos;
611
- for (var i = 0; i < declaracao.metodos.length; i++) {
612
- var metodoAtual = definirMetodos[i];
613
- var eInicializador = metodoAtual.simbolo.lexema === 'construtor';
614
- var funcao = new funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
615
- metodos[metodoAtual.simbolo.lexema] = funcao;
616
- }
617
- var deleguaClasse = new delegua_classe_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
618
- // TODO: Recolocar isso se for necessário.
619
- /* if (superClasse !== null) {
620
- this.ambiente = this.ambiente.enclosing;
621
- } */
622
- this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
623
- return null;
939
+ return __awaiter(this, void 0, void 0, function () {
940
+ var superClasse, variavelSuperClasse, metodos, definirMetodos, i, metodoAtual, eInicializador, funcao, deleguaClasse;
941
+ return __generator(this, function (_a) {
942
+ switch (_a.label) {
943
+ case 0:
944
+ superClasse = null;
945
+ if (!(declaracao.superClasse !== null)) return [3 /*break*/, 2];
946
+ return [4 /*yield*/, this.avaliar(declaracao.superClasse)];
947
+ case 1:
948
+ variavelSuperClasse = _a.sent();
949
+ superClasse = variavelSuperClasse.valor;
950
+ if (!(superClasse instanceof delegua_classe_1.DeleguaClasse)) {
951
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
952
+ }
953
+ _a.label = 2;
954
+ case 2:
955
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
956
+ if (declaracao.superClasse !== null) {
957
+ this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
958
+ }
959
+ metodos = {};
960
+ definirMetodos = declaracao.metodos;
961
+ for (i = 0; i < declaracao.metodos.length; i++) {
962
+ metodoAtual = definirMetodos[i];
963
+ eInicializador = metodoAtual.simbolo.lexema === 'construtor';
964
+ funcao = new funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
965
+ metodos[metodoAtual.simbolo.lexema] = funcao;
966
+ }
967
+ deleguaClasse = new delegua_classe_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
968
+ // TODO: Recolocar isso se for necessário.
969
+ /* if (superClasse !== null) {
970
+ this.ambiente = this.ambiente.enclosing;
971
+ } */
972
+ this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
973
+ return [2 /*return*/, null];
974
+ }
975
+ });
976
+ });
624
977
  };
625
978
  InterpretadorEguaClassico.prototype.visitarExpressaoAcessoMetodo = function (expressao) {
626
- var variavelObjeto = this.avaliar(expressao.objeto);
627
- var objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
628
- if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
629
- return objeto.get(expressao.simbolo) || null;
630
- }
631
- else if (objeto.constructor === Object) {
632
- return objeto[expressao.simbolo.lexema] || null;
633
- }
634
- else if (objeto instanceof modulo_1.DeleguaModulo) {
635
- return objeto[expressao.simbolo.lexema] || null;
636
- }
637
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você pode acessar métodos do objeto e dicionários.', expressao.linha);
979
+ return __awaiter(this, void 0, void 0, function () {
980
+ var variavelObjeto, objeto;
981
+ return __generator(this, function (_a) {
982
+ switch (_a.label) {
983
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
984
+ case 1:
985
+ variavelObjeto = _a.sent();
986
+ objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
987
+ if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
988
+ return [2 /*return*/, objeto.get(expressao.simbolo) || null];
989
+ }
990
+ else if (objeto.constructor === Object) {
991
+ return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
992
+ }
993
+ else if (objeto instanceof modulo_1.DeleguaModulo) {
994
+ return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
995
+ }
996
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
997
+ }
998
+ });
999
+ });
638
1000
  };
639
1001
  InterpretadorEguaClassico.prototype.visitarExpressaoIsto = function (expressao) {
640
1002
  return this.procurarVariavel(expressao.palavraChave, expressao);
641
1003
  };
642
1004
  InterpretadorEguaClassico.prototype.visitarExpressaoDicionario = function (expressao) {
643
- var dicionario = {};
644
- for (var i = 0; i < expressao.chaves.length; i++) {
645
- dicionario[this.avaliar(expressao.chaves[i])] = this.avaliar(expressao.valores[i]);
646
- }
647
- return dicionario;
1005
+ return __awaiter(this, void 0, void 0, function () {
1006
+ var dicionario, i, _a, _b;
1007
+ return __generator(this, function (_c) {
1008
+ switch (_c.label) {
1009
+ case 0:
1010
+ dicionario = {};
1011
+ i = 0;
1012
+ _c.label = 1;
1013
+ case 1:
1014
+ if (!(i < expressao.chaves.length)) return [3 /*break*/, 5];
1015
+ _a = dicionario;
1016
+ return [4 /*yield*/, this.avaliar(expressao.chaves[i])];
1017
+ case 2:
1018
+ _b = _c.sent();
1019
+ return [4 /*yield*/, this.avaliar(expressao.valores[i])];
1020
+ case 3:
1021
+ _a[_b] = _c.sent();
1022
+ _c.label = 4;
1023
+ case 4:
1024
+ i++;
1025
+ return [3 /*break*/, 1];
1026
+ case 5: return [2 /*return*/, dicionario];
1027
+ }
1028
+ });
1029
+ });
648
1030
  };
649
1031
  InterpretadorEguaClassico.prototype.visitarExpressaoVetor = function (expressao) {
650
- var valores = [];
651
- for (var i = 0; i < expressao.valores.length; i++) {
652
- valores.push(this.avaliar(expressao.valores[i]));
653
- }
654
- return valores;
1032
+ return __awaiter(this, void 0, void 0, function () {
1033
+ var valores, i, _a, _b;
1034
+ return __generator(this, function (_c) {
1035
+ switch (_c.label) {
1036
+ case 0:
1037
+ valores = [];
1038
+ i = 0;
1039
+ _c.label = 1;
1040
+ case 1:
1041
+ if (!(i < expressao.valores.length)) return [3 /*break*/, 4];
1042
+ _b = (_a = valores).push;
1043
+ return [4 /*yield*/, this.avaliar(expressao.valores[i])];
1044
+ case 2:
1045
+ _b.apply(_a, [_c.sent()]);
1046
+ _c.label = 3;
1047
+ case 3:
1048
+ i++;
1049
+ return [3 /*break*/, 1];
1050
+ case 4: return [2 /*return*/, valores];
1051
+ }
1052
+ });
1053
+ });
655
1054
  };
656
1055
  InterpretadorEguaClassico.prototype.visitarExpressaoSuper = function (expressao) {
657
1056
  var distancia = this.locais.get(expressao);
@@ -687,7 +1086,14 @@ var InterpretadorEguaClassico = /** @class */ (function () {
687
1086
  };
688
1087
  InterpretadorEguaClassico.prototype.executar = function (declaracao, mostrarResultado) {
689
1088
  if (mostrarResultado === void 0) { mostrarResultado = false; }
690
- return declaracao.aceitar(this);
1089
+ return __awaiter(this, void 0, void 0, function () {
1090
+ return __generator(this, function (_a) {
1091
+ switch (_a.label) {
1092
+ case 0: return [4 /*yield*/, declaracao.aceitar(this)];
1093
+ case 1: return [2 /*return*/, _a.sent()];
1094
+ }
1095
+ });
1096
+ });
691
1097
  };
692
1098
  /**
693
1099
  * Executa o último escopo empilhado no topo na pilha de escopos do Interpretador.
@@ -703,36 +1109,66 @@ var InterpretadorEguaClassico = /** @class */ (function () {
703
1109
  * @returns O resultado da execução do escopo, se houver.
704
1110
  */
705
1111
  InterpretadorEguaClassico.prototype.executarUltimoEscopo = function () {
706
- var ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
707
- try {
708
- var retornoExecucao = void 0;
709
- for (; !(retornoExecucao instanceof quebras_1.Quebra) &&
710
- ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
711
- retornoExecucao = this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
712
- }
713
- return retornoExecucao;
714
- }
715
- catch (erro) {
716
- return erro;
717
- }
718
- finally {
719
- this.pilhaEscoposExecucao.removerUltimo();
720
- }
1112
+ return __awaiter(this, void 0, void 0, function () {
1113
+ var ultimoEscopo, retornoExecucao, erro_9;
1114
+ return __generator(this, function (_a) {
1115
+ switch (_a.label) {
1116
+ case 0:
1117
+ ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
1118
+ _a.label = 1;
1119
+ case 1:
1120
+ _a.trys.push([1, 6, 7, 8]);
1121
+ retornoExecucao = void 0;
1122
+ _a.label = 2;
1123
+ case 2:
1124
+ if (!(!(retornoExecucao instanceof quebras_1.Quebra) &&
1125
+ ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length)) return [3 /*break*/, 5];
1126
+ return [4 /*yield*/, this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual])];
1127
+ case 3:
1128
+ retornoExecucao = _a.sent();
1129
+ _a.label = 4;
1130
+ case 4:
1131
+ ultimoEscopo.declaracaoAtual++;
1132
+ return [3 /*break*/, 2];
1133
+ case 5: return [2 /*return*/, retornoExecucao];
1134
+ case 6:
1135
+ erro_9 = _a.sent();
1136
+ return [2 /*return*/, erro_9];
1137
+ case 7:
1138
+ this.pilhaEscoposExecucao.removerUltimo();
1139
+ return [7 /*endfinally*/];
1140
+ case 8: return [2 /*return*/];
1141
+ }
1142
+ });
1143
+ });
721
1144
  };
722
1145
  InterpretadorEguaClassico.prototype.interpretar = function (declaracoes) {
723
- this.erros = [];
724
- var retornoResolvedor = this.resolvedor.resolver(declaracoes);
725
- this.locais = retornoResolvedor.locais;
726
- var escopoExecucao = {
727
- declaracoes: declaracoes,
728
- declaracaoAtual: 0,
729
- ambiente: new espaco_variaveis_1.EspacoVariaveis(),
730
- };
731
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
732
- this.executarUltimoEscopo();
733
- return {
734
- erros: this.erros,
735
- };
1146
+ return __awaiter(this, void 0, void 0, function () {
1147
+ var retornoResolvedor, escopoExecucao;
1148
+ return __generator(this, function (_a) {
1149
+ switch (_a.label) {
1150
+ case 0:
1151
+ this.erros = [];
1152
+ retornoResolvedor = this.resolvedor.resolver(declaracoes);
1153
+ this.locais = retornoResolvedor.locais;
1154
+ escopoExecucao = {
1155
+ declaracoes: declaracoes,
1156
+ declaracaoAtual: 0,
1157
+ ambiente: new espaco_variaveis_1.EspacoVariaveis(),
1158
+ };
1159
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
1160
+ return [4 /*yield*/, this.executarUltimoEscopo()];
1161
+ case 1:
1162
+ _a.sent();
1163
+ return [2 /*return*/, {
1164
+ erros: this.erros,
1165
+ }];
1166
+ }
1167
+ });
1168
+ });
1169
+ };
1170
+ InterpretadorEguaClassico.prototype.finalizacao = function () {
1171
+ this.funcaoDeRetorno();
736
1172
  };
737
1173
  return InterpretadorEguaClassico;
738
1174
  }());