Letting us redefine functions, reactively
This commit is contained in:
parent
33f3b2cfc2
commit
60c8f74d50
4 changed files with 169 additions and 3 deletions
|
|
@ -1,3 +1,7 @@
|
|||
import { tokenize } from './lexer'
|
||||
import { Parser } from './parser'
|
||||
import { recompile } from './compiler'
|
||||
|
||||
export const store: Record<string, any> = {};
|
||||
|
||||
export const _rt = {
|
||||
|
|
@ -42,7 +46,11 @@ export const _rt = {
|
|||
},
|
||||
rebind: (name: string, pathOrValue: any, maybeValue?: any) => {
|
||||
if (maybeValue === undefined) {
|
||||
store[name] = pathOrValue;
|
||||
if (pathOrValue && pathOrValue.ast) {
|
||||
recompile(name, pathOrValue._ast);
|
||||
} else {
|
||||
store[name] = pathOrValue;
|
||||
}
|
||||
} else {
|
||||
const path = pathOrValue as string[];
|
||||
let obj = store[name];
|
||||
|
|
@ -109,5 +117,12 @@ export const _rt = {
|
|||
default:
|
||||
return { width: 0, height: 0 };
|
||||
}
|
||||
},
|
||||
redefine: (name: string) => (code: string) => {
|
||||
const tokens = tokenize(`_tmp = ${code};`);
|
||||
const parser = new Parser(tokens, "");
|
||||
const defs = parser.parse();
|
||||
recompile(name, defs[0]. body);
|
||||
return { _tag: 'Ok' };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue