@@ -170,11 +170,6 @@ using namespace lean; // NOLINT
170170#define LEAN_SERVER_DEFAULT_MAX_HEARTBEAT 100000
171171#endif
172172
173- extern " C" void *initialize_Lean_Compiler_IR_EmitLLVM (uint8_t builtin,
174- lean_object *);
175- extern " C" object *lean_ir_emit_llvm (object *env, object *mod_name,
176- object *filepath, object *w);
177-
178173static void display_header (std::ostream & out) {
179174 out << " Lean (version " << get_version_string () << " , " << LEAN_STR (LEAN_BUILD_TYPE) << " )\n " ;
180175}
@@ -330,46 +325,61 @@ options set_config_option(options const & opts, char const * in) {
330325}
331326
332327namespace lean {
333- extern " C" object * lean_run_frontend (
328+ extern " C" object * lean_shell_main (
329+ object * args,
334330 object * input,
335331 object * opts,
336332 object * filename,
337333 object * main_module_name,
338334 uint32_t trust_level,
339335 object * olean_filename,
340336 object * ilean_filename,
337+ object * c_filename,
338+ object * bc_filename,
341339 uint8_t json_output,
342340 object * error_kinds,
343- object * plugins,
344341 bool print_stats,
345- object * header_file_name,
342+ object * setup_file_name,
343+ bool run,
346344 object * w
347345);
348- option_ref<elab_environment> run_new_frontend (
346+ uint32 run_shell_main (
347+ int argc, char * argv[],
349348 std::string const & input,
350349 options const & opts, std::string const & file_name,
351350 name const & main_module_name,
352351 uint32_t trust_level,
353352 optional<std::string> const & olean_file_name,
354353 optional<std::string> const & ilean_file_name,
354+ optional<std::string> const & c_file_name,
355+ optional<std::string> const & bc_file_name,
355356 uint8_t json_output,
356357 array_ref<name> const & error_kinds,
357358 bool print_stats,
358- optional<std::string> const & setup_file_name
359+ optional<std::string> const & setup_file_name,
360+ bool run
359361) {
360- return get_io_result<option_ref<elab_environment>>(lean_run_frontend (
362+ list_ref<string_ref> args;
363+ while (argc > 0 ) {
364+ argc--;
365+ args = list_ref<string_ref>(string_ref (argv[argc]), args);
366+ }
367+ return get_io_scalar_result<uint32>(lean_shell_main (
368+ args.steal (),
361369 mk_string (input),
362370 opts.to_obj_arg (),
363371 mk_string (file_name),
364372 main_module_name.to_obj_arg (),
365373 trust_level,
366374 olean_file_name ? mk_option_some (mk_string (*olean_file_name)) : mk_option_none (),
367375 ilean_file_name ? mk_option_some (mk_string (*ilean_file_name)) : mk_option_none (),
376+ c_file_name ? mk_option_some (mk_string (*c_file_name)) : mk_option_none (),
377+ bc_file_name ? mk_option_some (mk_string (*bc_file_name)) : mk_option_none (),
368378 json_output,
369379 error_kinds.to_obj_arg (),
370- mk_empty_array (),
371380 print_stats,
372381 setup_file_name ? mk_option_some (mk_string (*setup_file_name)) : mk_option_none (),
382+ run,
373383 io_mk_world ()
374384 ));
375385}
@@ -765,48 +775,12 @@ extern "C" LEAN_EXPORT int lean_main(int argc, char ** argv) {
765775
766776 if (!main_module_name)
767777 main_module_name = name (" _stdin" );
768- option_ref<elab_environment> opt_env = run_new_frontend (
778+ return run_shell_main (
779+ argc - optind, argv + optind,
769780 contents, opts, mod_fn, *main_module_name, trust_lvl,
770- olean_fn, ilean_fn, json_output, error_kinds, stats, setup_fn
781+ olean_fn, ilean_fn, c_output, llvm_output,
782+ json_output, error_kinds, stats, setup_fn, run
771783 );
772-
773- if (opt_env) {
774- elab_environment env = opt_env.get_val ();
775- if (run) {
776- uint32 ret = ir::run_main (env, opts, argc - optind, argv + optind);
777- return ret;
778- }
779- if (c_output) {
780- std::ofstream out (*c_output, std::ios_base::binary);
781- if (out.fail ()) {
782- std::cerr << " failed to create '" << *c_output << " '\n " ;
783- return 1 ;
784- }
785- time_task _ (" C code generation" , opts);
786- out << lean::ir::emit_c (env, *main_module_name).data ();
787- out.close ();
788- }
789- if (llvm_output) {
790- initialize_Lean_Compiler_IR_EmitLLVM (/* builtin*/ false ,
791- lean_io_mk_world ());
792- time_task _ (" LLVM code generation" , opts);
793- lean::consume_io_result (lean_ir_emit_llvm (
794- env.to_obj_arg (), (*main_module_name).to_obj_arg (),
795- lean::string_ref (*llvm_output).to_obj_arg (),
796- lean_io_mk_world ()));
797- }
798- }
799-
800- display_cumulative_profiling_times (std::cerr);
801-
802- #if defined(__has_feature)
803- #if __has_feature(address_sanitizer)
804- return opt_env ? 0 : 1 ;
805- #endif
806- #endif
807- // When not using the address/leak sanitizer, we interrupt execution without garbage collecting.
808- // This is useful when profiling improvements to Lean startup time.
809- exit (opt_env ? 0 : 1 );
810784 } catch (lean::throwable & ex) {
811785 std::cerr << ex.what () << " \n " ;
812786 } catch (std::bad_alloc & ex) {
0 commit comments