mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
WIP
This commit is contained in:
@@ -7,6 +7,7 @@ import {eval_frame} from './eval.js'
|
||||
export const pp_calltree = tree => ({
|
||||
id: tree.id,
|
||||
ok: tree.ok,
|
||||
value: tree.value,
|
||||
is_log: tree.is_log,
|
||||
has_more_children: tree.has_more_children,
|
||||
string: tree.code?.string,
|
||||
|
||||
14
src/effects.js
vendored
14
src/effects.js
vendored
@@ -177,7 +177,11 @@ export const render_common_side_effects = async (prev, next, command, ui) => {
|
||||
load_external_imports(next)
|
||||
}
|
||||
|
||||
if(prev.eval_modules_state != next.eval_modules_state) {
|
||||
if(
|
||||
prev.eval_modules_state != next.eval_modules_state
|
||||
&&
|
||||
next.eval_modules_state != null
|
||||
) {
|
||||
const s = next.eval_modules_state
|
||||
s.promise.then(result => {
|
||||
exec('eval_modules_finished', result, s.node, s.toplevel)
|
||||
@@ -188,7 +192,13 @@ export const render_common_side_effects = async (prev, next, command, ui) => {
|
||||
render_parse_result(ui, next)
|
||||
}
|
||||
|
||||
if(!next.parse_result.ok || next.loading_external_imports_state != null) {
|
||||
if(
|
||||
!next.parse_result.ok
|
||||
||
|
||||
next.loading_external_imports_state != null
|
||||
||
|
||||
next.eval_modules_state != null
|
||||
) {
|
||||
|
||||
// TODO if loading external imports, show loading indicator
|
||||
ui.calltree.clear_calltree()
|
||||
|
||||
11
src/eval.js
11
src/eval.js
@@ -260,16 +260,6 @@ const codegen = (node, cxt, parent) => {
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO remove
|
||||
const sync_promise = value => {
|
||||
if(value instanceof run_window.Promise.Original) {
|
||||
return value
|
||||
} else {
|
||||
return {is_sync_promise: true, then: fn => sync_promise(fn(value))}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
export const eval_modules = (
|
||||
parse_result,
|
||||
external_imports,
|
||||
@@ -955,6 +945,7 @@ const do_eval_frame_expr = (node, scope, callsleft) => {
|
||||
ok = true
|
||||
value = typeof(expr.result.value)
|
||||
} else if(node.operator == '-') {
|
||||
ok = true
|
||||
value = - expr.result.value
|
||||
} else if(node.operator == 'await') {
|
||||
const run_window = globalThis.run_window ?? globalThis
|
||||
|
||||
@@ -203,9 +203,20 @@ export const topsort_modules = (modules) => {
|
||||
}
|
||||
|
||||
export const has_toplevel_await = modules =>
|
||||
Object.values(modules).some(m =>
|
||||
m.children.find(c => c.type == 'unary' && c.operator == 'await' ) != null
|
||||
)
|
||||
Object.values(modules).some(m => node_has_toplevel_await(m))
|
||||
|
||||
const node_has_toplevel_await = node => {
|
||||
if(node.type == 'unary' && node.operator == 'await') {
|
||||
return true
|
||||
}
|
||||
if(node.type == 'function_expr') {
|
||||
return false
|
||||
}
|
||||
if(node.children == null) {
|
||||
return false
|
||||
}
|
||||
return node.children.find(c => node_has_toplevel_await(c)) != null
|
||||
}
|
||||
|
||||
// TODO not implemented
|
||||
// TODO detect cycles when loading modules
|
||||
|
||||
@@ -13,11 +13,23 @@ export const patch_promise = window => {
|
||||
(resolve, reject) => {
|
||||
fn(
|
||||
(value) => {
|
||||
status = {ok: true, value}
|
||||
if(is_constructor_finished) {
|
||||
this.status = status
|
||||
if(value instanceof window.Promise.Original) {
|
||||
value
|
||||
.then(v => {
|
||||
this.status = {ok: true, value: v}
|
||||
resolve(v)
|
||||
})
|
||||
.catch(e => {
|
||||
this.status = {ok: false, error: e}
|
||||
reject(e)
|
||||
})
|
||||
} else {
|
||||
status = {ok: true, value}
|
||||
if(is_constructor_finished) {
|
||||
this.status = status
|
||||
}
|
||||
resolve(value)
|
||||
}
|
||||
resolve(value)
|
||||
},
|
||||
(error) => {
|
||||
status = {ok: false, error}
|
||||
|
||||
Reference in New Issue
Block a user