@makano/rew 1.2.92 → 1.2.94
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
|
|
1
|
+
const { compile } = require("../modules/compiler")
|
2
|
+
|
3
|
+
const _compilePart = (code, filepath) => compile(
|
4
|
+
{
|
5
|
+
path: filepath,
|
6
|
+
content: code
|
7
|
+
},
|
8
|
+
{}
|
9
|
+
);
|
10
|
+
|
11
|
+
module.exports = (filepath) => ({
|
12
|
+
_compilePart: (code) => {
|
13
|
+
return _compilePart(code, filepath);
|
14
|
+
},
|
15
|
+
_call: (fn, ...args) => args.length ? fn.call(...args) : fn()
|
16
|
+
})
|
@@ -66,20 +66,20 @@ typef.is = function(func, returnType){
|
|
66
66
|
return typeis(func.returnType.defaultValue, returnType);
|
67
67
|
}
|
68
68
|
|
69
|
-
function typeis(obj, typeDef) {
|
69
|
+
function typeis(obj, typeDef, missingObjects = false) {
|
70
70
|
// Resolve Type
|
71
71
|
if (typeof typeDef == 'function' && typeDef.type instanceof Type) typeDef = typeDef.type;
|
72
72
|
|
73
73
|
if (typeDef.isConstucted && typeDef.class && !(obj instanceof typeDef.class)) {
|
74
|
-
return false;
|
74
|
+
return missingObjects ? [false] : false;
|
75
75
|
}
|
76
76
|
|
77
77
|
if (getType(obj) == 'object' && typeDef.type == 'function') {
|
78
|
-
return obj instanceof typeDef.class;
|
78
|
+
return missingObjects ? [obj instanceof typeDef.class] : obj instanceof typeDef.class;
|
79
79
|
}
|
80
80
|
|
81
81
|
if (getType(obj) !== typeDef.type) {
|
82
|
-
return false;
|
82
|
+
return missingObjects ? [false] : false;
|
83
83
|
}
|
84
84
|
|
85
85
|
if (!typeDef.isEmpty) {
|
@@ -91,14 +91,28 @@ function typeis(obj, typeDef) {
|
|
91
91
|
|
92
92
|
if (typeof propTypeDef === 'object') {
|
93
93
|
if (!typeis(obj[key], propTypeDef)) {
|
94
|
-
return false
|
94
|
+
return missingObjects ? [false, {
|
95
|
+
[key]: {
|
96
|
+
type_mismatch: propTypeDef,
|
97
|
+
given: obj[gen_key]
|
98
|
+
}
|
99
|
+
}] : false;
|
95
100
|
}
|
96
|
-
} else if (typeof obj[key] !== propTypeDef) {
|
97
|
-
return false
|
101
|
+
} else if (typeof obj[key] !== typeof propTypeDef) {
|
102
|
+
return missingObjects ? [false, {
|
103
|
+
[key]: obj[key] ? {
|
104
|
+
type_mismatch: typeof propTypeDef,
|
105
|
+
given: typeof obj[key]
|
106
|
+
} : {
|
107
|
+
not_found: true
|
108
|
+
}
|
109
|
+
}] : false;
|
98
110
|
}
|
99
111
|
}
|
100
112
|
if (typeDef.strict) {
|
101
|
-
if (Object.keys(obj).some((key) => !Object.keys(typeDef.defaultValue).includes(key))) return
|
113
|
+
if (Object.keys(obj).some((key) => !Object.keys(typeDef.defaultValue).includes(key))) return missingObjects ?
|
114
|
+
[false, Object.fromEntries(Object.keys(obj).filter((key) => !Object.keys(typeDef.defaultValue).includes(key)).map((key) => [key, { is_extra: true }]))]
|
115
|
+
: false;
|
102
116
|
}
|
103
117
|
} else if (typeDef.type == 'string') {
|
104
118
|
return typeDef.defaultValue == obj;
|
@@ -107,7 +121,7 @@ function typeis(obj, typeDef) {
|
|
107
121
|
}
|
108
122
|
}
|
109
123
|
|
110
|
-
return true;
|
124
|
+
return missingObjects ? [true] : true;
|
111
125
|
}
|
112
126
|
|
113
127
|
function typex(child, parent) {
|
@@ -181,7 +181,7 @@ function declareAlias(aliases, token) {
|
|
181
181
|
let nextToken = gnextToken(index, offset+1, tokens);
|
182
182
|
const args = nextToken.token.value;
|
183
183
|
setIndex(ti + offset);
|
184
|
-
return `${nextToken2.value} = ${token.value} ${args && args !== '(' && args !== '-' && args !== '=' ? `${args},` : ''} ${params.trim()
|
184
|
+
return `${nextToken2.value} = ${token.value} ${args && args !== '(' && args !== '{' && args !== '[' && args !== '-' && args !== '=' ? `${args},` : ''} ${params.trim() ? params.trim() + ', ' : ''}${args == '(' || args == '[' || args == '{' || args == '=' || args == '-' ? args : ''}`.replace(/,(| )$/, '');
|
185
185
|
} else if(nextToken?.value == ' ' && (isDecOnly || nextToken2?.token.value == '=' || nextToken2?.token.value == ':')){
|
186
186
|
nextToken.value = '';
|
187
187
|
if(isDecOnly){
|
@@ -330,6 +330,19 @@ function compileRewStuff(content, options) {
|
|
330
330
|
}
|
331
331
|
}
|
332
332
|
|
333
|
+
if (token.type === "COMMENT" && token.value.startsWith('#alias')) {
|
334
|
+
let value = '#declare';
|
335
|
+
if(token.value.match(/^#alias\*/)) value += '*';
|
336
|
+
let subs;
|
337
|
+
subs = token.value.replace(/^#alias/, '');
|
338
|
+
if(token.value.endsWith('*')) subs.split('*')[1];
|
339
|
+
|
340
|
+
value += ' key';
|
341
|
+
value += ' ' + subs.replace(/([\S]+)\s*=\s*([\S]+)/, '"$1" = $2').trim();
|
342
|
+
value += ';';
|
343
|
+
declareAlias(aliases, {...token, value});
|
344
|
+
}
|
345
|
+
|
333
346
|
if (token.type === "COMMENT" && token.value.startsWith('#declare')) {
|
334
347
|
if (token.value.includes(';')) {
|
335
348
|
declareAlias(aliases, token);
|
@@ -582,6 +595,8 @@ const compileCivetStuff = (file, options) => {
|
|
582
595
|
straceLog('OPTION_PREPARE() for CURRENTFILE as', preCompileOptions);
|
583
596
|
const prepared = compileRewStuff(file.content, preCompileOptions);
|
584
597
|
|
598
|
+
// console.log(prepared);
|
599
|
+
|
585
600
|
const compileOptions = {
|
586
601
|
...preCompileOptions,
|
587
602
|
bare: true,
|
@@ -12,6 +12,7 @@ const { USING_DEFAULT, Usage, Namespace } = require("../const/usage");
|
|
12
12
|
const runtime = require("./runtime");
|
13
13
|
const { permission } = require("process");
|
14
14
|
const { straceLog } = require("../misc/strace");
|
15
|
+
const reval = require("../functions/reval");
|
15
16
|
|
16
17
|
let mainFile = "";
|
17
18
|
const isMainFile = (filepath) => filepath == mainFile;
|
@@ -37,6 +38,7 @@ module.exports.prepareContext = function (
|
|
37
38
|
},
|
38
39
|
app: findAppInfo(filepath),
|
39
40
|
...fsLib(filepath),
|
41
|
+
...reval(filepath),
|
40
42
|
__using__: {}
|
41
43
|
};
|
42
44
|
if (options.useContext) {
|
@@ -46,11 +46,21 @@ module.exports.runPath = function runPath(filepath, options = {}, custom_context
|
|
46
46
|
}
|
47
47
|
|
48
48
|
compiled_code = preScript+'\n'+compiled_code;
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
|
50
|
+
let execd = exec(compiled_code, context, file.content);
|
51
|
+
|
52
|
+
if(context.module.main && (context.module.exports?.main || (typeof context.module.exports == "function" && context.module.exports.name == 'main'))){
|
53
|
+
const mainFn = context.module.exports.main ?? context.module.exports;
|
54
|
+
return {
|
55
|
+
context,
|
56
|
+
returns: mainFn(context.process.argv)
|
57
|
+
}
|
58
|
+
} else {
|
59
|
+
return {
|
60
|
+
context,
|
61
|
+
returns: execd,
|
62
|
+
};
|
63
|
+
}
|
54
64
|
}
|
55
65
|
|
56
66
|
if(options.async){
|