LISPTR bind_args(LISPTR formals, LISPTR acts, LISPTR prev) { if (!consp(formals)) { return prev; } return cons(cons(car(formals), consp(acts) ? eval(car(acts)) : NIL), bind_args(cdr(formals), consp(acts) ? cdr(acts) : NIL, prev)); }
bool command::process(term & t) { bool ret = false; term resp; #ifdef PRINTCMD char * tmpbuf = print_term(command); REMOTE_LOG(DBG, "========================================\nCOMMAND : %s %s\n========================================\n", CMD_NAME_STR(ERL_INT_VALUE(cmd)), tmpbuf); delete tmpbuf; #endif if(t.is_tuple() && t[1].is_integer()) { int cmd = t[1].v.i; resp.tuple(); resp.add(t[0]); resp.insert().integer(cmd); if((t.length() - 1) != (size_t)CMD_ARGS_COUNT(cmd)) { term & _t = resp.insert().tuple(); _t.insert().atom("error"); _t.insert().atom("badarg"); if(resp.is_undef()) REMOTE_LOG(ERR, "ERROR badarg %s expected %d, got %d\n", CMD_NAME_STR(cmd) , CMD_ARGS_COUNT(cmd), (t.length() - 1)); if(resp.is_undef()) REMOTE_LOG(CRT, "driver error: no resp generated, shutting down port\n"); vector<unsigned char> respv = tc.encode(resp); p.write_cmd(respv); } else { switch(cmd) { case RMOTE_MSG: ret = change_log_flag(t, resp); break; case GET_SESSN: ret = get_session(t, resp); break; case PUT_SESSN: ret = release_conn(t, resp); break; case CMT_SESSN: ret = commit(t, resp); break; case RBK_SESSN: ret = rollback(t, resp); break; case CMD_DSCRB: ret = describe(t, resp); break; case PREP_STMT: ret = prep_sql(t, resp); break; case BIND_ARGS: ret = bind_args(t, resp); break; case EXEC_STMT: ret = exec_stmt(t, resp); break; case FTCH_ROWS: ret = fetch_rows(t, resp); break; case CLSE_STMT: ret = close_stmt(t, resp); break; case GET_LOBDA: ret = get_lob_data(t, resp); break; case CMD_ECHOT: ret = echo(t, resp); break; case SESN_PING: ret = ping(t, resp); break; default: ret = true; break; } } } return ret; }
LISPTR apply(LISPTR f, LISPTR args) { if (symbolp(f)) { // get the function binding of f f = symbol_function(f); if (consp(f)) { // function defined as S-expr if (car(f) == LAMBDA) { LISPTR oldBindings = lexvars; // bind formal arguments to evaluated actual arguments: lexvars = bind_args(cadr(f), args, lexvars); f = progn(cddr(f)); lexvars = oldBindings; } } else if (compiled_function_p(f)) { // call compiled function with args f = call_compiled_fn(f, args); } } return f; }