New macro system and stdlib additions

This commit is contained in:
2025-11-21 14:25:03 +01:00
parent b77653f841
commit 603efef28e
230 changed files with 3033 additions and 16640 deletions

View File

@@ -116,7 +116,7 @@ async fn main() -> io::Result<ExitCode> {
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(i.i(&buf).await, sym!(usercode; i).await, &systems, ctx).await.unwrap();
let lexemes = lex(i.i(&buf).await, sym!(usercode; i), &systems, ctx).await.unwrap();
println!("{}", take_first(&ttv_fmt(&lexemes, &FmtCtxImpl { i }).await, true))
},
Commands::Parse { file } => {
@@ -124,7 +124,7 @@ async fn main() -> io::Result<ExitCode> {
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(i.i(&buf).await, sym!(usercode; i).await, &systems, ctx).await.unwrap();
let lexemes = lex(i.i(&buf).await, sym!(usercode; i), &systems, ctx).await.unwrap();
let Some(first) = lexemes.first() else {
println!("File empty!");
return;
@@ -134,7 +134,7 @@ async fn main() -> io::Result<ExitCode> {
rep: &reporter,
systems: &systems,
ctx: ctx.clone(),
src: sym!(usercode; i).await,
src: sym!(usercode; i),
};
let snip = Snippet::new(first, &lexemes);
let ptree = parse_items(&pctx, Substack::Bottom, snip).await.unwrap();
@@ -155,7 +155,7 @@ async fn main() -> io::Result<ExitCode> {
Commands::Repl => {
let mut counter = 0;
let mut imports = Vec::new();
let usercode_path = sym!(usercode; i).await;
let usercode_path = sym!(usercode; i);
let mut stdin = BufReader::new(stdin());
loop {
counter += 1;
@@ -238,7 +238,7 @@ async fn main() -> io::Result<ExitCode> {
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 parse_folder(&root, path, sym!(src; i).await, &reporter, ctx.clone()).await {
match parse_folder(&root, path, sym!(src; i), &reporter, ctx.clone()).await {
Ok(r) => root = r,
Err(e) => {
eprintln!("{e}");
@@ -282,12 +282,12 @@ async fn main() -> io::Result<ExitCode> {
},
Commands::Exec { proj, code } => {
let reporter = Reporter::new();
let path = sym!(usercode; i).await;
let path = sym!(usercode; i);
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 parse_folder(&root, path, sym!(src; i).await, &reporter, ctx.clone()).await {
match parse_folder(&root, path, sym!(src; i), &reporter, ctx.clone()).await {
Ok(r) => root = r,
Err(e) => {
eprintln!("{e}");
@@ -321,7 +321,7 @@ async fn main() -> io::Result<ExitCode> {
};
let reporter = Reporter::new();
let root = root.add_parsed(&entrypoint, path.clone(), &reporter).await;
let expr = ExprKind::Const(sym!(usercode::entrypoint; i).await).at(prefix_sr.pos());
let expr = ExprKind::Const(sym!(usercode::entrypoint; i)).at(prefix_sr.pos());
let mut xctx = ExecCtx::new(ctx.clone(), logger.clone(), root, expr).await;
xctx.set_gas(Some(1000));
xctx.execute().await;

View File

@@ -72,7 +72,7 @@ pub async fn parse_folder(
let hpctx = HostParseCtxImpl { ctx: ctx.clone(), rep, src: ns.clone(), systems: &systems };
let Some(fst) = lexemes.first() else { return Ok(Some(ParsedModule::new(false, []))) };
let items = parse_items(&hpctx, Substack::Bottom, Snippet::new(fst, &lexemes)).await?;
Ok(Some(ParsedModule::new(false, items)))
Ok(Some(ParsedModule::new(true, items)))
} else {
Ok(None)
}