static IEnumerable <SimEvent> Producer(SimEnvironment env, Store <int> store, int n) { var call = env.Call(FibonacciFunc(env, n)); yield return(call); store.Put((int)call.Value); }
static IEnumerable <SimEvent> FibonacciFunc(SimEnvironment env, int n) { if (n <= 0) { yield return(env.Exit(0)); } else if (n == 1) { yield return(env.Exit(1)); } else { var call = env.Call <int>(FibonacciFunc(env, n - 1)); yield return(call); var n1 = call.Value; call = env.Call <int>(FibonacciFunc(env, n - 2)); yield return(call); var n2 = call.Value; yield return(env.Exit(n1 + n2)); } }