-
Notifications
You must be signed in to change notification settings - Fork 2
Format improvements (WIP) #63
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
Draft
zero318
wants to merge
32
commits into
ExpHP:main
Choose a base branch
from
zero318:format_improvements_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
2ed6200
Add initial imm attribute support
zero318 a8b2ad4
Improve unsigned/hex support and update padding
zero318 e66c92d
Several suggested changes
zero318 f3de737
Change _ back to 4 bytes and add - for single bytes
zero318 96c1d4c
First batch of updated signatures
zero318 7fe31f4
Second batch of updated signatures
zero318 4d089ac
Add scratch registers for IN-StB and fix size arg sign
zero318 9605ae3
Third batch of updated signatures
zero318 5ff6724
Fourth batch of updated signatures
zero318 b3e8508
please let the merge work
zero318 b70b2ed
Fifth batch of updated signatures
zero318 17ce209
Sixth batch of updated signatures
zero318 92292d5
Seventh batch of updated signatures
zero318 3d32e3b
Eigth batch of updated signatures
zero318 88e5a47
Ninth batch of updated signatures and a few misc fixes
zero318 26f14dc
e
zero318 6e5e625
Fixed roundtrip problems
zero318 8d9e7a8
First attempt at th20 support
zero318 7a8dd56
Fix th20 std support
khang06 4e2e6a2
Merge pull request #2 from khang06/th20-std
zero318 ac21a91
Fix th20 std support (again)
khang06 fba8534
Merge pull request #3 from khang06/th20-std
zero318 e04f291
Fix more STD/MSG/END stuff for th20
zero318 20a4da0
Merge commit '7517af7ac0352ae0f42d0b998f46af7946521e9e' into neww-zero
ExpHP b2dcd1c
Merge commit '88e5a47a2f9bbdd5fdc999bec32999350faf59c' into neww-zero
ExpHP 7778c45
e
zero318 21c30dd
Fixed roundtrip problems
zero318 3bdc5fa
First attempt at th20 support
zero318 e9c3d28
Fix th20 std support
khang06 471b51d
Fix th20 std support (again)
khang06 1a5964e
Fix more STD/MSG/END stuff for th20
zero318 8eb4c4b
Merge branch 'format_improvements_test' of https://github.com/ExpHP/t…
zero318 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -775,44 +775,9 @@ impl Defs { | |
| /// Lookup table for decompiling constant values to enum consts. | ||
| #[derive(Debug, Clone)] | ||
| pub struct ConstNames { | ||
| pub enums: IdMap<Ident, ScalarValueMap<Sp<Ident>>>, | ||
| pub enums: IdMap<Ident, IdMap<i32, Sp<Ident>>>, | ||
| } | ||
|
|
||
| /// A map with ScalarValue keys, which uses bitwise-identity for floats. | ||
| #[derive(Debug, Clone)] | ||
| pub struct ScalarValueMap<T> { | ||
| ints: IdMap<i32, T>, | ||
| strings: IdMap<String, T>, | ||
| floats: IdMap<u32, T>, | ||
| } | ||
|
|
||
| impl<T> ScalarValueMap<T> { | ||
| pub fn new() -> Self { | ||
| ScalarValueMap { | ||
| ints: Default::default(), | ||
| strings: Default::default(), | ||
| floats: Default::default(), | ||
| } | ||
| } | ||
|
|
||
| pub fn insert(&mut self, key: ScalarValue, value: T) -> Option<T> { | ||
| match key { | ||
| ScalarValue::Int(x) => self.ints.insert(x, value), | ||
| ScalarValue::Float(x) => self.floats.insert(x.to_bits(), value), | ||
| ScalarValue::String(x) => self.strings.insert(x, value), | ||
| } | ||
| } | ||
|
|
||
| pub fn get(&self, key: &ScalarValue) -> Option<&T> { | ||
| match key { | ||
| ScalarValue::Int(x) => self.ints.get(x), | ||
| ScalarValue::Float(x) => self.floats.get(&x.to_bits()), | ||
| ScalarValue::String(x) => self.strings.get(x), | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| impl CompilerContext<'_> { | ||
| /// Get `value -> name` mappings for all enums and automatic consts, for decompilation or | ||
| /// pretty-printing purposes. | ||
|
|
@@ -827,11 +792,11 @@ impl CompilerContext<'_> { | |
| } | ||
|
|
||
| impl EnumData { | ||
| fn generate_lookup(&self, consts: &context::Consts) -> ScalarValueMap<Sp<Ident>> { | ||
| let mut out = ScalarValueMap::new(); | ||
| fn generate_lookup(&self, consts: &context::Consts) -> IdMap<i32, Sp<Ident>> { | ||
| let mut out = IdMap::new(); | ||
| for (ident, &const_id) in &self.consts { | ||
| let value = consts.get_cached_value(const_id).expect("evaluate_const_vars has not run! (bug!)"); | ||
| out.insert(value.clone(), ident.clone()); | ||
| out.insert(value.expect_int(), ident.clone()); | ||
| } | ||
| out | ||
| } | ||
|
|
@@ -1150,34 +1115,18 @@ impl Signature { | |
| signature_from_func_ast(ty_keyword, params) | ||
| } | ||
|
|
||
| pub(crate) fn validate(&self, ctx: &CompilerContext) -> Result<(), ErrorReported> { | ||
| self._check_non_optional_after_optional(ctx) | ||
| } | ||
|
|
||
| fn _check_non_optional_after_optional(&self, ctx: &CompilerContext) -> Result<(), ErrorReported> { | ||
| let mut first_optional = None; | ||
| for param in self.params.iter() { | ||
| if param.default.is_some() { | ||
| first_optional = Some(param); | ||
| } else if let Some(optional) = first_optional { | ||
| return Err(ctx.emitter.emit(error!( | ||
| message("invalid function signature"), | ||
| secondary(optional.useful_span, "optional parameter"), | ||
| primary(param.useful_span, "non-optional parameter after optional"), | ||
| ))); | ||
| } | ||
| } | ||
| pub(crate) fn validate(&self, _ctx: &CompilerContext) -> Result<(), ErrorReported> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was removed because its only purpose was to handle the padding arguments from old STD. This was refactored into the _ and - formats usable in any script type rather than optional arguments, so this check is unnecessary |
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Minimum number of arguments accepted. | ||
| pub fn min_args(&self) -> usize { | ||
| self.params.iter().take_while(|param| param.default.is_none()).count() | ||
| self.params.iter().fold(0, |count, param| count + param.default.is_none() as usize) | ||
| } | ||
|
|
||
| /// Maximum number of arguments accepted. | ||
| pub fn max_args(&self) -> usize { | ||
| self.params.len() | ||
| self.min_args() | ||
| } | ||
|
|
||
| /// Matches arguments at a call site to their corresponding parameters. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might prefer
signedrather thanunsignedto avoid double negativesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with
unsignedsince it's more of an exception to the norm than anything. I tend to structure my bools withtrueas the "do something different" value so that they don't need to be negated whenever being read, but I guess that doesn't matter as much withmatchsince you have to be explicit in both cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trueas "do something different" makes sense in C-likes where it's easy to zero-initialize things. It doesn't make so much sense in rust.