Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsed_to_ast fn in sway_core #2210

Merged
merged 2 commits into from
Jul 4, 2022
Merged
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
71 changes: 52 additions & 19 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,13 @@ pub enum BytecodeCompilationResult {
},
}

pub fn compile_to_ast(
input: Arc<str>,
pub fn parsed_to_ast(
parse_program: ParseProgram,
initial_namespace: namespace::Module,
build_config: Option<&BuildConfig>,
) -> CompileAstResult {
let mut warnings = Vec::new();
let mut errors = Vec::new();

let CompileResult {
value: parse_program_opt,
warnings: new_warnings,
errors: new_errors,
} = parse(input, build_config);
warnings.extend(new_warnings);
errors.extend(new_errors);
let parse_program = match parse_program_opt {
Some(parse_program) => parse_program,
None => {
errors = dedup_unsorted(errors);
warnings = dedup_unsorted(warnings);
return CompileAstResult::Failure { errors, warnings };
}
};

let CompileResult {
value: typed_program_result,
warnings: new_warnings,
Expand Down Expand Up @@ -278,6 +261,56 @@ pub fn compile_to_ast(
}
}

pub fn compile_to_ast(
input: Arc<str>,
initial_namespace: namespace::Module,
build_config: Option<&BuildConfig>,
) -> CompileAstResult {
let mut warnings = Vec::new();
let mut errors = Vec::new();

let CompileResult {
value: parse_program_opt,
warnings: new_warnings,
errors: new_errors,
} = parse(input, build_config);

warnings.extend(new_warnings);
errors.extend(new_errors);
let parse_program = match parse_program_opt {
Some(parse_program) => parse_program,
None => {
errors = dedup_unsorted(errors);
warnings = dedup_unsorted(warnings);
return CompileAstResult::Failure { errors, warnings };
}
};

match parsed_to_ast(parse_program, initial_namespace) {
CompileAstResult::Success {
typed_program,
warnings: new_warnings,
} => {
warnings.extend(new_warnings);
warnings = dedup_unsorted(warnings);
CompileAstResult::Success {
typed_program,
warnings,
}
}
CompileAstResult::Failure {
warnings: new_warnings,
errors: new_errors,
} => {
warnings.extend(new_warnings);
errors.extend(new_errors);
errors = dedup_unsorted(errors);
warnings = dedup_unsorted(warnings);
CompileAstResult::Failure { errors, warnings }
}
}
}

/// Given input Sway source code, compile to a [CompilationResult] which contains the asm in opcode
/// form (not raw bytes/bytecode).
pub fn compile_to_asm(
Expand Down