Jump to content
  • Advertisement
  • entries
    359
  • comments
    237
  • views
    189653

Tangent: Yield, part 4

Sign in to follow this  
Telastyn

255 views

Tonight I had a tiny bit of spare time to devote to tracking down the yield bug. Turned out to be three little bugs. The first was a mistake in pulling the stackframes off during the actual yield call. It kept the top frame pointing to itself for restart rather than just letting it restart. The second was a missing part of while loops. If the loop knew it could yield, it didn't reset the execution pointer when it was time to restart the loop. The third was improperly handling the 'end of method' implicit return. That causes the method to run 1 extra time before signaling 'done' in some cases.

The first two have been fixed, the third hasn't yet. I'll need to add that implied return statement or some workaround that detects it was hit and change behaviors.


But the target example code has been reached, so yield is now considered functional (if yet in need of polish). Behold, a simple Fibonacci program:


public yields<int> fib(){
local int a = 0;
local int b = 1;
local int c;

yield(a);
yield(b);
while(c < 100){
c = a + b;
yield(c);
a = b;
b = c;
}
return();
}

public static void main(){
foreach(int i in fib()){
print i " ";
}
}




The next test I think will involve making a functional language style take. That will involve testing yield generators with parameters, and phrase style yields. Eventually I want something like

foreach( int i in take 5 from the Fibonacci Sequence ){ ... }

to do what it means (possibly replacing 'take' with something more descriptive).
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!