-CFLAGS=-c -g
+CFLAGS=-c -g -Wparentheses
OBJS=lex.yy.o object.o list.o error.o number.o main.o interp.o
mojo: $(OBJS)
#include "mstrings.h"
+struct mojo_string* dup_string(char *s)
+{
+
+ struct mojo_string *str = zalloc(sizeof(struct mojo_list));
+ int len = strlen(s);
+ str->contents = strdup(s);
+ str->length = len;
+
+ return str;
+}
+
+void free_string(struct mojo_string *s)
+{
+ if (s == NULL)
+ return;
+
+ free(s->contents);
+ free(s);
+}
+
void create_string_object(void)
{
/* init number object */
number_object = clone_object(base_object);
number_object->type = T_STRING;
number_object->name = "String";
- number_object->value.i_value = 0;
+ number_object->value.s_value = dup_string("");
struct Object *plus_met = clone_object(builtin_object);
plus_met->name = "+";
#ifndef __MOJO_STRINGS__
#define __MOJO_STRINGS__
+struct mojo_string {
+ int length;
+ char *contents;
+};
#endif
void free_object(struct Object *o)
{
- if (o == NULL)
+ if (o == NULL || o == nil_object || o == base_object || o == number_object)
return;
/*
mojo_list_free(o->value.l_value);
}
- /* FIXME : free : the methods list, the methods and finally the object */
free(o);
}
struct Object * (*c_method)(struct Object *parent, struct Object *arg1, struct Object *arg2,
struct Object *arg3, struct Object *arg4);
struct mojo_list *l_value;
+ struct mojo_string *s_value;
struct Object *m_block;
+ struct Object *v_value; /* the value pointed to by a variable */
} value;
struct Object *methods; /* A list object */