October 30, 2003 5:02 pm (permalink)

A day at university

It was almost 10 am when I finished hacking this morning. Got some coffee, then drove to university.

Sounds like a normal student's day, but not for me - for me it was more like the first day at university after no longer being a student or something like that. Now being a full time hacker, I just went there to say goodbye to everyone. When I arrived there, I realized that I could really feel happy because of this - university is far from what it used to be when I started studying back in '96.

First of all, it's almost impossible to find any parking space - if you do find something which looks like one, well, you quickly realize that a lot of today's students urgently need to go back to driver's school - and learn how to park a car without consuming two or more parking spaces. Thought of having a second breakfast in the cafeteria, but no ... - it takes like forever to get something to eat or drink and then it's so overcrowded, dirty and people are smoking everywhere.

Walked around a bit and then decided to take the more expensive food in the cafeteria 'cause I just didn't feel like waiting in a queue for half an hour or so. Well, it was really expensive compared to Burger King or the local pizza service - payed almost EUR 8 with the salad, coffe and a dessert and it didn't taste very good.

Realized that it's a real nightmare to find a free table - most tables are already occupied and the ones which are not are full with other people's garbage. To make it worse, people are smoking all around you and you don't really feel compfortable. So, before I could eat, I found myself cleaning the table from other people's garbage. A task which isn't easy at all: either you bring the garbage to the dustbin like every good citizen does, but then you quickly realize that the table is already taken by someone else when you come back - or just throw everything onto the floor.

Finally finished eating - well, about half of it, it didn't taste good enough that I wanted to eat more than neccessary. Then, I just left - leaving the dishes and everything on the table .... "excuse me, sir! You must bring this ..." a staff member complained. My response was something like "f... you, I already cleaned two tables!"

Met a friend outside who was about to go to his class. We talked a bit, then he went inside and I went to my car. A few minutes later, he called me telling me that this class is so overcrowded that he couldn't even fit through the door! Hey, something should tell the fire department that there are four times more people in this room than allowed ...

Finally sat in my car, turned on the engines, but no .... of course, someone was too stupid to drive and had an accident at the exit of the parking lot, so I needed to wait about an hour until police and the tow-away vehicle where there. Found it very amusing to see other people sitting in their cars honking for a few minutes, then went to a pub nearby, got some hot tee and read the newspaper.

About an hour later, the jam was gone and I could finally drive home ....

Back home, I felt really happy that I'm not a student anymore and opened a Bofferding (a very good beer from Luxemburg), time to relax and enjoy my evening :-)

Posted by martin at October 30, 2003 5:02 pm.

October 30, 2003 09:28 am (permalink)

Mini and generics

Got up really early today. After checking my mail, I realized that Paolo and Zoltan had a really good idea how to solve these problems with mini. Hacked the whole day on it and finally got it working.

Instead of dealing with MONO_TYPE_VAR and MONO_TYPE_MVAR in mini, we just JIT the method for each instantiation. This creates some overhead since we're creating duplicate machine code for each instantiation, but removes a lot of complexity, so it's just the best and easiest approach for the moment.

Also added two new tests to mcs/tests/ - all tests except gen-12 and gen-21 should now succeed.

Posted by martin at October 30, 2003 09:28 am.

October 27, 2003 11:23 am (permalink)

A long hacking night

As you guys probably already know, this week is PDC week ...

It's currently 11:11 am local time and I hacked all night trying to get at least one of the examples to work. Well, I already realized last week that I could only fix one bug at a time and this strategy really worked out fine for me. However, each time I fixed one problem, another problem showed up - a problem which you could not see before because the problem you just fixed was hiding it ;-)

But hey, that's life of a software developer - and I can live very well with it. I mean, I acually just fixed a problem - there's one problem which is now gone and which'll never show up again, so I actually did something productive ...

However, sometimes you still have the aim and the passion of trying to fix everything at once - just to see one of these higly complex examples actually work. Well, that's fine - as long as you don't get too frustrated if you fail.

Tonight, I finally realized that it's still a very long way until we can actually run these examples - it may even be more difficult than compiling them. The problem is mini and the runtime: we need to add support for generic type and method parameters (MONO_TYPE_VAR and MONO_TYPE_MVAR) before we can run the more complicated examples.

Have a look at the following example:

class Foo<T> { T t; public Foo (T t) { this.t = t; } public void Hello () { // doesn't work in mini Test (t); } public void Test (T t) { } } class X { static void Main () { Foo<int> foo = new Foo<int> (); // Works foo.Hello (); // Works foo.Test (4); }

The problem is the Test (t) call in Foo.Hello() - at the time this method is JITed, we cannot know which type t is - for instance, it could be a reference or a value type.

Posted by martin at October 27, 2003 11:23 am.

October 25, 2003 12:41 pm (permalink)

My new television

Hacked the whole night until almost 1 pm on the problem I posted yesterday and I'm now almost done with it. My phone rang a few hours after I finally felt asleep, took a shower and went shopping with a friend. We finally went to Wal Mart, got some French fries and went inside ...

The funny thing is that I just wanted to by a cable and some CD-R's, but then I came home with the biggest television they had :-)

Martin and his television

As you can see on the picture, I really enjoyed watching Matrix on this huge screen :-)

Posted by martin at October 25, 2003 12:41 pm.

October 24, 2003 05:34 am (permalink)

Inheriting from a constructed type

While playing around with yesterday's example, I realized that there's another problem which needs to be solved first:

class Foo<T> { public void Hello () { } public void World (T t) { Hello (); } } class Bar : Foo<int> { public void Test () { Hello (); World (4); } }

The problem is that gmcs calls ConstructedType.ResolveAsTypeStep on Foo<int> before defining Foo's members. This makes the member lookup for Hello fail.

Posted by martin at October 24, 2003 05:34 am.

October 23, 2003 04:21 am (permalink)

A really exciting basketball game

Today, I watched a really exciting basketball game of our local club, TBB Trier. I was one of the first people who bought tickets last week, so we had excellent seats and the game was exciting until the very last second :-)

Not much news in C# generics land, however. You probably still remember the example I blogged yesterday, the

abstract class Ordered<T> { ... } class Point : Ordered<Point> { ... } one. I'm currenlty working on this.
Posted by martin at October 23, 2003 04:21 am.

October 21, 2003 06:32 am (permalink)

Default value expressions

Adding support for so-called default value expressions wan't really hard. Here's a small example:

public class Stack<T> { T t; public Stack (int n) { t = new T [n]; for (int i = 0; i < n; i++) t [i] = T.default; } }

The basic idea behind this is that a type parameter can either be a reference or a value type and that you may not know at compile time which one it is. This is also the reason why there is no explicit conversion between null and a type parameter.

Note that you may also use default on an arbitrary type, but the left-hand site of the default value expression must resolve to a type.

Posted by martin at October 21, 2003 06:32 am.

October 21, 2003 12:58 am (permalink)

About the examples

A few weeks ago, Miguel pointed me to an URL with C# generics examples: http://www.dina.kvl.dk/~sestoft/gcsharp/.

Today, I finally found the time to have a more in-depth look at them and I was wondering whether we can already compile them with gmcs.

Posted by martin at October 21, 2003 12:58 am.

October 17, 2003 6:34 pm (permalink)

All good things ... must come to an end

Tonight, I finally managed to watch the final three episodes of Dawson's Creek. It was a really long night, I started with episode 6x18 in the afternoon and then hacked two hours, watched another episode, hacked another two hours, ....

Finally, around 5 am, after finishing a great part of the generic method stuff and before watching 6x22 I quickly drove to the gas station, got some beer and chips and then enjoyed the last three episodes without any interruption.

Now, I'm still a bit tired because I went to bed around 9 am, but I must admit it was really worth it. I shouldn't write too much here 'cause the final season did not run on television here in Germany, so if anyone from Germany reads this, watch it for yourself and enjoy it :-)

For the next endless nights, I think I'll move on to the 5th season of Charmed which I already have almost completely. I could also watch the 4th season of Angel, but a good friend of mine is a big Angel fan, so we'll probably watch tihs together sometime.
Posted by martin at October 17, 2003 6:34 pm.

October 16, 2003 8:42 pm (permalink)

More reflection / runtime stuff

Hmm, I think I finally got things right wrt. type parameters of generic methods. Things are a bit difficult since the IL just contains the number of the generic parameter in the method signature, but we need to create a "real" class with the correct constraints and everything.
Posted by martin at October 16, 2003 8:42 pm.

October 11, 2003 7:01 pm (permalink)

A missed soccer game

Ok, I was really stupid today. Really, really stupid.

I planned everything. I had enough beer, popcorn, chips, told everyone that I'd be unavailable tonight, even got two Double Whopper's from Burger Kind so I won't depend on the pizza service delivering in time - and then ....

I missed the game :-(

I just blindly assumed that any important soccer games are in the evening, somewhere after 8 pm, but not in the afternoon. So now I can thank Ballack, Bobic and Kuranyi who shot the three winning goals and congratulate our national soccer team.
Posted by martin at October 11, 2003 7:01 pm.

October 10, 2003 11:19 am (permalink)

Generic Methods and Reflection

FedEx just woke me up and delivered me a really cool Novell backpack :-) Could not sleep very well anyways, so I just got more coffee and started hacking again.

Today, I'll do the reflection stuff for generic methods.

Posted by martin at October 10, 2003 11:19 am.

October 10, 2003 08:12 am (permalink)

Generic Methods

Before I turned on the television, I added some preliminary support for "real" generic methods, for instance:

class Stack<T> { public static void Hello (T t, S s, U u) { U v = u; } }

The runtime part was really easy and straightforward so far. There's just one small problem: TypeBuilder.DefineMethod() takes a Type[] array of the method's parameter types - so we need to create the generic parameters before we have the MethodBuilder. To keep things simple, I just added an index field to MonoReflectionGenericParam and added support for it to mono_reflection_define_generic_parameter(). There's now an overloaded version of TypeBuilder.DefineGenericParameter() which takes an index argument.

Adding support to gmcs was a bit more difficult as I already mentioned in my last blog. I added a new GenericMethod class (derives from DeclSpace) which is created just before calling new Method (...). We add the type parameters to the GenericMethod and use it as DeclSpace to lookup parameters and local variables.

There's a new tests/gen-15.cs example which can now be compiled by gmcs.

We cannot call generic methods yet, I need to add support to the runtime, class libs and gmcs for this first.

Posted by martin at October 10, 2003 08:12 am.

October 10, 2003 06:09 am (permalink)

A long and cold night

I just wanted to watch Episode 6x15 of Dawson's Creek and then continue hacking on C# generics, but then fate decided otherwise. Sometimes, people just don't think about the consequences of their actions and how this may affect other people's life. Got some very strong coffee after talking three hours on the phone and now I'm going back to C# generics. Maybe I also find the time to look at Ben's bug, let's see.
Posted by martin at October 10, 2003 06:09 am.

October 09, 2003 7:17 pm (permalink)

Generic Methods

The weather is still bad, it stopped raining this afternoon, but it's still cold. Unfortunately, I had no more coffee so I needed to drive to the next gas station to get some. Realized that a flight to Hawaii is about $1750, so I can't escape the rain and the cold. After breakfast, I realized that I'm already feeling a lot better and started with generic methods.

Started to do some MCS changes in preparation for generic methods. To keep the changes between mcs and gmcs to a minimum, I did all the DeclSpace and TypeContainer in the normal mcs and then merged things into gmcs when I was done with it.

In the non-generic case, a Method is always in it's class/struct's TypeContainer and this TypeContainer is passed to Method.Define() and Method.Emit(). For generic methods, we need to create a special GenericMethod instance which is derived from DeclSpace and which is used to lookup parameters and locals there.
Posted by martin at October 09, 2003 7:17 pm.

October 08, 2003 9:51 pm (permalink)

Runtime stuff

I'm finally done with my runtime changes. Realized that I was previously creating incorrect IL, so adding support for MONO_TYPE_VAR and MONO_TYPE_MVAR to mini isn't neccessary at all.

The next thing are "real" generic methods.
Posted by martin at October 08, 2003 9:51 pm.

October 08, 2003 5:53 pm (permalink)

Sick and cold

Spent most of yesterday in bed with a bad cold. Went to the doctor who prescribed me something and now I'm already feeling a lot better. Still a bit tired, but black tee helps ....

After playing a bit with ilasm and monodis, I think I finally know how this reflection stuff should work.
Posted by martin at October 08, 2003 5:53 pm.

October 06, 2003 10:54 am (permalink)

Instantiating generic types

The first thing which needs to be done is getting Type.GetMethods() right wrt. generic instances.

Suppose you have a generic type definition like this:

public class Stack<S> { public void Hello (S s) { } } public class Test<T> : Stack<T> { public void Foo (T t) { } }

Now, you want to instantiate Test to Test<int> - and you want to do this in the same assembly. This means that the underlying generic type is actually a TypeBuilder.

We need to consider two things here:

  • We can't just use klass->methods, but need to access the tb->methods array on the TypeBuilder instead. We still need to inflate the methods and we should just do this once.
  • When calling such a method, we need to insert a metadata fixup token and do a fixup just like we do it for a normal MethodBuilder.

I'm using a small trick to do this: the actual instantiation of a generic type is done in mono_reflection_bind_generic_parameters() which is called from Type.BindGenericParameters(). If the underlying generic type is a TypeBuilder, we populate iklass->methods from tb->methods and tb->ctors.

Posted by martin at October 06, 2003 10:54 am.

October 06, 2003 10:45 am (permalink)

Back from my weekend

Had a rather exciting weekend. A few friends were here, I showed them the city and then and we had a lot of fun :-)

Now, it's time to go back hacking and do something productive. I'm now trying to get all this runtime and reflection stuff right.
Posted by martin at October 06, 2003 10:45 am.

October 03, 2003 12:16 am (permalink)

Today, I switched to a new, much cooler blogging engine. My old blog can still be found here.
Posted by martin at October 03, 2003 12:16 am.