mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
refactor
This commit is contained in:
@@ -216,7 +216,7 @@ const replace_calltree_node = (root, node, replacement) => {
|
||||
const expand_calltree_node = (state, node) => {
|
||||
if(node.has_more_children) {
|
||||
const next_node = eval_expand_calltree_node(
|
||||
state.eval_cxt,
|
||||
state.rt_cxt,
|
||||
state.parse_result,
|
||||
node
|
||||
)
|
||||
|
||||
@@ -46,8 +46,8 @@ const apply_eval_result = (state, eval_result) => {
|
||||
...state,
|
||||
calltree: make_calltree(eval_result.calltree, null),
|
||||
calltree_node_by_loc: eval_result.calltree_node_by_loc,
|
||||
// TODO copy eval_cxt?
|
||||
eval_cxt: eval_result.eval_cxt,
|
||||
// TODO copy rt_cxt?
|
||||
rt_cxt: eval_result.rt_cxt,
|
||||
logs: {
|
||||
logs: collect_logs(eval_result.logs, eval_result.calltree),
|
||||
log_position: null
|
||||
@@ -90,7 +90,7 @@ const run_code = (s, dirty_files) => {
|
||||
// Shows that calltree is brand new and requires entire rerender
|
||||
calltree_changed_token: {},
|
||||
|
||||
eval_cxt: null,
|
||||
rt_cxt: null,
|
||||
logs: null,
|
||||
current_calltree_node: null,
|
||||
active_calltree_node: null,
|
||||
|
||||
@@ -40,7 +40,7 @@ export class IO_Trace {
|
||||
|
||||
const items = state.io_trace ?? []
|
||||
// Number of items that were used during execution
|
||||
const used_count = state.eval_cxt.io_trace_index ?? items.length
|
||||
const used_count = state.rt_cxt.io_trace_index ?? items.length
|
||||
|
||||
for(let i = 0; i < items.length; i++) {
|
||||
const item = items[i]
|
||||
|
||||
2
src/effects.js
vendored
2
src/effects.js
vendored
@@ -223,7 +223,7 @@ export const apply_side_effects = (prev, next, ui) => {
|
||||
if(
|
||||
prev.io_trace != next.io_trace
|
||||
||
|
||||
prev.eval_cxt?.io_trace_index != next.eval_cxt.io_trace_index
|
||||
prev.rt_cxt?.io_trace_index != next.rt_cxt.io_trace_index
|
||||
) {
|
||||
ui.render_io_trace(next)
|
||||
}
|
||||
|
||||
@@ -480,10 +480,10 @@ export const eval_modules = (
|
||||
return {
|
||||
modules: result.modules,
|
||||
logs: result.logs,
|
||||
eval_cxt: result.eval_cxt,
|
||||
rt_cxt: result.rt_cxt,
|
||||
calltree,
|
||||
calltree_node_by_loc: result.calltree_node_by_loc,
|
||||
io_trace: result.eval_cxt.io_trace,
|
||||
io_trace: result.rt_cxt.io_trace,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
src/index.js
12
src/index.js
@@ -255,17 +255,17 @@ export const with_code_execution = (action, state = get_state()) => {
|
||||
call toJSON(), which can call trigger deferred call (see lodash.js lazy
|
||||
chaining)
|
||||
*/
|
||||
if(state.eval_cxt != null) {
|
||||
state.eval_cxt.is_recording_deferred_calls = false
|
||||
state.eval_cxt.skip_save_ct_node_for_path = true
|
||||
if(state.rt_cxt != null) {
|
||||
state.rt_cxt.is_recording_deferred_calls = false
|
||||
state.rt_cxt.skip_save_ct_node_for_path = true
|
||||
}
|
||||
|
||||
try {
|
||||
return action()
|
||||
} finally {
|
||||
if(state.eval_cxt != null) {
|
||||
state.eval_cxt.is_recording_deferred_calls = true
|
||||
state.eval_cxt.skip_save_ct_node_for_path = false
|
||||
if(state.rt_cxt != null) {
|
||||
state.rt_cxt.is_recording_deferred_calls = true
|
||||
state.rt_cxt.skip_save_ct_node_for_path = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ const do_run = function*(module_fns, cxt, io_trace){
|
||||
modules: cxt.modules,
|
||||
calltree,
|
||||
logs: _logs,
|
||||
eval_cxt: cxt,
|
||||
rt_cxt: cxt,
|
||||
calltree_node_by_loc,
|
||||
}
|
||||
}
|
||||
@@ -130,9 +130,9 @@ const do_run = function*(module_fns, cxt, io_trace){
|
||||
export const run = gen_to_promise(function*(module_fns, cxt, io_trace) {
|
||||
const result = yield* do_run(module_fns, cxt, io_trace)
|
||||
|
||||
if(result.eval_cxt.io_trace_is_replay_aborted) {
|
||||
if(result.rt_cxt.io_trace_is_replay_aborted) {
|
||||
// TODO test next line
|
||||
result.eval_cxt.is_recording_deferred_calls = false
|
||||
result.rt_cxt.is_recording_deferred_calls = false
|
||||
|
||||
// run again without io trace
|
||||
return yield* do_run(module_fns, cxt, null)
|
||||
|
||||
16
test/test.js
16
test/test.js
@@ -2749,11 +2749,11 @@ const y = x()`
|
||||
assert_equal(s3.current_calltree_node.toplevel, true)
|
||||
|
||||
// Go back to fn
|
||||
assert_equal(s3.eval_cxt == null, false)
|
||||
assert_equal(s3.rt_cxt == null, false)
|
||||
const s4 = COMMANDS.move_cursor(
|
||||
{...s3,
|
||||
// Set eval_cxt to null, ensure eval would not be called again
|
||||
eval_cxt: null
|
||||
// Set rt_cxt to null, ensure eval would not be called again
|
||||
rt_cxt: null
|
||||
},
|
||||
code.indexOf('1')
|
||||
)
|
||||
@@ -2837,10 +2837,10 @@ const y = x()`
|
||||
|
||||
// Check that when we move cursor inside unreachable function, find_call
|
||||
// not called again
|
||||
assert_equal(s2.eval_cxt != null, true)
|
||||
assert_equal(s2.rt_cxt != null, true)
|
||||
const s3 = COMMANDS.move_cursor(
|
||||
// Set eval_cxt to null, ensure it would not be called again
|
||||
{...s2, eval_cxt: null},
|
||||
// Set rt_cxt to null, ensure it would not be called again
|
||||
{...s2, rt_cxt: null},
|
||||
code.indexOf('2')
|
||||
)
|
||||
assert_equal(s3.active_calltree_node, null)
|
||||
@@ -3858,7 +3858,7 @@ const y = x()`
|
||||
|
||||
const next = COMMANDS.input(initial, `const x = Math.random()*2`, 0).state
|
||||
assert_equal(next.value_explorer.result.value, 2)
|
||||
assert_equal(next.eval_cxt.io_trace_index, 1)
|
||||
assert_equal(next.rt_cxt.io_trace_index, 1)
|
||||
|
||||
// Patch Math.random to return 2.
|
||||
// TODO The first call to Math.random() is cached with value 1, and the
|
||||
@@ -4030,7 +4030,7 @@ const y = x()`
|
||||
const state = on_deferred_call(i)
|
||||
|
||||
// Deferred calls should not be record in cache
|
||||
assert_equal(state.eval_cxt.io_trace.length, 0)
|
||||
assert_equal(state.rt_cxt.io_trace.length, 0)
|
||||
}),
|
||||
|
||||
test('record io discard prev execution', () => {
|
||||
|
||||
Reference in New Issue
Block a user