-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.rs
More file actions
41 lines (28 loc) · 1.03 KB
/
compiler.rs
File metadata and controls
41 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::io::{Write, stdout};
use clap::Parser;
use reqlang_expr::{cliutil::read_in_source, prelude::*};
fn main() -> ExprResult<()> {
let args = Args::parse();
let source = read_in_source(args.path);
let ast: Expr = parse(&source).expect("should parse successfully");
let env = CompileTimeEnv::new(args.vars.clone(), vec![], vec![], vec![]);
let bytecode = compile(&mut (ast, 0..source.len()), &env)?;
eprintln!("{bytecode:#?}");
let _ = stdout().write_all(bytecode.codes());
Ok(())
}
#[derive(Parser, Debug)]
#[command(version, about = "Example CLI that compiles an expression")]
struct Args {
/// Path to expression file
path: Option<String>,
/// List of indexed variable names
#[arg(long, value_delimiter = ' ', num_args = 1..)]
vars: Vec<String>,
/// List of indexed prompt names
#[arg(long, value_delimiter = ' ', num_args = 1..)]
prompts: Vec<String>,
/// List of indexed secret names
#[arg(long, value_delimiter = ' ', num_args = 1..)]
secrets: Vec<String>,
}