Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

20230911 compile context #228

Open
wants to merge 2 commits into
base: base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/classic/clvm_tools/clvmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ pub fn write_sym_output(
.map(|_| ())
}

pub fn compile_clvm_text(
pub fn compile_clvm_text_maybe_opt(
allocator: &mut Allocator,
do_optimize: bool,
opts: Rc<dyn CompilerOpts>,
symbol_table: &mut HashMap<String, String>,
text: &str,
Expand All @@ -52,12 +53,19 @@ pub fn compile_clvm_text(
let dialect = detect_modern(allocator, assembled_sexp);
// Now the stepping is optional (None for classic) but we may communicate
// other information in dialect as well.
if let Some(dialect) = dialect.stepping {
if let Some(stepping) = dialect.stepping {
let runner = Rc::new(DefaultProgramRunner::new());
let opts = opts.set_optimize(true).set_frontend_opt(dialect > 21);
let opts = opts
.set_dialect(dialect)
.set_optimize(do_optimize || stepping > 22)
.set_frontend_opt(stepping == 22);

let unopt_res = compile_file(allocator, runner.clone(), opts, text, symbol_table);
let res = unopt_res.and_then(|x| run_optimizer(allocator, runner, Rc::new(x)));
let res = if do_optimize {
unopt_res.and_then(|x| run_optimizer(allocator, runner, Rc::new(x)))
} else {
unopt_res.map(Rc::new)
};

res.and_then(|x| {
convert_to_clvm_rs(allocator, x).map_err(|r| match r {
Expand All @@ -79,6 +87,25 @@ pub fn compile_clvm_text(
}
}

pub fn compile_clvm_text(
allocator: &mut Allocator,
opts: Rc<dyn CompilerOpts>,
symbol_table: &mut HashMap<String, String>,
text: &str,
input_path: &str,
classic_with_opts: bool,
) -> Result<NodePtr, EvalErr> {
compile_clvm_text_maybe_opt(
allocator,
true,
opts,
symbol_table,
text,
input_path,
classic_with_opts,
)
}

pub fn compile_clvm_inner(
allocator: &mut Allocator,
opts: Rc<dyn CompilerOpts>,
Expand Down
Loading
Loading