1use source_map_cache::SourceMap;
6use swamp_dep_loader::{DepLoaderError, RunMode};
7pub mod prelude;
8use crate::prelude::CompileAndCodeGenOptions;
9use swamp_analyzer::Program;
10use swamp_compile::CompileOptions;
11use swamp_error_report::ScriptResolveError;
12use swamp_runtime::CompileAndMaybeCodeGenResult;
13use swamp_runtime::prelude::CodeGenOptions;
14use swamp_semantic::SemanticError;
15use swamp_semantic::prelude::Error;
16
17#[derive(Debug)]
18pub enum ScriptError {
19 Error(Error),
20 DepLoaderError(DepLoaderError),
21}
22
23impl From<Error> for ScriptError {
24 fn from(err: Error) -> Self {
25 Self::Error(err)
26 }
27}
28
29impl From<DepLoaderError> for ScriptError {
30 fn from(err: DepLoaderError) -> Self {
31 Self::DepLoaderError(err)
32 }
33}
34
35#[derive(Debug)]
36pub enum LoaderErr {
37 CouldNotLoad,
38 SemanticError(SemanticError),
39 AnalyzerError(Error),
40}
41
42impl From<Error> for LoaderErr {
43 fn from(value: Error) -> Self {
44 Self::AnalyzerError(value)
45 }
46}
47
48pub fn compile_and_analyze(
49 module_path: &[String],
50 source_map: &mut SourceMap,
51) -> Result<Program, ScriptResolveError> {
52 let options = CompileOptions {
53 show_semantic: false,
54 show_modules: false,
55 show_types: false,
56 show_errors: true,
57 show_warnings: true,
58 show_hints: false,
59 show_information: false,
60 allow_unsafe: true,
61 };
62 swamp_compile::bootstrap_and_compile(source_map, module_path, &options)
63}
64
65pub fn compile_and_codegen(
66 module_path: &[String],
67 source_map: &mut SourceMap,
68) -> Option<CompileAndMaybeCodeGenResult> {
69 let options = CompileAndCodeGenOptions {
70 compile_options: CompileOptions {
71 show_semantic: false,
72 show_modules: false,
73 show_errors: false,
74 show_warnings: false,
75 show_hints: false,
76 show_information: false,
77 show_types: false,
78 allow_unsafe: true,
79 },
80 code_gen_options: CodeGenOptions {
81 show_disasm: false,
82 disasm_filter: None,
83 show_debug: false,
84 show_types: false,
85 ignore_host_call: false,
86 },
87 skip_codegen: false,
88 run_mode: RunMode::Deployed,
89 };
90 swamp_runtime::compile_and_code_gen(source_map, module_path, &options)
91}