JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Apr 03, 2007 7:17 pm Post subject: April 3 -- Coroutines, syntactic sugar, API reworked |
|
|
Good stuff!
Added/Removed
- Function literals can now have just an expression as their body, such as "function(x) x * x". This is turned into "function(x) { return x * x; }", but is much quicker to type.
- Added array.map(), array.apply(), array.reduce(), array.each(), array.filter(), array.find(), and array.bsearch(). Some of these go very nicely with the new function literal syntax
- Added postfix ++ and --, but since ++ and -- can't return values in MiniD, they are functionally equivalent to prefix ++ and --. They are also just converted to "+= 1" or "-= 1". This is mostly for convenience (for those of us who usually write their increments and decrements postfix (like me)).
- Added the "default assignment" operator. Instead of writing "if(x is null) x = 5;", you can now write "x ?= 5;". This does the exact same thing. Very useful for default parameters.
- Removed the Userdata type. User types should be done through classes, and classes offer more functionality and type safety than Userdata.
- Removed the Delegate type. It just doesn't really seem all that useful now.
- Added coroutines, and a new type to represent them, Thread. This means two new syntactic constructions -- coroutine expressions and yield expressions -- and some new baselib functions, namely isThread and currentThread.
- Added a baselib curry() function to kind of take the place of delegates.
Changed
- string.repeat() now accepts 0 repetitions as valid.
- Changed declarations a bit. Now, if neither "local" nor "global" are specified for a function or class, it defaults to "local" instead of "undefined." The "undefined" location has been removed; it was really annoying. Instead, to do forward declarations, just declare the local and assign a literal to it later.
- Function and class literals now have an optional name so you can name them something other than "literal at blah(10:20)" or something.
- table.each() now returns the table on which it was called.
- Reorganized some of the compiler. Basically refactored some stuff I've been meaning to for a while. It makes it a bit more robust as well, as far as what syntactic constructions are allowed.
- Changed the grammar of expressions slightly, since op= expressions, increment, and decrement are more like assignments than they are expressions.
- Changed parenthesized expressions so that if they are around a multiple-return expression (a function call or a 'vararg' expression), they will make that expression always return exactly 1 result, no more and no less, like in Lua.
- Big API changes. The .value functions in MDValue have been replaced with a templated opAssign. Templated .as() and .to() functions have been added to MDValue for conversion to D types. MDState.pop(), .getUpvalue(), and .getContext() and MDGlobalState.getGlobal() have been templated. The MDState.get___Param() functions have been merged into one templated .getParam() function. These changes make the API more consistent and flexible, and will also simplify writing the binding library.
- MDClosures can now be created with function pointers as well as delegates. This is also reflected in MDGlobalState.newClosure().
- Native function closures now take two parameters: the MDState as before, and a new uint for the number of parameters passed to the function. The MDState.numParams() function has been removed as a result.
- Changed the compiler to allow parenthesized expressions to come at the beginning of statements, since this can happen.
- Moved some source files around so it makes more sense now (test, minidc, and mdcl and their accompanying build files are now no longer in the minid package). This also makes it easier to compile these programs, since they no longer need a special flag to the compiler for the import path.
- Tables can no longer have null keys. Null keys mess up iteration.
Fixed
- Fixed a bug in the compiler with foreach loops where complex expressions in the container part would overwrite each other.
- Fixed a bug in tables where keys with different types that hashed to the same location (i.e. integer 97 and character 'a') would give an error when they're not supposed to. As a result, the MDValue opCmp overload now no longer throws errors when comparing different types. What used to be opCmp has now been renamed to compare, the old opEquals has been removed, and what used to be rawEquals is now opEquals.
- Fixed a bug in the oslib where it wouldn't compile under linux (stupid semantic error).
Hope the coroutines don't have many bugs.
I've got to get on documenting all this stuff. |
|