[fine] Support assignment to member, loops with iterators
Hmm it's starting to look like something.
This commit is contained in:
parent
3415b1a3f6
commit
239e859eaf
7 changed files with 360 additions and 171 deletions
|
|
@ -42,7 +42,7 @@ fun test() -> f64 {
|
|||
// | 0: LoadArgument(1)
|
||||
// | 1: LoadArgument(0)
|
||||
// | 2: PushString(0)
|
||||
// | 3: PushInt(37)
|
||||
// | 3: PushInt(33)
|
||||
// | 4: NewObject(2)
|
||||
// | 5: Return
|
||||
// | function Line (4 args, 0 locals):
|
||||
|
|
@ -52,7 +52,7 @@ fun test() -> f64 {
|
|||
// | 0: LoadArgument(1)
|
||||
// | 1: LoadArgument(0)
|
||||
// | 2: PushString(0)
|
||||
// | 3: PushInt(44)
|
||||
// | 3: PushInt(40)
|
||||
// | 4: NewObject(2)
|
||||
// | 5: Return
|
||||
// | function test (0 args, 3 locals):
|
||||
|
|
|
|||
|
|
@ -7,15 +7,6 @@ fun test() {
|
|||
let z = f.{let y = 222; foo };
|
||||
}
|
||||
|
||||
// NOTE: The AST allows for generic expressions to the right of the dot.
|
||||
// We need to make sure things are parsed correctly.
|
||||
//
|
||||
// TODO: Better parser recovery will improve the specifics of the errors.
|
||||
//
|
||||
// TODO: This is parsed wrong; the `{` is consumed after the '.' and it
|
||||
// should instead be ignored. This is the "greedy" expression parsing that
|
||||
// matklad talks about in his resilient parser article.
|
||||
//
|
||||
// @expect-errors:
|
||||
// | 7:12: Error at '{': expect ';' to end a let statement
|
||||
// | 7:12: Error at '{': expected an identifier after a '.' in member access
|
||||
// | 7:26: cannot find value foo here
|
||||
|
|
|
|||
|
|
@ -1,3 +1,21 @@
|
|||
class Finished {}
|
||||
let FINISHED = new Finished {};
|
||||
|
||||
class Iterator {
|
||||
current: f64;
|
||||
|
||||
fun next(self) -> f64 or Finished {
|
||||
if self.current < 10 {
|
||||
let result = self.current;
|
||||
self.current = self.current + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
FINISHED
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun test() -> f64 {
|
||||
let result = 1;
|
||||
let i = 0;
|
||||
|
|
@ -5,8 +23,15 @@ fun test() -> f64 {
|
|||
result = result * 2;
|
||||
i = i + 1;
|
||||
}
|
||||
result
|
||||
|
||||
let sum = 0;
|
||||
let it = new Iterator { current: 0 };
|
||||
while it.next() is v: f64 {
|
||||
sum = sum + v;
|
||||
}
|
||||
|
||||
result + sum
|
||||
}
|
||||
|
||||
// @no-errors
|
||||
// @eval: Float(1024.0)
|
||||
// @eval: Float(1069.0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue