Skip to content

Commit

Permalink
T_VAR
Browse files Browse the repository at this point in the history
  • Loading branch information
avorobey committed Jul 22, 2010
1 parent 50de72f commit 343a1f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern uint32_t next_cell;
#define T_FUNC 6 /* function, a.k.a. closure */
#define T_VECT 7 /* vector */
#define T_CHAR 8 /* character */
#define T_VAR 9 /* reference to a lexical variable */

/* true for builtin, as opposed to lambda-defined, functions */
#define BLTIN_MASK 16
Expand All @@ -51,6 +52,9 @@ extern uint32_t next_cell;
#define CHAR_VALUE(i) (unsigned char)(cells[i] >> 32)
#define INT32_VALUE(i) (int32_t)(cells[i] >> 32)

#define VAR_FRAME(i) (uint32_t)((cells[i] >> 32) & 0xFFFF)
#define VAR_SLOT(i) (uint32_t)((cells[i] >> 32) >> 16)

#define LIST_LIKE(i) (TYPE(i) == T_PAIR || i == C_EMPTY)

typedef uint32_t (*builtin_t)(uint32_t);
Expand Down
12 changes: 12 additions & 0 deletions sketch.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ uint32_t store_int32(int32_t num) {
return index;
}

uint32_t store_var(uint32_t slot, uint32_t frame) {
uint64_t value = T_VAR;
CHECK_CELLS(1);
uint32_t index = next_cell;
cells[next_cell++] = value | ((uint64_t)frame << 32) |
(uint64_t)slot << 48;
return index;
}

/* helper func to read a #(...) literal vector */
int read_vector(char **pstr, uint32_t *pindex) {
uint32_t initial_indices[2];
Expand Down Expand Up @@ -369,6 +378,9 @@ void dump_value(uint32_t index, int implicit_paren) {
else if (c == '\n') printf("newline");
else putchar(c);
break;
case T_VAR:
printf("#<var:%u,%u>", VAR_SLOT(index), VAR_FRAME(index));
break;
default:
break;
}
Expand Down

0 comments on commit 343a1f6

Please sign in to comment.