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

Codegen fixes #135

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Replace discriminant with variant in panic msg
archaephyrryx committed Dec 12, 2023
commit 88c6fd12265ce372c12db64d5b94c69070cc5c5a
1,616 changes: 808 additions & 808 deletions sample_codegen.rs

Large diffs are not rendered by default.

36 changes: 32 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -325,6 +325,37 @@ fn embed_byteset(bs: &ByteSet) -> RustExpr {
])])
}

fn name_for_decoder(dec: &Decoder) -> &'static str {
match dec {
Decoder::Call(_, _) => "Call",
Decoder::Fail => "Fail",
Decoder::EndOfInput => "EndOfInput",
Decoder::Align(_) => "Align",
Decoder::Byte(_) => "Byte",
Decoder::Variant(_, _) => "Variant",
Decoder::Parallel(_) => "Parallel",
Decoder::Branch(_, _) => "Branch",
Decoder::Tuple(_) => "Tuple",
Decoder::Record(_) => "Record",
Decoder::While(_, _) => "While",
Decoder::Until(_, _) => "Until",
Decoder::RepeatCount(_, _) => "RepeatCount",
Decoder::RepeatUntilLast(_, _) => "RepeatUntilLast",
Decoder::RepeatUntilSeq(_, _) => "RepeatUntilSeq",
Decoder::Peek(_) => "Peek",
Decoder::PeekNot(_) => "PeekNot",
Decoder::Slice(_, _) => "Slice",
Decoder::Bits(_) => "Bits",
Decoder::WithRelativeOffset(_, _) => "WithRelativeOffset",
Decoder::Map(_, _) => "Map",
Decoder::Compute(_) => "Compute",
Decoder::Let(_, _, _) => "Let",
Decoder::Match(_, _) => "Match",
Decoder::Dynamic(_, _, _) => "Dynamic",
Decoder::Apply(_) => "Apply",
}
}

// FIXME - implement something that actually works
fn invoke_decoder(decoder: &Decoder, input_varname: &Label) -> RustExpr {
match decoder {
@@ -401,10 +432,7 @@ fn invoke_decoder(decoder: &Decoder, input_varname: &Label) -> RustExpr {
other => {
let let_tmp = RustStmt::assign(
"tmp",
RustExpr::str_lit(format!(
"invoke_decoder @ {:?}",
std::mem::discriminant(other)
)),
RustExpr::str_lit(format!("invoke_decoder @ {}", name_for_decoder(other))),
);
RustExpr::BlockScope(
vec![let_tmp],