Implement correct for loop behavior#316
Conversation
|
In order to advance the iterator properly, we need variable mutability. We can return a new iterator for now but that's it |
|
To progress further, we need comparison operators in order for the |
107f18a to
ba56c46
Compare
Codecov Report
@@ Coverage Diff @@
## master #316 +/- ##
==========================================
+ Coverage 92.04% 92.76% +0.72%
==========================================
Files 41 41
Lines 4171 4230 +59
==========================================
+ Hits 3839 3924 +85
+ Misses 332 306 -26
Continue to review full report at Codecov.
|
29b2610 to
cf5a706
Compare
Add println and println_err instead of display
Skallwar
left a comment
There was a problem hiding this comment.
I wonder if this could be done via a jinko! macro combined with a format!. The code is ugly (and that's not your fault) but maybe a jinko! macro will be more elegant and (maybe) more performant?
There is almost no test for this feature, we should add some
Great works 🚀 🔥
| __builtin_string_display("to display", false); | ||
| __builtin_string_display_err("to display on err", true); |
There was a problem hiding this comment.
Not a big fan of this. If the user wants a new line, he just needs to add a '\n' on his string
There was a problem hiding this comment.
Well the issue is that for now these strings aren't parsed correctly... So if we were to do print("hey\n"), then the character \ and the character n would both get printed to the stdout. I think that maybe there should be a FIXME or something in the standard library
There was a problem hiding this comment.
Ok let's go with a FIXME and an issue
| @@ -77,32 +77,133 @@ impl Instruction for Loop { | |||
| // that that result, as a boolean, returns true. If it does, execute the | |||
| // body. If it does not, break from the for. | |||
There was a problem hiding this comment.
I guess this comment needs to be updated
There was a problem hiding this comment.
This is the behavior that I'd still want the loop blocks to have, but yeah it's not implemented right now. I'll add a FIXME
There was a problem hiding this comment.
Ooops I read that too fast. You're right it needs updating
| // We create new variables in the scope, with the required iterator's | ||
| // name from the user. We can create these variables with special names | ||
| // since we are only using them from the interpreter. Here, we prefix | ||
| // them with a plus sign to make sure they do not interact with the user. |
There was a problem hiding this comment.
This should be documented. The user needs to be aware that he is not allowed to use identifier starting with a '+' sign
There was a problem hiding this comment.
I don't know if it explicitly needs to be documented, as if the user tries to do it they will simply encounter a parse error (identifiers can only be comprised of underscores, digits and letters). Here, since we are creating them directly from the interpreter, we're allowed to, but it's an "edge case" and abusing the language since we're not going through the parser
There was a problem hiding this comment.
Documenting it to understand why there is a parser error is useful imao
There was a problem hiding this comment.
Do you mean in the parser or here? And do you mean by emitting an error or adding a comment? Because the user will never see those variables, ever. Think of them as the __<ident> variables we were talking about in gcc
| // let maybe_is_some = |ctx| { | ||
| // let instance = maybe_is_some.execute(ctx).unwrap(); | ||
| // JkBool::from_instance(&instance).0.clone() | ||
| // }; |
| counter = counter + 1; | ||
| } | ||
|
|
||
| // FIXME: Add assertion here |
There was a problem hiding this comment.
This needs to be fixed I guess
There was a problem hiding this comment.
I think it depends on #187 sadly. I'll fix the FIXME
| // // FIXME: This needs to change | ||
| // +iterator = next(+iterator); | ||
| // +maybe_value = current(+iterator); | ||
| // if !+maybe_value.is_some() { break } |
There was a problem hiding this comment.
Are we not doing this already? iterator.next() is in this PR
There was a problem hiding this comment.
Yes, but ideally we should simply be mutating the +iterator variable instead of creating a new iterator each time. Something like
func next(iter: &mut Iter) {
...
}Co-authored-by: Skallwar <esteban.blanc@epita.fr>
08cbdc4 to
663d019
Compare
Co-authored-by: Skallwar <esteban.blanc@epita.fr>
Co-authored-by: Skallwar <esteban.blanc@epita.fr>
Co-authored-by: Skallwar <esteban.blanc@epita.fr>
Co-authored-by: Skallwar <esteban.blanc@epita.fr>
Closes #132
Closes #322