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/src/error.js CHANGED
@@ -1,63 +1,75 @@
1
- const log = require('bunny-logger');
2
- const env = require('./env');
1
+ import log from 'bunny-logger';
2
+ import env from './env.js';
3
3
 
4
4
  class Error {
5
- constructor(){
6
- this.env_stack=[];
7
- }
8
- add_stack(e){
9
- this.env_stack.push(e);
10
- }
11
- pop_stack() {
12
- this.env_stack.pop();
13
- }
14
- print_env_stack(){
15
- log.error('err stack trace ...');
16
- this.env_stack.reverse().filter(e =>
17
- e._where.file
18
- ).map(e => {
19
- log.error(`in '${e._datum}' ${this.where_to_str(e._where)}`);
20
- });
21
- }
22
- where_to_str(where){
23
- var str = '';
24
- if(where.file) str += 'in ' + where.file +' ';
25
- str += 'at ' + where.line +','+ where.col;
26
- return str;
27
- }
28
- throw(msg, code){
29
- return this.new(msg, code);
30
- }
31
- new(msg, code){
32
- return {
33
- "_type" : "TC_ERR",
34
- "_where": undefined,
35
- "_datum": {"msg":msg,"code":code}
36
- }
37
- }
38
- require_handle(info_str){
39
- if(env.TOS() && env.TOS()._type == 'TC_ERR'){
40
- var x=env.s.pop();
41
- x._datum._msg += info_str;
42
- env.s.push(x);
43
- return true;
44
- }
45
- return false;
46
- }
47
- handle_repl(){
48
- if(this.require_handle()){
49
- log.error(`ERR: ${env.s.pop()._datum.msg}`);
50
- this.print_env_stack();
51
- }
52
- }
53
- handle_standard(){
54
- if(this.require_handle()){
55
- const e = env.s.pop();
56
- log.error(`ERR: ${e._datum.msg}`);
57
- this.print_env_stack();
58
- process.exit(e._datum.code ? e._datum.code : 1);
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
- module.exports = new Error();
75
+ export default new Error();