Function allocates object given it's class name and calls it's constructor.
Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- include/vm/class.h | 1 + test/arch-x86/Makefile | 2 +- test/jamvm/class-stub.c | 41 +++++++++++++++++++++++++++++++++++++++++ vm/class.c | 18 ++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletions(-) create mode 100644 test/jamvm/class-stub.c diff --git a/include/vm/class.h b/include/vm/class.h index 4ca0274..de63d5e 100644 --- a/include/vm/class.h +++ b/include/vm/class.h @@ -3,6 +3,7 @@ #include <vm/vm.h> +struct object *create_object(char *class_name); unsigned long is_object_instance_of(struct object *obj, struct object *type); void check_null(struct object *obj); void check_array(struct object *obj, unsigned int index); diff --git a/test/arch-x86/Makefile b/test/arch-x86/Makefile index 35a2981..b271f16 100644 --- a/test/arch-x86/Makefile +++ b/test/arch-x86/Makefile @@ -26,6 +26,7 @@ OBJS = \ ../jamvm/lock.o \ ../jamvm/thread-stub.o \ ../jamvm/resolve-stub.o \ + ../jamvm/class-stub.o \ ../../arch/x86/backtrace.o \ ../../vm/buffer.o \ ../../vm/die.o \ @@ -34,7 +35,6 @@ OBJS = \ ../../vm/string.o \ ../../vm/types.o \ ../../vm/zalloc.o \ - ../../vm/class.o \ ../../vm/radix-tree.o \ ../../jit/alloc.o \ ../../jit/basic-block.o \ diff --git a/test/jamvm/class-stub.c b/test/jamvm/class-stub.c new file mode 100644 index 0000000..63ae791 --- /dev/null +++ b/test/jamvm/class-stub.c @@ -0,0 +1,41 @@ +#include <vm/vm.h> +#include <stdlib.h> + +struct object *create_object(char *class_name) +{ + return NULL; +} + +unsigned long is_object_instance_of(struct object *obj, struct object *type) +{ + if (!obj) + return 0; + + return isInstanceOf(type, obj->class); +} + +void check_null(struct object *obj) +{ + if (!obj) + abort(); +} + +void check_array(struct object *obj, unsigned int index) +{ + struct classblock *cb = CLASS_CB(obj->class); + + if (!IS_ARRAY(cb)) + abort(); + + if (index >= ARRAY_LEN(obj)) + abort(); +} + +void check_cast(struct object *obj, struct object *type) +{ + if (!obj) + return; + + if (!isInstanceOf(type, obj->class)) + abort(); +} diff --git a/vm/class.c b/vm/class.c index c0e1e61..c62fdcc 100644 --- a/vm/class.c +++ b/vm/class.c @@ -27,6 +27,24 @@ #include <vm/vm.h> #include <stdlib.h> +struct object *create_object(char *class_name) +{ + Class *e_class; + struct object *obj; + MethodBlock *init; + + e_class = findSystemClass(class_name); + obj = allocObject(e_class); + if (!obj) + return NULL; + + init = lookupMethod(e_class, "<init>", "()V"); + if (init) + executeMethod(obj, init); + + return obj; +} + unsigned long is_object_instance_of(struct object *obj, struct object *type) { if (!obj) -- 1.6.0.6 ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel