force-lang 0.0.13 → 0.1.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.
package/src/native_lib.js CHANGED
@@ -1,1458 +1,1702 @@
1
- const log = require('bunny-logger');
2
- //const request = require('request-promise-native');
3
- const request = require('sync-request');
4
- const JSON5 = require('json5');
5
- const env = require('./env');
6
- const err = require('./error');
7
- const eval = require('./eval');
8
- const loadfile = require('./load-file');
9
- const obj_utils = require('./obj_utils');
10
- const vsprintf = require('format').vsprintf;
11
- const cheerio = require('cheerio');
12
-
13
- class NativeLib{
14
- constructor(){
15
- this.populate();
16
- }
17
- make_func_obj(func_name){
18
- return {
19
- "_type":"TC_COMP_FUNC",
20
- "_datum":func_name
21
- }
22
- }
23
-
24
- test_func(){
25
- log.info('...hai detto pippo?');
26
- }
27
- bye_func(){
28
- process.exit(0);
29
- }
30
- noop_func(){
31
- //do nothing (no operation)
32
- }
33
- print_stack_func(){
34
- env.print_stack();
35
- }
36
- print_env_func(){
37
- env.print_debug();
38
- }
39
- print_words_func(){
40
- let x = env._dict;
41
- //x=x.filter(item => item._type == 'TC_NATIVE_FUNC');
42
- for(var item of x){
43
- if(item._datum._type == 'TC_NATIVE_FUNC'|| item._datum._type == 'TC_COMP_FUNC'){
44
- //log.info(`${item._name} `);
45
- process.stdout.write(`${item._name} `);
46
- }
47
- }
48
- log.info('');
49
- }
50
- emit_func(){
51
- const x = env.s.pop();
52
- //log.info(x);
53
- if(x._type === 'TC_NUM'){
54
- process.stdout.write(String.fromCharCode(x._datum));
55
- return;
56
- }
57
- env.s.push(err.throw(`unknown item type ${x._type} of ${x._datum}`));
58
- }
59
- see_func(func_name){
60
- var x=env.lookup(func_name);
61
- if(!x){
62
- log.info('no word found...');
63
- return;
64
- }
65
- switch(x._datum._type){
66
- case 'TC_NATIVE_FUNC':
67
- log.info(`: ${x._name}`);
68
- log.info('<native func> ;');
69
- break;
70
- case 'TC_COMP_FUNC':
71
- log.info(`: ${x._name}`);
72
- process.stdout.write(` `);
73
- for(var n of x._datum._datum){
74
- process.stdout.write(`${n._datum} `);
75
- }
76
- log.info('');
77
- break;
78
- default:
79
- log.info('not a word...');
80
- break;
81
- }
82
- }
83
- print_tos_func(){
84
- const x = env.s.pop();
85
- if(!x) return;
86
- //log.info(x);
87
- switch(x._type){
88
- case 'TC_NUM':
89
- case 'TC_STR':
90
- case 'TC_BOOL':
91
- log.info(x._datum);
92
- break;
93
- case 'TC_JSON':
94
- log.info(obj_utils.stringify(x._datum));
95
- break;
96
- case 'TC_FUNC_JS':
97
- log.info('#-<js func>');
98
- break;
99
- case 'TC_LAMBDA_FUNC':
100
- log.info('#-<lambda func>');
101
- break;
102
- case 'TC_VAR':
103
- log.info(x._name);
104
- break;
105
- case 'TC_ERR':
106
- log.info(`ERR: ${x._datum.msg}`);
107
- break;
108
- default:
109
- log.info(`unknown: { ${x._type} ${x._datum} }`);
110
- break;
111
- }
112
- }
113
- print_debug_tos_func(){
114
- const x = env.s.pop();
115
- if(!x) return;
116
- //log.info(x);
117
- switch(x._type){
118
- case 'TC_NUM':
119
- case 'TC_STR':
120
- case 'TC_BOOL':
121
- log.info(`{ ${x._type} ${x._datum} }`);
122
- break;
123
- case 'TC_JSON':
124
- log.info(`{ ${x._type} ${obj_utils.stringify(x._datum)} }`);
125
- break;
126
- case 'TC_FUNC_JS':
127
- log.info('#-<js func>');
128
- break;
129
- case 'TC_LAMBDA_FUNC':
130
- log.info('#-<lambda func>');
131
- break;
132
- case 'TC_VAR':
133
- log.info(`{ ${x._type} ${x._name} ${obj_utils.stringify(x._datum._datum)} }`);
134
- break;
135
- case 'TC_ERR':
136
- log.info(`ERR: ${x._datum.msg}`);
137
- break;
138
- default:
139
- log.info(`unknown: { ${x._type} ${x._datum} }`);
140
- break;
141
- }
142
- }
143
- assign_var_func(){
144
- const varx = env.s.pop();
145
- const val = env.s.pop();
146
- if(!varx || !val) {
147
- env.s.push(err.throw('no items on top 2 elements of the stack... aborting'));
148
- return;
149
- }
150
- //log.info(varx);
151
- //log.info(val);
152
- switch(val._type){
153
- case'TC_NUM':
154
- case 'TC_STR':
155
- case 'TC_JSON':
156
- case 'TC_PROMISE':
157
- varx._datum = val;
158
- //env.set(varx._name, val, varx._type, varx._where);
159
- break;
160
- default:
161
- break;
162
- }
163
- }
164
- read_var_func(){
165
- const varx = env.s.pop();
166
- if(!varx) {
167
- env.s.push(err.throw('no element on top of the stack... aborting'));
168
- return;
169
- }
170
- //log.info(varx);
171
- switch(varx._datum._type){
172
- case'TC_NUM':
173
- case 'TC_STR':
174
- case 'TC_JSON':
175
- case 'TC_PROMISE':
176
- env.s.push(varx._datum);
177
- break;
178
- default:
179
- break;
180
- }
181
- }
182
- not_func(){
183
- if(!env.is_bool(env.TOS())){
184
- env.s.push(err.throw('TOS is not a bool. aborting operation...'));
185
- return;
186
- }
187
- let x = env.get_bool_val(env.s.pop());
188
- env.s.push(env.set_bool_val(!x));
189
- }
190
- and_func(){
191
- if(!env.is_bool(env.TOS())){
192
- env.s.push(err.throw('TOS is not a bool. aborting operation...'));
193
- return;
194
- }
195
- if(!env.is_bool(env.TOS2())){
196
- env.s.push(err.throw('TOS" is not a bool. aborting operation...'));
197
- return;
198
- }
199
- let a=env.get_bool_val(env.s.pop());
200
- let b=env.get_bool_val(env.s.pop());
201
- env.s.push(env.set_bool_val(a&&b));
202
- }
203
- or_func(){
204
- if(!env.is_bool(env.TOS())){
205
- env.s.push(err.throw('TOS is not a bool. aborting operation...'));
206
- return;
207
- }
208
- if(!env.is_bool(env.TOS2())){
209
- env.s.push(err.throw('TOS2 is not a bool. aborting operation...'));
210
- return;
211
- }
212
- let a=env.get_bool_val(env.s.pop());
213
- let b=env.get_bool_val(env.s.pop());
214
- env.s.push(env.set_bool_val(a||b));
215
- }
216
- is_num_func(){
217
- if(env.is_num(env.s.pop())){
218
- env.s.push(env.true_obj());
219
- return;
220
- }
221
- env.s.push(env.false_obj());
222
- }
223
- is_string_func(){
224
- if(env.is_string(env.s.pop())){
225
- env.s.push(env.true_obj());
226
- return;
227
- }
228
- env.s.push(env.false_obj());
229
- }
230
- is_list_func(){
231
- if(env.is_list(env.s.pop())){
232
- env.s.push(env.true_obj());
233
- return;
234
- }
235
- env.s.push(env.false_obj());
236
- }
237
- is_falsy_func(){
238
- let x = env.s.pop();
239
- if(x){
240
- switch(x._type){
241
- case 'TC_NUM':
242
- if(x._datum==0) return env.s.push(env.true_obj()); else return env.s.push(env.false_obj());
243
- break;
244
- case 'TC_STR':
245
- if(x._datum == '') return env.s.push(env.true_obj());
246
- break;
247
- case 'TC_BOOL':
248
- if(env.is_false(x)) return env.s.push(env.true_obj());
249
- break;
250
- case 'TC_JLIST':
251
- case 'TC_JOBJ':
252
- default:
253
- return env.s.push(env.false_obj());
254
- break;
255
- }
256
- }
257
- return env.s.push(env.true_obj());
258
- }
259
- dup_func(){
260
- env.s.push(env.TOS());
261
- }
262
- swap_func(){
263
- if(env.TOS() && env.TOS2()){
264
- let x = env.s.pop();
265
- let y = env.s.pop();
266
- env.s.push(x);
267
- env.s.push(y);
268
- return;
269
- }
270
- env.s.push(err.throw('not 2 elemets in the stack... aborting...'));
271
- }
272
- drop_func(){
273
- env.s.pop();
274
- }
275
- ndrop_func(){
276
- if(env.TOS() && env.TOS()._type=== 'TC_NUM'){
277
- try{
278
- let n=env.s.pop()._datum;
279
- while(n>0) {
280
- env.s.pop();
281
- n--;
282
- }
283
- return;
284
- }catch(e){
285
- env.s.push(err.throw(e));
286
- return;
287
- }
288
- }
289
- env.s.push(err.throw("invalid arguments type. TOS is not a number."));
290
- }
291
- nbye_func(){
292
- if(env.TOS() && env.TOS()._type == 'TC_NUM'){
293
- process.exit(env.s.pop()._datum);
294
- }
295
- env.s.push(err.throw('TOS not a number... aborting'));
296
- }
297
- over_func(){
298
- env.s.push(env.s.look_at(1));
299
- }
300
- num_plus_func(){
301
- if(env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM'){
302
- env.s.push({_type: 'TC_NUM', _datum: env.s.pop()._datum + env.s.pop()._datum});
303
- return;
304
- }
305
- env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
306
- }
307
- num_minus_func(){
308
- if(env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM'){
309
- let x = env.s.pop()._datum;
310
- let y = env.s.pop()._datum;
311
- env.s.push({_type: 'TC_NUM', _datum: y - x});
312
- return;
313
- }
314
- env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
315
- }
316
- num_times_func(){
317
- if(env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM'){
318
- env.s.push({_type: 'TC_NUM', _datum: env.s.pop()._datum * env.s.pop()._datum});
319
- return;
320
- }
321
- env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
322
- }
323
- num_div_func(){
324
- if(env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM'){
325
- let x = env.s.pop()._datum;
326
- let y = env.s.pop()._datum;
327
- env.s.push({_type: 'TC_NUM', _datum: y / x});
328
- return;
329
- }
330
- env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
331
- }
332
- plus_func(){
333
- eval.eval('f+');
334
- }
335
- minus_func(){
336
- eval.eval('n:-');
337
- }
338
- times_func(){
339
- eval.eval('n:*');
340
- }
341
- division_func(){
342
- eval.eval('n:/');
343
- }
344
- module_func(){
345
- eval.eval('n:%');
346
- }
347
- string_plus_func(){
348
- if(env.is_string(env.TOS()) || env.is_string(env.TOS2())){
349
- if(env.is_num(env.TOS()) || env.is_num(env.TOS2()) || env.is_string(env.TOS()) || env.is_string(env.TOS2())){
350
- const x= env.s.pop();
351
- const y= env.s.pop();
352
- env.s.push({"_type":"TC_STR","_datum":y._datum+x._datum});
353
- return;
354
- }
355
- }
356
- env.s.push(err.throw("invalid arguments type"));
357
- }
358
- array_plus_func(){
359
- if(env.is_list(env.TOS()) || env.is_list(env.TOS2())){
360
- const x= env.s.pop();
361
- const y= env.s.pop();
362
- env.s.push({"_type":"TC_JSON","_datum":y._datum.concat(x._datum)});
363
- return;
364
- }
365
- env.s.push(err.throw("invalid arguments type"));
366
- }
367
- array_at_func(){
368
- if(env.is_num(env.TOS()) && env.is_list(env.TOS2())){
369
- try{
370
- var index=env.s.pop()._datum;
371
- var arr=env.s.pop()._datum;
372
- if(index<0) index=arr.length+index;
373
- if(index>=arr.length || index<0){
374
- env.s.push(err.throw("invalid index bound"));
375
- return;
376
- }
377
- const value=arr[index];
378
- const xval=env.adj_bool_val(value);
379
- env.s.push({"_type":env.guess_type(value), "_datum":xval});
380
- return;
381
- }catch(e){
382
- env.s.push(err.throw(e));
383
- return;
384
- }
385
- }
386
- env.s.push(err.throw("invalid arguments type"));
387
- }
388
- array_set_at_func(){
389
- if(env.TOS() && env.is_num(env.TOS2()) && env.is_list(env.s.look_at(2))){
390
- try{
391
- var value=env.s.pop()._datum;
392
- var index=env.s.pop()._datum;
393
- var arr=env.s.pop()._datum;
394
- if(index<0) index=arr.length+index;
395
- if(index>=arr.length || index<0){
396
- env.s.push(err.throw("invalid index bound"));
397
- return;
398
- }
399
- arr[index]=value;
400
- env.s.push({"_type":"TC_JSON", "_datum":arr});
401
- return;
402
- }catch(e){
403
- env.s.push(err.throw(e));
404
- return;
405
- }
406
- }
407
- env.s.push(err.throw("invalid arguments type"));
408
- }
409
- object_at_func(){
410
- if(env.is_string(env.TOS()) && env.is_obj(env.TOS2())){
411
- try{
412
- var key=env.s.pop()._datum;
413
- var obj=env.s.pop()._datum;
414
- var value=obj[key];
415
- if(value){
416
- const xval=env.adj_bool_val(value);
417
- env.s.push({"_type":env.guess_type(value), "_datum":xval});
418
- return;
419
- }
420
- env.s.push(err.throw("invalid object key"));
421
- return;
422
- }catch(e){
423
- env.s.push(err.throw(e));
424
- return;
425
- }
426
- }
427
- env.s.push(err.throw("invalid arguments type"));
428
- }
429
- object_set_at_func(){
430
- if(env.TOS() && env.is_string(env.TOS2()) && env.is_obj(env.s.look_at(2))){
431
- try{
432
- var value=env.s.pop()._datum;
433
- var key=env.s.pop()._datum;
434
- var obj=env.s.pop()._datum;
435
- obj[key]=value;
436
- env.s.push({"_type":'TC_JSON', "_datum":obj});
437
- return;
438
- }catch(e){
439
- env.s.push(err.throw(e));
440
- return;
441
- }
442
- }
443
- env.s.push(err.throw("invalid arguments type"));
444
- }
445
- array_length_func(){
446
- if(env.is_list(env.TOS())){
447
- try{
448
- var x=env.s.pop()._datum.length;
449
- env.s.push({"_type":"TC_NUM","_datum":x});
450
- return;
451
- }catch(e){
452
- env.s.push(err.throw(e));
453
- return;
454
- }
455
- }
456
- env.s.push(err.throw("invalid arguments type. TOS not a list"));
457
- }
458
- array_push_func(){
459
- if(env.is_list(env.TOS2()) && env.TOS()){
460
- try{
461
- var value=env.s.pop()._datum;
462
- var arr=env.s.pop()._datum;
463
- arr.push(value);
464
- env.s.push({"_type":"TC_JSON","_datum":arr});
465
- return;
466
- }catch(e){
467
- env.s.push(err.throw(e));
468
- return;
469
- }
470
- }
471
- env.s.push(err.throw("invalid arguments type."));
472
- }
473
- array_pop_func(){
474
- if(env.is_list(env.TOS())){
475
- try{
476
- var value=env.s.pop()._datum.pop();
477
- const xval=env.adj_bool_val(value);
478
- env.s.push({"_type":env.guess_type(value), "_datum":xval});
479
- return;
480
- }catch(e){
481
- env.s.push(err.throw(e));
482
- return;
483
- }
484
- }
485
- env.s.push(err.throw("invalid arguments type. TOS not a list"));
486
- }
487
- object_keys_func(){
488
- if(env.is_obj(env.TOS())){
489
- try{
490
- var x=env.s.pop()._datum;
491
- env.s.push({"_type":"TC_JSON","_datum":Object.keys(x)});
492
- return;
493
- }catch(e){
494
- env.s.push(err.throw(e));
495
- return;
496
- }
497
- }
498
- env.s.push(err.throw("invalid arguments type."));
499
- }
500
- object_values_func(){
501
- if(env.is_obj(env.TOS())){
502
- try{
503
- var x=env.s.pop()._datum;
504
- env.s.push({"_type":"TC_JSON","_datum":Object.values(x)});
505
- return;
506
- }catch(e){
507
- env.s.push(err.throw(e));
508
- return;
509
- }
510
- }
511
- env.s.push(err.throw("invalid arguments type."));
512
- }
513
- string_split_func(){
514
- if(env.TOS() && env.is_string(env.TOS2())){
515
- try{
516
- var x=env.s.pop();
517
- var y=env.s.pop()._datum;
518
- var z;
519
- if(env.is_string(x)){
520
- z=y.split(x._datum);
521
- }
522
- if(env.is_obj(x)){
523
- z=y.split(x._datum.separator, x._datum.limit);
524
- }
525
- if(z){
526
- env.s.push({"_type":"TC_JSON","_datum":z});
527
- return;
528
- }
529
- }catch(e){
530
- env.s.push(err.throw(e));
531
- return;
532
- }
533
- }
534
- env.s.push(err.throw("invalid arguments type."));
535
- }
536
- string_join_func(){
537
- if(env.is_string(env.TOS()) && env.is_list(env.TOS2())){
538
- try{
539
- var separator=env.s.pop()._datum;
540
- var list=env.s.pop()._datum;
541
- env.s.push({"_type":"TC_STR","_datum":list.join(separator)});
542
- return;
543
- }catch(e){
544
- env.s.push(err.throw(e));
545
- return;
546
- }
547
- }
548
- env.s.push(err.throw("invalid arguments type."));
549
- }
550
- json_stringify_func(){
551
- if(env.is_json(env.TOS())){
552
- try{
553
- env.s.push({"_type":"TC_STR","_datum":JSON5.stringify(env.s.pop()._datum)});
554
- }catch(e){
555
- env.s.push(err.throw(e));
556
- }
557
- return;
558
- }
559
- env.s.push(err.throw("invalid arguments type."));
560
- }
561
- json_parse_func(){
562
- if(env.is_string(env.TOS())){
563
- try{
564
- env.s.push({"_type":"TC_JSON","_datum":JSON5.parse(env.s.pop()._datum)});
565
- }catch(e){
566
- env.s.push(err.throw(e));
567
- }
568
- return;
569
- }
570
- env.s.push(err.throw("invalid arguments type."));
571
- }
572
- string_at_func(){
573
- if(env.is_num(env.TOS()) && env.is_string(env.TOS2())){
574
- try{
575
- var index=env.s.pop()._datum;
576
- var str=env.s.pop()._datum;
577
- if(index<0) index=str.length+index;
578
- env.s.push({"_type":"TC_STR","_datum":str[index]});
579
- }catch(e){
580
- env.s.push(err.throw(e));
581
- }
582
- return;
583
- }
584
- env.s.push(err.throw("invalid arguments type."));
585
- }
586
- string_set_at_func(){
587
- if(env.is_string(env.TOS()) && env.is_num(env.TOS2()) && env.is_string(env.s.look_at(2))){
588
- try{
589
- var replacement=env.s.pop()._datum;
590
- var index=env.s.pop()._datum;
591
- var str=env.s.pop()._datum;
592
- if(index<0) index=str.length+index;
593
- var result=str.substr(0, index) + replacement+ str.substr(index + replacement.length);
594
- env.s.push({"_type":"TC_STR","_datum":result});
595
- }catch(e){
596
- env.s.push(err.throw(e));
597
- }
598
- return;
599
- }
600
- env.s.push(err.throw("invalid arguments type."));
601
- }
602
- equal_func(){
603
- if(env.TOS() && env.TOS2()){
604
- try{
605
- var x=env.s.pop()._datum;
606
- var y=env.s.pop()._datum;
607
- env.s.push({"_type":"TC_BOOL","_datum":y===x ? 'T' : 'F'});
608
- }catch(e){
609
- env.s.push(err.throw(e));
610
- }
611
- return;
612
- }
613
- env.s.push(err.throw("invalid arguments type."));
614
- }
615
- eq_func(){
616
- if(env.TOS() && env.TOS2()){
617
- try{
618
- var x=env.s.pop()._datum;
619
- var y=env.s.pop()._datum;
620
- env.s.push({"_type":"TC_BOOL","_datum":y==x ? 'T' : 'F'});
621
- }catch(e){
622
- env.s.push(err.throw(e));
623
- }
624
- return;
625
- }
626
- env.s.push(err.throw("invalid arguments type."));
627
- }
628
- num_minor_func(){
629
- if(env.is_num(env.TOS()) && env.is_num(env.TOS2())){
630
- try{
631
- var x=env.s.pop()._datum;
632
- var y=env.s.pop()._datum;
633
- env.s.push({"_type":"TC_BOOL","_datum":y<x ? 'T' : 'F'});
634
- }catch(e){
635
- env.s.push(err.throw(e));
636
- }
637
- return;
638
- }
639
- env.s.push(err.throw("invalid arguments type."));
640
- }
641
- num_major_func(){
642
- if(env.is_num(env.TOS()) && env.is_num(env.TOS2())){
643
- try{
644
- var x=env.s.pop()._datum;
645
- var y=env.s.pop()._datum;
646
- env.s.push({"_type":"TC_BOOL","_datum":y>x ? 'T' : 'F'});
647
- }catch(e){
648
- env.s.push(err.throw(e));
649
- }
650
- return;
651
- }
652
- env.s.push(err.throw("invalid arguments type."));
653
- }
654
- num_min_eq_func(){
655
- if(env.is_num(env.TOS()) && env.is_num(env.TOS2())){
656
- try{
657
- var x=env.s.pop()._datum;
658
- var y=env.s.pop()._datum;
659
- env.s.push({"_type":"TC_BOOL","_datum":y<=x ? 'T' : 'F'});
660
- }catch(e){
661
- env.s.push(err.throw(e));
662
- }
663
- return;
664
- }
665
- env.s.push(err.throw("invalid arguments type."));
666
- }
667
- num_maj_eq_func(){
668
- if(env.is_num(env.TOS()) && env.is_num(env.TOS2())){
669
- try{
670
- var x=env.s.pop()._datum;
671
- var y=env.s.pop()._datum;
672
- env.s.push({"_type":"TC_BOOL","_datum":y>=x ? 'T' : 'F'});
673
- }catch(e){
674
- env.s.push(err.throw(e));
675
- }
676
- return;
677
- }
678
- env.s.push(err.throw("invalid arguments type."));
679
- }
680
- delete_dict_func(){
681
- if(env.TOS() && env.TOS()._type=='TC_STR'){
682
- try{
683
- env.delete(env.s.pop()._datum);
684
- }catch(e){
685
- env.s.push(err.throw(e));
686
- }
687
- return;
688
- }
689
- env.s.push(err.throw("invalid arguments type."));
690
- }
691
- net_request_func(){ //async....
692
- if(env.is_obj(env.TOS())){
693
- try{
694
- //let resp= await request(env.s.pop()._datum);
695
- let x=env.s.pop()._datum;
696
- let resp= request(x.method,x.url,x);
697
- //env.s.push({"_type":"TC_STR","_datum":resp});
698
- env.s.push({"_type":"TC_STR","_datum":resp.body.toString('utf8')});
699
- }catch(e){
700
- env.s.push(err.throw(e));
701
- }
702
- return;
703
- }
704
- env.s.push(err.throw("invalid arguments type."));
705
- }
706
- included_func(){
707
- if(env.is_string(env.TOS())){
708
- try{
709
- const arg= env.s.pop()._datum;
710
- const filename = loadfile.resolve_path(arg);
711
- var x = loadfile.loadsync(filename);
712
- eval.eval(x);
713
- return;
714
- }catch(e){
715
- env.s.push(err.throw(e));
716
- return;
717
- }
718
- }
719
- env.s.push(err.throw("invalid arguments type"));
720
- }
721
- file_slurp_func(){
722
- if(env.is_string(env.TOS())){
723
- try{
724
- const arg= env.s.pop()._datum;
725
- const filename = loadfile.resolve_path(arg);
726
- var x = loadfile.loadsync(filename);
727
- env.s.push({"_type":"TC_STR","_datum":x});
728
- return;
729
- }catch(e){
730
- env.s.push(err.throw(e));
731
- return;
732
- }
733
- }
734
- env.s.push(err.throw("invalid arguments type"));
735
- }
736
- file_write_func(){
737
- if(env.TOS() && env.TOS2() && env.is_string(env.TOS()) && env.is_string(env.TOS2())){
738
- try{
739
- const arg= env.s.pop()._datum;
740
- const filename = loadfile.resolve_path(arg);
741
- const data = env.s.pop()._datum;
742
- loadfile.writesync(filename, data);
743
- return;
744
- }catch(e){
745
- env.s.push(err.throw(e));
746
- return;
747
- }
748
- }
749
- env.s.push(err.throw("invalid arguments type. 2 Strings are expected."));
750
- }
751
- file_append_func(){
752
- if(env.TOS() && env.TOS2() && env.is_string(env.TOS()) && env.is_string(env.TOS2())){
753
- try{
754
- const arg= env.s.pop()._datum;
755
- const filename = loadfile.resolve_path(arg);
756
- const data = env.s.pop()._datum;
757
- loadfile.appendsync(filename, data);
758
- return;
759
- }catch(e){
760
- env.s.push(err.throw(e));
761
- return;
762
- }
763
- }
764
- env.s.push(err.throw("invalid arguments type. 2 Strings are expected."));
765
- }
766
- file_exists_func(){
767
- if(env.TOS() && env.is_string(env.TOS())){
768
- try{
769
- const arg= env.s.pop()._datum;
770
- const filename = loadfile.resolve_path(arg);
771
- let exists=loadfile.existssync(filename);
772
- env.s.push(env.set_bool_val(exists));
773
- return;
774
- }catch(e){
775
- env.s.push(err.throw(e));
776
- return;
777
- }
778
- }
779
- env.s.push(err.throw("invalid arguments type. a String is expected."));
780
- }
781
- throw_func(){
782
- if(env.TOS() && env.TOS()._type == 'TC_STR'){
783
- env.s.push(err.throw(env.s.pop()._datum));
784
- return;
785
- }
786
- if(env.TOS() && env.TOS()._type == 'TC_JSON'){
787
- const err_arg = env.s.pop();
788
- env.s.push(err.throw(err_arg._datum.msg, err_arg._datum.code));
789
- return;
790
- }
791
- env.s.push(err.throw('invalid throw argument in TOS'));
792
- }
793
- require_js_func(){
794
- if(env.TOS() && env.TOS()._type == 'TC_STR'){
795
- try{
796
- const arg= env.s.pop()._datum;
797
- const filename = loadfile.resolve_path(arg);
798
- var js=require(filename);
799
- env.s.push({"_type":env.guess_type(js),"_datum":js});
800
- return;
801
- }catch(e){
802
- env.s.push(err.throw(e));
803
- return;
804
- }
805
- }
806
- env.s.push(err.throw('invalid request-js argument type'));
807
- }
808
- funcjs_exec_func(){
809
- try{
810
- if(env.TOS() && env.TOS()._type=='TC_LAMBDA_FUNC'){
811
- eval.eval_parsed(env.s.pop()._datum);
812
- return;
813
- }
814
- if(env.TOS() && env.TOS()._type == 'TC_FUNC_JS'){
815
- var x=env.s.pop()._datum;
816
- var arity=x.length;
817
- var args=[];
818
- //log.info(arity);
819
- while(arity>0){
820
- args.unshift(env.s.pop()._datum);
821
- arity--;
822
- }
823
- //log.info(args);
824
- var y=x.apply(null,args);
825
- //log.info(y);
826
- if(y) env.s.push({"_type":env.guess_type(y),"_datum":y});
827
- return;
828
- }
829
- if(env.TOS() && env.TOS()._type == 'TC_STR' && env.TOS2() && env.TOS2()._type=='TC_JSON'){
830
- var method=env.s.pop()._datum;
831
- var method_list=method.split(".");
832
- var x=env.s.pop()._datum;
833
- var funcall=x;
834
- for(var item of method_list){
835
- funcall=funcall[item];
836
- }
837
- //log.info(funcall);
838
- var arity=funcall.length;
839
- var args=[];
840
- //log.info(arity);
841
- while(arity>0){
842
- args.unshift(env.s.pop()._datum);
843
- arity--;
844
- }
845
- //log.info(args);
846
- var y=funcall.apply(x,args);
847
- //log.info(y);
848
- if(y) env.s.push({"_type":env.guess_type(y),"_datum":y});
849
- return;
850
- }
851
- env.s.push(err.throw('invalid funcall-js argument type'));
852
- }catch(e){
853
- env.s.push(err.throw(e));
854
- }
855
- }
856
- handle_repl_func(){
857
- err.handle_repl();
858
- }
859
- handle_standard_func(){
860
- err.handle_standard();
861
- }
862
- regex_test_func(){
863
- try{
864
- if(env.is_obj(env.TOS()) && env.is_string(env.TOS2())){
865
- var rex_obj = env.s.pop(),_datum;
866
- var str = env.s.pop()._datum;
867
- var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
868
- const result = my_rex.test(str);
869
- env.s.push(
870
- result ?
871
- env.true_obj() :
872
- env.false_obj()
873
- );
874
- return;
875
- }
876
- if(env.is_string(env.TOS()) && env.is_string(env.TOS2())){
877
- var rex = env.s.pop()._datum;
878
- var str = env.s.pop()._datum;
879
- var my_rex = new RegExp(rex);
880
- const result = my_rex.test(str);
881
- env.s.push(
882
- result ?
883
- env.true_obj() :
884
- env.false_obj()
885
- );
886
- return;
887
- }
888
- env.s.push(err.throw('invalid regex test argument type'));
889
- }catch(e){
890
- env.s.push(err.throw(e));
891
- }
892
- }
893
- regex_exec_func(){
894
- try{
895
- if(env.is_obj(env.TOS()) && env.is_string(env.TOS2())){
896
- var rex_obj = env.s.pop(),_datum;
897
- var str = env.s.pop()._datum;
898
- var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
899
- const result = my_rex.exec(str);
900
- env.s.push(
901
- result ?
902
- {"_type":"TC_JSON","_datum":result} :
903
- 0
904
- );
905
- return;
906
- }
907
- if(env.is_string(env.TOS()) && env.is_string(env.TOS2())){
908
- var rex = env.s.pop()._datum;
909
- var str = env.s.pop()._datum;
910
- var my_rex = new RegExp(rex);
911
- const result = my_rex.exec(str);
912
- env.s.push(
913
- result ?
914
- {"_type":"TC_JSON","_datum":result} :
915
- 0
916
- );
917
- return;
918
- }
919
- env.s.push(err.throw('invalid regex exec argument type'));
920
- }catch(e){
921
- env.s.push(err.throw(e));
922
- }
923
- }
924
- regex_match_func(){
925
- try{
926
- if(env.is_obj(env.TOS()) && env.is_string(env.TOS2())){
927
- var rex_obj = env.s.pop(),_datum;
928
- var str = env.s.pop()._datum;
929
- var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
930
- const result = str.match(my_rex);
931
- env.s.push(
932
- result ?
933
- {"_type":"TC_JSON","_datum":result} :
934
- 0
935
- );
936
- return;
937
- }
938
- if(env.is_string(env.TOS()) && env.is_string(env.TOS2())){
939
- var rex = env.s.pop()._datum;
940
- var str = env.s.pop()._datum;
941
- var my_rex = new RegExp(rex);
942
- const result = str.match(my_rex);
943
- env.s.push(
944
- result ?
945
- {"_type":"TC_JSON","_datum":result} :
946
- 0
947
- );
948
- return;
949
- }
950
- env.s.push(err.throw('invalid regex match argument type'));
951
- }catch(e){
952
- env.s.push(err.throw(e));
953
- }
954
- }
955
- regex_search_func(){
956
- try{
957
- if(env.is_obj(env.TOS()) && env.is_string(env.TOS2())){
958
- var rex_obj = env.s.pop(),_datum;
959
- var str = env.s.pop()._datum;
960
- var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
961
- const result = str.search(my_rex);
962
- env.s.push({"_type":"TC_NUM","_datum":result});
963
- return;
964
- }
965
- if(env.is_string(env.TOS()) && env.is_string(env.TOS2())){
966
- var rex = env.s.pop()._datum;
967
- var str = env.s.pop()._datum;
968
- var my_rex = new RegExp(rex);
969
- const result = str.search(my_rex);
970
- env.s.push({"_type":"TC_NUM","_datum":result});
971
- return;
972
- }
973
- env.s.push(err.throw('invalid regex search argument type'));
974
- }catch(e){
975
- env.s.push(err.throw(e));
976
- }
977
- }
978
- regex_replace_func(){
979
- try{
980
- if(env.is_obj(env.TOS()) && env.is_string(env.TOS2()) && env.is_string(env.s.look_at(2))){
981
- var rex_obj = env.s.pop(),_datum;
982
- var replace = env.s.pop()._datum;
983
- var str = env.s.pop()._datum;
984
- var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
985
- const result = str.replace(my_rex, replace);
986
- env.s.push({"_type":"TC_JSON","_datum":result});
987
- return;
988
- }
989
- if(env.is_string(env.TOS()) && env.is_string(env.TOS2()) && env.is_string(env.s.look_at(2))){
990
- var rex = env.s.pop()._datum;
991
- var replace = env.s.pop()._datum;
992
- var str = env.s.pop()._datum;
993
- var my_rex = new RegExp(rex);
994
- const result = str.replace(my_rex, replace);
995
- env.s.push({"_type":"TC_STR","_datum":result});
996
- return;
997
- }
998
- env.s.push(err.throw('invalid regex replace argument type'));
999
- }catch(e){
1000
- env.s.push(err.throw(e));
1001
- }
1002
- }
1003
- array_shift_func(){
1004
- try{
1005
- if(env.is_list(env.TOS())){
1006
- let value = env.s.pop()._datum.shift();
1007
- const xval=env.adj_bool_val(value);
1008
- env.s.push({"_type":env.guess_type(value), "_datum":xval});
1009
- return;
1010
- }
1011
- env.s.push(err.throw('invalid operation. TOS is not an list'));
1012
- }catch(e){
1013
- env.s.push(err.throw(e));
1014
- }
1015
- }
1016
- array_unshift_func(){
1017
- try{
1018
- if(env.TOS() && env.is_list(env.TOS2())){
1019
- let value = env.s.pop()._datum;
1020
- let array = env.s.pop()._datum;
1021
- array.unshift(value);
1022
- env.s.push({"_type":"TC_JSON", "_datum":array});
1023
- return;
1024
- }
1025
- env.s.push(err.throw('invalid operation. TOS2 is not an list'));
1026
- }catch(e){
1027
- env.s.push(err.throw(e));
1028
- }
1029
- }
1030
- array_each_func(){
1031
- try{
1032
- if(env.TOS() && env.TOS()._type=='TC_LAMBDA_FUNC' && env.is_list(env.TOS2())){
1033
- let funcall = env.s.pop()._datum;
1034
- let array = env.s.pop()._datum;
1035
- //Vx€array, !!funcall
1036
- while(array.length >0 ){
1037
- var value = array.shift();
1038
- const xval=env.adj_bool_val(value);
1039
- env.s.push({"_type":env.guess_type(value), "_datum":xval});
1040
- eval.eval_parsed(funcall);
1041
- }
1042
- return;
1043
- }
1044
- env.s.push(err.throw('invalid arguments. TOS should be a LAMBDA function and TOS2 should be a list'));
1045
- }catch(e){
1046
- env.s.push(err.throw(e));
1047
- }
1048
- }
1049
- parse_args_func(){
1050
- try{
1051
- if(env.is_list(env.TOS())){
1052
- const rx_double_dash = /^\-\-[a-zA-Z0-9]+/;
1053
- const rx_single_dash = /^\-[a-zA-Z0-9]+/;
1054
- const rx_no_dash = /^[^\-]/;
1055
- const rx_two_dashes = /^\-\-/;
1056
- let args = {argv:[]};
1057
- const params_data = env.s.pop()._datum;
1058
- //log.info(params_data);
1059
- let param_found=false;
1060
- let test_col, is_dash;
1061
- let argv = env.lookup('os:argv')._datum._datum;
1062
- argv.shift(); argv.shift(); argv.shift();
1063
- //log.info(argv);
1064
- while(argv.length > 0) {
1065
- let item = argv.shift();
1066
- is_dash=0;
1067
- // log.info(item);
1068
- // if(rx_double_dash.test(item)){
1069
- // test_col= 1;
1070
- // is_dash = true;
1071
- // }
1072
- // if(rx_single_dash.test(item)) {
1073
- // test_col = 0;
1074
- // is_dash = true;
1075
- // }
1076
-
1077
- // if(is_dash) {
1078
- // param_found = false;
1079
- // for(var param_item of params_data){
1080
- // log.info(param_item[test_col]);
1081
- // if(param_item[test_col]=== (test_col === 0)? item.match(rx_single_dash)[0] : item.match(rx_double_dash[0])){
1082
- // log.info('d: ',param_item);
1083
- // param_found = true;
1084
- // break;
1085
- // }
1086
- // }
1087
- // //if ! invalid parameter
1088
- // if(!param_found) log.info(`invalid parameter ${item}`);
1089
- // }
1090
-
1091
- if(rx_double_dash.test(item)){
1092
- param_found = false;
1093
- for(var param_item of params_data){
1094
- if(param_item[1]===item.match(rx_double_dash)[0]){
1095
- //log.info('dd: ',param_item);
1096
- param_found = true;
1097
- switch(param_item[2]){
1098
- case 'y':
1099
- //log.info('ha param');
1100
- if(argv[0] && rx_no_dash.test(argv[0])){
1101
- args[param_item[1].replace(rx_two_dashes,'')] = argv.shift();
1102
- } else {
1103
- log.info(`error, parameter ${item} needs value...`);
1104
- //error needs param...
1105
- }
1106
- break;
1107
- case 'n':
1108
- //log.info('no param');
1109
- args[param_item[1].replace(rx_two_dashes,'')] = true;
1110
- break;
1111
- case '?':
1112
- //log.info('opt param');
1113
- if(argv[0] && rx_no_dash.test(argv[0])){
1114
- args[param_item[1].replace(rx_two_dashes,'')] = argv[0];
1115
- }else{
1116
- args[param_item[1].replace(rx_two_dashes,'')] = true;
1117
- }
1118
- break;
1119
- default:
1120
-
1121
- break;
1122
- }
1123
- break;
1124
- }
1125
- }
1126
- //if ! invalid parameter
1127
- if(!param_found) log.info(`invalid parameter ${item}`);
1128
- }else if(rx_single_dash.test(item)) {
1129
- param_found= false;
1130
- for(var param_item of params_data){
1131
- if(param_item[0]===item.match(rx_single_dash)[0]){
1132
- //log.info('sd: ',param_item);
1133
- param_found = true;
1134
- switch(param_item[2]){
1135
- case 'y':
1136
- //log.info('ha param');
1137
- if(argv[0] && rx_no_dash.test(argv[0])){
1138
- args[param_item[1].replace(rx_two_dashes,'')] = argv.shift();
1139
- } else {
1140
- log.info(`error, parameter ${item} needs value...`);
1141
- //error needs param...
1142
- }
1143
- break;
1144
- case 'n':
1145
- //log.info('no param');
1146
- args[param_item[1].replace(rx_two_dashes,'')] = true;
1147
- break;
1148
- case '?':
1149
- //log.info('opt param');
1150
- if(argv[0] && rx_no_dash.test(argv[0])){
1151
- args[param_item[1].replace(rx_two_dashes,'')] = argv[0];
1152
- }else{
1153
- args[param_item[1].replace(rx_two_dashes,'')] = true;
1154
- }
1155
- break;
1156
- default:
1157
-
1158
- break;
1159
- }
1160
- break;
1161
- }
1162
- }
1163
- if(!param_found) log.info(`invalid parameter ${item}`);
1164
- }else {
1165
- //else{
1166
- //normal argv...
1167
- args.argv.push(item);
1168
- }
1169
- }
1170
- //log.info(args);
1171
- env.s.push({"_type":"TC_JSON", "_datum":args});
1172
- return;
1173
- }
1174
- env.s.push(err.throw('invalid arguments. TOS should be a list'));
1175
- }catch(e){
1176
- env.s.push(err.throw(e));
1177
- }
1178
- }
1179
- await_func(){
1180
- if(env.TOS() && env.TOS()._type=== 'TC_PROMISE'){
1181
- try{
1182
- env.s.pop()._datum.then(x => {
1183
- env.s.push({"_type":env.guess_type(x), "_datum":x});
1184
- });
1185
- return;
1186
- }catch(e){
1187
- env.s.push(err.throw(e));
1188
- return;
1189
- }
1190
- }
1191
- env.s.push(err.throw("invalid arguments type. a Promise was expected."));
1192
- }
1193
- string_format_func(){
1194
- if(env.TOS() && env.TOS2() && env.is_string(env.TOS2()) && env.is_list(env.TOS())){
1195
- try{
1196
- const args_list=env.s.pop()._datum;
1197
- const fmt=env.s.pop()._datum;
1198
- env.s.push({"_type":"TC_STR", "_datum":vsprintf(fmt,args_list)});
1199
- return;
1200
- }catch(e){
1201
- env.s.push(err.throw(e));
1202
- return;
1203
- }
1204
- }
1205
- env.s.push(err.throw("invalid arguments type. a String and a List in TOS and TOS2 was expected."));
1206
- }
1207
- string_length_func(){
1208
- if(env.TOS() && env.is_string(env.TOS())){
1209
- try{
1210
- const str=env.s.pop()._datum;
1211
- env.s.push({"_type":"TC_NUM", "_datum":str.length});
1212
- return;
1213
- }catch(e){
1214
- env.s.push(err.throw(e));
1215
- return;
1216
- }
1217
- }
1218
- env.s.push(err.throw("invalid arguments type. a String was expected."));
1219
- }
1220
- string_to_upper_func(){
1221
- if(env.TOS() && env.is_string(env.TOS())){
1222
- try{
1223
- const str=env.s.pop()._datum;
1224
- env.s.push({"_type":"TC_STR", "_datum":str.toUpperCase()});
1225
- return;
1226
- }catch(e){
1227
- env.s.push(err.throw(e));
1228
- return;
1229
- }
1230
- }
1231
- env.s.push(err.throw("invalid arguments type. a String was expected."));
1232
- }
1233
- string_to_lower_func(){
1234
- if(env.TOS() && env.is_string(env.TOS())){
1235
- try{
1236
- const str=env.s.pop()._datum;
1237
- env.s.push({"_type":"TC_STR", "_datum":str.toLowerCase()});
1238
- return;
1239
- }catch(e){
1240
- env.s.push(err.throw(e));
1241
- return;
1242
- }
1243
- }
1244
- env.s.push(err.throw("invalid arguments type. a String was expected."));
1245
- }
1246
- xml_load_func(){
1247
- if(env.TOS() && env.is_string(env.TOS())){
1248
- try{
1249
- const str=env.s.pop()._datum;
1250
- const $ = cheerio.load(str);
1251
- env.s.push({"_type":env.guess_type($), "_datum":$});
1252
- return;
1253
- }catch(e){
1254
- env.s.push(err.throw(e));
1255
- return;
1256
- }
1257
- }
1258
- env.s.push(err.throw("invalid arguments type. a String was expected."));
1259
- }
1260
- xml_loadXML_func(){
1261
- if(env.TOS() && env.is_string(env.TOS())){
1262
- try{
1263
- const str=env.s.pop()._datum;
1264
- const $ = cheerio.load(str, {xmlMode: true});
1265
- env.s.push({"_type":env.guess_type($), "_datum":$});
1266
- return;
1267
- }catch(e){
1268
- env.s.push(err.throw(e));
1269
- return;
1270
- }
1271
- }
1272
- env.s.push(err.throw("invalid arguments type. a String was expected."));
1273
- }
1274
- xml_select_func(){
1275
- if(env.TOS() && env.TOS2() && env.TOS2()._type=="TC_FUNC_JS" && env.is_string(env.TOS())){
1276
- try{
1277
- const arg=env.s.pop()._datum;
1278
- const $=env.s.pop()._datum;
1279
- const resp=$(arg);
1280
- env.s.push({"_type":env.guess_type(resp), "_datum":resp});
1281
- return;
1282
- }catch(e){
1283
- env.s.push(err.throw(e));
1284
- return;
1285
- }
1286
- }
1287
- env.s.push(err.throw("invalid arguments type. a XML object was expected."));
1288
- }
1289
- xml_get_text_func(){
1290
- if(env.TOS() && env.is_json(env.TOS())){
1291
- try{
1292
- const $=env.s.pop()._datum;
1293
- const resp=$.text();
1294
- env.s.push({"_type":env.guess_type(resp), "_datum":resp});
1295
- return;
1296
- }catch(e){
1297
- env.s.push(err.throw(e));
1298
- return;
1299
- }
1300
- }
1301
- env.s.push(err.throw("invalid arguments type. a JSON object was expected."));
1302
- }
1303
- xml_get_html_func(){
1304
- if(env.TOS() && env.is_json(env.TOS())){
1305
- try{
1306
- const $=env.s.pop()._datum;
1307
- const resp=$.html();
1308
- env.s.push({"_type":env.guess_type(resp), "_datum":resp});
1309
- return;
1310
- }catch(e){
1311
- env.s.push(err.throw(e));
1312
- return;
1313
- }
1314
- }
1315
- env.s.push(err.throw("invalid arguments type. a JSON object was expected."));
1316
- }
1317
- xml_get_attr_func(){
1318
- if(env.TOS() && env.is_string(env.TOS()) && env.TOS2() && env.is_json(env.TOS2())){
1319
- try{
1320
- const attr=env.s.pop()._datum;
1321
- const $=env.s.pop()._datum;
1322
- const resp=$.attr(attr);
1323
- env.s.push({"_type":env.guess_type(resp), "_datum":resp});
1324
- return;
1325
- }catch(e){
1326
- env.s.push(err.throw(e));
1327
- return;
1328
- }
1329
- }
1330
- env.s.push(err.throw("invalid arguments type. a JSON object was expected."));
1331
- }
1332
- xml_has_class_func(){
1333
- if(env.TOS() && env.is_string(env.TOS()) && env.TOS2() && env.is_json(env.TOS2())){
1334
- try{
1335
- const attr=env.s.pop()._datum;
1336
- const $=env.s.pop()._datum;
1337
- const resp=$.hasClass(attr);
1338
- env.s.push(env.set_bool_val(resp));
1339
- return;
1340
- }catch(e){
1341
- env.s.push(err.throw(e));
1342
- return;
1343
- }
1344
- }
1345
- env.s.push(err.throw("invalid arguments type. a JSON object was expected."));
1346
- }
1347
- xml_get_val_func(){
1348
- if(env.TOS() && env.is_json(env.TOS())){
1349
- try{
1350
- const $=env.s.pop()._datum;
1351
- const resp=$.val();
1352
- env.s.push({"_type":env.guess_type(resp), "_datum":resp});
1353
- return;
1354
- }catch(e){
1355
- env.s.push(err.throw(e));
1356
- return;
1357
- }
1358
- }
1359
- env.s.push(err.throw("invalid arguments type. a JSON object was expected."));
1360
- }
1361
- populate_repl(){
1362
- env.set('handle',{_type: 'TC_NATIVE_FUNC', _datum: this.handle_repl_func}, 'TC_WORD');
1363
- }
1364
- populate(){
1365
- env.set('pippo',{_type: 'TC_NATIVE_FUNC', _datum: this.test_func}, 'TC_WORD');
1366
- env.set('bye',{_type: 'TC_NATIVE_FUNC', _datum: this.bye_func}, 'TC_WORD');
1367
- env.set('noop',{_type: 'TC_NATIVE_FUNC', _datum: this.noop_func}, 'TC_WORD');
1368
- env.set('.s',{_type: 'TC_NATIVE_FUNC', _datum: this.print_stack_func}, 'TC_WORD');
1369
- env.set('.e',{_type: 'TC_NATIVE_FUNC', _datum: this.print_env_func}, 'TC_WORD');
1370
- env.set('words',{_type: 'TC_NATIVE_FUNC', _datum: this.print_words_func}, 'TC_WORD');
1371
- env.set('emit',{_type: 'TC_NATIVE_FUNC', _datum: this.emit_func}, 'TC_WORD');
1372
- env.set('.',{_type: 'TC_NATIVE_FUNC', _datum: this.print_tos_func}, 'TC_WORD');
1373
- env.set('.?',{_type: 'TC_NATIVE_FUNC', _datum: this.print_debug_tos_func}, 'TC_WORD');
1374
- env.set('!',{_type: 'TC_NATIVE_FUNC', _datum: this.assign_var_func}, 'TC_WORD');
1375
- env.set('@',{_type: 'TC_NATIVE_FUNC', _datum: this.read_var_func}, 'TC_WORD');
1376
- env.set('not',{_type: 'TC_NATIVE_FUNC', _datum: this.not_func}, 'TC_WORD');
1377
- env.set('and',{_type: 'TC_NATIVE_FUNC', _datum: this.and_func}, 'TC_WORD');
1378
- env.set('or',{_type: 'TC_NATIVE_FUNC', _datum: this.or_func}, 'TC_WORD');
1379
- env.set('is_num',{_type: 'TC_NATIVE_FUNC', _datum: this.is_num_func}, 'TC_WORD');
1380
- env.set('is_string',{_type: 'TC_NATIVE_FUNC', _datum: this.is_string_func}, 'TC_WORD');
1381
- env.set('is_list',{_type: 'TC_NATIVE_FUNC', _datum: this.is_list_func}, 'TC_WORD');
1382
- env.set('is_falsy',{_type: 'TC_NATIVE_FUNC', _datum: this.is_falsy_func}, 'TC_WORD');
1383
- env.set('dup',{_type: 'TC_NATIVE_FUNC', _datum: this.dup_func}, 'TC_WORD');
1384
- env.set('swap',{_type: 'TC_NATIVE_FUNC', _datum: this.swap_func}, 'TC_WORD');
1385
- env.set('drop',{_type: 'TC_NATIVE_FUNC', _datum: this.drop_func}, 'TC_WORD');
1386
- env.set('ndrop',{_type: 'TC_NATIVE_FUNC', _datum: this.ndrop_func}, 'TC_WORD');
1387
- env.set('nbye',{_type: 'TC_NATIVE_FUNC', _datum: this.nbye_func}, 'TC_WORD');
1388
- env.set('over',{_type: 'TC_NATIVE_FUNC', _datum: this.over_func}, 'TC_WORD');
1389
- env.set('n:+',{_type: 'TC_NATIVE_FUNC', _datum: this.num_plus_func}, 'TC_WORD');
1390
- env.set('n:-',{_type: 'TC_NATIVE_FUNC', _datum: this.num_minus_func}, 'TC_WORD');
1391
- env.set('n:*',{_type: 'TC_NATIVE_FUNC', _datum: this.num_times_func}, 'TC_WORD');
1392
- env.set('n:/',{_type: 'TC_NATIVE_FUNC', _datum: this.num_div_func}, 'TC_WORD');
1393
- env.set('+',{_type: 'TC_NATIVE_FUNC', _datum: this.plus_func}, 'TC_WORD');
1394
- env.set('-',{_type: 'TC_NATIVE_FUNC', _datum: this.minus_func}, 'TC_WORD');
1395
- env.set('*',{_type: 'TC_NATIVE_FUNC', _datum: this.times_func}, 'TC_WORD');
1396
- env.set('/',{_type: 'TC_NATIVE_FUNC', _datum: this.division_func}, 'TC_WORD');
1397
- env.set('%',{_type: 'TC_NATIVE_FUNC', _datum: this.module_func}, 'TC_WORD');
1398
- env.set('handle',{_type: 'TC_NATIVE_FUNC', _datum: this.handle_standard_func}, 'TC_WORD');
1399
- env.set('throw',{_type: 'TC_NATIVE_FUNC', _datum: this.throw_func}, 'TC_WORD');
1400
- env.set('s:+',{_type: 'TC_NATIVE_FUNC', _datum: this.string_plus_func}, 'TC_WORD');
1401
- env.set('a:+',{_type: 'TC_NATIVE_FUNC', _datum: this.array_plus_func}, 'TC_WORD');
1402
- env.set('included',{_type: 'TC_NATIVE_FUNC', _datum: this.included_func}, 'TC_WORD');
1403
- env.set('a:@',{_type: 'TC_NATIVE_FUNC', _datum: this.array_at_func}, 'TC_WORD');
1404
- env.set('a:!',{_type: 'TC_NATIVE_FUNC', _datum: this.array_set_at_func}, 'TC_WORD');
1405
- env.set('m:@',{_type: 'TC_NATIVE_FUNC', _datum: this.object_at_func}, 'TC_WORD');
1406
- env.set('m:!',{_type: 'TC_NATIVE_FUNC', _datum: this.object_set_at_func}, 'TC_WORD');
1407
- env.set('a:len',{_type: 'TC_NATIVE_FUNC', _datum: this.array_length_func}, 'TC_WORD');
1408
- env.set('a:push',{_type: 'TC_NATIVE_FUNC', _datum: this.array_push_func}, 'TC_WORD');
1409
- env.set('a:pop',{_type: 'TC_NATIVE_FUNC', _datum: this.array_pop_func}, 'TC_WORD');
1410
- env.set('m:keys',{_type: 'TC_NATIVE_FUNC', _datum: this.object_keys_func}, 'TC_WORD');
1411
- env.set('m:values',{_type: 'TC_NATIVE_FUNC', _datum: this.object_values_func}, 'TC_WORD');
1412
- env.set('s:split',{_type: 'TC_NATIVE_FUNC', _datum: this.string_split_func}, 'TC_WORD');
1413
- env.set('s:join',{_type: 'TC_NATIVE_FUNC', _datum: this.string_join_func}, 'TC_WORD');
1414
- env.set('j:stringify',{_type: 'TC_NATIVE_FUNC', _datum: this.json_stringify_func}, 'TC_WORD');
1415
- env.set('j:parse',{_type: 'TC_NATIVE_FUNC', _datum: this.json_parse_func}, 'TC_WORD');
1416
- env.set('s:@',{_type: 'TC_NATIVE_FUNC', _datum: this.string_at_func}, 'TC_WORD');
1417
- env.set('s:!',{_type: 'TC_NATIVE_FUNC', _datum: this.string_set_at_func}, 'TC_WORD');
1418
- env.set('=',{_type: 'TC_NATIVE_FUNC', _datum: this.equal_func}, 'TC_WORD');
1419
- env.set('===',{_type: 'TC_NATIVE_FUNC', _datum: this.equal_func}, 'TC_WORD');
1420
- env.set('==',{_type: 'TC_NATIVE_FUNC', _datum: this.eq_func}, 'TC_WORD');
1421
- env.set('<',{_type: 'TC_NATIVE_FUNC', _datum: this.num_minor_func}, 'TC_WORD');
1422
- env.set('>',{_type: 'TC_NATIVE_FUNC', _datum: this.num_major_func}, 'TC_WORD');
1423
- env.set('<=',{_type: 'TC_NATIVE_FUNC', _datum: this.num_min_eq_func}, 'TC_WORD');
1424
- env.set('>=',{_type: 'TC_NATIVE_FUNC', _datum: this.num_maj_eq_func}, 'TC_WORD');
1425
- env.set('f:slurp',{_type: 'TC_NATIVE_FUNC', _datum: this.file_slurp_func}, 'TC_WORD');
1426
- env.set('f:write',{_type: 'TC_NATIVE_FUNC', _datum: this.file_write_func}, 'TC_WORD');
1427
- env.set('f:append',{_type: 'TC_NATIVE_FUNC', _datum: this.file_append_func}, 'TC_WORD');
1428
- env.set('f:exists',{_type: 'TC_NATIVE_FUNC', _datum: this.file_exists_func}, 'TC_WORD');
1429
- env.set('net:request',{_type: 'TC_NATIVE_FUNC', _datum: this.net_request_func}, 'TC_WORD');
1430
- env.set('j:require-js',{_type: 'TC_NATIVE_FUNC', _datum: this.require_js_func}, 'TC_WORD');
1431
- env.set('!!',{_type: 'TC_NATIVE_FUNC', _datum: this.funcjs_exec_func}, 'TC_WORD');
1432
- env.set('G:delete',{_type: 'TC_NATIVE_FUNC', _datum: this.delete_dict_func}, 'TC_WORD');
1433
- env.set('rx:test',{_type: 'TC_NATIVE_FUNC', _datum: this.regex_test_func}, 'TC_WORD');
1434
- env.set('rx:exec',{_type: 'TC_NATIVE_FUNC', _datum: this.regex_exec_func}, 'TC_WORD');
1435
- env.set('rx:match',{_type: 'TC_NATIVE_FUNC', _datum: this.regex_match_func}, 'TC_WORD');
1436
- env.set('rx:search',{_type: 'TC_NATIVE_FUNC', _datum: this.regex_search_func}, 'TC_WORD');
1437
- env.set('rx:replace',{_type: 'TC_NATIVE_FUNC', _datum: this.regex_replace_func}, 'TC_WORD');
1438
- env.set('a:shift',{_type: 'TC_NATIVE_FUNC', _datum: this.array_shift_func}, 'TC_WORD');
1439
- env.set('a:unshift',{_type: 'TC_NATIVE_FUNC', _datum: this.array_unshift_func}, 'TC_WORD');
1440
- env.set('a:each',{_type: 'TC_NATIVE_FUNC', _datum: this.array_each_func}, 'TC_WORD');
1441
- env.set('os:parse-args',{_type: 'TC_NATIVE_FUNC', _datum: this.parse_args_func}, 'TC_WORD');
1442
- env.set('await',{_type: 'TC_NATIVE_FUNC', _datum: this.await_func}, 'TC_WORD');
1443
- env.set('s:format',{_type: 'TC_NATIVE_FUNC', _datum: this.string_format_func}, 'TC_WORD');
1444
- env.set('s:len',{_type: 'TC_NATIVE_FUNC', _datum: this.string_length_func}, 'TC_WORD');
1445
- env.set('s:to_upper',{_type: 'TC_NATIVE_FUNC', _datum: this.string_to_upper_func}, 'TC_WORD');
1446
- env.set('s:to_lower',{_type: 'TC_NATIVE_FUNC', _datum: this.string_to_lower_func}, 'TC_WORD');
1447
- env.set('xml:loadDOM',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_load_func}, 'TC_WORD');
1448
- env.set('xml:loadXML',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_loadXML_func}, 'TC_WORD');
1449
- env.set('xml:$',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_select_func}, 'TC_WORD');
1450
- env.set('xml:get_text',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_get_text_func}, 'TC_WORD');
1451
- env.set('xml:get_html',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_get_html_func}, 'TC_WORD');
1452
- env.set('xml:get_attr',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_get_attr_func}, 'TC_WORD');
1453
- env.set('xml:has_class',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_has_class_func}, 'TC_WORD');
1454
- env.set('xml:get_val',{_type: 'TC_NATIVE_FUNC', _datum: this.xml_get_val_func}, 'TC_WORD');
1455
- }
1456
- };
1457
-
1458
- module.exports = new NativeLib();
1
+ import log from 'bunny-logger';
2
+ // const request = require('request-promise-native');
3
+ import JSON5 from 'json5';
4
+ import { vsprintf } from 'sprintf-js';
5
+ import * as cheerio from 'cheerio';
6
+ import { execSync } from 'child_process';
7
+ import got from 'got';
8
+ import env from './env.js';
9
+ import err from './error.js';
10
+ import evalx from './eval.js';
11
+ import loadfile from './load-file.js';
12
+ import obj_utils from './obj_utils.js';
13
+
14
+ class NativeLib {
15
+ constructor() {
16
+ this.populate();
17
+ }
18
+
19
+ make_func_obj(func_name) {
20
+ return {
21
+ _type: 'TC_COMP_FUNC',
22
+ _datum: func_name,
23
+ };
24
+ }
25
+
26
+ test_func() {
27
+ log.info('...hai detto pippo?');
28
+ }
29
+
30
+ bye_func() {
31
+ process.exit(0);
32
+ }
33
+
34
+ noop_func() {
35
+ // do nothing (no operation)
36
+ }
37
+
38
+ print_stack_func() {
39
+ env.print_stack();
40
+ }
41
+
42
+ print_env_func() {
43
+ env.print_debug();
44
+ }
45
+
46
+ print_words_func() {
47
+ const x = env._dict;
48
+ // x=x.filter(item => item._type == 'TC_NATIVE_FUNC');
49
+ for (const item of x) {
50
+ if (item._datum._type == 'TC_NATIVE_FUNC' || item._datum._type == 'TC_COMP_FUNC') {
51
+ // log.info(`${item._name} `);
52
+ process.stdout.write(`${item._name} `);
53
+ }
54
+ }
55
+ log.info('');
56
+ }
57
+
58
+ emit_func() {
59
+ const x = env.s.pop();
60
+ // log.info(x);
61
+ if (x._type === 'TC_NUM') {
62
+ process.stdout.write(String.fromCharCode(x._datum));
63
+ return;
64
+ }
65
+ env.s.push(err.throw(`unknown item type ${x._type} of ${x._datum}`));
66
+ }
67
+
68
+ see_func(func_name) {
69
+ const x = env.lookup(func_name);
70
+ if (!x) {
71
+ log.info('no word found...');
72
+ return;
73
+ }
74
+ switch (x._datum._type) {
75
+ case 'TC_NATIVE_FUNC':
76
+ log.info(`: ${x._name}`);
77
+ log.info('<native func> ;');
78
+ break;
79
+ case 'TC_COMP_FUNC':
80
+ log.info(`: ${x._name}`);
81
+ process.stdout.write(` `);
82
+ for (const n of x._datum._datum) {
83
+ process.stdout.write(`${n._datum} `);
84
+ }
85
+ log.info('');
86
+ break;
87
+ default:
88
+ log.info('not a word...');
89
+ break;
90
+ }
91
+ }
92
+
93
+ print_tos_func() {
94
+ const x = env.s.pop();
95
+ if (!x) {
96
+ return;
97
+ }
98
+ // log.info(x);
99
+ switch (x._type) {
100
+ case 'TC_NUM':
101
+ case 'TC_STR':
102
+ case 'TC_BOOL':
103
+ log.info(x._datum);
104
+ break;
105
+ case 'TC_JSON':
106
+ log.info(obj_utils.stringify(x._datum));
107
+ break;
108
+ case 'TC_FUNC_JS':
109
+ log.info('#-<js func>');
110
+ break;
111
+ case 'TC_LAMBDA_FUNC':
112
+ log.info('#-<lambda func>');
113
+ break;
114
+ case 'TC_VAR':
115
+ log.info(x._name);
116
+ break;
117
+ case 'TC_ERR':
118
+ log.info(`ERR: ${x._datum.msg}`);
119
+ break;
120
+ default:
121
+ log.info(`unknown: { ${x._type} ${x._datum} }`);
122
+ break;
123
+ }
124
+ }
125
+
126
+ print_debug_tos_func() {
127
+ const x = env.s.pop();
128
+ if (!x) {
129
+ return;
130
+ }
131
+ // log.info(x);
132
+ switch (x._type) {
133
+ case 'TC_NUM':
134
+ case 'TC_STR':
135
+ case 'TC_BOOL':
136
+ log.info(`{ ${x._type} ${x._datum} }`);
137
+ break;
138
+ case 'TC_JSON':
139
+ log.info(`{ ${x._type} ${obj_utils.stringify(x._datum)} }`);
140
+ break;
141
+ case 'TC_FUNC_JS':
142
+ log.info('#-<js func>');
143
+ break;
144
+ case 'TC_LAMBDA_FUNC':
145
+ log.info('#-<lambda func>');
146
+ break;
147
+ case 'TC_VAR':
148
+ log.info(`{ ${x._type} ${x._name} ${obj_utils.stringify(x._datum._datum)} }`);
149
+ break;
150
+ case 'TC_ERR':
151
+ log.info(`ERR: ${x._datum.msg}`);
152
+ break;
153
+ default:
154
+ log.info(`unknown: { ${x._type} ${x._datum} }`);
155
+ break;
156
+ }
157
+ }
158
+
159
+ assign_var_func() {
160
+ const varx = env.s.pop();
161
+ const val = env.s.pop();
162
+ if (!varx || !val) {
163
+ env.s.push(err.throw('no items on top 2 elements of the stack... aborting'));
164
+ return;
165
+ }
166
+ // log.info(varx);
167
+ // log.info(val);
168
+ switch (val._type) {
169
+ case 'TC_NUM':
170
+ case 'TC_STR':
171
+ case 'TC_JSON':
172
+ case 'TC_BOOL':
173
+ case 'TC_PROMISE':
174
+ varx._datum = val;
175
+ // env.set(varx._name, val, varx._type, varx._where);
176
+ break;
177
+ default:
178
+ break;
179
+ }
180
+ }
181
+
182
+ read_var_func() {
183
+ const varx = env.s.pop();
184
+ if (!varx) {
185
+ env.s.push(err.throw('no element on top of the stack... aborting'));
186
+ return;
187
+ }
188
+ // log.info(varx);
189
+ switch (varx._datum._type) {
190
+ case 'TC_NUM':
191
+ case 'TC_STR':
192
+ case 'TC_JSON':
193
+ case 'TC_BOOL':
194
+ case 'TC_PROMISE':
195
+ env.s.push(varx._datum);
196
+ break;
197
+ default:
198
+ break;
199
+ }
200
+ }
201
+
202
+ not_func() {
203
+ if (!env.is_bool(env.TOS())) {
204
+ env.s.push(err.throw('TOS is not a bool. aborting operation...'));
205
+ return;
206
+ }
207
+ const x = env.get_bool_val(env.s.pop());
208
+ env.s.push(env.set_bool_val(!x));
209
+ }
210
+
211
+ and_func() {
212
+ if (!env.is_bool(env.TOS())) {
213
+ env.s.push(err.throw('TOS is not a bool. aborting operation...'));
214
+ return;
215
+ }
216
+ if (!env.is_bool(env.TOS2())) {
217
+ env.s.push(err.throw('TOS" is not a bool. aborting operation...'));
218
+ return;
219
+ }
220
+ const a = env.get_bool_val(env.s.pop());
221
+ const b = env.get_bool_val(env.s.pop());
222
+ env.s.push(env.set_bool_val(a && b));
223
+ }
224
+
225
+ or_func() {
226
+ if (!env.is_bool(env.TOS())) {
227
+ env.s.push(err.throw('TOS is not a bool. aborting operation...'));
228
+ return;
229
+ }
230
+ if (!env.is_bool(env.TOS2())) {
231
+ env.s.push(err.throw('TOS2 is not a bool. aborting operation...'));
232
+ return;
233
+ }
234
+ const a = env.get_bool_val(env.s.pop());
235
+ const b = env.get_bool_val(env.s.pop());
236
+ env.s.push(env.set_bool_val(a || b));
237
+ }
238
+
239
+ is_num_func() {
240
+ if (env.is_num(env.s.pop())) {
241
+ env.s.push(env.true_obj());
242
+ return;
243
+ }
244
+ env.s.push(env.false_obj());
245
+ }
246
+
247
+ is_string_func() {
248
+ if (env.is_string(env.s.pop())) {
249
+ env.s.push(env.true_obj());
250
+ return;
251
+ }
252
+ env.s.push(env.false_obj());
253
+ }
254
+
255
+ is_list_func() {
256
+ if (env.is_list(env.s.pop())) {
257
+ env.s.push(env.true_obj());
258
+ return;
259
+ }
260
+ env.s.push(env.false_obj());
261
+ }
262
+
263
+ is_falsy_func() {
264
+ const x = env.s.pop();
265
+ if (x) {
266
+ switch (x._type) {
267
+ case 'TC_NUM':
268
+ if (x._datum == 0) {
269
+ return env.s.push(env.true_obj());
270
+ }
271
+ return env.s.push(env.false_obj());
272
+ break;
273
+ case 'TC_STR':
274
+ if (x._datum == '') {
275
+ return env.s.push(env.true_obj());
276
+ }
277
+ break;
278
+ case 'TC_BOOL':
279
+ if (env.is_false(x)) {
280
+ return env.s.push(env.true_obj());
281
+ }
282
+ break;
283
+ case 'TC_JLIST':
284
+ case 'TC_JOBJ':
285
+ default:
286
+ return env.s.push(env.false_obj());
287
+ break;
288
+ }
289
+ }
290
+ return env.s.push(env.true_obj());
291
+ }
292
+
293
+ dup_func() {
294
+ env.s.push(env.TOS());
295
+ }
296
+
297
+ swap_func() {
298
+ if (env.TOS() && env.TOS2()) {
299
+ const x = env.s.pop();
300
+ const y = env.s.pop();
301
+ env.s.push(x);
302
+ env.s.push(y);
303
+ return;
304
+ }
305
+ env.s.push(err.throw('not 2 elemets in the stack... aborting...'));
306
+ }
307
+
308
+ drop_func() {
309
+ env.s.pop();
310
+ }
311
+
312
+ ndrop_func() {
313
+ if (env.TOS() && env.TOS()._type === 'TC_NUM') {
314
+ try {
315
+ let n = env.s.pop()._datum;
316
+ while (n > 0) {
317
+ env.s.pop();
318
+ n--;
319
+ }
320
+ return;
321
+ } catch (e) {
322
+ env.s.push(err.throw(e));
323
+ return;
324
+ }
325
+ }
326
+ env.s.push(err.throw('invalid arguments type. TOS is not a number.'));
327
+ }
328
+
329
+ nbye_func() {
330
+ if (env.TOS() && env.TOS()._type == 'TC_NUM') {
331
+ process.exit(env.s.pop()._datum);
332
+ }
333
+ env.s.push(err.throw('TOS not a number... aborting'));
334
+ }
335
+
336
+ over_func() {
337
+ env.s.push(env.s.look_at(1));
338
+ }
339
+
340
+ num_plus_func() {
341
+ if (env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM') {
342
+ env.s.push({
343
+ _type: 'TC_NUM',
344
+ _datum: env.s.pop()._datum + env.s.pop()._datum,
345
+ });
346
+ return;
347
+ }
348
+ env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
349
+ }
350
+
351
+ num_minus_func() {
352
+ if (env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM') {
353
+ const x = env.s.pop()._datum;
354
+ const y = env.s.pop()._datum;
355
+ env.s.push({ _type: 'TC_NUM', _datum: y - x });
356
+ return;
357
+ }
358
+ env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
359
+ }
360
+
361
+ num_times_func() {
362
+ if (env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM') {
363
+ env.s.push({
364
+ _type: 'TC_NUM',
365
+ _datum: env.s.pop()._datum * env.s.pop()._datum,
366
+ });
367
+ return;
368
+ }
369
+ env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
370
+ }
371
+
372
+ num_div_func() {
373
+ if (env.TOS() && env.TOS()._type == 'TC_NUM' && env.TOS2() && env.TOS2()._type == 'TC_NUM') {
374
+ const x = env.s.pop()._datum;
375
+ const y = env.s.pop()._datum;
376
+ env.s.push({ _type: 'TC_NUM', _datum: y / x });
377
+ return;
378
+ }
379
+ env.s.push(err.throw('no numbers on top 2 elements of the stack... aborting'));
380
+ }
381
+
382
+ async plus_func() {
383
+ await evalx.eval('f+');
384
+ }
385
+
386
+ async minus_func() {
387
+ await evalx.eval('n:-');
388
+ }
389
+
390
+ async times_func() {
391
+ await evalx.eval('n:*');
392
+ }
393
+
394
+ async division_func() {
395
+ await evalx.eval('n:/');
396
+ }
397
+
398
+ async module_func() {
399
+ await evalx.eval('n:%');
400
+ }
401
+
402
+ string_plus_func() {
403
+ if (env.is_string(env.TOS()) || env.is_string(env.TOS2())) {
404
+ if (env.is_num(env.TOS()) || env.is_num(env.TOS2()) || env.is_string(env.TOS()) || env.is_string(env.TOS2())) {
405
+ const x = env.s.pop();
406
+ const y = env.s.pop();
407
+ env.s.push({ _type: 'TC_STR', _datum: y._datum + x._datum });
408
+ return;
409
+ }
410
+ }
411
+ env.s.push(err.throw('invalid arguments type'));
412
+ }
413
+
414
+ array_plus_func() {
415
+ if (env.is_list(env.TOS()) || env.is_list(env.TOS2())) {
416
+ const x = env.s.pop();
417
+ const y = env.s.pop();
418
+ env.s.push({ _type: 'TC_JSON', _datum: y._datum.concat(x._datum) });
419
+ return;
420
+ }
421
+ env.s.push(err.throw('invalid arguments type'));
422
+ }
423
+
424
+ array_at_func() {
425
+ if (env.is_num(env.TOS()) && env.is_list(env.TOS2())) {
426
+ try {
427
+ let index = env.s.pop()._datum;
428
+ const arr = env.s.pop()._datum;
429
+ if (index < 0) {
430
+ index = arr.length + index;
431
+ }
432
+ if (index >= arr.length || index < 0) {
433
+ env.s.push(err.throw('invalid index bound'));
434
+ return;
435
+ }
436
+ const value = arr[index];
437
+ const xval = env.adj_bool_val(value);
438
+ env.s.push({ _type: env.guess_type(value), _datum: xval });
439
+ return;
440
+ } catch (e) {
441
+ env.s.push(err.throw(e));
442
+ return;
443
+ }
444
+ }
445
+ env.s.push(err.throw('invalid arguments type'));
446
+ }
447
+
448
+ array_set_at_func() {
449
+ if (env.TOS() && env.is_num(env.TOS2()) && env.is_list(env.s.look_at(2))) {
450
+ try {
451
+ const value = env.s.pop()._datum;
452
+ let index = env.s.pop()._datum;
453
+ const arr = env.s.pop()._datum;
454
+ if (index < 0) {
455
+ index = arr.length + index;
456
+ }
457
+ if (index >= arr.length || index < 0) {
458
+ env.s.push(err.throw('invalid index bound'));
459
+ return;
460
+ }
461
+ arr[index] = value;
462
+ env.s.push({ _type: 'TC_JSON', _datum: arr });
463
+ return;
464
+ } catch (e) {
465
+ env.s.push(err.throw(e));
466
+ return;
467
+ }
468
+ }
469
+ env.s.push(err.throw('invalid arguments type'));
470
+ }
471
+
472
+ object_at_func() {
473
+ if (env.is_string(env.TOS()) && env.is_obj(env.TOS2())) {
474
+ try {
475
+ const key = env.s.pop()._datum;
476
+ const obj = env.s.pop()._datum;
477
+ const value = obj[key];
478
+ if (value) {
479
+ const xval = env.adj_bool_val(value);
480
+ env.s.push({ _type: env.guess_type(value), _datum: xval });
481
+ return;
482
+ }
483
+ // env.s.push(err.throw("invalid object key"));
484
+ env.s.push({ _type: 'TC_UNDEF', _datum: 'undefined' });
485
+ return;
486
+ } catch (e) {
487
+ env.s.push(err.throw(e));
488
+ return;
489
+ }
490
+ }
491
+ env.s.push(err.throw('invalid arguments type'));
492
+ }
493
+
494
+ object_set_at_func() {
495
+ if (env.TOS() && env.is_string(env.TOS2()) && env.is_obj(env.s.look_at(2))) {
496
+ try {
497
+ const value = env.s.pop()._datum;
498
+ const key = env.s.pop()._datum;
499
+ const obj = env.s.pop()._datum;
500
+ obj[key] = value;
501
+ env.s.push({ _type: 'TC_JSON', _datum: obj });
502
+ return;
503
+ } catch (e) {
504
+ env.s.push(err.throw(e));
505
+ return;
506
+ }
507
+ }
508
+ env.s.push(err.throw('invalid arguments type'));
509
+ }
510
+
511
+ array_length_func() {
512
+ if (env.is_list(env.TOS())) {
513
+ try {
514
+ const x = env.s.pop()._datum.length;
515
+ env.s.push({ _type: 'TC_NUM', _datum: x });
516
+ return;
517
+ } catch (e) {
518
+ env.s.push(err.throw(e));
519
+ return;
520
+ }
521
+ }
522
+ env.s.push(err.throw('invalid arguments type. TOS not a list'));
523
+ }
524
+
525
+ array_push_func() {
526
+ if (env.is_list(env.TOS2()) && env.TOS()) {
527
+ try {
528
+ const value = env.s.pop()._datum;
529
+ const arr = env.s.pop()._datum;
530
+ arr.push(value);
531
+ env.s.push({ _type: 'TC_JSON', _datum: arr });
532
+ return;
533
+ } catch (e) {
534
+ env.s.push(err.throw(e));
535
+ return;
536
+ }
537
+ }
538
+ env.s.push(err.throw('invalid arguments type.'));
539
+ }
540
+
541
+ array_pop_func() {
542
+ if (env.is_list(env.TOS())) {
543
+ try {
544
+ const value = env.s.pop()._datum.pop();
545
+ const xval = env.adj_bool_val(value);
546
+ env.s.push({ _type: env.guess_type(value), _datum: xval });
547
+ return;
548
+ } catch (e) {
549
+ env.s.push(err.throw(e));
550
+ return;
551
+ }
552
+ }
553
+ env.s.push(err.throw('invalid arguments type. TOS not a list'));
554
+ }
555
+
556
+ object_keys_func() {
557
+ if (env.is_obj(env.TOS())) {
558
+ try {
559
+ const x = env.s.pop()._datum;
560
+ env.s.push({ _type: 'TC_JSON', _datum: Object.keys(x) });
561
+ return;
562
+ } catch (e) {
563
+ env.s.push(err.throw(e));
564
+ return;
565
+ }
566
+ }
567
+ env.s.push(err.throw('invalid arguments type.'));
568
+ }
569
+
570
+ object_values_func() {
571
+ if (env.is_obj(env.TOS())) {
572
+ try {
573
+ const x = env.s.pop()._datum;
574
+ env.s.push({ _type: 'TC_JSON', _datum: Object.values(x) });
575
+ return;
576
+ } catch (e) {
577
+ env.s.push(err.throw(e));
578
+ return;
579
+ }
580
+ }
581
+ env.s.push(err.throw('invalid arguments type.'));
582
+ }
583
+
584
+ string_split_func() {
585
+ if (env.TOS() && env.is_string(env.TOS2())) {
586
+ try {
587
+ const x = env.s.pop();
588
+ const y = env.s.pop()._datum;
589
+ let z;
590
+ if (env.is_string(x)) {
591
+ z = y.split(x._datum);
592
+ }
593
+ if (env.is_obj(x)) {
594
+ z = y.split(x._datum.separator, x._datum.limit);
595
+ }
596
+ if (z) {
597
+ env.s.push({ _type: 'TC_JSON', _datum: z });
598
+ return;
599
+ }
600
+ } catch (e) {
601
+ env.s.push(err.throw(e));
602
+ return;
603
+ }
604
+ }
605
+ env.s.push(err.throw('invalid arguments type.'));
606
+ }
607
+
608
+ string_join_func() {
609
+ if (env.is_string(env.TOS()) && env.is_list(env.TOS2())) {
610
+ try {
611
+ const separator = env.s.pop()._datum;
612
+ const list = env.s.pop()._datum;
613
+ env.s.push({ _type: 'TC_STR', _datum: list.join(separator) });
614
+ return;
615
+ } catch (e) {
616
+ env.s.push(err.throw(e));
617
+ return;
618
+ }
619
+ }
620
+ env.s.push(err.throw('invalid arguments type.'));
621
+ }
622
+
623
+ json_stringify_func() {
624
+ if (env.is_json(env.TOS())) {
625
+ try {
626
+ env.s.push({
627
+ _type: 'TC_STR',
628
+ _datum: JSON5.stringify(env.s.pop()._datum),
629
+ });
630
+ } catch (e) {
631
+ env.s.push(err.throw(e));
632
+ }
633
+ return;
634
+ }
635
+ env.s.push(err.throw('invalid arguments type.'));
636
+ }
637
+
638
+ json_parse_func() {
639
+ if (env.is_string(env.TOS())) {
640
+ try {
641
+ env.s.push({
642
+ _type: 'TC_JSON',
643
+ _datum: JSON5.parse(env.s.pop()._datum),
644
+ });
645
+ } catch (e) {
646
+ env.s.push(err.throw(e));
647
+ }
648
+ return;
649
+ }
650
+ env.s.push(err.throw('invalid arguments type.'));
651
+ }
652
+
653
+ string_at_func() {
654
+ if (env.is_num(env.TOS()) && env.is_string(env.TOS2())) {
655
+ try {
656
+ let index = env.s.pop()._datum;
657
+ const str = env.s.pop()._datum;
658
+ if (index < 0) {
659
+ index = str.length + index;
660
+ }
661
+ env.s.push({ _type: 'TC_STR', _datum: str[index] });
662
+ } catch (e) {
663
+ env.s.push(err.throw(e));
664
+ }
665
+ return;
666
+ }
667
+ env.s.push(err.throw('invalid arguments type.'));
668
+ }
669
+
670
+ string_set_at_func() {
671
+ if (env.is_string(env.TOS()) && env.is_num(env.TOS2()) && env.is_string(env.s.look_at(2))) {
672
+ try {
673
+ const replacement = env.s.pop()._datum;
674
+ let index = env.s.pop()._datum;
675
+ const str = env.s.pop()._datum;
676
+ if (index < 0) {
677
+ index = str.length + index;
678
+ }
679
+ const result = str.substr(0, index) + replacement + str.substr(index + replacement.length);
680
+ env.s.push({ _type: 'TC_STR', _datum: result });
681
+ } catch (e) {
682
+ env.s.push(err.throw(e));
683
+ }
684
+ return;
685
+ }
686
+ env.s.push(err.throw('invalid arguments type.'));
687
+ }
688
+
689
+ equal_func() {
690
+ if (env.TOS() && env.TOS2()) {
691
+ try {
692
+ const x = env.s.pop()._datum;
693
+ const y = env.s.pop()._datum;
694
+ env.s.push({ _type: 'TC_BOOL', _datum: y === x ? 'T' : 'F' });
695
+ } catch (e) {
696
+ env.s.push(err.throw(e));
697
+ }
698
+ return;
699
+ }
700
+ env.s.push(err.throw('invalid arguments type.'));
701
+ }
702
+
703
+ eq_func() {
704
+ if (env.TOS() && env.TOS2()) {
705
+ try {
706
+ const x = env.s.pop()._datum;
707
+ const y = env.s.pop()._datum;
708
+ env.s.push({ _type: 'TC_BOOL', _datum: y == x ? 'T' : 'F' });
709
+ } catch (e) {
710
+ env.s.push(err.throw(e));
711
+ }
712
+ return;
713
+ }
714
+ env.s.push(err.throw('invalid arguments type.'));
715
+ }
716
+
717
+ num_minor_func() {
718
+ if (env.is_num(env.TOS()) && env.is_num(env.TOS2())) {
719
+ try {
720
+ const x = env.s.pop()._datum;
721
+ const y = env.s.pop()._datum;
722
+ env.s.push({ _type: 'TC_BOOL', _datum: y < x ? 'T' : 'F' });
723
+ } catch (e) {
724
+ env.s.push(err.throw(e));
725
+ }
726
+ return;
727
+ }
728
+ env.s.push(err.throw('invalid arguments type.'));
729
+ }
730
+
731
+ num_major_func() {
732
+ if (env.is_num(env.TOS()) && env.is_num(env.TOS2())) {
733
+ try {
734
+ const x = env.s.pop()._datum;
735
+ const y = env.s.pop()._datum;
736
+ env.s.push({ _type: 'TC_BOOL', _datum: y > x ? 'T' : 'F' });
737
+ } catch (e) {
738
+ env.s.push(err.throw(e));
739
+ }
740
+ return;
741
+ }
742
+ env.s.push(err.throw('invalid arguments type.'));
743
+ }
744
+
745
+ num_min_eq_func() {
746
+ if (env.is_num(env.TOS()) && env.is_num(env.TOS2())) {
747
+ try {
748
+ const x = env.s.pop()._datum;
749
+ const y = env.s.pop()._datum;
750
+ env.s.push({ _type: 'TC_BOOL', _datum: y <= x ? 'T' : 'F' });
751
+ } catch (e) {
752
+ env.s.push(err.throw(e));
753
+ }
754
+ return;
755
+ }
756
+ env.s.push(err.throw('invalid arguments type.'));
757
+ }
758
+
759
+ num_maj_eq_func() {
760
+ if (env.is_num(env.TOS()) && env.is_num(env.TOS2())) {
761
+ try {
762
+ const x = env.s.pop()._datum;
763
+ const y = env.s.pop()._datum;
764
+ env.s.push({ _type: 'TC_BOOL', _datum: y >= x ? 'T' : 'F' });
765
+ } catch (e) {
766
+ env.s.push(err.throw(e));
767
+ }
768
+ return;
769
+ }
770
+ env.s.push(err.throw('invalid arguments type.'));
771
+ }
772
+
773
+ delete_dict_func() {
774
+ if (env.TOS() && env.TOS()._type == 'TC_STR') {
775
+ try {
776
+ env.delete(env.s.pop()._datum);
777
+ } catch (e) {
778
+ env.s.push(err.throw(e));
779
+ }
780
+ return;
781
+ }
782
+ env.s.push(err.throw('invalid arguments type.'));
783
+ }
784
+
785
+ async net_request_func() {
786
+ // async....
787
+ if (env.is_obj(env.TOS())) {
788
+ try {
789
+ // //let resp= await request(env.s.pop()._datum);
790
+ const x = env.s.pop()._datum;
791
+ const { url } = x;
792
+ delete x.url;
793
+ // let resp= request(x.method,x.url,x);
794
+ const resp = await got(url, x).text();
795
+ // //env.s.push({"_type":"TC_STR","_datum":resp});
796
+ // env.s.push({"_type":"TC_STR","_datum":resp.body.toString('utf8')});
797
+ env.s.push({ _type: env.guess_type(resp), _datum: resp });
798
+ } catch (e) {
799
+ const errObj = {
800
+ code: e.response?.statusCode,
801
+ body: e.response?.body,
802
+ error: { name: e.name, code: e.code, msg: e.message },
803
+ };
804
+ // env.s.push({"_type":env.guess_type(errObj),"_datum":errObj});
805
+ env.s.push(err.throw(JSON.stringify(errObj)));
806
+ }
807
+ return;
808
+ }
809
+ env.s.push(err.throw('invalid arguments type.'));
810
+ }
811
+
812
+ async included_func() {
813
+ if (env.is_string(env.TOS())) {
814
+ try {
815
+ const arg = env.s.pop()._datum;
816
+ const filename = loadfile.resolve_path(arg);
817
+ const x = loadfile.loadsync(filename);
818
+ await evalx.eval(x);
819
+ return;
820
+ } catch (e) {
821
+ env.s.push(err.throw(e));
822
+ return;
823
+ }
824
+ }
825
+ env.s.push(err.throw('invalid arguments type'));
826
+ }
827
+
828
+ file_slurp_func() {
829
+ if (env.is_string(env.TOS())) {
830
+ try {
831
+ const arg = env.s.pop()._datum;
832
+ const filename = loadfile.resolve_path(arg);
833
+ const x = loadfile.loadsync(filename);
834
+ env.s.push({ _type: 'TC_STR', _datum: x });
835
+ return;
836
+ } catch (e) {
837
+ env.s.push(err.throw(e));
838
+ return;
839
+ }
840
+ }
841
+ env.s.push(err.throw('invalid arguments type'));
842
+ }
843
+
844
+ file_write_func() {
845
+ if (env.TOS() && env.TOS2() && env.is_string(env.TOS()) && env.is_string(env.TOS2())) {
846
+ try {
847
+ const arg = env.s.pop()._datum;
848
+ const filename = loadfile.resolve_path(arg);
849
+ const data = env.s.pop()._datum;
850
+ loadfile.writesync(filename, data);
851
+ return;
852
+ } catch (e) {
853
+ env.s.push(err.throw(e));
854
+ return;
855
+ }
856
+ }
857
+ env.s.push(err.throw('invalid arguments type. 2 Strings are expected.'));
858
+ }
859
+
860
+ file_append_func() {
861
+ if (env.TOS() && env.TOS2() && env.is_string(env.TOS()) && env.is_string(env.TOS2())) {
862
+ try {
863
+ const arg = env.s.pop()._datum;
864
+ const filename = loadfile.resolve_path(arg);
865
+ const data = env.s.pop()._datum;
866
+ loadfile.appendsync(filename, data);
867
+ return;
868
+ } catch (e) {
869
+ env.s.push(err.throw(e));
870
+ return;
871
+ }
872
+ }
873
+ env.s.push(err.throw('invalid arguments type. 2 Strings are expected.'));
874
+ }
875
+
876
+ file_exists_func() {
877
+ if (env.TOS() && env.is_string(env.TOS())) {
878
+ try {
879
+ const arg = env.s.pop()._datum;
880
+ const filename = loadfile.resolve_path(arg);
881
+ const exists = loadfile.existssync(filename);
882
+ env.s.push(env.set_bool_val(exists));
883
+ return;
884
+ } catch (e) {
885
+ env.s.push(err.throw(e));
886
+ return;
887
+ }
888
+ }
889
+ env.s.push(err.throw('invalid arguments type. a String is expected.'));
890
+ }
891
+
892
+ throw_func() {
893
+ if (env.TOS() && env.TOS()._type == 'TC_STR') {
894
+ env.s.push(err.throw(env.s.pop()._datum));
895
+ return;
896
+ }
897
+ if (env.TOS() && env.TOS()._type == 'TC_JSON') {
898
+ const err_arg = env.s.pop();
899
+ env.s.push(err.throw(err_arg._datum.msg, err_arg._datum.code));
900
+ return;
901
+ }
902
+ env.s.push(err.throw('invalid throw argument in TOS'));
903
+ }
904
+
905
+ require_js_func() {
906
+ if (env.TOS() && env.TOS()._type == 'TC_STR') {
907
+ try {
908
+ const arg = env.s.pop()._datum;
909
+ const filename = loadfile.resolve_path(arg);
910
+ const js = import(filename);
911
+ env.s.push({ _type: env.guess_type(js), _datum: js });
912
+ return;
913
+ } catch (e) {
914
+ env.s.push(err.throw(e));
915
+ return;
916
+ }
917
+ }
918
+ env.s.push(err.throw('invalid request-js argument type'));
919
+ }
920
+
921
+ async funcjs_exec_func() {
922
+ try {
923
+ if (env.TOS() && env.TOS()._type == 'TC_LAMBDA_FUNC') {
924
+ await evalx.eval_parsed(env.s.pop()._datum);
925
+ return;
926
+ }
927
+ if (env.TOS() && env.TOS()._type == 'TC_FUNC_JS') {
928
+ var x = env.s.pop()._datum;
929
+ var arity = x.length;
930
+ var args = [];
931
+ // log.info(arity);
932
+ while (arity > 0) {
933
+ args.unshift(env.s.pop()._datum);
934
+ arity--;
935
+ }
936
+ // log.info(args);
937
+ var y = x.apply(null, args);
938
+ // log.info(y);
939
+ if (y) {
940
+ env.s.push({ _type: env.guess_type(y), _datum: y });
941
+ }
942
+ return;
943
+ }
944
+ if (env.TOS() && env.TOS()._type == 'TC_STR' && env.TOS2() && env.TOS2()._type == 'TC_JSON') {
945
+ const method = env.s.pop()._datum;
946
+ const method_list = method.split('.');
947
+ var x = env.s.pop()._datum;
948
+ let funcall = x;
949
+ for (const item of method_list) {
950
+ funcall = funcall[item];
951
+ }
952
+ // log.info(funcall);
953
+ var arity = funcall.length;
954
+ var args = [];
955
+ // log.info(arity);
956
+ while (arity > 0) {
957
+ args.unshift(env.s.pop()._datum);
958
+ arity--;
959
+ }
960
+ // log.info(args);
961
+ var y = funcall.apply(x, args);
962
+ // log.info(y);
963
+ if (y) {
964
+ env.s.push({ _type: env.guess_type(y), _datum: y });
965
+ }
966
+ return;
967
+ }
968
+ env.s.push(err.throw('invalid funcall-js argument type'));
969
+ } catch (e) {
970
+ env.s.push(err.throw(e));
971
+ }
972
+ }
973
+
974
+ handle_repl_func() {
975
+ err.handle_repl();
976
+ }
977
+
978
+ handle_standard_func() {
979
+ err.handle_standard();
980
+ }
981
+
982
+ regex_test_func() {
983
+ try {
984
+ if (env.is_obj(env.TOS()) && env.is_string(env.TOS2())) {
985
+ const rex_obj = env.s.pop();
986
+ let _datum;
987
+ var str = env.s.pop()._datum;
988
+ var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
989
+ const result = my_rex.test(str);
990
+ env.s.push(result ? env.true_obj() : env.false_obj());
991
+ return;
992
+ }
993
+ if (env.is_string(env.TOS()) && env.is_string(env.TOS2())) {
994
+ const rex = env.s.pop()._datum;
995
+ var str = env.s.pop()._datum;
996
+ var my_rex = new RegExp(rex);
997
+ const result = my_rex.test(str);
998
+ env.s.push(result ? env.true_obj() : env.false_obj());
999
+ return;
1000
+ }
1001
+ env.s.push(err.throw('invalid regex test argument type'));
1002
+ } catch (e) {
1003
+ env.s.push(err.throw(e));
1004
+ }
1005
+ }
1006
+
1007
+ regex_exec_func() {
1008
+ try {
1009
+ if (env.is_obj(env.TOS()) && env.is_string(env.TOS2())) {
1010
+ const rex_obj = env.s.pop();
1011
+ let _datum;
1012
+ var str = env.s.pop()._datum;
1013
+ var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
1014
+ const result = my_rex.exec(str);
1015
+ env.s.push(result ? { _type: 'TC_JSON', _datum: result } : 0);
1016
+ return;
1017
+ }
1018
+ if (env.is_string(env.TOS()) && env.is_string(env.TOS2())) {
1019
+ const rex = env.s.pop()._datum;
1020
+ var str = env.s.pop()._datum;
1021
+ var my_rex = new RegExp(rex);
1022
+ const result = my_rex.exec(str);
1023
+ env.s.push(result ? { _type: 'TC_JSON', _datum: result } : 0);
1024
+ return;
1025
+ }
1026
+ env.s.push(err.throw('invalid regex exec argument type'));
1027
+ } catch (e) {
1028
+ env.s.push(err.throw(e));
1029
+ }
1030
+ }
1031
+
1032
+ regex_match_func() {
1033
+ try {
1034
+ if (env.is_obj(env.TOS()) && env.is_string(env.TOS2())) {
1035
+ const rex_obj = env.s.pop();
1036
+ let _datum;
1037
+ var str = env.s.pop()._datum;
1038
+ var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
1039
+ const result = str.match(my_rex);
1040
+ env.s.push(result ? { _type: 'TC_JSON', _datum: result } : 0);
1041
+ return;
1042
+ }
1043
+ if (env.is_string(env.TOS()) && env.is_string(env.TOS2())) {
1044
+ const rex = env.s.pop()._datum;
1045
+ var str = env.s.pop()._datum;
1046
+ var my_rex = new RegExp(rex);
1047
+ const result = str.match(my_rex);
1048
+ env.s.push(result ? { _type: 'TC_JSON', _datum: result } : 0);
1049
+ return;
1050
+ }
1051
+ env.s.push(err.throw('invalid regex match argument type'));
1052
+ } catch (e) {
1053
+ env.s.push(err.throw(e));
1054
+ }
1055
+ }
1056
+
1057
+ regex_search_func() {
1058
+ try {
1059
+ if (env.is_obj(env.TOS()) && env.is_string(env.TOS2())) {
1060
+ const rex_obj = env.s.pop();
1061
+ let _datum;
1062
+ var str = env.s.pop()._datum;
1063
+ var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
1064
+ const result = str.search(my_rex);
1065
+ env.s.push({ _type: 'TC_NUM', _datum: result });
1066
+ return;
1067
+ }
1068
+ if (env.is_string(env.TOS()) && env.is_string(env.TOS2())) {
1069
+ const rex = env.s.pop()._datum;
1070
+ var str = env.s.pop()._datum;
1071
+ var my_rex = new RegExp(rex);
1072
+ const result = str.search(my_rex);
1073
+ env.s.push({ _type: 'TC_NUM', _datum: result });
1074
+ return;
1075
+ }
1076
+ env.s.push(err.throw('invalid regex search argument type'));
1077
+ } catch (e) {
1078
+ env.s.push(err.throw(e));
1079
+ }
1080
+ }
1081
+
1082
+ regex_replace_func() {
1083
+ try {
1084
+ if (env.is_obj(env.TOS()) && env.is_string(env.TOS2()) && env.is_string(env.s.look_at(2))) {
1085
+ const rex_obj = env.s.pop();
1086
+ let _datum;
1087
+ var replace = env.s.pop()._datum;
1088
+ var str = env.s.pop()._datum;
1089
+ var my_rex = new RegExp(rex_obj.rex, rex_obj.flags);
1090
+ const result = str.replace(my_rex, replace);
1091
+ env.s.push({ _type: 'TC_JSON', _datum: result });
1092
+ return;
1093
+ }
1094
+ if (env.is_string(env.TOS()) && env.is_string(env.TOS2()) && env.is_string(env.s.look_at(2))) {
1095
+ const rex = env.s.pop()._datum;
1096
+ var replace = env.s.pop()._datum;
1097
+ var str = env.s.pop()._datum;
1098
+ var my_rex = new RegExp(rex);
1099
+ const result = str.replace(my_rex, replace);
1100
+ env.s.push({ _type: 'TC_STR', _datum: result });
1101
+ return;
1102
+ }
1103
+ env.s.push(err.throw('invalid regex replace argument type'));
1104
+ } catch (e) {
1105
+ env.s.push(err.throw(e));
1106
+ }
1107
+ }
1108
+
1109
+ array_shift_func() {
1110
+ try {
1111
+ if (env.is_list(env.TOS())) {
1112
+ const value = env.s.pop()._datum.shift();
1113
+ const xval = env.adj_bool_val(value);
1114
+ env.s.push({ _type: env.guess_type(value), _datum: xval });
1115
+ return;
1116
+ }
1117
+ env.s.push(err.throw('invalid operation. TOS is not an list'));
1118
+ } catch (e) {
1119
+ env.s.push(err.throw(e));
1120
+ }
1121
+ }
1122
+
1123
+ array_unshift_func() {
1124
+ try {
1125
+ if (env.TOS() && env.is_list(env.TOS2())) {
1126
+ const value = env.s.pop()._datum;
1127
+ const array = env.s.pop()._datum;
1128
+ array.unshift(value);
1129
+ env.s.push({ _type: 'TC_JSON', _datum: array });
1130
+ return;
1131
+ }
1132
+ env.s.push(err.throw('invalid operation. TOS2 is not an list'));
1133
+ } catch (e) {
1134
+ env.s.push(err.throw(e));
1135
+ }
1136
+ }
1137
+
1138
+ async array_each_func() {
1139
+ try {
1140
+ if (env.TOS() && env.TOS()._type == 'TC_LAMBDA_FUNC' && env.is_list(env.TOS2())) {
1141
+ const funcall = env.s.pop()._datum;
1142
+ const array = env.s.pop()._datum;
1143
+ // Vx€array, !!funcall
1144
+ while (array.length > 0) {
1145
+ const value = array.shift();
1146
+ const xval = env.adj_bool_val(value);
1147
+ env.s.push({ _type: env.guess_type(value), _datum: xval });
1148
+ await evalx.eval_parsed(funcall);
1149
+ }
1150
+ return;
1151
+ }
1152
+ env.s.push(err.throw('invalid arguments. TOS should be a LAMBDA function and TOS2 should be a list'));
1153
+ } catch (e) {
1154
+ env.s.push(err.throw(e));
1155
+ }
1156
+ }
1157
+
1158
+ parse_args_func() {
1159
+ try {
1160
+ if (env.is_list(env.TOS())) {
1161
+ const rx_double_dash = /^\-\-[a-zA-Z0-9]+/;
1162
+ const rx_single_dash = /^\-[a-zA-Z0-9]+/;
1163
+ const rx_no_dash = /^[^\-]/;
1164
+ const rx_two_dashes = /^\-\-/;
1165
+ const args = { argv: [] };
1166
+ const params_data = env.s.pop()._datum;
1167
+ // log.info(params_data);
1168
+ let param_found = false;
1169
+ let test_col;
1170
+ let is_dash;
1171
+ const argv = env.lookup('os:argv')._datum._datum;
1172
+ argv.shift();
1173
+ argv.shift();
1174
+ argv.shift();
1175
+ // log.info(argv);
1176
+ while (argv.length > 0) {
1177
+ const item = argv.shift();
1178
+ is_dash = 0;
1179
+ // log.info(item);
1180
+ // if(rx_double_dash.test(item)){
1181
+ // test_col= 1;
1182
+ // is_dash = true;
1183
+ // }
1184
+ // if(rx_single_dash.test(item)) {
1185
+ // test_col = 0;
1186
+ // is_dash = true;
1187
+ // }
1188
+
1189
+ // if(is_dash) {
1190
+ // param_found = false;
1191
+ // for(var param_item of params_data){
1192
+ // log.info(param_item[test_col]);
1193
+ // if(param_item[test_col]=== (test_col === 0)? item.match(rx_single_dash)[0] : item.match(rx_double_dash[0])){
1194
+ // log.info('d: ',param_item);
1195
+ // param_found = true;
1196
+ // break;
1197
+ // }
1198
+ // }
1199
+ // //if ! invalid parameter
1200
+ // if(!param_found) log.info(`invalid parameter ${item}`);
1201
+ // }
1202
+
1203
+ if (rx_double_dash.test(item)) {
1204
+ param_found = false;
1205
+ for (var param_item of params_data) {
1206
+ if (param_item[1] === item.match(rx_double_dash)[0]) {
1207
+ // log.info('dd: ',param_item);
1208
+ param_found = true;
1209
+ switch (param_item[2]) {
1210
+ case 'y':
1211
+ // log.info('ha param');
1212
+ if (argv[0] && rx_no_dash.test(argv[0])) {
1213
+ args[param_item[1].replace(rx_two_dashes, '')] = argv.shift();
1214
+ } else {
1215
+ log.info(`error, parameter ${item} needs value...`);
1216
+ // error needs param...
1217
+ }
1218
+ break;
1219
+ case 'n':
1220
+ // log.info('no param');
1221
+ args[param_item[1].replace(rx_two_dashes, '')] = true;
1222
+ break;
1223
+ case '?':
1224
+ // log.info('opt param');
1225
+ if (argv[0] && rx_no_dash.test(argv[0])) {
1226
+ args[param_item[1].replace(rx_two_dashes, '')] = argv[0];
1227
+ } else {
1228
+ args[param_item[1].replace(rx_two_dashes, '')] = true;
1229
+ }
1230
+ break;
1231
+ default:
1232
+ break;
1233
+ }
1234
+ break;
1235
+ }
1236
+ }
1237
+ // if ! invalid parameter
1238
+ if (!param_found) {
1239
+ log.info(`invalid parameter ${item}`);
1240
+ }
1241
+ } else if (rx_single_dash.test(item)) {
1242
+ param_found = false;
1243
+ for (var param_item of params_data) {
1244
+ if (param_item[0] === item.match(rx_single_dash)[0]) {
1245
+ // log.info('sd: ',param_item);
1246
+ param_found = true;
1247
+ switch (param_item[2]) {
1248
+ case 'y':
1249
+ // log.info('ha param');
1250
+ if (argv[0] && rx_no_dash.test(argv[0])) {
1251
+ args[param_item[1].replace(rx_two_dashes, '')] = argv.shift();
1252
+ } else {
1253
+ log.info(`error, parameter ${item} needs value...`);
1254
+ // error needs param...
1255
+ }
1256
+ break;
1257
+ case 'n':
1258
+ // log.info('no param');
1259
+ args[param_item[1].replace(rx_two_dashes, '')] = true;
1260
+ break;
1261
+ case '?':
1262
+ // log.info('opt param');
1263
+ if (argv[0] && rx_no_dash.test(argv[0])) {
1264
+ args[param_item[1].replace(rx_two_dashes, '')] = argv[0];
1265
+ } else {
1266
+ args[param_item[1].replace(rx_two_dashes, '')] = true;
1267
+ }
1268
+ break;
1269
+ default:
1270
+ break;
1271
+ }
1272
+ break;
1273
+ }
1274
+ }
1275
+ if (!param_found) {
1276
+ log.info(`invalid parameter ${item}`);
1277
+ }
1278
+ } else {
1279
+ // else{
1280
+ // normal argv...
1281
+ args.argv.push(item);
1282
+ }
1283
+ }
1284
+ // log.info(args);
1285
+ env.s.push({ _type: 'TC_JSON', _datum: args });
1286
+ return;
1287
+ }
1288
+ env.s.push(err.throw('invalid arguments. TOS should be a list'));
1289
+ } catch (e) {
1290
+ env.s.push(err.throw(e));
1291
+ }
1292
+ }
1293
+
1294
+ async await_func() {
1295
+ if (env.TOS() && env.TOS()._type === 'TC_PROMISE') {
1296
+ try {
1297
+ const x = await env.s.pop()._datum;
1298
+ env.s.push({ _type: env.guess_type(x), _datum: x });
1299
+ // env.s.pop()._datum.then(x => {
1300
+ // env.s.push({"_type":env.guess_type(x), "_datum":x});
1301
+ // });
1302
+ return;
1303
+ } catch (e) {
1304
+ env.s.push(err.throw(e));
1305
+ return;
1306
+ }
1307
+ }
1308
+ env.s.push(err.throw('invalid arguments type. a Promise was expected.'));
1309
+ }
1310
+
1311
+ string_format_func() {
1312
+ if (env.TOS() && env.TOS2() && env.is_string(env.TOS2()) && env.is_list(env.TOS())) {
1313
+ try {
1314
+ const args_list = env.s.pop()._datum;
1315
+ const fmt = env.s.pop()._datum;
1316
+ env.s.push({ _type: 'TC_STR', _datum: vsprintf(fmt, args_list) });
1317
+ return;
1318
+ } catch (e) {
1319
+ env.s.push(err.throw(e));
1320
+ return;
1321
+ }
1322
+ }
1323
+ env.s.push(err.throw('invalid arguments type. a String and a List in TOS and TOS2 was expected.'));
1324
+ }
1325
+
1326
+ string_length_func() {
1327
+ if (env.TOS() && env.is_string(env.TOS())) {
1328
+ try {
1329
+ const str = env.s.pop()._datum;
1330
+ env.s.push({ _type: 'TC_NUM', _datum: str.length });
1331
+ return;
1332
+ } catch (e) {
1333
+ env.s.push(err.throw(e));
1334
+ return;
1335
+ }
1336
+ }
1337
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1338
+ }
1339
+
1340
+ string_to_upper_func() {
1341
+ if (env.TOS() && env.is_string(env.TOS())) {
1342
+ try {
1343
+ const str = env.s.pop()._datum;
1344
+ env.s.push({ _type: 'TC_STR', _datum: str.toUpperCase() });
1345
+ return;
1346
+ } catch (e) {
1347
+ env.s.push(err.throw(e));
1348
+ return;
1349
+ }
1350
+ }
1351
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1352
+ }
1353
+
1354
+ string_to_lower_func() {
1355
+ if (env.TOS() && env.is_string(env.TOS())) {
1356
+ try {
1357
+ const str = env.s.pop()._datum;
1358
+ env.s.push({ _type: 'TC_STR', _datum: str.toLowerCase() });
1359
+ return;
1360
+ } catch (e) {
1361
+ env.s.push(err.throw(e));
1362
+ return;
1363
+ }
1364
+ }
1365
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1366
+ }
1367
+
1368
+ xml_load_func() {
1369
+ if (env.TOS() && env.is_string(env.TOS())) {
1370
+ try {
1371
+ const str = env.s.pop()._datum;
1372
+ const $ = cheerio.load(str);
1373
+ env.s.push({ _type: env.guess_type($), _datum: $ });
1374
+ return;
1375
+ } catch (e) {
1376
+ env.s.push(err.throw(e));
1377
+ return;
1378
+ }
1379
+ }
1380
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1381
+ }
1382
+
1383
+ xml_loadXML_func() {
1384
+ if (env.TOS() && env.is_string(env.TOS())) {
1385
+ try {
1386
+ const str = env.s.pop()._datum;
1387
+ const $ = cheerio.load(str, { xmlMode: true });
1388
+ env.s.push({ _type: env.guess_type($), _datum: $ });
1389
+ return;
1390
+ } catch (e) {
1391
+ env.s.push(err.throw(e));
1392
+ return;
1393
+ }
1394
+ }
1395
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1396
+ }
1397
+
1398
+ xml_select_func() {
1399
+ if (env.TOS() && env.TOS2() && env.TOS2()._type == 'TC_FUNC_JS' && env.is_string(env.TOS())) {
1400
+ try {
1401
+ const arg = env.s.pop()._datum;
1402
+ const $ = env.s.pop()._datum;
1403
+ const resp = $(arg);
1404
+ env.s.push({ _type: env.guess_type(resp), _datum: resp });
1405
+ return;
1406
+ } catch (e) {
1407
+ env.s.push(err.throw(e));
1408
+ return;
1409
+ }
1410
+ }
1411
+ env.s.push(err.throw('invalid arguments type. a XML object was expected.'));
1412
+ }
1413
+
1414
+ xml_get_text_func() {
1415
+ if (env.TOS() && env.is_json(env.TOS())) {
1416
+ try {
1417
+ const $ = env.s.pop()._datum;
1418
+ const resp = $.text();
1419
+ env.s.push({ _type: env.guess_type(resp), _datum: resp });
1420
+ return;
1421
+ } catch (e) {
1422
+ env.s.push(err.throw(e));
1423
+ return;
1424
+ }
1425
+ }
1426
+ env.s.push(err.throw('invalid arguments type. a JSON object was expected.'));
1427
+ }
1428
+
1429
+ xml_get_html_func() {
1430
+ if (env.TOS() && env.is_json(env.TOS())) {
1431
+ try {
1432
+ const $ = env.s.pop()._datum;
1433
+ const resp = $.html();
1434
+ env.s.push({ _type: env.guess_type(resp), _datum: resp });
1435
+ return;
1436
+ } catch (e) {
1437
+ env.s.push(err.throw(e));
1438
+ return;
1439
+ }
1440
+ }
1441
+ env.s.push(err.throw('invalid arguments type. a JSON object was expected.'));
1442
+ }
1443
+
1444
+ xml_get_attr_func() {
1445
+ if (env.TOS() && env.is_string(env.TOS()) && env.TOS2() && env.is_json(env.TOS2())) {
1446
+ try {
1447
+ const attr = env.s.pop()._datum;
1448
+ const $ = env.s.pop()._datum;
1449
+ const resp = $.attr(attr);
1450
+ env.s.push({ _type: env.guess_type(resp), _datum: resp });
1451
+ return;
1452
+ } catch (e) {
1453
+ env.s.push(err.throw(e));
1454
+ return;
1455
+ }
1456
+ }
1457
+ env.s.push(err.throw('invalid arguments type. a JSON object was expected.'));
1458
+ }
1459
+
1460
+ xml_has_class_func() {
1461
+ if (env.TOS() && env.is_string(env.TOS()) && env.TOS2() && env.is_json(env.TOS2())) {
1462
+ try {
1463
+ const attr = env.s.pop()._datum;
1464
+ const $ = env.s.pop()._datum;
1465
+ const resp = $.hasClass(attr);
1466
+ env.s.push(env.set_bool_val(resp));
1467
+ return;
1468
+ } catch (e) {
1469
+ env.s.push(err.throw(e));
1470
+ return;
1471
+ }
1472
+ }
1473
+ env.s.push(err.throw('invalid arguments type. a JSON object was expected.'));
1474
+ }
1475
+
1476
+ xml_get_val_func() {
1477
+ if (env.TOS() && env.is_json(env.TOS())) {
1478
+ try {
1479
+ const $ = env.s.pop()._datum;
1480
+ const resp = $.val();
1481
+ env.s.push({ _type: env.guess_type(resp), _datum: resp });
1482
+ return;
1483
+ } catch (e) {
1484
+ env.s.push(err.throw(e));
1485
+ return;
1486
+ }
1487
+ }
1488
+ env.s.push(err.throw('invalid arguments type. a JSON object was expected.'));
1489
+ }
1490
+
1491
+ os_exec() {
1492
+ if (env.TOS() && env.is_string(env.TOS())) {
1493
+ try {
1494
+ const str = env.s.pop()._datum;
1495
+ const output = execSync(str).toString();
1496
+ env.s.push({ _type: env.guess_type(output), _datum: output });
1497
+ return;
1498
+ } catch (e) {
1499
+ env.s.push(err.throw(e));
1500
+ return;
1501
+ }
1502
+ }
1503
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1504
+ }
1505
+
1506
+ os_exec_i() {
1507
+ if (env.TOS() && env.is_string(env.TOS())) {
1508
+ try {
1509
+ const str = env.s.pop()._datum;
1510
+ execSync(str, { stdio: 'inherit' });
1511
+ return;
1512
+ } catch (e) {
1513
+ env.s.push(err.throw(e));
1514
+ return;
1515
+ }
1516
+ }
1517
+ env.s.push(err.throw('invalid arguments type. a String was expected.'));
1518
+ }
1519
+
1520
+ put_r_stack() {
1521
+ if (env.TOS()) {
1522
+ try {
1523
+ const element = env.s.pop();
1524
+ env.s.rpush(element);
1525
+ return;
1526
+ } catch (e) {
1527
+ env.s.push(err.throw(e));
1528
+ return;
1529
+ }
1530
+ }
1531
+ env.s.push(err.throw('empty stack. Cannot move to r-stack.'));
1532
+ }
1533
+
1534
+ get_r_stack() {
1535
+ if (env.RTOS()) {
1536
+ try {
1537
+ const element = env.s.rpop();
1538
+ env.s.push(element);
1539
+ return;
1540
+ } catch (e) {
1541
+ env.s.push(err.throw(e));
1542
+ return;
1543
+ }
1544
+ }
1545
+ env.s.push(err.throw('empty r-stack. Cannot move to stack.'));
1546
+ }
1547
+
1548
+ list_head() {
1549
+ if (env.is_list(env.TOS())) {
1550
+ try {
1551
+ const value = env.s.pop()._datum[0];
1552
+ const xval = env.adj_bool_val(value);
1553
+ env.s.push({ _type: env.guess_type(value), _datum: xval });
1554
+ return;
1555
+ } catch (e) {
1556
+ env.s.push(err.throw(e));
1557
+ return;
1558
+ }
1559
+ }
1560
+ env.s.push(err.throw('invalid arguments type. TOS not a list'));
1561
+ }
1562
+
1563
+ list_tail() {
1564
+ if (env.is_list(env.TOS())) {
1565
+ try {
1566
+ const value = env.s.pop()._datum;
1567
+ value.shift();
1568
+ // const xval=env.adj_bool_val(value);
1569
+ env.s.push({ _type: env.guess_type(value), _datum: value });
1570
+ return;
1571
+ } catch (e) {
1572
+ env.s.push(err.throw(e));
1573
+ return;
1574
+ }
1575
+ }
1576
+ env.s.push(err.throw('invalid arguments type. TOS not a list'));
1577
+ }
1578
+
1579
+ string_to_number_func() {
1580
+ if (env.is_string(env.TOS())) {
1581
+ try {
1582
+ let value = env.s.pop()._datum;
1583
+ value = Number(value);
1584
+ if (isNaN(value)) {
1585
+ throw 'NaN';
1586
+ }
1587
+ env.s.push({ _type: env.guess_type(value), _datum: value });
1588
+ return;
1589
+ } catch (e) {
1590
+ env.s.push(err.throw(e));
1591
+ return;
1592
+ }
1593
+ }
1594
+ env.s.push(err.throw('invalid arguments type. TOS not a string'));
1595
+ }
1596
+
1597
+ populate_repl() {
1598
+ env.set('handle', { _type: 'TC_NATIVE_FUNC', _datum: this.handle_repl_func }, 'TC_WORD');
1599
+ }
1600
+
1601
+ populate() {
1602
+ env.set('pippo', { _type: 'TC_NATIVE_FUNC', _datum: this.test_func }, 'TC_WORD');
1603
+ env.set('bye', { _type: 'TC_NATIVE_FUNC', _datum: this.bye_func }, 'TC_WORD');
1604
+ env.set('noop', { _type: 'TC_NATIVE_FUNC', _datum: this.noop_func }, 'TC_WORD');
1605
+ env.set('.s', { _type: 'TC_NATIVE_FUNC', _datum: this.print_stack_func }, 'TC_WORD');
1606
+ env.set('.e', { _type: 'TC_NATIVE_FUNC', _datum: this.print_env_func }, 'TC_WORD');
1607
+ env.set('words', { _type: 'TC_NATIVE_FUNC', _datum: this.print_words_func }, 'TC_WORD');
1608
+ env.set('emit', { _type: 'TC_NATIVE_FUNC', _datum: this.emit_func }, 'TC_WORD');
1609
+ env.set('.', { _type: 'TC_NATIVE_FUNC', _datum: this.print_tos_func }, 'TC_WORD');
1610
+ env.set('.?', { _type: 'TC_NATIVE_FUNC', _datum: this.print_debug_tos_func }, 'TC_WORD');
1611
+ env.set('!', { _type: 'TC_NATIVE_FUNC', _datum: this.assign_var_func }, 'TC_WORD');
1612
+ env.set('@', { _type: 'TC_NATIVE_FUNC', _datum: this.read_var_func }, 'TC_WORD');
1613
+ env.set('not', { _type: 'TC_NATIVE_FUNC', _datum: this.not_func }, 'TC_WORD');
1614
+ env.set('and', { _type: 'TC_NATIVE_FUNC', _datum: this.and_func }, 'TC_WORD');
1615
+ env.set('or', { _type: 'TC_NATIVE_FUNC', _datum: this.or_func }, 'TC_WORD');
1616
+ env.set('is_num', { _type: 'TC_NATIVE_FUNC', _datum: this.is_num_func }, 'TC_WORD');
1617
+ env.set('is_string', { _type: 'TC_NATIVE_FUNC', _datum: this.is_string_func }, 'TC_WORD');
1618
+ env.set('is_list', { _type: 'TC_NATIVE_FUNC', _datum: this.is_list_func }, 'TC_WORD');
1619
+ env.set('is_falsy', { _type: 'TC_NATIVE_FUNC', _datum: this.is_falsy_func }, 'TC_WORD');
1620
+ env.set('dup', { _type: 'TC_NATIVE_FUNC', _datum: this.dup_func }, 'TC_WORD');
1621
+ env.set('swap', { _type: 'TC_NATIVE_FUNC', _datum: this.swap_func }, 'TC_WORD');
1622
+ env.set('drop', { _type: 'TC_NATIVE_FUNC', _datum: this.drop_func }, 'TC_WORD');
1623
+ env.set('ndrop', { _type: 'TC_NATIVE_FUNC', _datum: this.ndrop_func }, 'TC_WORD');
1624
+ env.set('nbye', { _type: 'TC_NATIVE_FUNC', _datum: this.nbye_func }, 'TC_WORD');
1625
+ env.set('over', { _type: 'TC_NATIVE_FUNC', _datum: this.over_func }, 'TC_WORD');
1626
+ env.set('n:+', { _type: 'TC_NATIVE_FUNC', _datum: this.num_plus_func }, 'TC_WORD');
1627
+ env.set('n:-', { _type: 'TC_NATIVE_FUNC', _datum: this.num_minus_func }, 'TC_WORD');
1628
+ env.set('n:*', { _type: 'TC_NATIVE_FUNC', _datum: this.num_times_func }, 'TC_WORD');
1629
+ env.set('n:/', { _type: 'TC_NATIVE_FUNC', _datum: this.num_div_func }, 'TC_WORD');
1630
+ env.set('+', { _type: 'TC_NATIVE_FUNC', _datum: this.plus_func }, 'TC_WORD');
1631
+ env.set('-', { _type: 'TC_NATIVE_FUNC', _datum: this.minus_func }, 'TC_WORD');
1632
+ env.set('*', { _type: 'TC_NATIVE_FUNC', _datum: this.times_func }, 'TC_WORD');
1633
+ env.set('/', { _type: 'TC_NATIVE_FUNC', _datum: this.division_func }, 'TC_WORD');
1634
+ env.set('%', { _type: 'TC_NATIVE_FUNC', _datum: this.module_func }, 'TC_WORD');
1635
+ env.set('handle', { _type: 'TC_NATIVE_FUNC', _datum: this.handle_standard_func }, 'TC_WORD');
1636
+ env.set('throw', { _type: 'TC_NATIVE_FUNC', _datum: this.throw_func }, 'TC_WORD');
1637
+ env.set('s:+', { _type: 'TC_NATIVE_FUNC', _datum: this.string_plus_func }, 'TC_WORD');
1638
+ env.set('a:+', { _type: 'TC_NATIVE_FUNC', _datum: this.array_plus_func }, 'TC_WORD');
1639
+ env.set('included', { _type: 'TC_NATIVE_FUNC', _datum: this.included_func }, 'TC_WORD');
1640
+ env.set('a:@', { _type: 'TC_NATIVE_FUNC', _datum: this.array_at_func }, 'TC_WORD');
1641
+ env.set('a:!', { _type: 'TC_NATIVE_FUNC', _datum: this.array_set_at_func }, 'TC_WORD');
1642
+ env.set('m:@', { _type: 'TC_NATIVE_FUNC', _datum: this.object_at_func }, 'TC_WORD');
1643
+ env.set('m:!', { _type: 'TC_NATIVE_FUNC', _datum: this.object_set_at_func }, 'TC_WORD');
1644
+ env.set('a:len', { _type: 'TC_NATIVE_FUNC', _datum: this.array_length_func }, 'TC_WORD');
1645
+ env.set('a:push', { _type: 'TC_NATIVE_FUNC', _datum: this.array_push_func }, 'TC_WORD');
1646
+ env.set('a:pop', { _type: 'TC_NATIVE_FUNC', _datum: this.array_pop_func }, 'TC_WORD');
1647
+ env.set('m:keys', { _type: 'TC_NATIVE_FUNC', _datum: this.object_keys_func }, 'TC_WORD');
1648
+ env.set('m:values', { _type: 'TC_NATIVE_FUNC', _datum: this.object_values_func }, 'TC_WORD');
1649
+ env.set('s:split', { _type: 'TC_NATIVE_FUNC', _datum: this.string_split_func }, 'TC_WORD');
1650
+ env.set('s:join', { _type: 'TC_NATIVE_FUNC', _datum: this.string_join_func }, 'TC_WORD');
1651
+ env.set('j:stringify', { _type: 'TC_NATIVE_FUNC', _datum: this.json_stringify_func }, 'TC_WORD');
1652
+ env.set('j:parse', { _type: 'TC_NATIVE_FUNC', _datum: this.json_parse_func }, 'TC_WORD');
1653
+ env.set('s:@', { _type: 'TC_NATIVE_FUNC', _datum: this.string_at_func }, 'TC_WORD');
1654
+ env.set('s:!', { _type: 'TC_NATIVE_FUNC', _datum: this.string_set_at_func }, 'TC_WORD');
1655
+ env.set('=', { _type: 'TC_NATIVE_FUNC', _datum: this.equal_func }, 'TC_WORD');
1656
+ env.set('===', { _type: 'TC_NATIVE_FUNC', _datum: this.equal_func }, 'TC_WORD');
1657
+ env.set('==', { _type: 'TC_NATIVE_FUNC', _datum: this.eq_func }, 'TC_WORD');
1658
+ env.set('<', { _type: 'TC_NATIVE_FUNC', _datum: this.num_minor_func }, 'TC_WORD');
1659
+ env.set('>', { _type: 'TC_NATIVE_FUNC', _datum: this.num_major_func }, 'TC_WORD');
1660
+ env.set('<=', { _type: 'TC_NATIVE_FUNC', _datum: this.num_min_eq_func }, 'TC_WORD');
1661
+ env.set('>=', { _type: 'TC_NATIVE_FUNC', _datum: this.num_maj_eq_func }, 'TC_WORD');
1662
+ env.set('f:slurp', { _type: 'TC_NATIVE_FUNC', _datum: this.file_slurp_func }, 'TC_WORD');
1663
+ env.set('f:write', { _type: 'TC_NATIVE_FUNC', _datum: this.file_write_func }, 'TC_WORD');
1664
+ env.set('f:append', { _type: 'TC_NATIVE_FUNC', _datum: this.file_append_func }, 'TC_WORD');
1665
+ env.set('f:exists', { _type: 'TC_NATIVE_FUNC', _datum: this.file_exists_func }, 'TC_WORD');
1666
+ env.set('net:request', { _type: 'TC_NATIVE_FUNC', _datum: this.net_request_func }, 'TC_WORD');
1667
+ env.set('j:require-js', { _type: 'TC_NATIVE_FUNC', _datum: this.require_js_func }, 'TC_WORD');
1668
+ env.set('!!', { _type: 'TC_NATIVE_FUNC', _datum: this.funcjs_exec_func }, 'TC_WORD');
1669
+ env.set('G:delete', { _type: 'TC_NATIVE_FUNC', _datum: this.delete_dict_func }, 'TC_WORD');
1670
+ env.set('rx:test', { _type: 'TC_NATIVE_FUNC', _datum: this.regex_test_func }, 'TC_WORD');
1671
+ env.set('rx:exec', { _type: 'TC_NATIVE_FUNC', _datum: this.regex_exec_func }, 'TC_WORD');
1672
+ env.set('rx:match', { _type: 'TC_NATIVE_FUNC', _datum: this.regex_match_func }, 'TC_WORD');
1673
+ env.set('rx:search', { _type: 'TC_NATIVE_FUNC', _datum: this.regex_search_func }, 'TC_WORD');
1674
+ env.set('rx:replace', { _type: 'TC_NATIVE_FUNC', _datum: this.regex_replace_func }, 'TC_WORD');
1675
+ env.set('a:shift', { _type: 'TC_NATIVE_FUNC', _datum: this.array_shift_func }, 'TC_WORD');
1676
+ env.set('a:unshift', { _type: 'TC_NATIVE_FUNC', _datum: this.array_unshift_func }, 'TC_WORD');
1677
+ env.set('a:each', { _type: 'TC_NATIVE_FUNC', _datum: this.array_each_func }, 'TC_WORD');
1678
+ env.set('os:parse-args', { _type: 'TC_NATIVE_FUNC', _datum: this.parse_args_func }, 'TC_WORD');
1679
+ env.set('await', { _type: 'TC_NATIVE_FUNC', _datum: this.await_func }, 'TC_WORD');
1680
+ env.set('s:format', { _type: 'TC_NATIVE_FUNC', _datum: this.string_format_func }, 'TC_WORD');
1681
+ env.set('s:len', { _type: 'TC_NATIVE_FUNC', _datum: this.string_length_func }, 'TC_WORD');
1682
+ env.set('s:to_upper', { _type: 'TC_NATIVE_FUNC', _datum: this.string_to_upper_func }, 'TC_WORD');
1683
+ env.set('s:to_lower', { _type: 'TC_NATIVE_FUNC', _datum: this.string_to_lower_func }, 'TC_WORD');
1684
+ env.set('xml:loadDOM', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_load_func }, 'TC_WORD');
1685
+ env.set('xml:loadXML', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_loadXML_func }, 'TC_WORD');
1686
+ env.set('xml:$', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_select_func }, 'TC_WORD');
1687
+ env.set('xml:get_text', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_get_text_func }, 'TC_WORD');
1688
+ env.set('xml:get_html', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_get_html_func }, 'TC_WORD');
1689
+ env.set('xml:get_attr', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_get_attr_func }, 'TC_WORD');
1690
+ env.set('xml:has_class', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_has_class_func }, 'TC_WORD');
1691
+ env.set('xml:get_val', { _type: 'TC_NATIVE_FUNC', _datum: this.xml_get_val_func }, 'TC_WORD');
1692
+ env.set('os:exec', { _type: 'TC_NATIVE_FUNC', _datum: this.os_exec }, 'TC_WORD');
1693
+ env.set('os:exec-i', { _type: 'TC_NATIVE_FUNC', _datum: this.os_exec_i }, 'TC_WORD');
1694
+ env.set('>r', { _type: 'TC_NATIVE_FUNC', _datum: this.put_r_stack }, 'TC_WORD');
1695
+ env.set('r>', { _type: 'TC_NATIVE_FUNC', _datum: this.get_r_stack }, 'TC_WORD');
1696
+ env.set('a:head', { _type: 'TC_NATIVE_FUNC', _datum: this.list_head }, 'TC_WORD');
1697
+ env.set('a:tail', { _type: 'TC_NATIVE_FUNC', _datum: this.list_tail }, 'TC_WORD');
1698
+ env.set('s:to_num', { _type: 'TC_NATIVE_FUNC', _datum: this.string_to_number_func }, 'TC_WORD');
1699
+ }
1700
+ }
1701
+
1702
+ export default new NativeLib();