Skip to content

Commit

Permalink
change set_car
Browse files Browse the repository at this point in the history
  • Loading branch information
mmitou committed Nov 20, 2010
1 parent 2aa1b39 commit 4850faf
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions lispobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ static void *get_val(cell *c, int i)
static void *set_val(cell *c, int i, lispobj *obj)
{
void *result = NULL;
if(is_cell(c))
{
result = c->value[i];
c->value[i] = obj;
}
else
{
fprintf(stderr, "ERROR: %p is not cell\n", c);
}
result = c->value[i];
c->value[i] = obj;
return result;
}

Expand Down Expand Up @@ -101,7 +94,7 @@ symbol *new_symbol(char *name)
name_size++, p++);
symbol_name = (char *)malloc(name_size);
strcpy(symbol_name, name);
s->value[0] = symbol_name;
set_car(s, symbol_name);
return s;
}

Expand All @@ -124,7 +117,7 @@ bool equal_symbol(symbol *l, symbol *r)
/*@null@*/
char *sym_to_string(symbol *s)
{
return (char *)(s->value[0]);
return (char *)(car(s));
}

/* integer */
Expand All @@ -135,7 +128,7 @@ integer *new_integer(int x)
int *p = (int *)malloc(sizeof(int));
i->tid = INTEGER;
*p = x;
i->value[0] = p;
set_car(i, p);
return i;
}

Expand All @@ -146,7 +139,7 @@ bool is_integer(integer *i)

int integer_to_int(integer *i)
{
return *(int *)(i->value[0]);
return *(int *)(car(i));
}

bool equal_integer(integer *l, integer *r)
Expand All @@ -167,8 +160,8 @@ character *new_character(char c)
char *d = (char *)malloc(sizeof(char));
chrctr->tid = CHARACTER;
*d = c;
chrctr->value[0] = d;
chrctr->value[1] = NULL;
set_car(chrctr, d);
set_cdr(chrctr, NULL);
return chrctr;
}

Expand Down Expand Up @@ -246,7 +239,7 @@ string *new_string(char *s)
while(*i != '\0')
{
d = new_character(*i);
c->value[1] = d;
set_cdr(c, d);
c = d;
++i;
}
Expand Down Expand Up @@ -526,7 +519,7 @@ lispobj *eval(lispobj *exp, environment *env)
/*@null@*/
lispobj *apply_prim_proc(prim_proc *proc, list *arg)
{
lispobj *(*p)(list *) = proc->value[0];
lispobj *(*p)(list *) = car(proc);
return p(arg);
}

Expand Down Expand Up @@ -574,7 +567,7 @@ prim_proc *new_prim_proc(lispobj *(*p)(list *))
{
prim_proc *proc = (prim_proc*)malloc(sizeof(prim_proc));
proc->tid = PRIM_PROC;
proc->value[0] = (void*)p;
set_car(proc, (void*)p);

return proc;
}
Expand All @@ -584,7 +577,7 @@ syntax *new_syntax(lispobj *(*p)(list *,environment *))
{
syntax *s = (syntax *)malloc(sizeof(syntax));
s->tid = SYNTAX;
s->value[0] = (void*)p;
set_car(s, (void*)p);

return s;
}
Expand All @@ -598,7 +591,7 @@ int is_syntax(lispobj *obj)
lispobj *eval_syntax(syntax *s, list *operands, environment *env)
{
lispobj *(*evaluate)(list *, environment *);
evaluate = s->value[0];
evaluate = car(s);
return evaluate(operands, env);
}

Expand Down Expand Up @@ -658,17 +651,17 @@ lambda *new_lambda(list *arg_body, environment *env)
{
lambda *l = (lambda *)malloc(sizeof(lambda));
l->tid = LAMBDA;
l->value[0] = arg_body;
l->value[1] = env;
set_car(l, arg_body);
set_cdr(l, env);
return l;
}

/*@null@*/
lispobj *apply_lambda(lambda *l, list *vals)
{
list *vars = car((list*)(l->value[0]));
list *body = cdr((list*)(l->value[0]));
environment *env = l->value[1];
list *vars = car(car(l));
list *body = cdr(car(l));
environment *env = cdr(l);
env = extend_env(vars, vals, env);
return syntax_begin(body, env);
}
Expand Down

0 comments on commit 4850faf

Please sign in to comment.