forked from Orchid/orchid
Fixed a very nasty deadlock
This commit is contained in:
510
orcx/src/main.rs
510
orcx/src/main.rs
@@ -4,10 +4,13 @@ use tokio::time::Instant;
|
||||
pub mod parse_folder;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::pin::pin;
|
||||
use std::process::{Command, ExitCode};
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_fn_stream::try_stream;
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
@@ -187,253 +190,294 @@ async fn main() -> io::Result<ExitCode> {
|
||||
let logger = get_logger(&args);
|
||||
let logger2 = logger.clone();
|
||||
unsafe { STARTUP = Some(Instant::now()) };
|
||||
local_set.spawn_local(with_stash(async move {
|
||||
let ctx = &Ctx::new(SpawnerImpl, logger2);
|
||||
let extensions = get_all_extensions(&args, ctx).try_collect::<Vec<Extension>>().await.unwrap();
|
||||
time_print(&args, "Extensions loaded");
|
||||
match args.command {
|
||||
Commands::Lex { file } => {
|
||||
let (_, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
let mut file = File::open(file.as_std_path()).unwrap();
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let lexemes = lex(is(&buf).await, sym!(usercode), &systems, ctx).await.unwrap();
|
||||
println!("{}", take_first(&ttv_fmt(&lexemes, &FmtCtxImpl::default()).await, true))
|
||||
},
|
||||
Commands::Parse { file } => {
|
||||
let (_, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
let mut file = File::open(file.as_std_path()).unwrap();
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let lexemes = lex(is(&buf).await, sym!(usercode), &systems, ctx).await.unwrap();
|
||||
let Some(first) = lexemes.first() else {
|
||||
println!("File empty!");
|
||||
return;
|
||||
};
|
||||
let pctx = HostParseCtxImpl { systems: &systems, ctx: ctx.clone(), src: sym!(usercode) };
|
||||
let snip = Snippet::new(first, &lexemes);
|
||||
match with_reporter(parse_items(&pctx, Substack::Bottom, snip)).await.unwrap() {
|
||||
Err(errv) => {
|
||||
eprintln!("{errv}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
},
|
||||
Ok(ptree) if ptree.is_empty() => {
|
||||
eprintln!("File empty only after parsing, but no errors were reported");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
},
|
||||
Ok(ptree) =>
|
||||
for item in ptree {
|
||||
println!("{}", take_first(&item.print(&FmtCtxImpl::default()).await, true))
|
||||
},
|
||||
};
|
||||
},
|
||||
Commands::Repl => {
|
||||
let mut counter = 0;
|
||||
let mut imports = Vec::new();
|
||||
let usercode_path = sym!(usercode);
|
||||
let mut stdin = BufReader::new(stdin());
|
||||
loop {
|
||||
counter += 1;
|
||||
let (mut root, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
print!("\\.> ");
|
||||
std::io::stdout().flush().unwrap();
|
||||
let mut prompt = String::new();
|
||||
stdin.read_line(&mut prompt).await.unwrap();
|
||||
let name = is(&format!("_{counter}")).await;
|
||||
let path = usercode_path.suffix([name.clone()]).await;
|
||||
let mut lexemes =
|
||||
lex(is(prompt.trim()).await, path.clone(), &systems, ctx).await.unwrap();
|
||||
let Some(discr) = lexemes.first() else { continue };
|
||||
writeln!(
|
||||
log("debug"),
|
||||
"lexed: {}",
|
||||
take_first(&ttv_fmt(&lexemes, &FmtCtxImpl::default()).await, true)
|
||||
)
|
||||
.await;
|
||||
let prefix_sr = SrcRange::zw(path.clone(), 0);
|
||||
let process_lexemes = async |lexemes: &[ParsTokTree]| {
|
||||
let snippet = Snippet::new(&lexemes[0], lexemes);
|
||||
let parse_ctx =
|
||||
HostParseCtxImpl { ctx: ctx.clone(), src: path.clone(), systems: &systems[..] };
|
||||
match try_with_reporter(parse_item(&parse_ctx, Substack::Bottom, vec![], snippet)).await
|
||||
{
|
||||
Ok(items) => Some(items),
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
None
|
||||
},
|
||||
}
|
||||
let ctx = Ctx::new(SpawnerImpl, logger2);
|
||||
let (signal_end_main, on_end_main) = futures::channel::oneshot::channel();
|
||||
let ctx1 = ctx.clone();
|
||||
local_set.spawn_local(async move {
|
||||
let ctx = &ctx1;
|
||||
with_stash(async move {
|
||||
let extensions =
|
||||
get_all_extensions(&args, ctx).try_collect::<Vec<Extension>>().await.unwrap();
|
||||
time_print(&args, "Extensions loaded");
|
||||
match args.command {
|
||||
Commands::Lex { file } => {
|
||||
let (_, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
let mut file = File::open(file.as_std_path()).unwrap();
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let lexemes = lex(is(&buf).await, sym!(usercode), &systems, ctx).await.unwrap();
|
||||
println!("{}", take_first(&ttv_fmt(&lexemes, &FmtCtxImpl::default()).await, true))
|
||||
},
|
||||
Commands::Parse { file } => {
|
||||
let (_, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
let mut file = File::open(file.as_std_path()).unwrap();
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let lexemes = lex(is(&buf).await, sym!(usercode), &systems, ctx).await.unwrap();
|
||||
let Some(first) = lexemes.first() else {
|
||||
println!("File empty!");
|
||||
return;
|
||||
};
|
||||
let add_imports = |items: &mut Vec<Item>, imports: &[Import]| {
|
||||
items.extend(imports.iter().map(|import| Item::new(import.sr.clone(), import.clone())));
|
||||
};
|
||||
if discr.is_kw(is("import").await) {
|
||||
let Some(import_lines) = process_lexemes(&lexemes).await else { continue };
|
||||
imports.extend(import_lines.into_iter().map(|it| match it.kind {
|
||||
ItemKind::Import(imp) => imp,
|
||||
_ => panic!("Expected imports from import line"),
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
if !discr.is_kw(is("let").await) {
|
||||
let prefix = [is("export").await, is("let").await, name.clone(), is("=").await];
|
||||
lexemes.splice(0..0, prefix.map(|n| Token::Name(n).at(prefix_sr.clone())));
|
||||
}
|
||||
let Some(mut new_lines) = process_lexemes(&lexemes).await else { continue };
|
||||
let const_decl = new_lines.iter().exactly_one().expect("Multiple lines from let");
|
||||
let input_sr = const_decl.sr.map_range(|_| 0..0);
|
||||
let const_name = match &const_decl.kind {
|
||||
ItemKind::Member(ParsedMember { name: const_name, .. }) => const_name.clone(),
|
||||
_ => panic!("Expected exactly one constant declaration from let"),
|
||||
};
|
||||
add_imports(&mut new_lines, &imports);
|
||||
imports.push(Import::new(input_sr.clone(), VPath::new(path.segs()), const_name.clone()));
|
||||
let new_module = ParsedModule::new(true, new_lines);
|
||||
match with_reporter(root.add_parsed(&new_module, path.clone())).await {
|
||||
Ok(new) => root = new,
|
||||
let pctx = HostParseCtxImpl { systems: &systems, ctx: ctx.clone(), src: sym!(usercode) };
|
||||
let snip = Snippet::new(first, &lexemes);
|
||||
match with_reporter(parse_items(&pctx, Substack::Bottom, snip)).await.unwrap() {
|
||||
Err(errv) => {
|
||||
eprintln!("{errv}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
}
|
||||
eprintln!("parsed");
|
||||
let entrypoint =
|
||||
ExprKind::Const(path.suffix([const_name.clone()]).await).at(input_sr.pos());
|
||||
let mut xctx = ExecCtx::new(root.clone(), entrypoint).await;
|
||||
eprintln!("executed");
|
||||
xctx.set_gas(Some(1000));
|
||||
xctx.execute().await;
|
||||
match xctx.result() {
|
||||
ExecResult::Value(val) => println!(
|
||||
"{const_name} = {}",
|
||||
take_first(&val.print(&FmtCtxImpl::default()).await, false)
|
||||
),
|
||||
ExecResult::Err(e) => println!("error: {e}"),
|
||||
ExecResult::Gas(_) => println!("Ran out of gas!"),
|
||||
}
|
||||
}
|
||||
},
|
||||
Commands::ModTree { proj, prefix } => {
|
||||
let (mut root, _systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
if let Some(proj_path) = proj {
|
||||
let path = proj_path.into_std_path_buf();
|
||||
match try_with_reporter(parse_folder(&root, path, sym!(src), ctx.clone())).await {
|
||||
Ok(r) => root = r,
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
Ok(ptree) if ptree.is_empty() => {
|
||||
eprintln!("File empty only after parsing, but no errors were reported");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
let prefix = match prefix {
|
||||
Some(pref) => VPath::parse(&pref).await,
|
||||
None => VPath::new([]),
|
||||
};
|
||||
let root_data = root.0.read().await;
|
||||
print_mod(&root_data.root, prefix, &root_data).await;
|
||||
async fn print_mod(module: &Module, path: VPath, root: &RootData) {
|
||||
let indent = " ".repeat(path.len());
|
||||
for (key, tgt) in &module.imports {
|
||||
match tgt {
|
||||
Ok(tgt) => println!("{indent}import {key} => {}", tgt.target),
|
||||
Err(opts) => println!(
|
||||
"{indent}import {key} conflicts between {}",
|
||||
opts.iter().map(|i| &i.target).join(" ")
|
||||
),
|
||||
}
|
||||
}
|
||||
for (key, mem) in &module.members {
|
||||
let new_path = path.clone().name_with_suffix(key.clone()).to_sym().await;
|
||||
match mem.kind(root.ctx.clone(), &root.consts).await {
|
||||
MemberKind::Module(module) => {
|
||||
println!("{indent}module {key} {{");
|
||||
print_mod(module, VPath::new(new_path.segs()), root).boxed_local().await;
|
||||
println!("{indent}}}")
|
||||
Ok(ptree) =>
|
||||
for item in ptree {
|
||||
println!("{}", take_first(&item.print(&FmtCtxImpl::default()).await, true))
|
||||
},
|
||||
MemberKind::Const => {
|
||||
let value = root.consts.get(&new_path).expect("Missing const!");
|
||||
println!("{indent}const {key} = {}", fmt(value).await)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Commands::Exec { proj, code } => {
|
||||
let path = sym!(usercode);
|
||||
let prefix_sr = SrcRange::zw(path.clone(), 0);
|
||||
let (mut root, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
if let Some(proj_path) = proj {
|
||||
let path = proj_path.into_std_path_buf();
|
||||
match try_with_reporter(parse_folder(&root, path, sym!(src), ctx.clone())).await {
|
||||
Ok(r) => root = r,
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
let mut lexemes = match lex(is(code.trim()).await, path.clone(), &systems, ctx).await {
|
||||
Ok(lexemes) => {
|
||||
};
|
||||
},
|
||||
Commands::Repl => {
|
||||
let mut counter = 0;
|
||||
let mut imports = Vec::new();
|
||||
let usercode_path = sym!(usercode);
|
||||
let mut stdin = BufReader::new(stdin());
|
||||
loop {
|
||||
counter += 1;
|
||||
let (mut root, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
print!("\\.> ");
|
||||
std::io::stdout().flush().unwrap();
|
||||
let mut prompt = String::new();
|
||||
stdin.read_line(&mut prompt).await.unwrap();
|
||||
let name = is(&format!("_{counter}")).await;
|
||||
let path = usercode_path.suffix([name.clone()]).await;
|
||||
let mut lexemes =
|
||||
lex(is(prompt.trim()).await, path.clone(), &systems, ctx).await.unwrap();
|
||||
let Some(discr) = lexemes.first() else { continue };
|
||||
writeln!(
|
||||
log("debug"),
|
||||
"lexed: {}",
|
||||
fmt_v::<ParsTokTree>(lexemes.iter()).await.join(" ")
|
||||
take_first(&ttv_fmt(&lexemes, &FmtCtxImpl::default()).await, true)
|
||||
)
|
||||
.await;
|
||||
lexemes
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
};
|
||||
let parse_ctx =
|
||||
HostParseCtxImpl { ctx: ctx.clone(), src: path.clone(), systems: &systems[..] };
|
||||
let prefix = [is("export").await, is("let").await, is("entrypoint").await, is("=").await];
|
||||
lexemes.splice(0..0, prefix.map(|n| Token::Name(n).at(prefix_sr.clone())));
|
||||
let snippet = Snippet::new(&lexemes[0], &lexemes);
|
||||
let entrypoint = match try_with_reporter(parse_item(
|
||||
&parse_ctx,
|
||||
Substack::Bottom,
|
||||
vec![],
|
||||
snippet,
|
||||
))
|
||||
.await
|
||||
{
|
||||
Ok(items) => ParsedModule::new(true, items),
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
};
|
||||
let root = match with_reporter(root.add_parsed(&entrypoint, path.clone())).await {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
Ok(new_root) => new_root,
|
||||
};
|
||||
let expr = ExprKind::Const(sym!(usercode::entrypoint)).at(prefix_sr.pos());
|
||||
let mut xctx = ExecCtx::new(root, expr).await;
|
||||
xctx.set_gas(Some(10_000));
|
||||
xctx.execute().await;
|
||||
match xctx.result() {
|
||||
ExecResult::Value(val) => {
|
||||
println!("{}", take_first(&val.print(&FmtCtxImpl::default()).await, false))
|
||||
},
|
||||
ExecResult::Err(e) => println!("error: {e}"),
|
||||
ExecResult::Gas(_) => println!("Ran out of gas!"),
|
||||
}
|
||||
},
|
||||
let prefix_sr = SrcRange::zw(path.clone(), 0);
|
||||
let process_lexemes = async |lexemes: &[ParsTokTree]| {
|
||||
let snippet = Snippet::new(&lexemes[0], lexemes);
|
||||
let parse_ctx =
|
||||
HostParseCtxImpl { ctx: ctx.clone(), src: path.clone(), systems: &systems[..] };
|
||||
match try_with_reporter(parse_item(&parse_ctx, Substack::Bottom, vec![], snippet))
|
||||
.await
|
||||
{
|
||||
Ok(items) => Some(items),
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
None
|
||||
},
|
||||
}
|
||||
};
|
||||
let add_imports = |items: &mut Vec<Item>, imports: &[Import]| {
|
||||
items
|
||||
.extend(imports.iter().map(|import| Item::new(import.sr.clone(), import.clone())));
|
||||
};
|
||||
if discr.is_kw(is("import").await) {
|
||||
let Some(import_lines) = process_lexemes(&lexemes).await else { continue };
|
||||
imports.extend(import_lines.into_iter().map(|it| match it.kind {
|
||||
ItemKind::Import(imp) => imp,
|
||||
_ => panic!("Expected imports from import line"),
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
if !discr.is_kw(is("let").await) {
|
||||
let prefix = [is("export").await, is("let").await, name.clone(), is("=").await];
|
||||
lexemes.splice(0..0, prefix.map(|n| Token::Name(n).at(prefix_sr.clone())));
|
||||
}
|
||||
let Some(mut new_lines) = process_lexemes(&lexemes).await else { continue };
|
||||
let const_decl = new_lines.iter().exactly_one().expect("Multiple lines from let");
|
||||
let input_sr = const_decl.sr.map_range(|_| 0..0);
|
||||
let const_name = match &const_decl.kind {
|
||||
ItemKind::Member(ParsedMember { name: const_name, .. }) => const_name.clone(),
|
||||
_ => panic!("Expected exactly one constant declaration from let"),
|
||||
};
|
||||
add_imports(&mut new_lines, &imports);
|
||||
imports.push(Import::new(
|
||||
input_sr.clone(),
|
||||
VPath::new(path.segs()),
|
||||
const_name.clone(),
|
||||
));
|
||||
let new_module = ParsedModule::new(true, new_lines);
|
||||
match with_reporter(root.add_parsed(&new_module, path.clone())).await {
|
||||
Ok(new) => root = new,
|
||||
Err(errv) => {
|
||||
eprintln!("{errv}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
}
|
||||
eprintln!("parsed");
|
||||
let entrypoint =
|
||||
ExprKind::Const(path.suffix([const_name.clone()]).await).at(input_sr.pos());
|
||||
let mut xctx = ExecCtx::new(root.clone(), entrypoint).await;
|
||||
eprintln!("executed");
|
||||
xctx.set_gas(Some(1000));
|
||||
xctx.execute().await;
|
||||
match xctx.result() {
|
||||
ExecResult::Value(val) => println!(
|
||||
"{const_name} = {}",
|
||||
take_first(&val.print(&FmtCtxImpl::default()).await, false)
|
||||
),
|
||||
ExecResult::Err(e) => println!("error: {e}"),
|
||||
ExecResult::Gas(_) => println!("Ran out of gas!"),
|
||||
}
|
||||
}
|
||||
},
|
||||
Commands::ModTree { proj, prefix } => {
|
||||
let (mut root, _systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
if let Some(proj_path) = proj {
|
||||
let path = proj_path.into_std_path_buf();
|
||||
match try_with_reporter(parse_folder(&root, path, sym!(src), ctx.clone())).await {
|
||||
Ok(r) => root = r,
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
let prefix = match prefix {
|
||||
Some(pref) => VPath::parse(&pref).await,
|
||||
None => VPath::new([]),
|
||||
};
|
||||
let root_data = root.0.read().await;
|
||||
print_mod(&root_data.root, prefix, &root_data).await;
|
||||
async fn print_mod(module: &Module, path: VPath, root: &RootData) {
|
||||
let indent = " ".repeat(path.len());
|
||||
for (key, tgt) in &module.imports {
|
||||
match tgt {
|
||||
Ok(tgt) => println!("{indent}import {key} => {}", tgt.target),
|
||||
Err(opts) => println!(
|
||||
"{indent}import {key} conflicts between {}",
|
||||
opts.iter().map(|i| &i.target).join(" ")
|
||||
),
|
||||
}
|
||||
}
|
||||
for (key, mem) in &module.members {
|
||||
let new_path = path.clone().name_with_suffix(key.clone()).to_sym().await;
|
||||
match mem.kind(root.ctx.clone(), &root.consts).await {
|
||||
MemberKind::Module(module) => {
|
||||
println!("{indent}module {key} {{");
|
||||
print_mod(module, VPath::new(new_path.segs()), root).boxed_local().await;
|
||||
println!("{indent}}}")
|
||||
},
|
||||
MemberKind::Const => {
|
||||
let value = root.consts.get(&new_path).expect("Missing const!");
|
||||
println!("{indent}const {key} = {}", fmt(value).await)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Commands::Exec { proj, code } => {
|
||||
let path = sym!(usercode);
|
||||
let prefix_sr = SrcRange::zw(path.clone(), 0);
|
||||
let (mut root, systems) = init_systems(&args.system, &extensions).await.unwrap();
|
||||
if let Some(proj_path) = proj {
|
||||
let path = proj_path.into_std_path_buf();
|
||||
match try_with_reporter(parse_folder(&root, path, sym!(src), ctx.clone())).await {
|
||||
Ok(r) => root = r,
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
let mut lexemes = match lex(is(code.trim()).await, path.clone(), &systems, ctx).await {
|
||||
Ok(lexemes) => {
|
||||
writeln!(
|
||||
log("debug"),
|
||||
"lexed: {}",
|
||||
fmt_v::<ParsTokTree>(lexemes.iter()).await.join(" ")
|
||||
)
|
||||
.await;
|
||||
lexemes
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
};
|
||||
let parse_ctx =
|
||||
HostParseCtxImpl { ctx: ctx.clone(), src: path.clone(), systems: &systems[..] };
|
||||
let prefix = [is("export").await, is("let").await, is("entrypoint").await, is("=").await];
|
||||
lexemes.splice(0..0, prefix.map(|n| Token::Name(n).at(prefix_sr.clone())));
|
||||
let snippet = Snippet::new(&lexemes[0], &lexemes);
|
||||
let entrypoint = match try_with_reporter(parse_item(
|
||||
&parse_ctx,
|
||||
Substack::Bottom,
|
||||
vec![],
|
||||
snippet,
|
||||
))
|
||||
.await
|
||||
{
|
||||
Ok(items) => ParsedModule::new(true, items),
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
};
|
||||
let root = match with_reporter(root.add_parsed(&entrypoint, path.clone())).await {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
*exit_code1.borrow_mut() = ExitCode::FAILURE;
|
||||
return;
|
||||
},
|
||||
Ok(new_root) => new_root,
|
||||
};
|
||||
let expr = ExprKind::Const(sym!(usercode::entrypoint)).at(prefix_sr.pos());
|
||||
let mut xctx = ExecCtx::new(root.clone(), expr).await;
|
||||
xctx.set_gas(Some(10_000));
|
||||
xctx.execute().await;
|
||||
match xctx.result() {
|
||||
ExecResult::Value(val) => {
|
||||
println!("{}", take_first(&val.print(&FmtCtxImpl::default()).await, false))
|
||||
},
|
||||
ExecResult::Err(e) => println!("error: {e}"),
|
||||
ExecResult::Gas(_) => println!("Ran out of gas!"),
|
||||
}
|
||||
},
|
||||
};
|
||||
})
|
||||
.await;
|
||||
signal_end_main.send(()).expect("cleanup should still be waiting");
|
||||
});
|
||||
let cleanup = async {
|
||||
if on_end_main.await.is_err() {
|
||||
return;
|
||||
}
|
||||
}));
|
||||
with_interner(local_interner(), with_logger(logger, local_set)).await;
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
let mut extensions = HashMap::new();
|
||||
let systems = ctx.systems.read().await.values().filter_map(|v| v.upgrade()).collect_vec();
|
||||
let exprs = ctx.exprs.iter().collect_vec();
|
||||
for system in &systems {
|
||||
extensions.insert(system.ext().name().clone(), system.ext().clone());
|
||||
}
|
||||
if extensions.is_empty() && systems.is_empty() && exprs.is_empty() {
|
||||
return;
|
||||
}
|
||||
eprintln!("Shutdown is taking long. The following language constructs are still live:");
|
||||
eprintln!("Extensions: {}", extensions.keys().join(", "));
|
||||
for sys in &systems {
|
||||
eprintln!("System: {:?} = {}", sys.id(), sys.ctor().name())
|
||||
}
|
||||
for (rc, expr) in &exprs {
|
||||
eprintln!("{rc}x {:?} = {}", expr.id(), fmt(expr).await)
|
||||
}
|
||||
};
|
||||
futures::future::select(
|
||||
pin!(cleanup),
|
||||
pin!(with_interner(local_interner(), with_logger(logger, local_set))),
|
||||
)
|
||||
.await;
|
||||
let x = *exit_code.borrow();
|
||||
Ok(x)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user