@designliquido/delegua 0.0.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +9 -1
  2. package/bin/delegua +1 -1
  3. package/bin/delegua.cmd +1 -1
  4. package/bin/package.json +51 -0
  5. package/index.js +27 -0
  6. package/index.js.map +1 -0
  7. package/package.json +10 -5
  8. package/src/ambiente.js +34 -38
  9. package/src/ambiente.js.map +1 -0
  10. package/src/avaliador-sintatico/dialetos/egua-classico.js +635 -0
  11. package/src/avaliador-sintatico/dialetos/egua-classico.js.map +1 -0
  12. package/src/avaliador-sintatico/dialetos/index.js +14 -0
  13. package/src/avaliador-sintatico/dialetos/index.js.map +1 -0
  14. package/src/avaliador-sintatico/index.js +635 -0
  15. package/src/avaliador-sintatico/index.js.map +1 -0
  16. package/src/avaliador-sintatico/parser-error.js +27 -0
  17. package/src/avaliador-sintatico/parser-error.js.map +1 -0
  18. package/src/bibliotecas/bibliotecaGlobal.js +97 -0
  19. package/src/bibliotecas/bibliotecaGlobal.js.map +1 -0
  20. package/src/bibliotecas/importarBiblioteca.js +32 -0
  21. package/src/bibliotecas/importarBiblioteca.js.map +1 -0
  22. package/src/construtos/assign-subscript.js +35 -0
  23. package/src/construtos/assign-subscript.js.map +1 -0
  24. package/src/construtos/atribuir.js +34 -0
  25. package/src/construtos/atribuir.js.map +1 -0
  26. package/src/construtos/binario.js +35 -0
  27. package/src/construtos/binario.js.map +1 -0
  28. package/src/construtos/call.js +35 -0
  29. package/src/construtos/call.js.map +1 -0
  30. package/src/construtos/conjunto.js +35 -0
  31. package/src/construtos/conjunto.js.map +1 -0
  32. package/src/construtos/dicionario.js +34 -0
  33. package/src/construtos/dicionario.js.map +1 -0
  34. package/src/construtos/expr.js +11 -0
  35. package/src/construtos/expr.js.map +1 -0
  36. package/src/construtos/funcao.js +34 -0
  37. package/src/construtos/funcao.js.map +1 -0
  38. package/src/construtos/get.js +34 -0
  39. package/src/construtos/get.js.map +1 -0
  40. package/src/construtos/grouping.js +33 -0
  41. package/src/construtos/grouping.js.map +1 -0
  42. package/src/construtos/index.js +31 -0
  43. package/src/construtos/index.js.map +1 -0
  44. package/src/construtos/isto.js +33 -0
  45. package/src/construtos/isto.js.map +1 -0
  46. package/src/construtos/literal.js +33 -0
  47. package/src/construtos/literal.js.map +1 -0
  48. package/src/construtos/logical.js +35 -0
  49. package/src/construtos/logical.js.map +1 -0
  50. package/src/construtos/subscript.js +35 -0
  51. package/src/construtos/subscript.js.map +1 -0
  52. package/src/construtos/super.js +34 -0
  53. package/src/construtos/super.js.map +1 -0
  54. package/src/construtos/unario.js +34 -0
  55. package/src/construtos/unario.js.map +1 -0
  56. package/src/construtos/variavel.js +33 -0
  57. package/src/construtos/variavel.js.map +1 -0
  58. package/src/construtos/vetor.js +33 -0
  59. package/src/construtos/vetor.js.map +1 -0
  60. package/src/declaracoes/index.js +249 -0
  61. package/src/declaracoes/index.js.map +1 -0
  62. package/src/delegua.js +110 -83
  63. package/src/delegua.js.map +1 -0
  64. package/src/estruturas/callable.js +15 -4
  65. package/src/estruturas/callable.js.map +1 -0
  66. package/src/estruturas/classe.js +44 -30
  67. package/src/estruturas/classe.js.map +1 -0
  68. package/src/estruturas/funcao-padrao.js +38 -0
  69. package/src/estruturas/funcao-padrao.js.map +1 -0
  70. package/src/estruturas/funcao.js +71 -52
  71. package/src/estruturas/funcao.js.map +1 -0
  72. package/src/estruturas/index.js +19 -0
  73. package/src/estruturas/index.js.map +1 -0
  74. package/src/estruturas/instancia.js +23 -22
  75. package/src/estruturas/instancia.js.map +1 -0
  76. package/src/estruturas/modulo.js +14 -8
  77. package/src/estruturas/modulo.js.map +1 -0
  78. package/src/excecoes/break-exception.js +27 -0
  79. package/src/excecoes/break-exception.js.map +1 -0
  80. package/src/excecoes/continue-exception.js +27 -0
  81. package/src/excecoes/continue-exception.js.map +1 -0
  82. package/src/excecoes/erro-em-tempo-de-execucao.js +31 -0
  83. package/src/excecoes/erro-em-tempo-de-execucao.js.map +1 -0
  84. package/src/excecoes/index.js +17 -0
  85. package/src/excecoes/index.js.map +1 -0
  86. package/src/excecoes/return-exception.js +30 -0
  87. package/src/excecoes/return-exception.js.map +1 -0
  88. package/src/interfaces/avaliador-sintatico-interface.js +3 -0
  89. package/src/interfaces/avaliador-sintatico-interface.js.map +1 -0
  90. package/src/interfaces/index.js +19 -0
  91. package/src/interfaces/index.js.map +1 -0
  92. package/src/interfaces/interpretador-interface.js +3 -0
  93. package/src/interfaces/interpretador-interface.js.map +1 -0
  94. package/src/interfaces/lexador-interface.js +3 -0
  95. package/src/interfaces/lexador-interface.js.map +1 -0
  96. package/src/interfaces/pilha-interface.js +3 -0
  97. package/src/interfaces/pilha-interface.js.map +1 -0
  98. package/src/interfaces/resolvedor-interface.js +3 -0
  99. package/src/interfaces/resolvedor-interface.js.map +1 -0
  100. package/src/interfaces/simbolo-interface.js +3 -0
  101. package/src/interfaces/simbolo-interface.js.map +1 -0
  102. package/src/interpretador/dialetos/egua-classico.js +656 -0
  103. package/src/interpretador/dialetos/egua-classico.js.map +1 -0
  104. package/src/interpretador/dialetos/index.js +14 -0
  105. package/src/interpretador/dialetos/index.js.map +1 -0
  106. package/src/interpretador/index.js +665 -0
  107. package/src/interpretador/index.js.map +1 -0
  108. package/src/lexador/dialetos/egua-classico.js +287 -0
  109. package/src/lexador/dialetos/egua-classico.js.map +1 -0
  110. package/src/lexador/dialetos/index.js +14 -0
  111. package/src/lexador/dialetos/index.js.map +1 -0
  112. package/src/lexador/index.js +287 -0
  113. package/src/lexador/index.js.map +1 -0
  114. package/src/resolvedor/Pilha.js +27 -0
  115. package/src/resolvedor/Pilha.js.map +1 -0
  116. package/src/resolvedor/ResolverError.js +29 -0
  117. package/src/resolvedor/ResolverError.js.map +1 -0
  118. package/src/resolvedor/dialetos/egua-classico.js +331 -0
  119. package/src/resolvedor/dialetos/egua-classico.js.map +1 -0
  120. package/src/resolvedor/dialetos/index.js +14 -0
  121. package/src/resolvedor/dialetos/index.js.map +1 -0
  122. package/src/resolvedor/index.js +331 -0
  123. package/src/resolvedor/index.js.map +1 -0
  124. package/src/tiposDeSimbolos.js +25 -23
  125. package/src/tiposDeSimbolos.js.map +1 -0
  126. package/src/web.js +64 -68
  127. package/src/web.js.map +1 -0
  128. package/.github/CONTRIBUTING.md +0 -0
  129. package/.github/workflows/principal.yml +0 -20
  130. package/.release-it.json +0 -8
  131. package/.vscode/launch.json +0 -29
  132. package/.vscode/settings.json +0 -3
  133. package/LICENSE +0 -21
  134. package/babel.config.js +0 -1
  135. package/indice.js +0 -14
  136. package/src/erro.js +0 -18
  137. package/src/estruturas/funcaoPadrao.js +0 -18
  138. package/src/expr.js +0 -228
  139. package/src/interpretador.js +0 -802
  140. package/src/lexer.js +0 -316
  141. package/src/lib/globalLib.js +0 -171
  142. package/src/lib/importStdlib.js +0 -32
  143. package/src/parser.js +0 -822
  144. package/src/resolver.js +0 -425
  145. package/src/stmt.js +0 -215
  146. package/testes/testes.egua +0 -630
package/src/lexer.js DELETED
@@ -1,316 +0,0 @@
1
- const tiposDeSimbolos = require("./tiposDeSimbolos.js");
2
-
3
- const palavrasReservadas = {
4
- e: tiposDeSimbolos.E,
5
- em: tiposDeSimbolos.EM,
6
- classe: tiposDeSimbolos.CLASSE,
7
- senao: tiposDeSimbolos.SENAO,
8
- falso: tiposDeSimbolos.FALSO,
9
- para: tiposDeSimbolos.PARA,
10
- funcao: tiposDeSimbolos.FUNCAO,
11
- se: tiposDeSimbolos.SE,
12
- senaose: tiposDeSimbolos.SENAOSE,
13
- nulo: tiposDeSimbolos.NULO,
14
- ou: tiposDeSimbolos.OU,
15
- escreva: tiposDeSimbolos.ESCREVA,
16
- retorna: tiposDeSimbolos.RETORNA,
17
- super: tiposDeSimbolos.SUPER,
18
- isto: tiposDeSimbolos.ISTO,
19
- verdadeiro: tiposDeSimbolos.VERDADEIRO,
20
- var: tiposDeSimbolos.VAR,
21
- fazer: tiposDeSimbolos.FAZER,
22
- enquanto: tiposDeSimbolos.ENQUANTO,
23
- pausa: tiposDeSimbolos.PAUSA,
24
- continua: tiposDeSimbolos.CONTINUA,
25
- escolha: tiposDeSimbolos.ESCOLHA,
26
- caso: tiposDeSimbolos.CASO,
27
- padrao: tiposDeSimbolos.PADRAO,
28
- importar: tiposDeSimbolos.IMPORTAR,
29
- tente: tiposDeSimbolos.TENTE,
30
- pegue: tiposDeSimbolos.PEGUE,
31
- finalmente: tiposDeSimbolos.FINALMENTE,
32
- herda: tiposDeSimbolos.HERDA
33
- };
34
-
35
- class Simbolo {
36
- constructor(tipo, lexeme, literal, linha) {
37
- this.tipo = tipo;
38
- this.lexeme = lexeme;
39
- this.literal = literal;
40
- this.linha = linha;
41
- }
42
-
43
- toString() {
44
- return this.tipo + " " + this.lexeme + " " + this.literal;
45
- }
46
- }
47
-
48
- /**
49
- * O Lexador é responsável por transformar o código em uma coleção de tokens de linguagem.
50
- * Cada token de linguagem é representado por um tipo, um lexema e informações da linha de código em que foi expresso.
51
- * Também é responsável por mapear as palavras reservadas da linguagem, que não podem ser usadas por outras
52
- * estruturas, tais como nomes de variáveis, funções, literais, classes e assim por diante.
53
- */
54
- module.exports = class Lexer {
55
- constructor(codigo, Delegua) {
56
- this.Delegua = Delegua;
57
- this.codigo = codigo;
58
-
59
- this.simbolos = [];
60
-
61
- this.inicio = 0;
62
- this.atual = 0;
63
- this.linha = 1;
64
- }
65
-
66
- eDigito(caractere) {
67
- return caractere >= "0" && caractere <= "9";
68
- }
69
-
70
- eAlfabeto(caractere) {
71
- return (caractere >= "a" && caractere <= "z") || (caractere >= "A" && caractere <= "Z") || caractere == "_";
72
- }
73
-
74
- eAlfabetoOuDigito(caractere) {
75
- return this.eDigito(caractere) || this.eAlfabeto(caractere);
76
- }
77
-
78
- eFinalDoCodigo() {
79
- return this.atual >= this.codigo.length;
80
- }
81
-
82
- avancar() {
83
- this.atual += 1;
84
- return this.codigo[this.atual - 1];
85
- }
86
-
87
- adicionarSimbolo(tipo, literal = null) {
88
- const texto = this.codigo.substring(this.inicio, this.atual);
89
- this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha));
90
- }
91
-
92
- match(esperado) {
93
- if (this.eFinalDoCodigo()) {
94
- return false;
95
- }
96
-
97
- if (this.codigo[this.atual] !== esperado) {
98
- return false;
99
- }
100
-
101
- this.atual += 1;
102
- return true;
103
- }
104
-
105
- peek() {
106
- if (this.eFinalDoCodigo()) return "\0";
107
- return this.codigo.charAt(this.atual);
108
- }
109
-
110
- peekNext() {
111
- if (this.atual + 1 >= this.codigo.length) return "\0";
112
- return this.codigo.charAt(this.atual + 1);
113
- }
114
-
115
- voltar() {
116
- return this.codigo.charAt(this.atual - 1);
117
- }
118
-
119
- analisarTexto(texto = '"') {
120
- while (this.peek() !== texto && !this.eFinalDoCodigo()) {
121
- if (this.peek() === "\n") this.linha = +1;
122
- this.avancar();
123
- }
124
-
125
- if (this.eFinalDoCodigo()) {
126
- this.Delegua.lexerError(
127
- this.linha,
128
- this.voltar(),
129
- "Texto não finalizado."
130
- );
131
- return;
132
- }
133
-
134
- this.avancar();
135
-
136
- const valor = this.codigo.substring(this.inicio + 1, this.atual - 1);
137
- this.adicionarSimbolo(tiposDeSimbolos.TEXTO, valor);
138
- }
139
-
140
- analisarNumero() {
141
- while (this.eDigito(this.peek())) {
142
- this.avancar();
143
- }
144
-
145
- if (this.peek() == "." && this.eDigito(this.peekNext())) {
146
- this.avancar();
147
-
148
- while (this.eDigito(this.peek())) {
149
- this.avancar();
150
- }
151
- }
152
-
153
- const numeroCompleto = this.codigo.substring(this.inicio, this.atual);
154
- this.adicionarSimbolo(tiposDeSimbolos.NUMERO, parseFloat(numeroCompleto));
155
- }
156
-
157
- identificarPalavraChave() {
158
- while (this.eAlfabetoOuDigito(this.peek())) {
159
- this.avancar();
160
- }
161
-
162
- const codigo = this.codigo.substring(this.inicio, this.atual);
163
- const tipo = codigo in palavrasReservadas ? palavrasReservadas[codigo] : tiposDeSimbolos.IDENTIFICADOR;
164
-
165
- this.adicionarSimbolo(tipo);
166
- }
167
-
168
- scanToken() {
169
- const caractere = this.avancar();
170
-
171
- switch (caractere) {
172
- case "[":
173
- this.adicionarSimbolo(tiposDeSimbolos.COLCHETE_ESQUERDO);
174
- break;
175
- case "]":
176
- this.adicionarSimbolo(tiposDeSimbolos.COLCHETE_DIREITO);
177
- break;
178
- case "(":
179
- this.adicionarSimbolo(tiposDeSimbolos.PARENTESE_ESQUERDO);
180
- break;
181
- case ")":
182
- this.adicionarSimbolo(tiposDeSimbolos.PARENTESE_DIREITO);
183
- break;
184
- case "{":
185
- this.adicionarSimbolo(tiposDeSimbolos.CHAVE_ESQUERDA);
186
- break;
187
- case "}":
188
- this.adicionarSimbolo(tiposDeSimbolos.CHAVE_DIREITA);
189
- break;
190
- case ",":
191
- this.adicionarSimbolo(tiposDeSimbolos.COMMA);
192
- break;
193
- case ".":
194
- this.adicionarSimbolo(tiposDeSimbolos.DOT);
195
- break;
196
- case "-":
197
- if (this.match("=")) {
198
- this.adicionarSimbolo(tiposDeSimbolos.MENOR_IGUAL);
199
- }
200
- this.adicionarSimbolo(tiposDeSimbolos.SUBTRACAO);
201
- break;
202
- case "+":
203
- if (this.match("=")) {
204
- this.adicionarSimbolo(tiposDeSimbolos.MAIS_IGUAL);
205
- }
206
- this.adicionarSimbolo(tiposDeSimbolos.ADICAO);
207
- break;
208
- case ":":
209
- this.adicionarSimbolo(tiposDeSimbolos.COLON);
210
- break;
211
- case ";":
212
- this.adicionarSimbolo(tiposDeSimbolos.SEMICOLON);
213
- break;
214
- case "%":
215
- this.adicionarSimbolo(tiposDeSimbolos.MODULUS);
216
- break;
217
- case "*":
218
- if (this.peek() === "*") {
219
- this.avancar();
220
- this.adicionarSimbolo(tiposDeSimbolos.STAR_STAR);
221
- break;
222
- }
223
- this.adicionarSimbolo(tiposDeSimbolos.STAR);
224
- break;
225
- case "!":
226
- this.adicionarSimbolo(
227
- this.match("=") ? tiposDeSimbolos.DIFERENTE : tiposDeSimbolos.NEGACAO
228
- );
229
- break;
230
- case "=":
231
- this.adicionarSimbolo(
232
- this.match("=") ? tiposDeSimbolos.IGUAL_IGUAL : tiposDeSimbolos.IGUAL
233
- );
234
- break;
235
-
236
- case "&":
237
- this.adicionarSimbolo(tiposDeSimbolos.BIT_AND);
238
- break;
239
-
240
- case "~":
241
- this.adicionarSimbolo(tiposDeSimbolos.BIT_NOT);
242
- break;
243
-
244
- case "|":
245
- this.adicionarSimbolo(tiposDeSimbolos.BIT_OR);
246
- break;
247
-
248
- case "^":
249
- this.adicionarSimbolo(tiposDeSimbolos.BIT_XOR);
250
- break;
251
-
252
- case "<":
253
- if (this.match("=")) {
254
- this.adicionarSimbolo(tiposDeSimbolos.MENOR_IGUAL);
255
- } else if (this.match("<")) {
256
- this.adicionarSimbolo(tiposDeSimbolos.MENOR_MENOR);
257
- } else {
258
- this.adicionarSimbolo(tiposDeSimbolos.MENOR);
259
- }
260
- break;
261
-
262
- case ">":
263
- if (this.match("=")) {
264
- this.adicionarSimbolo(tiposDeSimbolos.MAIOR_IGUAL);
265
- } else if (this.match(">")) {
266
- this.adicionarSimbolo(tiposDeSimbolos.MAIOR_MAIOR);
267
- } else {
268
- this.adicionarSimbolo(tiposDeSimbolos.MAIOR);
269
- }
270
- break;
271
-
272
- case "/":
273
- if (this.match("/")) {
274
- while (this.peek() != "\n" && !this.eFinalDoCodigo()) this.avancar();
275
- } else {
276
- this.adicionarSimbolo(tiposDeSimbolos.SLASH);
277
- }
278
- break;
279
-
280
- // Esta sessão ignora espaços em branco na tokenização
281
- case " ":
282
- case "\r":
283
- case "\t":
284
- break;
285
-
286
- // tentativa de pulhar linha com \n que ainda não funciona
287
- case "\n":
288
- this.linha += 1;
289
- break;
290
-
291
- case '"':
292
- this.analisarTexto('"');
293
- break;
294
-
295
- case "'":
296
- this.analisarTexto("'");
297
- break;
298
-
299
- default:
300
- if (this.eDigito(caractere)) this.analisarNumero();
301
- else if (this.eAlfabeto(caractere)) this.identificarPalavraChave();
302
- else this.Delegua.lexerError(this.linha, caractere, "Caractere inesperado.");
303
- }
304
- }
305
-
306
- scan() {
307
- while (!this.eFinalDoCodigo()) {
308
- this.inicio = this.atual;
309
- this.scanToken();
310
- }
311
-
312
- this.simbolos.push(new Simbolo(tiposDeSimbolos.EOF, "", null, this.linha));
313
-
314
- return this.simbolos;
315
- }
316
- };
@@ -1,171 +0,0 @@
1
- const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao,
2
- DeleguaFuncao = require("../estruturas/funcao.js"),
3
- DeleguaInstancia = require("../estruturas/instancia.js"),
4
- FuncaoPadrao = require("../estruturas/funcaoPadrao.js"),
5
- DeleguaClasse = require("../estruturas/classe.js");
6
-
7
-
8
- module.exports = function (interpretador, globals) {
9
- // Retorna um número aleatório entre 0 e 1.
10
- globals.definirVariavel(
11
- "aleatorio",
12
- new FuncaoPadrao(1, function () {
13
- return Math.random();
14
- })
15
- );
16
-
17
- // Retorna um número aleatório de acordo com o parâmetro passado.
18
- // MIN(inclusivo) - MAX(exclusivo)
19
- globals.definirVariavel(
20
- "aleatorioEntre",
21
- new FuncaoPadrao(1, function (min, max) {
22
- if (typeof min !== 'number' || typeof max !== 'number') {
23
- throw new ErroEmTempoDeExecucao(
24
- this.simbolo,
25
- "Os dois parâmetros devem ser do tipo número."
26
- );
27
- }
28
-
29
- return Math.floor(Math.random() * (max - min)) + min;
30
- })
31
- );
32
-
33
- globals.definirVariavel(
34
- "inteiro",
35
- new FuncaoPadrao(1, function (valor) {
36
- if (valor === undefined || valor === null) {
37
- throw new ErroEmTempoDeExecucao(
38
- this.simbolo,
39
- "Somente números podem passar para inteiro."
40
- );
41
- }
42
-
43
- if (!/^-{0,1}\d+$/.test(valor) && !/^\d+\.\d+$/.test(valor)) {
44
- throw new ErroEmTempoDeExecucao(
45
- this.simbolo,
46
- "Somente números podem passar para inteiro."
47
- );
48
- }
49
-
50
- return parseInt(valor);
51
- })
52
- );
53
-
54
- globals.definirVariavel(
55
- "mapear",
56
- new FuncaoPadrao(1, function (array, callback) {
57
- if (!Array.isArray(array)) {
58
- throw new ErroEmTempoDeExecucao(
59
- this.simbolo,
60
- "Parâmetro inválido. O primeiro parâmetro da função, deve ser um array."
61
- );
62
- }
63
-
64
- if (callback.constructor.nome !== 'DeleguaFuncao') {
65
- throw new ErroEmTempoDeExecucao(
66
- this.simbolo,
67
- "Parâmetro inválido. O segundo parâmetro da função, deve ser uma função."
68
- );
69
- }
70
-
71
- let provisorio = [];
72
- for (let indice = 0; indice < array.length; ++indice) {
73
- provisorio.push(
74
- callback.call(
75
- interpretador, [array[indice]]
76
- )
77
- );
78
- }
79
-
80
- return provisorio;
81
- })
82
- );
83
-
84
- globals.definirVariavel(
85
- "ordenar",
86
- new FuncaoPadrao(1, function (obj) {
87
- if (Array.isArray(obj) == false) {
88
- throw new ErroEmTempoDeExecucao(
89
- this.simbolo,
90
- "Valor Inválido. Objeto inserido não é um vetor."
91
- );
92
- }
93
-
94
- let trocado;
95
- let length = obj.length;
96
- do {
97
- trocado = false;
98
- for (var i = 0; i < length - 1; i++) {
99
- if (obj[i] > obj[i + 1]) {
100
- [obj[i], obj[i + 1]] = [obj[i + 1], obj[i]];
101
- trocado = true;
102
- }
103
- }
104
- } while (trocado);
105
- return obj;
106
- })
107
- );
108
-
109
- globals.definirVariavel(
110
- "real",
111
- new FuncaoPadrao(1, function (valor) {
112
- if (!/^-{0,1}\d+$/.test(valor) && !/^\d+\.\d+$/.test(valor))
113
- throw new ErroEmTempoDeExecucao(
114
- this.simbolo,
115
- "Somente números podem passar para real."
116
- );
117
- return parseFloat(valor);
118
- })
119
- );
120
-
121
- globals.definirVariavel(
122
- "tamanho",
123
- new FuncaoPadrao(1, function (objeto) {
124
- if (!isNaN(objeto)) {
125
- throw new ErroEmTempoDeExecucao(
126
- this.simbolo,
127
- "Não é possível encontrar o tamanho de um número."
128
- );
129
- }
130
-
131
- if (objeto instanceof DeleguaInstancia) {
132
- throw new ErroEmTempoDeExecucao(
133
- this.simbolo,
134
- "Você não pode encontrar o tamanho de uma declaração."
135
- );
136
- }
137
-
138
- if (objeto instanceof DeleguaFuncao) {
139
- return objeto.declaracao.parametros.length;
140
- }
141
-
142
- if (objeto instanceof FuncaoPadrao) {
143
- return objeto.valorAridade;
144
- }
145
-
146
- if (objeto instanceof DeleguaClasse) {
147
- let metodos = objeto.metodos;
148
- let tamanho = 0;
149
-
150
- if (metodos.init && metodos.init.eInicializador) {
151
- tamanho = metodos.init.declaracao.parametros.length;
152
- }
153
-
154
- return tamanho;
155
- }
156
-
157
- return objeto.length;
158
- })
159
- );
160
-
161
- globals.definirVariavel(
162
- "texto",
163
- new FuncaoPadrao(1, function (valor) {
164
- return `${valor}`;
165
- })
166
- );
167
-
168
- globals.definirVariavel("exports", {});
169
-
170
- return globals;
171
- };
@@ -1,32 +0,0 @@
1
- const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao,
2
- FuncaoPadrao = require("../estruturas/funcaoPadrao.js"),
3
- DeleguaModulo = require("../estruturas/modulo.js");
4
-
5
- const carregarModulo = function (nomeDoModulo, caminhoDoModulo) {
6
- let dadosDoModulo;
7
- try {
8
- dadosDoModulo = require(caminhoDoModulo);
9
- } catch (erro) {
10
- throw new ErroEmTempoDeExecucao(nomeDoModulo, `Biblioteca ${nomeDoModulo} não encontrada para importação.`);
11
- }
12
-
13
- let novoModulo = new DeleguaModulo(nomeDoModulo);
14
-
15
- let chaves = Object.keys(dadosDoModulo);
16
- for (let i = 0; i < chaves.length; i++) {
17
- const moduloAtual = dadosDoModulo[chaves[i]];
18
-
19
- if (typeof moduloAtual === "function") {
20
- novoModulo[chaves[i]] = new FuncaoPadrao(moduloAtual.length, moduloAtual);
21
- } else {
22
- novoModulo[chaves[i]] = moduloAtual;
23
- }
24
- }
25
-
26
- return novoModulo;
27
- };
28
-
29
- module.exports = function (nome) {
30
- //TODO:Samuel: Precisa testar ainda.
31
- return carregarModulo(nome, nome);
32
- };