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
improve variants, consistent type order
archaephyrryx committed Dec 12, 2023
commit 78629270b8c5c0b876eba1405324cac74ee235ff
1,208 changes: 604 additions & 604 deletions sample_codegen.rs

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -217,6 +217,7 @@ impl Codegen {
// REVIEW - should we force an exact match?
match matching {
Some(RustVariant::Unit(_)) => {
// FIXME - this is not quite correct, as it calls `Var(inner)` where `inner = ()` instead of `Var`
let _inner = self.translate(inner, Some(&RustType::UNIT));
CaseLogic::Derived(DerivedLogic::VariantOf(constr, Box::new(_inner)))
}
@@ -1222,9 +1223,10 @@ impl SequentialLogic {
// FIXME - this may be incorrect since we don't always know the type-context (e.g. if we are in an enum)
(
body,
Some(RustExpr::local(con.clone()).call_with([RustExpr::Tuple(
names.into_iter().map(RustExpr::local).collect(),
)])),
Some(
RustExpr::local(con.clone())
.call_with(names.into_iter().map(RustExpr::local)),
),
)
} else {
(
@@ -1411,7 +1413,9 @@ pub fn print_program(program: &Program) {
let mut codegen = Codegen::new();
let mut items = Vec::new();
codegen.populate_decoder_types(program);
for (tdef, ixlab) in codegen.namegen.revmap.iter() {
let mut tdefs = Vec::from_iter(codegen.namegen.revmap.iter());
tdefs.sort_by_key(|(_, ix)| *ix);
for (tdef, ixlab) in tdefs.into_iter() {
let it = RustItem::from_decl(RustDecl::TypeDef(ixlab.into(), tdef.clone()));
items.push(it);
}