🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: foreach beginnings

Published January 19, 2009
Advertisement
As usual, I'm not as bright as I think. the yield stuff ran into a roadblock because the vague design proved not viable for anything beyond the simplest case. And it's not the sort of thing that you can just look up... Full coroutines are not the sort of thing I want (or rather want to dedicate the time to implement well), and everything else is how to hack the behavior using goto or exceptions or C macros.

So I went to work on foreach. The thread about for loops in the last posting was actually pretty insightful. In general people seem not to care for the C style loop so much. And while it might be interesting to leave such a construct to the library, I think it's something that's used enough that it should be dealt with.

"Make the easy things easy."

So, foreach will exist at least as a statement; mostly the same as C#:

foreach (  in ){...}


It's slightly unlike C# in that it is built after generics. The IEnumerable expression must be of a compatible type to the variable; I'm not auto-casting from Object.

The parser and code generation worked pretty well with minor bughunting. Unfortunately, I ran into IEnumerable importing problems (since fixed) and bug #14 (the runtime doesn't generate local variables within sub-blocks). So it looks like I'll need to get to that bug a little before I anticipated.

That'll be a bit of work, but should then allow this to work as expected. Then on to yield completion and a few example programs. By then I'll probably need to do some backfill on phrases and generics where I missed some stuff.
Previous Entry Tangent: Yield, part 1
Next Entry Tangent: foreach.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement