I have a nice, elegant (IMO) piece of code that I wrote that I want to port to other languages ββlike C ++, Java, etc.
The problem I am facing is twofold:
- The code uses
yield - The code is very recursive
Getting rid of yield manually is possible, but very tiring - the process is very mechanical and, obviously, automatically.
At the same time, the state machine that the C # compiler translates into this is very ugly - it is practically not applicable for porting. (I tried to decompile it, it's just unreadable.)
I am wondering if I have any other options besides just spending days on this to get rid of yield manually?
Or is there some kind of tool that can convert yield blocks to the (readable) state of the machine, which I can then transfer as normal code?
In case you are interested in what I mean by the term βvery recursiveβ - the code below is basically the code structure (the actual thing is only ~ 66 lines, this is not a very long function):
static IEnumerable<ReturnType> MyRecursiveYielder(args) { if (blah1) yield return foo; else if (blah2) foreach (var foo1 in foo2.Blah()) foreach (var item in MyRecursiveYielder(moreArgs)) yield return item; else { var state = new State(); foreach (var item in blah) foreach (var item2 in MyRecursiveYielder(otherArgs)) foreach (var item3 in blah3) { foreach (var result in MyRecursiveYielder(yetMoreArgs))) yield return result; foobar1(); } while (condition) foreach (var foo in blah) foreach (var result in MyRecursiveYielder(argh))) { if (condition2) foreach (var result in MyRecursiveYielder(almostThere))) yield return result; foobar2(); } } }
source share