SE *get_se() { switch(token.type) { case TEOF: return new_sym(strdup("#eof")); case TNUM: return new_num(atoi(token.buf)); case TSYM: return new_sym(strdup(token.buf)); case TQUOTE: get_token(); /* ! */ return new_cons(new_sym(strdup("quote")), new_cons(get_se(),NIL)); case TLPAR: return get_cdr(); default: break; /* err! */ } return NIL; /* notreached */ }
void sym_set_scalar(int width, int *eval_flags, scalar_t sc, ident_t id, sym_t sym){ int ivalue; /* Find the symbol - it is does not exist make a new one */ sym_t newsym = sym_lookup(id, sym); if (newsym == NULL) { newsym = new_sym(id, sym); } /* Make sure that any existing one is of the right type */ if (newsym->type == SYM_VECTOR) { /* errx(1, "%s is not a scalar", ident_str(id)); */ fprintf(stderr, "%s is not a scalar(lowercase)\n", ident_str(id)); exit(1); } /* Create a new scalar if needed */ if (newsym->type == SYM_UNKNOWN || newsym->scalar->width < width) { if (newsym->type == SYM_SCALAR) scalar_free(newsym->scalar); newsym->type = SYM_SCALAR; newsym->scalar = new_scalar(width); } /* Copy in the values */ for (ivalue=0; ivalue < width; ivalue++) { if (eval_flags != NULL && !eval_flags[ivalue]) continue; newsym->scalar->vals[ivalue] = sc->vals[ivalue]; } return; }
void sym_set_vector(int width, int *eval_flags, vector_t v, ident_t id, sym_t sym){ int ivalue, iel; scalar_t sc; /* Find the symbol - it is does not exist make a new one */ sym_t newsym = sym_lookup(id, sym); if (newsym == NULL) { newsym = new_sym(id, sym); } /* Make sure that any existing one is of the right type */ if (newsym->type == SYM_SCALAR) { /* errx(1, "%s is not a vector", ident_str(id)); */ fprintf(stderr, "%s is not a vector\n", ident_str(id)); exit(1); } /* Create a new vector if needed - either it does not exist or the length is changing or the width is increasing*/ if (newsym->type == SYM_UNKNOWN || newsym->vector->len != v->len || (newsym->vector->len > 0 && newsym->vector->el[0]->width < width) ) { /* Free an existing vector. If eval_flags is set, then we cannot change the length of the vector */ if (newsym->type == SYM_VECTOR) { if (eval_flags != NULL && newsym->vector->len != v->len) { /* errx(1, "assigned vector must match length of %s in if", ident_str(id)); */ fprintf(stderr, "assigned vector must match length of %s in if", ident_str(id)); exit(1); } vector_free(newsym->vector); } newsym->type = SYM_VECTOR; newsym->vector = new_vector(); for (iel=0; iel < v->len; iel++) { sc = new_scalar(width); vector_append(newsym->vector, sc); scalar_free(sc); } } /* Copy in the values */ for (ivalue=0; ivalue < width; ivalue++) { if (eval_flags != NULL && !eval_flags[ivalue]) continue; for (iel=0; iel < v->len; iel++) { newsym->vector->el[iel]->vals[ivalue] = v->el[iel]->vals[ivalue]; } } return; }
void sym_declare_ident(ident_t id, sym_t sym) { (void) new_sym(id, sym); return; }
sym_t sym_enter_scope(sym_t sym) { sym_t newsym = new_sym(NEW_SCOPE, sym); return newsym; }