From 28332b874edf5a29084592214c4624520b37cec2 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Thu, 23 Nov 2023 14:51:10 +0800 Subject: [PATCH] refactor --- src/calltree.js | 2 +- src/cmd.js | 6 +++--- src/editor/io_trace.js | 2 +- src/effects.js | 2 +- src/eval.js | 4 ++-- src/index.js | 12 ++++++------ src/runtime.js | 6 +++--- test/test.js | 16 ++++++++-------- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/calltree.js b/src/calltree.js index a691ce7..61664fd 100644 --- a/src/calltree.js +++ b/src/calltree.js @@ -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 ) diff --git a/src/cmd.js b/src/cmd.js index 3265e75..08274d5 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -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, diff --git a/src/editor/io_trace.js b/src/editor/io_trace.js index 67391fb..d1a924e 100644 --- a/src/editor/io_trace.js +++ b/src/editor/io_trace.js @@ -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] diff --git a/src/effects.js b/src/effects.js index eabf639..312f360 100644 --- a/src/effects.js +++ b/src/effects.js @@ -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) } diff --git a/src/eval.js b/src/eval.js index d82435e..8056913 100644 --- a/src/eval.js +++ b/src/eval.js @@ -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, } } diff --git a/src/index.js b/src/index.js index 94f298e..30a347d 100644 --- a/src/index.js +++ b/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 } } } diff --git a/src/runtime.js b/src/runtime.js index b8e8f0b..b907bef 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -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) diff --git a/test/test.js b/test/test.js index 9c1200b..4ceb45a 100644 --- a/test/test.js +++ b/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', () => {