mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
rename trace -> __trace
This commit is contained in:
22
src/eval.js
22
src/eval.js
@@ -88,14 +88,14 @@ const codegen_function_expr = (node, cxt) => {
|
|||||||
|
|
||||||
// TODO first create all functions, then assign __closure, after everything
|
// TODO first create all functions, then assign __closure, after everything
|
||||||
// is declared. See 'out of order decl' test. Currently we assign __closure
|
// is declared. See 'out of order decl' test. Currently we assign __closure
|
||||||
// on first call (see `trace`)
|
// on first call (see `__trace`)
|
||||||
const get_closure = `() => ({${[...node.closed].join(',')}})`
|
const get_closure = `() => ({${[...node.closed].join(',')}})`
|
||||||
|
|
||||||
return `trace(${call}, "${node.name}", ${argscount}, ${location}, ${get_closure})`
|
return `__trace(${call}, "${node.name}", ${argscount}, ${location}, ${get_closure})`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO if statically can prove that function is hosted, then do not codegen
|
// TODO if statically can prove that function is hosted, then do not codegen
|
||||||
// trace
|
// __trace
|
||||||
const codegen_function_call = (node, cxt) => {
|
const codegen_function_call = (node, cxt) => {
|
||||||
|
|
||||||
const do_codegen = n => codegen(n, cxt)
|
const do_codegen = n => codegen(n, cxt)
|
||||||
@@ -113,10 +113,10 @@ const codegen_function_call = (node, cxt) => {
|
|||||||
return `(
|
return `(
|
||||||
__obj = ${do_codegen(node.fn.object)},
|
__obj = ${do_codegen(node.fn.object)},
|
||||||
__fn = __obj${op}[${do_codegen(node.fn.property)}],
|
__fn = __obj${op}[${do_codegen(node.fn.property)}],
|
||||||
trace_call(__fn, __obj, ${args})
|
__trace_call(__fn, __obj, ${args})
|
||||||
)`
|
)`
|
||||||
} else {
|
} else {
|
||||||
return `trace_call(${do_codegen(node.fn)}, null, ${args})`
|
return `__trace_call(${do_codegen(node.fn)}, null, ${args})`
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ const codegen = (node, cxt, parent) => {
|
|||||||
return '...(' + do_codegen(node.expr) + ')'
|
return '...(' + do_codegen(node.expr) + ')'
|
||||||
} else if(node.type == 'new') {
|
} else if(node.type == 'new') {
|
||||||
const args = `[${node.args.children.map(do_codegen).join(',')}]`
|
const args = `[${node.args.children.map(do_codegen).join(',')}]`
|
||||||
return `trace_call(${do_codegen(node.constructor)}, null, ${args}, true)`
|
return `__trace_call(${do_codegen(node.constructor)}, null, ${args}, true)`
|
||||||
} else if(node.type == 'grouping'){
|
} else if(node.type == 'grouping'){
|
||||||
return '(' + do_codegen(node.expr) + ')'
|
return '(' + do_codegen(node.expr) + ')'
|
||||||
} else if(node.type == 'array_destructuring') {
|
} else if(node.type == 'array_destructuring') {
|
||||||
@@ -266,7 +266,7 @@ export const eval_modules = (
|
|||||||
calltree_changed_token,
|
calltree_changed_token,
|
||||||
location
|
location
|
||||||
) => {
|
) => {
|
||||||
// TODO gensym __modules, __exports, children
|
// TODO gensym __modules, __exports, __trace, __trace_call
|
||||||
|
|
||||||
// TODO bug if module imported twice, once as external and as regular
|
// TODO bug if module imported twice, once as external and as regular
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ export const eval_modules = (
|
|||||||
node.fn.apply(node.context, node.args)
|
node.fn.apply(node.context, node.args)
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// do nothing. Exception was caught and recorded inside 'trace'
|
// do nothing. Exception was caught and recorded inside '__trace'
|
||||||
}
|
}
|
||||||
is_recording_deferred_calls = true
|
is_recording_deferred_calls = true
|
||||||
return do_expand_calltree_node(node)
|
return do_expand_calltree_node(node)
|
||||||
@@ -435,7 +435,7 @@ export const eval_modules = (
|
|||||||
node.fn.apply(node.context, node.args)
|
node.fn.apply(node.context, node.args)
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// do nothing. Exception was caught and recorded inside 'trace'
|
// do nothing. Exception was caught and recorded inside '__trace'
|
||||||
}
|
}
|
||||||
|
|
||||||
if(found_call != null) {
|
if(found_call != null) {
|
||||||
@@ -491,7 +491,7 @@ export const eval_modules = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const trace = (fn, name, argscount, __location, get_closure) => {
|
const __trace = (fn, name, argscount, __location, get_closure) => {
|
||||||
const result = (...args) => {
|
const result = (...args) => {
|
||||||
if(result.__closure == null) {
|
if(result.__closure == null) {
|
||||||
result.__closure = get_closure()
|
result.__closure = get_closure()
|
||||||
@@ -587,7 +587,7 @@ export const eval_modules = (
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
const trace_call = (fn, context, args, is_new = false) => {
|
const __trace_call = (fn, context, args, is_new = false) => {
|
||||||
if(fn != null && fn.__location != null && !is_new) {
|
if(fn != null && fn.__location != null && !is_new) {
|
||||||
// Call will be traced, because tracing code is already embedded inside
|
// Call will be traced, because tracing code is already embedded inside
|
||||||
// fn
|
// fn
|
||||||
|
|||||||
14
test/test.js
14
test/test.js
@@ -25,20 +25,6 @@ import {
|
|||||||
|
|
||||||
export const tests = [
|
export const tests = [
|
||||||
|
|
||||||
// TODO
|
|
||||||
/*
|
|
||||||
test('trace', () => {
|
|
||||||
assert_code_evals_to(`
|
|
||||||
const trace = () => 1;
|
|
||||||
trace()
|
|
||||||
|
|
||||||
`,
|
|
||||||
|
|
||||||
1
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
*/
|
|
||||||
|
|
||||||
test('invalid token in the beginning', () => {
|
test('invalid token in the beginning', () => {
|
||||||
const result = parse('# import')
|
const result = parse('# import')
|
||||||
assert_equal(result, {
|
assert_equal(result, {
|
||||||
|
|||||||
Reference in New Issue
Block a user