Metamorphing Machine I rather be this walking metamorphosis
than having that old formed opinion about everything!

Let's build a transpiler! Part 52

This is the fifty-second post in a series of building a transpiler.
You can find the previous ones here.


What do you think will be printed on the console while running the code below?

using System;

namespace WTFCS
class Program
static void Main()
TestParams(1, 2, null);
TestParams(1, null);

static void TestParams(params object[] values)

It will print 3, 2, and then throw an exception, System.NullReferenceException: Object reference not set to an instance of an object.

When the calling code has more than one argument or no argument at all, C# creates an array to pass to TestParams' method's params parameter.
But when there is only one, and it happens to be the literal null, then it decides to not come up with an array and passes the null as is.
The exception is due to trying to access the Length property on an unset values object.
To circumvent it, we should change that offending line to be:

TestParams(new object[] { null });

Back to business

Last time, I said I was still figuring out what my next step would be.
Believe it or not, it was around four months ago. Things did not play out how I wanted them to.

First, I started to build up a new pretty-printer. For that, I needed to deal with comments properly. A good pretty-printer should not discard comments, after all.
I changed a lot of things, but comments still appeared at random places in the generated HTML.
I had to give up, but now I had a screwed-up codebase. I failed to backup everything before churning code like a mad man.

Then, I had to stop and work on a different project that would get me some money. It did not yet, but I'm close.
After a couple of months, I got back to our transpiler one more time.
I put in my mind that I should have a fully functional VBScript transpiler. The problem is, my code was slow, painstakingly slow. I could not rely on my pool-of-Type trick mentioned here.
I had to give up one more time.

Then I had to go back to that other project for an additional couple of months.
Now that I'm back, I have a codebase that needs cleaning and no clear goal in mind.
Besides that, my urge to have a VB6 compatible transpiler decreased a little with the emergence of twinBASIC.

Having said that, I'm putting the transpiler project on hold. I did not give up entirely yet, though. Let's see how things will go.

Next week we'll see how to deal with unions the VB way.

Andrej Biasic