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