Browse Source

Sol Part 8: We're Not Sure How It Works, and We Don't Ask!

master
Grissess 7 years ago
parent
commit
54c9b32582
  1. 2
      build.sh
  2. 2
      buildgrammar.sh
  3. 2
      builtins.c
  4. 4
      sol.h
  5. 30
      util.c

2
build.sh

@ -1,5 +1,3 @@
bison -rall -fall -d parser.y
flex tokenizer.lex
gcc -c -g lex.yy.c
gcc -c -g parser.tab.c
gcc -c -g astprint.c

2
buildgrammar.sh

@ -0,0 +1,2 @@
bison -rall -fall -d parser.y
flex tokenizer.lex

2
builtins.c

@ -67,11 +67,11 @@ sol_object_t *sol_f_try(sol_state_t *state, sol_object_t *args) {
sol_obj_free(func);
sol_obj_free(fargs);
if(sol_has_error(state)) {
sol_clear_error(state);
sol_object_t *err = sol_get_error(state);
sol_object_t *zero = sol_new_int(state, 0);
sol_obj_free(res);
sol_obj_free(one);
sol_clear_error(state);
sol_list_insert(state, ls, 0, err);
sol_obj_free(err);
sol_list_insert(state, ls, 0, zero);

4
sol.h

@ -297,4 +297,8 @@ sol_object_t *sol_f_mcell_free(sol_state_t *, sol_object_t *);
int sol_validate_list(sol_state_t *, sol_object_t *);
int sol_validate_map(sol_state_t *, sol_object_t *);
// util.c
sol_object_t *sol_util_call(sol_state_t *, sol_object_t *, int, ...)
#endif

30
util.c

@ -0,0 +1,30 @@
#include "sol.h"
#include <stdarg.h>
sol_object_t *sol_util_call(sol_state_t *state, sol_object_t *func, int elems, ...) {
va_list va;
sol_object_t *args = sol_new_list(state), *res = NULL;
int i;
if(sol_has_error(state)) return sol_incref(state->None);
sol_list_insert(state, args, 0, func);
va_start(va, elems);
for(i=0; i<elems; i++) {
sol_list_insert(state, args, i+1, va_arg(va, sol_object_t *));
}
va_end(va);
if(!func->ops->call) return sol_incref(state->None);
res = func->ops->call(state, args);
if(!res) res = sol_incref(state->None);
if(sol_has_error(state)) {
sol_clear_error(state);
sol_obj_free(res);
res = sol_incref(state->None);
}
return res;
}
Loading…
Cancel
Save