x + 3;
# Test the value of x, and execute a block it is true
-
-x = 3 ifTrue: [ x y z | # doStuff... ]
+# Note that a block doesn't get parameters, only
+x = 3 ifTrue: [ # doStuff... ]
Hacking
=======
extern int yylex();
extern char *yytext;
-int eval_image(FILE *fp)
+struct Object *apply_block(struct Object *o)
{
- struct Object *o1 = clone_object(number_object);
- struct Object *o2 = clone_object(number_object);
-
- if (o1 == NULL || o2 == NULL)
- fail("Unable to clone both objects");
-
- o1->value.i_value = 2;
- o2->value.i_value = 2;
-
- struct Object *met = lookup_method(o1, "+");
+ if (o == NULL || o->type != T_BLOCK)
+ return NULL;
- if (met == NULL)
- fail("Unable to lookup method");
-
- struct Object *ret = met->value.c_method(o1, o2, NULL);
-
- fail("valeur : %d", ret->value.i_value);
+ int i = 0;
+ for (i = 0; i < list_length(o); i++) {
+
+
+ }
+}
+int eval_image(FILE *fp)
+{
+ struct Object* stack = clone_object(list_object);
int r;
while((r = yylex()) != T_EOF) {
switch(r) {
case NUMBER:
{
- puts("ho");
- struct Object *o1 = clone_object(number_object);
- struct Object *o2 = clone_object(number_object);
-
- if (o1 == NULL || o2 == NULL)
- fail("Unable to clone both objects");
-
- printf("%s\n", yytext);
- o1->value.i_value = atoi(yytext);
- o2->value.i_value = 3;
-
- struct Object *met = lookup_method(o1, "+");
- printf("%s", met->name);
- if (met == NULL)
- fail("Unable to lookup method");
-
- struct Object *ret = met->value.c_method(o1, o2, NULL);
-
- printf("valeur : %d\n", ret->value.i_value);
}
default:
break;
%%
-[0-9]+ { return NUMBER; }
+[0-9]+ { return NUMBER; }
+";" { return COMMA; }
\"[:alnum:]+\" { return STRING; }
[:alnum:]+ { return SYMBOL; }
<<EOF>> { return T_EOF; }
fail("Unable to create a method %d %d", __FILE__, __LINE__);
met->type = T_BUILTIN;
- met->value.c_method = (struct Object * (*)(struct Object *parent, struct Object *arg1,
- struct Object *arg2))list_append;
+ met->name = "+";
+ met->value.c_method = BUILTIN_CAST list_append;
list_append(l1, met);
met = zalloc(sizeof(struct Object));
fail("Unable to create a method %d %d", __FILE__, __LINE__);
met->type = T_BUILTIN;
- met->value.c_method = (struct Object * (*)(struct Object *parent, struct Object *arg1,
- struct Object *arg2))list_remove;
+ met->name = "remove";
+ met->value.c_method = BUILTIN_CAST list_remove;
list_append(l1, met);
met = zalloc(sizeof(struct Object));
fail("Unable to create a method %d %d", __FILE__, __LINE__);
met->type = T_BUILTIN;
- met->value.c_method = (struct Object * (*)(struct Object *parent, struct Object *arg1,
- struct Object *arg2))list_nth;
+ met->name = "nth:";
+ met->value.c_method = BUILTIN_CAST list_nth;
list_append(l1, met);
met = zalloc(sizeof(struct Object));
fail("Unable to create a method %d %d", __FILE__, __LINE__);
met->type = T_BUILTIN;
- met->value.c_method = (struct Object * (*)(struct Object *parent, struct Object *arg1,
- struct Object *arg2))list_last;
+ met->name = "last";
+ met->value.c_method = BUILTIN_CAST list_last;
list_append(l1, met);
list_object->methods = l1;
struct Object* list_append(struct Object *list, struct Object *o)
{
- if (list == NULL || list->type != T_LIST || list->value.l_value == NULL)
+ if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
return nil_object;
if (o == NULL)
struct Object* list_remove(struct Object *list)
{
- if (list == NULL || list->type != T_LIST || list->value.l_value == NULL)
+ if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
return nil_object;
mojo_list_remove(list->value.l_value);
struct Object* list_nth(struct Object *list, int n)
{
- if (list == NULL || list->type != T_LIST || list->value.l_value == NULL)
+ if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
return nil_object;
struct Object *o = mojo_list_nth(list->value.l_value, n);
struct Object* list_last(struct Object *list)
{
- if (list == NULL || list->type != T_LIST || list->value.l_value == NULL)
+ if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
return nil_object;
struct Object *o = mojo_list_last(list->value.l_value);
struct Object* list_length(struct Object *list)
{
- if (list == NULL || list->type != T_LIST || list->value.l_value == NULL)
+ if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
return nil_object;
struct Object *o = clone_object(number_object);
new->super = o->super;
new->type = o->type;
new->name = strndup(o->name, 255); /* FIXME : test the value of strdup */
- new->methods = create_list_object();
+ new->methods = (struct Object *) create_list_object();
struct Object *met;
/* We need to create the list object before everything else because it is
needed for the method dictionnaries.
*/
- list_object = create_list_object();
+ list_object = (struct Object *) create_list_object();
/* init nil object */
nil_object = new_object();
}; /* the base types */
+/* this cast is to silence some warnings sent by the compiler */
+#define BUILTIN_CAST (struct Object * (*)(struct Object *parent, struct Object *arg1,\
+ struct Object *arg2, struct Object *arg3, struct Object *arg4))
+
struct Object {
struct Object *super;
char *name;
union {
signed int i_value;
char c_value;
- struct Object * (*c_method)(struct Object *parent, struct Object *arg1, struct Object *arg2);
+ 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 Object *m_block;
} value;
struct Object *methods; /* A list object */
+ struct Object *symtab; /* The list of symbols defined at this point */
};
struct Object *lookup_method(struct Object *o, char *name);
#define SYMBOL 0
#define NUMBER 1
#define STRING 2
+#define COMMA 3
#define T_EOF 99
#endif