Returned from Italy

This commit is contained in:
2025-07-18 16:29:52 +02:00
parent fe89188c4b
commit 19f2c6426a
17 changed files with 149 additions and 258 deletions

View File

@@ -1,3 +1,5 @@
pub mod parse_folder;
use std::cell::RefCell;
use std::fs::File;
use std::io::{Read, Write};
@@ -6,6 +8,7 @@ use std::process::{Command, ExitCode};
use std::rc::Rc;
use async_std::io::stdin;
use async_std::path::PathBuf;
use async_stream::try_stream;
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};
@@ -27,6 +30,8 @@ use orchid_host::system::init_systems;
use substack::Substack;
use tokio::task::{LocalSet, spawn_local};
use crate::parse_folder::parse_folder;
#[derive(Parser, Debug)]
#[command(version, about, long_about)]
pub struct Args {
@@ -54,6 +59,8 @@ pub enum Commands {
},
Repl,
Execute {
#[arg(long)]
proj: Option<Utf8PathBuf>,
#[arg()]
code: String,
},
@@ -117,7 +124,7 @@ async fn main() -> io::Result<ExitCode> {
};
let reporter = Reporter::new();
let pctx = HostParseCtxImpl {
reporter: &reporter,
rep: &reporter,
systems: &systems,
ctx: ctx.clone(),
src: sym!(usercode; i).await,
@@ -155,7 +162,7 @@ async fn main() -> io::Result<ExitCode> {
let reporter = Reporter::new();
let parse_ctx = HostParseCtxImpl {
ctx: ctx.clone(),
reporter: &reporter,
rep: &reporter,
src: path.clone(),
systems: &systems[..],
};
@@ -185,18 +192,29 @@ async fn main() -> io::Result<ExitCode> {
ExecResult::Gas(_) => println!("Ran out of gas!"),
}
},
Commands::Execute { code } => {
let (root, systems) = init_systems(&args.system, &extensions).await.unwrap();
Commands::Execute { proj, code } => {
let reporter = Reporter::new();
let (mut root, systems) = init_systems(&args.system, &extensions).await.unwrap();
if let Some(proj_path) = proj {
let path = PathBuf::from(proj_path.into_std_path_buf());
match parse_folder(&root, path, sym!(src; i).await, &reporter, ctx.clone()).await {
Ok(r) => root = r,
Err(e) => {
eprintln!("{e}");
*exit_code1.borrow_mut() = ExitCode::FAILURE;
return;
},
}
}
let lexemes =
lex(i.i(code.trim()).await, sym!(usercode; i).await, &systems, ctx).await.unwrap();
if args.logs {
println!("lexed: {}", take_first(&ttv_fmt(&lexemes, &FmtCtxImpl { i }).await, true));
}
let path = sym!(usercode; i).await;
let reporter = Reporter::new();
let parse_ctx = HostParseCtxImpl {
ctx: ctx.clone(),
reporter: &reporter,
rep: &reporter,
src: path.clone(),
systems: &systems[..],
};