force-lang 0.0.12 → 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/.eslintrc.cjs +54 -0
- package/README.md +40 -15
- package/doc/force-lang.1 +55 -36
- package/doc/force.1 +55 -36
- package/examples/cli-args.j +3 -3
- package/examples/nodejs-js-interaction.j +2 -1
- package/examples/testjs.js +2 -2
- package/examples/web_scrap.j +17 -0
- package/force +88 -88
- package/force-lang-0.1.0.tgz +0 -0
- package/package.json +17 -14
- package/src/BKlib.j +51 -0
- package/src/env.js +221 -162
- package/src/error.js +71 -59
- package/src/eval.js +454 -299
- package/src/force-lang.js +38 -34
- package/src/lib.j +17 -0
- package/src/load-file.js +62 -35
- package/src/native_lib.js +1702 -1230
- package/src/obj_utils.js +20 -18
- package/src/read.js +431 -309
- package/src/stack.js +113 -68
- package/src/token-stream.js +34 -28
- package/tests/pippo.j +1 -1
- package/tests/test-js-require.js +13 -9
- package/tests/test.j +1 -1
- package/tests/unit_tests.j +1 -1
- package/.eslintrc.js +0 -60
package/src/error.js
CHANGED
|
@@ -1,63 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import log from 'bunny-logger';
|
|
2
|
+
import env from './env.js';
|
|
3
3
|
|
|
4
4
|
class Error {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
this.env_stack = [];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
add_stack(e) {
|
|
10
|
+
this.env_stack.push(e);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pop_stack() {
|
|
14
|
+
this.env_stack.pop();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
print_env_stack() {
|
|
18
|
+
log.error('err stack trace ...');
|
|
19
|
+
this.env_stack
|
|
20
|
+
.reverse()
|
|
21
|
+
.filter(e => e._where.file)
|
|
22
|
+
.map(e => {
|
|
23
|
+
log.error(`in '${e._datum}' ${this.where_to_str(e._where)}`);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
where_to_str(where) {
|
|
28
|
+
let str = '';
|
|
29
|
+
if (where.file) {
|
|
30
|
+
str += `in ${where.file} `;
|
|
31
|
+
}
|
|
32
|
+
str += `at ${where.line},${where.col}`;
|
|
33
|
+
return str;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw(msg, code) {
|
|
37
|
+
return this.new(msg, code);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
new(msg, code) {
|
|
41
|
+
return {
|
|
42
|
+
_type: 'TC_ERR',
|
|
43
|
+
_where: undefined,
|
|
44
|
+
_datum: { msg, code },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
require_handle(info_str) {
|
|
49
|
+
if (env.TOS() && env.TOS()._type == 'TC_ERR') {
|
|
50
|
+
const x = env.s.pop();
|
|
51
|
+
x._datum._msg += info_str;
|
|
52
|
+
env.s.push(x);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
handle_repl() {
|
|
59
|
+
if (this.require_handle()) {
|
|
60
|
+
log.error(`ERR: ${env.s.pop()._datum.msg}`);
|
|
61
|
+
this.print_env_stack();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handle_standard() {
|
|
66
|
+
if (this.require_handle()) {
|
|
67
|
+
const e = env.s.pop();
|
|
68
|
+
log.error(`ERR: ${e._datum.msg}`);
|
|
69
|
+
this.print_env_stack();
|
|
70
|
+
process.exit(e._datum.code ? e._datum.code : 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
|
|
75
|
+
export default new Error();
|