How not to make a virtual machine (label-based threading)

I’m a better coder than when I woke up this morning, even if I don’t have anything substantive (like an improved virtual machine) to show for it.  For example, I now know:

  • gcc lets you get the address of a local label by saying “&&labelname”.
  • gcc lets you jump to an address (“calculated goto”) stored in a void pointer by saying “goto *ptr”.
  • gcc lets you define nested C functions.
  • Visual Studio doesn’t let you do any of these things – but you can work around that with inline assembly.

It’s all Joe Eager’s fault (I kid, I kid).  Joe mentioned something about threaded code this morning, and soon enough one thing led to another and I was making proof-of-concept virtual machines to test out threaded code with local label jumps – this in contrast to my current “one big switch” architecture and my old threaded code with function pointers.

Read the rest of this entry »

MadStone postmortem

Jacob’s MadStone postmortem report was published on Gamasutra today.  It’s a really interesting read, check it out!

http://www.gamasutra.com/view/feature/3903/postmortem_riverman_medias_.php

Slag gen2: First results

After spending months rewriting the compiler, weeks on the new virtual machine, and days debugging various low-level errors, I’ve gotten everything stable enough to compile & run my prime number speed test (and consequently a good chunk of the standard library).  The results:

Gen1 virtual machine: 25.40 seconds.

Gen2 virtual machine: 11.87 seconds.

Ergo: wooooooo!

Read the rest of this entry »

New Age Gauntlet

I’ve been playing a lot of Left 4 Dead lately.  It’s super-fun: in each of the levels (4 scenarios with 5 big levels each) you and three other players must survive hordes of zombies to reach the Safe Room or the transport out of the city.

Farm

Read the rest of this entry »

Understanding class members and singletons

Here’s a bit of background on class members and singletons to flesh out my previous post on automatic singletons.

First let’s look at regular classes and objects.  A class defines how an object behaves and what properties it has.  If we wanted to make an adventure-RPG we might define classes for Torch, Horse, Ration, Weapon, and others.  In Slag:

Read the rest of this entry »

Automatic singletons and eliminating class members

It’s the same story as always.  After being mildly irritated by something for a long period of time, I finally notice it and then decide to do something about it.

This time it’s class properties and methods – also known as static variables and methods.  Not only do they complicate my compilers (“do everything twice… once for the class members and once for the object members”) and not only are they hard for beginners to grasp, but they’re just plain awkward to use.  Inheritance doesn’t work quite right (you can’t use super.method_name()), you can’t give anything a “this” reference, and you can’t get Class object metadata or do a toString().

Thinking about it today, I realized something important and fundamental: class members are a kludge.

Read the rest of this entry »

Access methods potentially harmful

As one of the last born into the “C generation”, I learned programming in the twilight of the procedural years. Like many others, I initially fit the newly-emerging object-oriented concepts into my C worldview, thinking of objects as “structures with access methods”: if you have a Clock object with {hours,minutes} values, then you write a pair of access methods for each value: getHours(), setHours(), getMinutes(), and setMinutes(), allowing for access control and implementation independence. Sounds good, right?

Read the rest of this entry »

Make yourself useful, do-while

Here’s a tedious loop pattern I find myself typing all the time:

    control-code
    while (condition)
      body
      control-code
    endWhile

Read the rest of this entry »

Things aren’t looking good for repeat..until

I’m probably going to cut “repeat..until” from gen2 Slag.

  • I used it literally 4 times in the 10,000 lines of the Slag standard library.
  • It can easily be replaced with a while() loop.
  • I always forget it’s there until I try and use “repeat” as a variable name.
  • Likewise, I’d kind of like to use “repeat” as a variable name again.

I guess it’s just one of those things that sounded cool but never proved itself.

Murphy mentioned the other day that every feature proposal in C# starts out with negative 100 points.  People then try to come up useful cases for the feature, each rated with some number of points to offset the initial score.  Only features that end up with a net positive score are actually implemented.

It’s a neat idea, although thankfully since Slag is just a little fish (but growing!) I can afford to just put things in & rip ‘em out later.  Anyways, “repeat..until” is currently at (-99), so I’m gonna ditch it.

Oh wait – let’s look at the MadStone source code!  Here we go.  Hmm…. zero uses.  Yep.

Fast call dispatch for aspects and interfaces

Up until now, the call-related speed issue I’ve been most worried about in the Slag VM has been aspect call dispatch (e.g. interface call dispatch).  Ironically, while thinking about multimethods (previous post) I just figured out a way to turn aspect calls into standard dynamic calls!

Read the rest of this entry »