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/force-lang.js CHANGED
@@ -1,39 +1,43 @@
1
- //const repl = require('repl');
2
- const log = require('bunny-logger');
3
- const NativeLib = require('./native_lib');
4
- const eval = require('./eval');
5
- const loadfile = require('./load-file');
6
- const env = require('./env');
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
- constructor(){
11
- env.set('os:cwd',{_type: 'TC_STR', _datum: process.cwd()}, 'TC_VAR');
12
- env.set('os:argv',{_type: 'TC_JSON', _datum: process.argv}, 'TC_VAR');
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
- async load_lib(){
18
- await eval.load_lib();
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
- module.exports = new Force();
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
- const {promisify} = require('util');
2
- const fs = require('fs');
3
- const log = require('bunny-logger');
4
- const path = require('path');
5
- const env = require('./env');
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
- module.exports = {
10
- load: async filename => {
11
- var 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
- var 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= path.join(xpath, filename);
63
- return xpath;
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
+ };