diff runtime/array.c @ 7:d61550e2c001

Added current work on new runtime
author Mike Pavone <pavone@retrodev.com>
date Wed, 13 May 2009 00:47:40 -0400
parents
children 3e20ed8959c4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/array.c	Wed May 13 00:47:40 2009 -0400
@@ -0,0 +1,26 @@
+#include "array.h"
+#include "integer.h"
+
+Func(Array,0,
+	;)
+	Ret(0, new_object(TYPE_ARRAY))
+	Return
+EndFunc
+
+Method(Index,Array,2,
+	_t_Int32 * idx;)
+	Param(1,idx,Int32)
+	if (idx->num < 0 || idx->num >= me->numels) {
+		Ret(0, NULL)
+		Ret(1, me)
+	} else {
+		Ret(1, NULL)
+		if (me->contents_type) {
+			Ret(0, copy_from_raw(me->conents_type, (char *)me + sizeof(*me) + (idx->num * sizeof(object *))))
+		} else {
+			Ret(0, add_ref((object *)((char *)me + sizeof(*me) + (idx->num * sizeof(object *)))))
+		}
+		release_ref(me);
+	}
+EndFunc
+