Squeak 4.0 VM Redesign usingOOC style?

Peter William Lount peter at ActiveInfo.CA
Mon Apr 19 03:22:46 UTC 2004


Note: subject simplifed.

Hi David,

I'm glad that it's somewhat object oriented down below in the squak vm. I'd
expect that from Alan, Dan and the crew.

What I'm suggesting is that the specific Object Oriented C (OOC) "Coding
Style" (http://iolanguage.com/Software/C/Notes/OOC.html), that Steve Dekorte
invented, be used for ALL generated Squeak VM C code and ALL hand written
Squeak C code. This includes the embedding and multiple vm capabilities.
This plain C code style would present people with a very clear Objective-C
like coding style enhancing the readability of the generated and handwritten
code.

An excellent example is here http://iolanguage.com/Software/C/Notes/OOC.tgz.
I've snipped out a part of the example and included it below.

Two files define the "Employee" object class. Notice how there are class
methods as well as instance methods! Each instance method also defines the
receiver of the "message" as "self". This enables the C code within the
methods to refer to "self" and instance variables as "self->variablename".

Since these are simply naming and organization conventions they have little
or no impact upon performance. Ok, maybe, if you want to split hairs, a
minor amount when the receiver is included as the first parameter in
instance methods but that's almost non-existant and certainly worth it for
clarity and the capabilies it provides.

Notice that all "message sends" in the OOC style are "static" sends. There
is no message lookup. That's a simplification that this approach takes. It
works great for programs like "virtual machines" since they need to be fast
anyway and limit what they do.

If "OSWindows" were written in this style a new window could easily be
instantiated. Having a list of them in C would be good but if there is a way
of tracking them in Smalltalk level code that might not be needed. This
would apply for most if not all low level OOC objects in the squeak vm.

I suspect that the vm generator would be easy to adapt to emit this style of
output. Adding the receiver could be a bit interesting. Of course all the
manually written files would need to be converted.

What do you think? If you really want to see a work of beautiful C code (yes
it is possible) take a look at the full source code for the Io Language vm.
Wow!  http://www.iolanguage.com/Downloads/. Also see this source code for
how Io implements multiple virtual machines in one process space and how it
can be "embedded" in another C program. This would enable Squeak to be
embedded in the Apache web server like Perl or PHP can be. This would enable
Squeak to compete with those languages in web serious environments on an
equal footing in terms of system configuration choices with Apache.

All the best,

Peter

The main.c program file contains:

#include <stdio.h>
#include <Employee.h>

int main (int argc, const char * argv[])
{
    Employee *e = Employee_new();
    Person_name_((Person *)e, "John Doe");
    Employee_group_(e, "Sprockets");
    Employee_print(e);
    return 0;
}


File Employee.h contains:

#ifndef Employee_DEFINED
#define Employee_DEFINED 1

#include "Person.h"

typedef struct
{
  Person parent;
  char *group;
} Employee;

Employee *Employee_new(void);
void Employee_init(Employee *self);
void Employee_dealloc(Employee *self);
void Employee_free(Employee *self);

void Employee_group_(Employee *self, char *group);
char *Employee_group(Employee *self);

void Employee_print(Employee *self);

#endif





File Employee.c contains:

#include "Employee.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Employee *Employee_new(void)
{
  Employee *self = calloc(1, sizeof(Employee));
  Employee_init(self);
  return self;
}

void Employee_init(Employee *self)
{
  Person_init((Person *)self);
  Employee_group_(self, "");
}

void Employee_dealloc(Employee *self)
{
  Person_dealloc((Person *)self);
  free(self->group);
  free(self);
}

void Employee_free(Employee *self)
{
  Employee_dealloc(self);
  free(self);
}

void Employee_group_(Employee *self, char *group)
{ self->group = strcpy(realloc(self->group, strlen(group)+1), group); }

char *Employee_group(Employee *self) { return self->group; }

void Employee_print(Employee *self)
{
  printf("direct access:\n");
  printf("name = %s\n", self->parent.name);
  printf("group = %s\n", self->group);

  printf("\nusing accessors:\n");
  printf("name = %s\n", Person_name((Person *)self));
  printf("group = %s\n", Employee_group(self));
}









More information about the Squeak-dev mailing list