#include "IoState.h"
#include "IoObject.h"

IoObject *IoVector_proto(void *state);
IoObject *IoBox_proto(void *state);

void IoVectorInit(IoObject *context)
{
IoState *self = ((IoObject *)context)->tag->state;
        IoObject_setSlot_to_(context, SIOSYMBOL("Vector"), IoVector_proto(self));

        IoObject_setSlot_to_(context, SIOSYMBOL("Box"), IoBox_proto(self));
	char *s;

	s = "Point := Vector clone setSize(2) \n"
  	"Color := Vector clone setSize(4)\n"
  	"\n"
  	"Box copy := method(box,\n"
  	"    self origin copy(box origin)\n"
  	"    self size copy(box size)\n"
  	")\n"
  	"\n"
  	"Sequence asVector := method(Vector clone copy(self))\n"
  	"\n"
  	"vector := method(\n"
  	"	v := Vector clone setSize(0)\n"
  	"	call message arguments foreach(i, arg, \n"
  	"		v atPut(i, call sender doMessage(arg))\n"
  	"	)\n"
  	"	v\n"
  	")\n"
  	"\n"
  	"Vector append := method(v,\n"
  	"    n := self size\n"
  	"    self setSize(n+1)\n"
  	"    self atPut(n, v)\n"
  	")\n"
  	"\n"
  	"Vector derivative := method(\n"
  	"    last := self at(0)\n"
  	"    for(i, 1, self size - 1,\n"
  	"        v := self at(i)\n"
  	"        self atPut(i - 1, v - last)\n"
  	"        last = v\n"
  	"    )\n"
  	"    self\n"
  	")\n"
  	"\n"
  	"Vector average := method(p,\n"
  	"    last := self at(0)\n"
  	"    for(i, 1, self size - 1,\n"
  	"        v := self at(i)\n"
  	"        self atPut(i - 1, (v + last) / 2)\n"
  	"        last = v\n"
  	"    )\n"
  	"    self\n"
  	")\n"
  	"\n"
  	"List asVector := method(\n"
  	"        v := Vector clone setSize(0)\n"
  	"        self foreach(d, v append(d))\n"
  	"        v\n"
  	")\n"
  	"\n"
  	"Vector do(\n"
  	"	asString := method(self serialized asString)\n"
  	"	\n"
  	"	serialized := method(b, \n"
  	"		if(b == nil, b := Sequence clone)\n"
  	"		b appendSeq(\"vector(\")\n"
  	"		if(size > 0,\n"
  	"			for (i, 0, size - 1,\n"
  	"				if(i > 0, b appendSeq(\", \"))\n"
  	"				b appendSeq(self at(i) asString)\n"
  	"			)\n"
  	"		)\n"
  	"		b appendSeq(\")\")\n"
  	"	)\n"
  	"\n"
  	"	asSimpleString := method(\n"
  	"		result := Sequence clone appendSeq(\"vector(\")\n"
  	"		if(size > 0,\n"
  	"			values := result\n"
  	"			for(i, 0, size - 1,\n"
  	"				if(i > 0, values appendSeq(\", \"))\n"
  	"				values appendSeq(self at(i) asString)\n"
  	"				if(values == result and values size > 30,\n"
  	"					values := Sequence clone\n"
  	"				)\n"
  	"			)\n"
  	"			if(values != result,\n"
  	"				if(values size <= 10,\n"
  	"					result appendSeq(values)\n"
  	"				,\n"
  	"					result appendSeq(\", ...\")\n"
  	"				)\n"
  	"			)\n"
  	"		)\n"
  	"		result appendSeq(\")\")\n"
  	"	)\n"
  	"\n"
  	"	print := method(self serialized print)\n"
  	")\n"
  	"\n"
  	"Box do(\n"
  	"	asString := method(self serialized asString)\n"
  	"	\n"
  	"	serialized := method(b, \n"
  	"		if(b == nil, b := Sequence clone)\n"
  	"		b appendSeq(\"Box clone do(\")\n"
  	"		b appendSeq(\"setOrigin(\")\n"
  	"		origin serialized(b)\n"
  	"		b appendSeq(\"); \")\n"
  	"		b appendSeq(\"setSize(\")\n"
  	"		size serialized(b)\n"
  	"		b appendSeq(\"));\")\n"
  	"	)\n"
  	"\n"
  	"	print := method(self serialized print)\n"
  	")\n"
  	"\n"
  	"Vector";

	IoState_rawOn_doCString_withLabel_(self, context, s, "Vector.io");

}

