Adding measure to new compile code. Cleaning up debug
This commit is contained in:
parent
2cd5a609bb
commit
cc9f5959d7
5 changed files with 63 additions and 20 deletions
|
|
@ -99,7 +99,7 @@ function sanitize(name: string): string {
|
|||
|
||||
if (ops[name]) return ops[name];
|
||||
|
||||
const natives = ['measureText', 'storeSearch', 'debug', 'len', 'slice', 'str'];
|
||||
const natives = ['measure', 'measureText', 'storeSearch', 'debug', 'len', 'slice', 'str'];
|
||||
if (natives.includes(name)) return `_rt.${name}`;
|
||||
|
||||
const reserved = [
|
||||
|
|
@ -214,23 +214,12 @@ export function compileAndRun(defs: Definition[]) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
const compiledDefs = defs.map(def =>
|
||||
`const ${sanitize(def.name)} = ${compile(def.body)};`
|
||||
).join('\n');
|
||||
*/
|
||||
|
||||
const lastName = defs[defs.length - 1].name;
|
||||
const defNames = defs.map(d => sanitize(d.name)).join(', ');
|
||||
|
||||
const code = `${compiledDefs.join('\n')}
|
||||
return { ${defNames}, __result: ${sanitize(lastName)} };`;
|
||||
|
||||
// console.log('--- Compiled Code ---');
|
||||
// console.log(code);
|
||||
// console.log('=====================');
|
||||
|
||||
const fn = new Function('_rt', code);
|
||||
const allDefs = fn(_rt);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue