Commit Graph
483 Commits
Author SHA1 Message Date
Bob Nystrom 48db3a9620 Start adding support for runtime errors:
- Primitives can now signal an error.
- An error prints a callstack and ends the current (and right 
  now only) fiber.
- Arithmetic operators error if the operand is not a number.
- Real error for method not found.
- Associate source file name, and method names with functions.
- Debug line number info for functions.

Unfortunately, this regresses perf on fib about 15%, mostly
because of the better checking in arithmetic ops.

There's still a bunch of clean up to do, but this is a big step
in the right direction.
2014-01-01 13:25:24 -08:00
Bob Nystrom c8fe27d6c4 Allow empty blocks. 2013-12-29 10:46:21 -08:00
Bob Nystrom a8c725ea3f Use growable buffers for bytecode and strings.
Ensures the compiler can handle long chunks of code and strings.
2013-12-27 07:22:43 -08:00
Bob Nystrom 507e89d3b3 Range operators!
Added ".." and "..." infix operators. Num implements them to
return Range objects. Those in turn implement the iterator
protocol, so now numeric for loops are easy:

    for (i in 1..10) { ... }

I also cleaned up the Wren benchmarks to use this.

In the process, I discovered the method_call benchmark really
just showed loop peformance, so I unrolled the loops in all of
the languages to stress method calls.
2013-12-25 15:01:45 -08:00
Bob Nystrom e6e7b2594c For loops! 2013-12-24 21:04:11 -08:00
Bob Nystrom 1e0401bfc1 Allow statement bodies for flow control.
This means this works now:

  if (foo) return bar
2013-12-24 10:27:48 -08:00
Bob Nystrom 8c85232b90 Break statements. 2013-12-24 10:15:50 -08:00
Bob Nystrom 5a2fde0c2c Collapse duplicate constants and check for overflow. 2013-12-23 15:08:47 -08:00
Bob Nystrom c8cb0be816 Better handling for lexing errors. 2013-12-23 14:51:06 -08:00
Bob Nystrom 1503e74233 Get rid of unused DUP instruction. 2013-12-23 11:37:47 -08:00
Bob Nystrom 9235a7e38f Fields in closures. 2013-12-23 11:17:40 -08:00
Bob Nystrom ad1fcf66bc Superclass calls in closures. 2013-12-22 20:46:12 -08:00
Bob Nystrom 3c8b4c009f Allow variables without initializers. 2013-12-22 18:47:58 -08:00
Bob Nystrom 7868287f89 Make IO.write() call toString on its argument. 2013-12-22 11:50:00 -08:00
Bob Nystrom 2ec01c558f Clean up the root of the class/metaclass hierarchy. 2013-12-21 20:44:37 -08:00
Bob Nystrom 6c3aa85228 Make IO a static class instead of a singleton. 2013-12-21 19:25:09 -08:00
Bob Nystrom 24a6f4cd8c Closing over "this". 2013-12-21 15:55:08 -08:00
Bob Nystrom 76ac818eaf Subscript setters. 2013-12-21 09:37:59 -08:00
Bob Nystrom f2b036420d Fix a bunch of test TODOs.
- Added a bunch of tests.
- Removed some TODOs for stuff that's already done.
- Made list literals handle newlines better.
2013-12-20 12:42:11 -08:00
Bob Nystrom e83d0bb360 Setters! 2013-12-20 07:05:31 -08:00
Bob Nystrom f9099791a1 Add another test for constructor syntax. 2013-12-19 09:10:45 -08:00
Bob Nystrom 4d67f2270a Use more conventional syntax for constructors.
They are now invoked like "new Foo".
Also, superclass constructors are now much less semantically
and syntactically weird. Since the instance is created before
any constructor is called, there's no point in time where the
instance isn't there.
2013-12-19 07:02:27 -08:00
Bob Nystrom e7cf8ffe2e Make method_call benchmark use inheritance.
This also fixes a bug where constructors weren't being bound
correctly, and eliminates some unneeded instructions when
compiling ifs.

I also tweaked the other method_call languages to match Wren's.
Since Wren needs to do a super call to get to the parent _count,
the other languages do now too.

This is nice too because it means we're benchmarking super 
calls.
2013-12-18 07:37:41 -08:00
Bob Nystrom 271fcec81b Start getting superclass constructors working.
This also means the metaclass inheritance hierarchy parallels
the regular inheritance chain so that the subclass can find
the superclass constructor.
2013-12-17 09:39:05 -08:00
Bob Nystrom 70e548657e Don't allow "super" outside of methods. 2013-12-15 22:08:40 -08:00
Bob Nystrom f5e4f95069 Write some more scope edge case tests. 2013-12-14 16:36:19 -08:00
Bob Nystrom 7fe60499db Get rid of my name from TODOs. Anyone can do them. 2013-12-14 15:28:18 -08:00
Bob Nystrom d54bca3067 Get basic superclass method calls working. 2013-12-13 08:37:49 -08:00
Bob Nystrom 510e3fc383 Add test for default constructor. 2013-12-10 21:58:02 -08:00
Bob Nystrom c1cfe1b9f6 Handle inherited fields correctly. 2013-12-10 16:13:25 -08:00
Bob Nystrom 3f24515496 Don't allow method names to overflow. 2013-12-06 20:09:43 -08:00
Bob Nystrom 6a0d550562 Bitwise ~ operator. 2013-12-04 22:09:31 -08:00
Bob Nystrom c91fcd12cc Treat ";" like newlines. 2013-12-04 19:12:21 -08:00
Bob Nystrom 157944aa27 Get closures working!
In the process, I had to change the grammar. There is now a strong
separation between statements and expressions. The code was just wrong
before when it popped locals at the end of a block scope because there
could be temporaries on the stack if the block was in expression
position. This fixes that.

Still need to implement closing over `this`.
2013-12-04 07:43:50 -08:00
Bob Nystrom 60c97b5c2f Make sure we don't go over the maximum number of locals. 2013-11-30 18:51:27 -08:00
Bob Nystrom 88852960ca Handle local variable shadowing. 2013-11-30 18:28:01 -08:00
Bob Nystrom b390bdf604 Clean up constructor tests. 2013-11-29 15:21:36 -08:00
Bob Nystrom 325bb281a5 Allow 16 arguments, and handle going over that correctly. 2013-11-29 15:08:27 -08:00
Bob Nystrom 5f1d5cfa85 Do not allow fields outside of classes. 2013-11-29 10:53:56 -08:00
Bob Nystrom 1bfa252a70 List.removeAt(). 2013-11-27 10:20:32 -08:00
Bob Nystrom f8ded27376 List.clear and List.insert(). 2013-11-26 23:11:11 -08:00
Bob Nystrom 56449cdbef Reorganize tests. 2013-11-26 22:52:00 -08:00
Bob Nystrom 897a396599 List.add() method. 2013-11-26 18:02:10 -08:00
Bob Nystrom eaeec01dc6 Get inheritance and core classes more correctly wired up. 2013-11-26 07:52:37 -08:00
Bob Nystrom c99f4d7834 Subscript operator for lists. 2013-11-24 19:08:46 -08:00
Bob Nystrom 7a343f2ecf List literals. 2013-11-24 13:38:31 -08:00
Bob Nystrom f9b008e283 Subscript operators! 2013-11-24 10:45:07 -08:00
Bob Nystrom e3e1f7f3d4 Start working on string escapes. 2013-11-23 21:00:47 -08:00
Bob Nystrom a5bbe81280 Start to get instance fields working. 2013-11-23 14:55:05 -08:00
Bob Nystrom 3b0e962a05 Named, user-defined constructors. 2013-11-20 07:20:16 -08:00