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

feat: remainder operator #135

Merged
merged 3 commits into from
Apr 18, 2020
Merged

feat: remainder operator #135

merged 3 commits into from
Apr 18, 2020

Conversation

wackbyte
Copy link
Contributor

Adds the remainder operators % and %=. Please tell me if I missed anything. 🙂

@codecov
Copy link

codecov bot commented Apr 14, 2020

Codecov Report

Merging #135 into master will increase coverage by 0.18%.
The diff coverage is 84.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
+ Coverage   81.73%   81.92%   +0.18%     
==========================================
  Files         141      141              
  Lines        9035     9055      +20     
==========================================
+ Hits         7385     7418      +33     
+ Misses       1650     1637      -13     
Impacted Files Coverage Δ
crates/mun_codegen/src/test.rs 97.53% <ø> (ø)
crates/mun_hir/src/ty/tests.rs 96.05% <ø> (ø)
crates/mun_syntax/src/parsing/parser.rs 80.92% <50.00%> (-0.42%) ⬇️
crates/mun_codegen/src/ir/body.rs 83.56% <72.72%> (-0.37%) ⬇️
crates/mun_hir/src/expr.rs 85.44% <100.00%> (+1.79%) ⬆️
crates/mun_runtime/src/test.rs 98.72% <100.00%> (+0.01%) ⬆️
crates/mun_syntax/src/ast/expr_extensions.rs 81.17% <100.00%> (+1.65%) ⬆️
...ates/mun_syntax/src/parsing/grammar/expressions.rs 94.09% <100.00%> (+0.05%) ⬆️
crates/mun_syntax/src/ast/generated.rs 77.13% <0.00%> (+1.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39babc4...bc52b76. Read the comment docs.

@Wodann
Copy link
Collaborator

Wodann commented Apr 14, 2020

Nice work! The PR looks good overall.

I had one question, does the signed remainder do the same thing as Rust, e.g. -2 % 5 == -2? I tried looking up the apropiate LLVM docs, but couldn't easily find them (on mobile)..

@wackbyte
Copy link
Contributor Author

I got a panic when I tried to test that 😬

@wackbyte
Copy link
Contributor Author

Never mind, it works when I'm not trying to pass it into an extern fn.
I'll try to fix it.

@wackbyte
Copy link
Contributor Author

Wait, no. It doesn't work when I use it in a pub fn 😬

@wackbyte
Copy link
Contributor Author

Here's the script:

pub fn main() {
    let x = -2 % 5;
}

Here's the backtrace.

It looks like the error starts here with the LHS' type being unknown. Maybe it has something to do with the unary minus operator?

@wackbyte
Copy link
Contributor Author

Yeah, it's probably the unary minus operator, as this same error happens with other operators, and it doesn't which side the negative number is on.

@wackbyte
Copy link
Contributor Author

Fixing that's outside the scope of this PR, though ¯\_(ツ)_/¯

(sorry for the wall of text 😅)

@wackbyte
Copy link
Contributor Author

I implemented unary operator IR generation anyways, but the type is still unknown for whatever reason.

@wackbyte
Copy link
Contributor Author

Anyways, this should be working. That unary op stuff doesn't have anything to do with this.

Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I think you got them all. I only have one comment.

crates/mun_codegen/src/ir/body.rs Outdated Show resolved Hide resolved
@baszalmstra
Copy link
Collaborator

Maybe you can add a test like Wodann mentioned using this:

pub fn main() {
    let x = (0-2) % 5;
}

Im missing a few tests to see if the output actually makes sense (I dont exactly know what LLVM does)

@baszalmstra baszalmstra merged commit 5ee17f3 into mun-lang:master Apr 18, 2020
@wackbyte wackbyte deleted the rem-op branch April 19, 2020 16:42
@Wodann Wodann added this to the Mun v0.2 milestone May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants