static functions are being called. closes #8
parent
d5cbae0c1c
commit
2d7c0442e0
15
Instance.js
15
Instance.js
|
|
@ -11,7 +11,7 @@ export default class Instance extends Serializable {
|
|||
|
||||
// reconstruct context when we need it...
|
||||
createContext() {
|
||||
const ctx = {};
|
||||
let ctx = {};
|
||||
for(const name in this.links) {
|
||||
ctx[name] = this.links[name];
|
||||
}
|
||||
|
|
@ -19,6 +19,13 @@ export default class Instance extends Serializable {
|
|||
ctx[name] = this.module.imports[name];
|
||||
this.locals.push(name);
|
||||
}
|
||||
ctx = {
|
||||
...ctx,
|
||||
...this.system.staticInstances
|
||||
}
|
||||
for(const identifier in this.system.staticInstances) {
|
||||
this.locals.push(identifier);
|
||||
}
|
||||
ctx.create = this.system.newInstance.bind(this.system);
|
||||
this.locals.push('create');
|
||||
this.context = ctx;
|
||||
|
|
@ -46,10 +53,14 @@ export default class Instance extends Serializable {
|
|||
});
|
||||
}
|
||||
|
||||
hasPublicFunction(name) {
|
||||
return (name in this.module.functions);
|
||||
}
|
||||
|
||||
invokeInternal(name, ...args) {
|
||||
// console.log('invoking', name);
|
||||
const content = this.module.functions[name];
|
||||
if(!content) throw new TypeError(content + ' is not a function!');
|
||||
if(!content) throw new TypeError(name + ' is not a function!');
|
||||
return evalInContext(content, this.context, this.locals);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ export default class Module {
|
|||
}
|
||||
singleton = false;
|
||||
keepalive = false;
|
||||
'static' = null;
|
||||
|
||||
async directive({value}) {
|
||||
this[value] = true;
|
||||
async directive({directive, value}) {
|
||||
this[directive] = value ?? true;
|
||||
}
|
||||
|
||||
async link({required, array, name}) {
|
||||
|
|
|
|||
28
System.js
28
System.js
|
|
@ -11,16 +11,37 @@ export default class System extends Serializable {
|
|||
instances = [];
|
||||
modules = null;
|
||||
namespace = null;
|
||||
staticInstances = {};
|
||||
|
||||
constructor(modules, location = '.running') {
|
||||
super();
|
||||
this.modules = modules;
|
||||
this.createNamespace();
|
||||
const bootModules = this.deriveBootModules();
|
||||
this.createStaticInstances();
|
||||
|
||||
log('instantiating modules...');
|
||||
for(const name of bootModules)
|
||||
log('instantiating boot modules...');
|
||||
for(const name of bootModules) {
|
||||
log(' ' + name);
|
||||
this.newInstance(name);
|
||||
}
|
||||
}
|
||||
|
||||
createStaticInstances() {
|
||||
log('deriving static modules...');
|
||||
const staticModules = this.modules.filter((module) => {
|
||||
return !!module.static;
|
||||
}).map((module) => {
|
||||
log(' ' + module.name.full);
|
||||
return module;
|
||||
});
|
||||
|
||||
log('instantiating static modules...');
|
||||
for(const module of staticModules) {
|
||||
log(' ' + module.static + ': ' + module.name.full);
|
||||
this.staticInstances[module.static] =
|
||||
this.newInstance(module.name.full, {});
|
||||
}
|
||||
}
|
||||
|
||||
deriveBootModules() {
|
||||
|
|
@ -59,7 +80,8 @@ export default class System extends Serializable {
|
|||
newInstance(name, args = {}) {
|
||||
const instance = this.createInstance(name, args);
|
||||
const link = instance.link;
|
||||
instance.invokeInternal('restore');
|
||||
if(instance.hasPublicFunction('restore'))
|
||||
instance.invokeInternal('restore');
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,11 +13,12 @@ STATEMENT -> _ LINK_DECLARATION EOL {% ([,stuff]) => { return stuff } %}
|
|||
FUNCTION_DECLARATION -> _ IDENTIFIER _ PARAMETERS:? _ JS_BLOCK EOL {% ([,name,,params,,block]) => { return { type: 'function', name: name, block, parameters: params } } %}
|
||||
| _ %ASYNC __ IDENTIFIER _ PARAMETERS:? _ JS_BLOCK_ASYNC EOL {% ([,,,name,,params,,block]) => { return { type: 'function', name: name, block, parameters: params } } %}
|
||||
|
||||
DIRECTIVE_STATEMENT -> DIRECTIVE __ OPEN_PARAMETERS EOL {% ([,directive,,parameters]) => { return { type: 'directive', value: directive, parameters }} %}
|
||||
| DIRECTIVE EOL {% ([directive,,]) => { return { type: 'directive', value: directive }} %}
|
||||
DIRECTIVE_STATEMENT -> DIRECTIVE __ IDENTIFIER EOL {% ([directive,,identifier]) => { return { type: 'directive', directive, value: identifier }} %}
|
||||
| DIRECTIVE EOL {% ([directive]) => { return { type: 'directive', directive }} %}
|
||||
|
||||
DIRECTIVE -> %SINGLETON {% () => 'singleton' %}
|
||||
| %KEEPALIVE {% () => 'keepalive' %}
|
||||
| %STATIC {% () => 'static' %}
|
||||
|
||||
LINK_DECLARATION -> LINK __ IDENTIFIER {% ([,,id]) => { return { type: 'link', array: false, required: false, name: id }} %}
|
||||
| LINK_ARR __ IDENTIFIER {% ([,,id]) => { return { type: 'link', array: true, required: false, name: id }} %}
|
||||
|
|
@ -32,7 +33,7 @@ NAMESPACE -> IDENTIFIER
|
|||
|
||||
OPEN_PARAMETERS -> _ IDENTIFIER _ ADDITIONAL_PARAMETERS:? _ {% ([,identifier,,more,]) => more ? [identifier, ...more] : [identifier] %}
|
||||
PARAMETERS -> _ %LPAREN _ IDENTIFIER _ ADDITIONAL_PARAMETERS:? _ %RPAREN _ {% ([,,,identifier,,more,,,]) => more ? [identifier, ...more] : [identifier] %}
|
||||
ADDITIONAL_PARAMETERS -> "," _ IDENTIFIER _ ADDITIONAL_PARAMETERS:? {% ([,,identifier,,more]) => more ? [identifier, ...more] : [identifier] %}
|
||||
ADDITIONAL_PARAMETERS -> %COMMA _ IDENTIFIER _ ADDITIONAL_PARAMETERS:? {% ([,,identifier,,more]) => more ? [identifier, ...more] : [identifier] %}
|
||||
|
||||
EOL -> _ %SEMICOLON:?
|
||||
STRING -> %STRING {% ([d]) => d.value.substring(1, d.value.length - 1) %}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
namespace vogue
|
||||
static Interface;
|
||||
|
||||
import 'terminal-kit' as terminalKit;
|
||||
|
||||
choice(message, choices, type) {
|
||||
console.log('im being called!');
|
||||
// const {terminal} = terminalKit;
|
||||
// type ??= 'string';
|
||||
|
||||
// return new Promise(res => {
|
||||
|
||||
// terminal.saveCursor();
|
||||
// // terminal(message.split(/\x1b\[39m/g).join(', '));
|
||||
// // const loc = await new Promise (res => terminal.getCursorLocation((err, x, y) => res([x, y])));
|
||||
// for(const part of message.split(/\x1b\[39m/g)) {
|
||||
// terminal.cyan(part);
|
||||
// }
|
||||
// terminal.cyan('\n');
|
||||
|
||||
// terminal.singleColumnMenu(choices, (error, response) => {
|
||||
// terminal.restoreCursor();
|
||||
// terminal.cyan(`${message} `);
|
||||
// terminal(response.selectedText + '\n').eraseDisplayBelow();
|
||||
// if(type === 'string') {
|
||||
// res(response.selectedText);
|
||||
// } else {
|
||||
// res(response.selectedIndex);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
}
|
||||
|
|
@ -3,7 +3,9 @@ singleton;
|
|||
|
||||
link currentSave;
|
||||
|
||||
restore {
|
||||
async restore {
|
||||
terminalkit.terminal.cyan('~Welcome to Vogue~\n');
|
||||
this.currentSave ??= create('world', {});
|
||||
// console.log(Interface);
|
||||
const choice = await Interface.choice('select a thing', ['a', 'b', 'c']);
|
||||
}
|
||||
Reference in New Issue