Пример #1
0
lval* lval_eval_sexpr(lval* v) {

  /* Evaluate Children */
  for (int i = 0; i < v->count; i++) {
    v->cell[i] = lval_eval(v->cell[i]);
  }

  /* Error Checking */
  for (int i = 0; i < v->count; i++) {
    if (v->cell[i]->type == LVAL_ERR) { return lval_take(v, i); }
  }

  /* Empty Expression */
  if (v->count == 0) { return v; }

  /* Single Expression */
  if (v->count == 1) { return lval_take(v, 0); }

  /* Ensure First Element is Symbol */
  lval* f = lval_pop(v, 0);
  if (f->type != LVAL_SYM) {
    lval_del(f); lval_del(v);
    return lval_err("S-expression Does not start with symbol.");
  }

  /* Call builtin with operator */
  lval* result = builtin_op(v, f->sym);
  lval_del(f);
  return result;
}
Пример #2
0
lval_t* builtin(lval_t* a,const char* func){
    if(strcmp("head", func) == 0) return builtin_head(a);
    if(strcmp("tail" ,func) == 0) return builtin_tail(a);
    if(strstr("+-/*", func) == 0) return builtin_op(a, func);
    lval_free(a);
    return lval_err("Unknown Function");
}
Пример #3
0
lval *builtin(lval *v, char *func) {
    if (strcmp("head", func) == 0) {
        return builtin_head(v);
    }
    if (strcmp("tail", func) == 0) {
        return builtin_tail(v);
    }
    if (strcmp("init", func) == 0) {
        return builtin_init(v);
    }
    if (strcmp("join", func) == 0) {
        return builtin_join(v);
    }
    if (strcmp("eval", func) == 0) {
        return builtin_eval(v);
    }
    if (strcmp("list", func) == 0) {
        return builtin_list(v);
    }
    if (strcmp("cons", func) == 0) {
        return builtin_cons(v);
    }
    if (strcmp("len", func) == 0) {
        return builtin_len(v);
    }

    return builtin_op(v, func);
}
Пример #4
0
lval* lval_eval_sexpr(lval* v) {
    for (int i = 0; i < v->count; i++) {
        if (v->cell[i]->type != LVAL_ERR) {
            v->cell[i] = lval_eval(v->cell[i]);
        } else {
            return lval_take(v, i);
        }
    }

    if (v->count == 0) {
        return v;
    }

    if (v->count == 1) {
        return lval_take(v, 0);
    }

    lval* f = lval_pop(v, 0);

    if (f->type != LVAL_SYM) {
        lval_free(f);
        lval_free(v);
        return lval_err("S-Expression doesn't start with symbol!");
    }

    lval* result = builtin_op(v, f->sym);
    lval_free(f);

    return result;
}
Пример #5
0
lval* builtin(lval* a, char* func) {
  if (strcmp("join", func) == 0) { return builtin_join(a); }
  if (strcmp("list", func) == 0) { return builtin_list(a); }
  if (strcmp("eval", func) == 0) { return builtin_eval(a); }
  if (strcmp("tail", func) == 0) { return builtin_tail(a); }
  if (strcmp("head", func) == 0) { return builtin_head(a); }
  if (strstr("+-/*", func)) { return builtin_op(a, func); }
  lval_del(a);
  return lval_err("Unknown Function!");
}
Пример #6
0
lval *builtin(lenv *e, lval *a, char *func)
{
  if (strcmp("eval", func) == 0) { return builtin_eval(e, a); }
  if (strcmp("head", func) == 0) { return builtin_head(e, a); }
  if (strcmp("join", func) == 0) { return builtin_join(e, a); }
  if (strcmp("list", func) == 0) { return builtin_list(e, a); }
  if (strcmp("tail", func) == 0) { return builtin_tail(e, a); }
  if (strstr("+-*%/", func))     { return builtin_op(e, a, func); }
  lval_del(a);
  return lval_err("Unknown function %s", func);
}
Пример #7
0
inline lval_t* builtin_div(lenv*e, lval* a){ return builtin_op(e, a, "*");  }
Пример #8
0
lval *builtin_mod(lenv *e, lval *a)
{

  return builtin_op(e, a, "%");
}
Пример #9
0
void simple_parser::add_builtin_op(symbol const & s, family_id fid, decl_kind kind) {
    SASSERT(!m_builtin.contains(s));
    SASSERT(!m_vars.contains(s));
    m_builtin.insert(s, builtin_op(fid, kind));
}
Пример #10
0
lval* builtin_sub(lenv* env, lval* node) { return builtin_op(env, node, '-'); }
Пример #11
0
// Math - multiplication
lval* builtin_mul(lenv* e, lval* a)
{
  return builtin_op(e, a, "*");
}
Пример #12
0
lval* builtin_mod(lenv* env, lval* node) { return builtin_op(env, node, '%'); }
Пример #13
0
lval* builtin_div(lenv* env, lval* node) { return builtin_op(env, node, '/'); }
Пример #14
0
lval* builtin_mul(lenv* env, lval* node) { return builtin_op(env, node, '*'); }
Пример #15
0
// Math - addition
lval* builtin_add(lenv* e, lval* a)
{
  return builtin_op(e, a, "+");
}
Пример #16
0
// Math - subtraction
lval* builtin_sub(lenv* e, lval* a)
{
  return builtin_op(e, a, "-");
}
Пример #17
0
lval* builtin_pow(lenv* e, lval* a) { return builtin_op(e, a, "^"); }
Пример #18
0
// Math - division
lval* builtin_div(lenv* e, lval* a)
{
  return builtin_op(e, a, "/");
}
Пример #19
0
lval* builtin_add(lenv* env, lval* node) { return builtin_op(env, node, '+'); }