Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Jan 4, 2024
1 parent 2b4764a commit 0ba4c0e
Show file tree
Hide file tree
Showing 25 changed files with 951 additions and 796 deletions.
6 changes: 5 additions & 1 deletion src/classic/bins/shrink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ fn main() {
.err_into()
.and_then(|parsed_program| frontend(opts.clone(), &parsed_program))
.and_then(|program| {
let e = Evaluator::new(opts.clone(), runner.clone(), program.compileform().helpers.clone());
let e = Evaluator::new(
opts.clone(),
runner.clone(),
program.compileform().helpers.clone(),
);
e.shrink_bodyform(
&mut allocator,
program.compileform().args.clone(),
Expand Down
11 changes: 7 additions & 4 deletions src/classic/clvm_tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ pub fn cldb(args: &[String]) {
&mut includes,
);
if do_optimize {
unopt_res.and_then(|x| run_optimizer(&mut allocator, runner.clone(), Rc::new(x.to_sexp())))
unopt_res.and_then(|x| {
run_optimizer(&mut allocator, runner.clone(), Rc::new(x.to_sexp()))
})
} else {
unopt_res.map(|x| Rc::new(x.to_sexp()))
}
Expand Down Expand Up @@ -931,7 +933,8 @@ fn perform_preprocessing(
let (stepping_form_text, parsed) =
parse_module_and_get_sigil(opts.clone(), input_file, program_text)?;
let frontend = frontend(opts, &parsed)?;
let whole_mod = render_mod_with_sigil(input_file, &stepping_form_text, &frontend.compileform())?;
let whole_mod =
render_mod_with_sigil(input_file, &stepping_form_text, &frontend.compileform())?;

stdout.write_str(&format!("{}", whole_mod));
Ok(())
Expand Down Expand Up @@ -1429,8 +1432,8 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
.and_then(|pre_forms| {
let context = standard_type_context();
let compileform = frontend(opts.clone(), &pre_forms)?;
let target_type =
context.typecheck_chialisp_program(opts.clone(), &compileform.compileform())?;
let target_type = context
.typecheck_chialisp_program(opts.clone(), &compileform.compileform())?;
Ok(context.reify(&target_type, None))
})
{
Expand Down
130 changes: 54 additions & 76 deletions src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::compiler::clvm::{run, truthy};
use crate::compiler::compiler::is_at_capture;
use crate::compiler::comptypes::{
fold_m, join_vecs_to_string, list_to_cons, Binding, BindingPattern, BodyForm, CallSpec,
Callable, CompileErr, CompileForm, CompiledCode, CompilerOpts, CompilerOutput, ConstantKind, DefunCall,
DefunData, HelperForm, InlineFunction, LetData, LetFormInlineHint, LetFormKind, PrimaryCodegen,
RawCallSpec, SyntheticType,
Callable, CompileErr, CompileForm, CompiledCode, CompilerOpts, CompilerOutput, ConstantKind,
DefunCall, DefunData, HelperForm, InlineFunction, LetData, LetFormInlineHint, LetFormKind,
PrimaryCodegen, RawCallSpec, SyntheticType,
};
use crate::compiler::debug::{build_swap_table_mut, relabel};
use crate::compiler::evaluate::{Evaluator, EVAL_STACK_LIMIT};
Expand Down Expand Up @@ -339,12 +339,10 @@ pub fn get_callable(
}
(_, _, _, _, true, _) => Ok(Callable::RunCompiler),
(_, _, _, _, _, true) => Ok(Callable::EnvPath),
_ => {
Err(CompileErr(
l.clone(),
format!("no such callable '{}'", decode_string(name)),
))
}
_ => Err(CompileErr(
l.clone(),
format!("no such callable '{}'", decode_string(name)),
)),
}
}
SExp::Integer(_, v) => Ok(Callable::CallPrim(l.clone(), SExp::Integer(l, v.clone()))),
Expand Down Expand Up @@ -641,21 +639,16 @@ fn compile_call(
);

let mut unused_symbol_table = HashMap::new();
let mut context_wrapper = CompileContextWrapper::from_context(context, &mut unused_symbol_table);
let code =
updated_opts
.compile_program(
&mut context_wrapper.context,
Rc::new(use_body),
)?;
let mut context_wrapper =
CompileContextWrapper::from_context(context, &mut unused_symbol_table);
let code = updated_opts
.compile_program(&mut context_wrapper.context, Rc::new(use_body))?;

match code {
CompilerOutput::Program(code) => {
Ok(CompiledCode(
call.loc.clone(),
Rc::new(primquote(call.loc.clone(), Rc::new(code))),
))
}
CompilerOutput::Program(code) => Ok(CompiledCode(
call.loc.clone(),
Rc::new(primquote(call.loc.clone(), Rc::new(code))),
)),
CompilerOutput::Module(_) => {
todo!();
}
Expand Down Expand Up @@ -685,10 +678,7 @@ pub fn do_mod_codegen(
// A mod form yields the compiled code.
let without_env = opts.set_start_env(None).set_in_defun(false);
let mut throwaway_symbols = HashMap::new();
let mut context_wrapper = CompileContextWrapper::from_context(
context,
&mut throwaway_symbols,
);
let mut context_wrapper = CompileContextWrapper::from_context(context, &mut throwaway_symbols);
let code = codegen(&mut context_wrapper.context, without_env, program)?;
Ok(CompiledCode(
program.loc.clone(),
Expand Down Expand Up @@ -914,28 +904,23 @@ fn codegen_(
);

let mut unused_symbol_table = HashMap::new();
let code =
{
let mut context_wrapper = CompileContextWrapper::from_context(
context,
&mut unused_symbol_table
);
let code =
updated_opts
.compile_program(
&mut context_wrapper.context,
Rc::new(tocompile),
)?;
match code {
CompilerOutput::Program(p) => p,
CompilerOutput::Module(_) => {
todo!();
}
let code = {
let mut context_wrapper =
CompileContextWrapper::from_context(context, &mut unused_symbol_table);
let code = updated_opts
.compile_program(&mut context_wrapper.context, Rc::new(tocompile))?;
match code {
CompilerOutput::Program(p) => p,
CompilerOutput::Module(_) => {
todo!();
}
};
}
};

let code = context.post_codegen_function_optimize(opts.clone(), Some(h), Rc::new(code))?;
let code = fail_if_present(defun.loc.clone(), &compiler.inlines, &defun.name, code)?;
let code =
context.post_codegen_function_optimize(opts.clone(), Some(h), Rc::new(code))?;
let code =
fail_if_present(defun.loc.clone(), &compiler.inlines, &defun.name, code)?;
let code = fail_if_present(defun.loc.clone(), &compiler.defuns, &defun.name, code)?;
return Ok(compiler.add_defun(
&defun.name,
Expand Down Expand Up @@ -1423,20 +1408,16 @@ fn start_codegen(
let updated_opts = opts.set_code_generator(code_generator.clone());
let mut unused_symbols = HashMap::new();
let runner = context.runner();
let mut context_wrapper = CompileContextWrapper::from_context(
context,
&mut unused_symbols
);
let code =
match updated_opts.compile_program(
&mut context_wrapper.context,
Rc::new(expand_program),
)? {
CompilerOutput::Program(code) => code,
CompilerOutput::Module(_) => {
todo!();
}
};
let mut context_wrapper =
CompileContextWrapper::from_context(context, &mut unused_symbols);
let code = match updated_opts
.compile_program(&mut context_wrapper.context, Rc::new(expand_program))?
{
CompilerOutput::Program(code) => code,
CompilerOutput::Module(_) => {
todo!();
}
};

run(
context_wrapper.context.allocator(),
Expand Down Expand Up @@ -1514,23 +1495,20 @@ fn start_codegen(

let mut unused_symbols = HashMap::new();
let runner = context.runner();
let mut context_wrapper = CompileContextWrapper::from_context(
context,
&mut unused_symbols
);
let code =
match updated_opts.compile_program(
&mut context_wrapper.context,
macro_program,
)? {
CompilerOutput::Program(p) => p,
CompilerOutput::Module(_) => {
todo!();
}
};
let mut context_wrapper =
CompileContextWrapper::from_context(context, &mut unused_symbols);
let code = match updated_opts
.compile_program(&mut context_wrapper.context, macro_program)?
{
CompilerOutput::Program(p) => p,
CompilerOutput::Module(_) => {
todo!();
}
};

let optimized_code =
context_wrapper.context.macro_optimization(opts.clone(), Rc::new(code.clone()))?;
let optimized_code = context_wrapper
.context
.macro_optimization(opts.clone(), Rc::new(code.clone()))?;

code_generator.add_macro(&mac.name, optimized_code)
}
Expand Down
Loading

0 comments on commit 0ba4c0e

Please sign in to comment.