2009/7/1 Tomek Grabiec <tgrab...@gmail.com>:
> This field allows to distinguish between regular classes, array classes and
> primitive type classes.
>
> Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
> ---
>  include/vm/class.h |   14 +++++++++++++-
>  vm/class.c         |    1 +
>  vm/classloader.c   |    3 +++
>  3 files changed, 17 insertions(+), 1 deletions(-)
>
> diff --git a/include/vm/class.h b/include/vm/class.h
> index d70cc83..69dc484 100644
> --- a/include/vm/class.h
> +++ b/include/vm/class.h
> @@ -18,10 +18,17 @@ enum vm_class_state {
>        VM_CLASS_INITIALIZED,
>  };
>
> +enum vm_class_kind {
> +       VM_CLASS_KIND_PRIMITIVE,
> +       VM_CLASS_KIND_ARRAY,
> +       VM_CLASS_KIND_REGULAR
> +};
> +
>  struct vm_class {
>        const struct cafebabe_class *class;
>
>        enum vm_class_state state;
> +       enum vm_class_kind kind;

This is just a TINY nitpick, but I think I'd put this member first.

I don't know about you, but I find it more intuitive to let data
dependencies in database scheme go from left to right, e.g. you always
put "id" in the first column because it determines the rest of the
columns.

The new member "kind" determines other fields, for example "class" (if
it's ARRAY or PRIMITIVE, ->class _must always_ be NULL), so it should
come first here too.

>
>        char *name;
>
> @@ -67,7 +74,12 @@ static inline bool vm_class_is_interface(const struct 
> vm_class *vmc)
>
>  static inline bool vm_class_is_array_class(const struct vm_class *vmc)
>  {
> -       return vmc->name && vmc->name[0] == '[';
> +       return vmc->kind == VM_CLASS_KIND_ARRAY;
> +}
> +
> +static inline bool vm_class_is_primitive_class(const struct vm_class *vmc)
> +{
> +       return vmc->kind == VM_CLASS_KIND_PRIMITIVE;
>  }
>
>  struct vm_class *vm_class_resolve_class(const struct vm_class *vmc, uint16_t 
> i);
> diff --git a/vm/class.c b/vm/class.c
> index b48e43a..91ba8da 100644
> --- a/vm/class.c
> +++ b/vm/class.c
> @@ -121,6 +121,7 @@ extern struct vm_class *vm_java_lang_Class;
>  int vm_class_link(struct vm_class *vmc, const struct cafebabe_class *class)
>  {
>        vmc->class = class;
> +       vmc->kind = VM_CLASS_KIND_REGULAR;

For the same reason, the two previous lines should be switched.

>
>        const struct cafebabe_constant_info_class *constant_class;
>        if (cafebabe_class_constant_get_class(class,
> diff --git a/vm/classloader.c b/vm/classloader.c
> index 3096d7e..eff2815 100644
> --- a/vm/classloader.c
> +++ b/vm/classloader.c
> @@ -331,6 +331,7 @@ struct vm_class *load_primitive_array_class(const char 
> *class_name,
>        array_class->object_size = 0;
>        array_class->vtable_size = 0;
>        array_class->primitive_vm_type = class_name_to_vm_type(class_name);
> +       array_class->kind = VM_CLASS_KIND_ARRAY;

...and this should go on top.

>
>        return array_class;
>  }
> @@ -354,6 +355,7 @@ struct vm_class *load_class_array_class(const char 
> *array_class_name,
>        array_class->methods = NULL;
>        array_class->object_size = 0;
>        array_class->vtable_size = 0;
> +       array_class->kind = VM_CLASS_KIND_ARRAY;

And this.

>
>        return array_class;
>  }
> @@ -376,6 +378,7 @@ struct vm_class *classloader_load_primitive(const char 
> *class_name)
>        class->methods = NULL;
>        class->object_size = 0;
>        class->vtable_size = 0;
> +       class->kind = VM_CLASS_KIND_PRIMITIVE;

And this.


But as to the idea of the patch, I completely agree :-)

Acked-by: Vegard Nossum <vegard.nos...@gmail.com>


Vegard

------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to