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/.eslintrc.cjs +54 -0
- package/README.md +19 -14
- package/doc/force-lang.1 +33 -35
- package/doc/force.1 +33 -35
- package/examples/cli-args.j +2 -2
- package/examples/nodejs-js-interaction.j +2 -1
- package/examples/testjs.js +2 -2
- package/examples/web_scrap.j +3 -0
- package/force +88 -88
- package/force-lang-0.1.0.tgz +0 -0
- package/package.json +17 -15
- package/src/BKlib.j +51 -0
- package/src/env.js +221 -162
- package/src/error.js +71 -59
- package/src/eval.js +454 -319
- package/src/force-lang.js +38 -34
- package/src/lib.j +11 -0
- package/src/load-file.js +62 -62
- package/src/native_lib.js +1702 -1458
- package/src/obj_utils.js +20 -18
- package/src/read.js +431 -309
- package/src/stack.js +113 -72
- 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/force-lang.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
//const repl = require('repl');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// const repl = require('repl');
|
|
2
|
+
import log from 'bunny-logger';
|
|
3
|
+
import NativeLib from './native_lib.js';
|
|
4
|
+
import evalx from './eval.js';
|
|
5
|
+
import loadfile from './load-file.js';
|
|
6
|
+
import env from './env.js';
|
|
7
7
|
|
|
8
8
|
class Force {
|
|
9
|
+
constructor() {
|
|
10
|
+
env.set('os:cwd', { _type: 'TC_STR', _datum: process.cwd() }, 'TC_VAR');
|
|
11
|
+
env.set('os:argv', { _type: 'TC_JSON', _datum: process.argv }, 'TC_VAR');
|
|
12
|
+
env.set('os:__dirname', { _type: 'TC_STR', _datum: import.meta.dirname }, 'TC_VAR');
|
|
13
|
+
env.set('os:bin', { _type: 'TC_STR', _datum: '' }, 'TC_VAR');
|
|
14
|
+
}
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
env.set('os:__dirname',{_type: 'TC_STR', _datum: __dirname}, 'TC_VAR');
|
|
14
|
-
env.set('os:bin',{_type: 'TC_STR', _datum: ''}, 'TC_VAR');
|
|
15
|
-
}
|
|
16
|
+
async load_lib() {
|
|
17
|
+
await evalx.load_lib();
|
|
18
|
+
}
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
load_lib_sync(){
|
|
21
|
-
eval.load_lib();
|
|
22
|
-
}
|
|
23
|
-
async eval_file(filename){
|
|
24
|
-
env.set('os:bin',{_type: 'TC_STR', _datum: filename}, 'TC_VAR');
|
|
25
|
-
eval.eval(await loadfile.load(filename), filename);
|
|
26
|
-
}
|
|
27
|
-
eval_file_sync(filename){
|
|
28
|
-
env.set('os:bin',{_type: 'TC_STR', _datum: filename}, 'TC_VAR');
|
|
29
|
-
eval.eval(loadfile.loadsync(filename), filename);
|
|
30
|
-
}
|
|
31
|
-
exec(script){
|
|
32
|
-
eval.eval(script, '<stdin>');
|
|
33
|
-
}
|
|
34
|
-
populate_repl(){
|
|
35
|
-
NativeLib.populate_repl();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
20
|
+
load_lib_sync() {
|
|
21
|
+
evalx.load_lib();
|
|
22
|
+
}
|
|
38
23
|
|
|
39
|
-
|
|
24
|
+
async eval_file(filename) {
|
|
25
|
+
env.set('os:bin', { _type: 'TC_STR', _datum: filename }, 'TC_VAR');
|
|
26
|
+
await evalx.eval(await loadfile.load(filename), filename);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// deprecated ...
|
|
30
|
+
// eval_file_sync(filename){
|
|
31
|
+
// env.set('os:bin',{_type: 'TC_STR', _datum: filename}, 'TC_VAR');
|
|
32
|
+
// evalx.eval(loadfile.loadsync(filename), filename);
|
|
33
|
+
// }
|
|
34
|
+
async exec(script) {
|
|
35
|
+
await evalx.eval(script, '<stdin>');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
populate_repl() {
|
|
39
|
+
NativeLib.populate_repl();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default new Force();
|
package/src/lib.j
CHANGED
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
: ddup
|
|
17
17
|
over over ;
|
|
18
18
|
|
|
19
|
+
: nop
|
|
20
|
+
noop ;
|
|
21
|
+
|
|
19
22
|
: ndrop2
|
|
20
23
|
dup is_num if
|
|
21
24
|
'no number on TOS' throw else
|
|
@@ -41,3 +44,11 @@
|
|
|
41
44
|
|
|
42
45
|
: j:decode
|
|
43
46
|
j:parse ;
|
|
47
|
+
|
|
48
|
+
: a:nth \ (a n -- o)
|
|
49
|
+
0 begin ddup > while >r >r a:tail r> r> 1 + repeat ddrop a:shift ;
|
|
50
|
+
|
|
51
|
+
: s:chomp \ ( s -- s )
|
|
52
|
+
"" "\n$" rx:replace ;
|
|
53
|
+
|
|
54
|
+
\ a:find notes \ [11,22,33] ( 22 = ) ( >r dup a:len begin dup 0 > while 1 - ddup a:nth dup r> dup >r !! T = if nop else "T" . dup . then drop repeat "f" . r> drop drop drop ) !!
|
package/src/load-file.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import log from 'bunny-logger';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import env from './env.js';
|
|
6
6
|
|
|
7
7
|
const fs_readFile = promisify(fs.readFile);
|
|
8
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
9
|
+
export default {
|
|
10
|
+
load: async filename => {
|
|
11
|
+
let x;
|
|
12
|
+
try {
|
|
13
|
+
x = await fs_readFile(filename, 'utf8');
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw `error loading ${filename} file`;
|
|
16
|
+
// log.error(`error loading ${filename} file`);
|
|
17
|
+
// process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
return x;
|
|
20
|
+
},
|
|
21
|
+
loadsync: filename => {
|
|
22
|
+
let x;
|
|
23
|
+
try {
|
|
24
|
+
x = fs.readFileSync(filename, 'utf8');
|
|
25
|
+
} catch (e) {
|
|
26
|
+
throw `error loading ${filename} file`;
|
|
27
|
+
// log.error(`error loading ${filename} file`);
|
|
28
|
+
// process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
return x;
|
|
31
|
+
},
|
|
32
|
+
writesync: (filename, data) => {
|
|
33
|
+
try {
|
|
34
|
+
fs.writeFileSync(filename, data);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw `error writing to ${filename} file`;
|
|
37
|
+
// log.error(`error loading ${filename} file`);
|
|
38
|
+
// process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
appendsync: (filename, data) => {
|
|
42
|
+
try {
|
|
43
|
+
fs.appendFileSync(filename, data);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
throw `error writing to ${filename} file`;
|
|
46
|
+
// log.error(`error loading ${filename} file`);
|
|
47
|
+
// process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
existssync: filename => {
|
|
51
|
+
try {
|
|
52
|
+
return fs.existsSync(filename);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
throw `error writing to ${filename} file`;
|
|
55
|
+
// log.error(`error loading ${filename} file`);
|
|
56
|
+
// process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
resolve_path: filename => {
|
|
60
|
+
const bin = env.lookup('os:bin')._datum._datum;
|
|
61
|
+
let xpath = bin == '' ? path.resolve(bin) : path.dirname(path.resolve(bin));
|
|
62
|
+
xpath = filename.startsWith('/') ? filename : path.join(xpath, filename);
|
|
63
|
+
return xpath;
|
|
64
|
+
},
|
|
65
|
+
};
|