Bläddra i källkod

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

Grissess 6 år sedan
förälder
incheckning
54c9b32582
5 ändrade filer med 37 tillägg och 3 borttagningar
  1. 0
    2
      build.sh
  2. 2
    0
      buildgrammar.sh
  3. 1
    1
      builtins.c
  4. 4
    0
      sol.h
  5. 30
    0
      util.c

+ 0
- 2
build.sh Visa fil

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

+ 2
- 0
buildgrammar.sh Visa fil

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

+ 1
- 1
builtins.c Visa fil

@@ -67,11 +67,11 @@ sol_object_t *sol_f_try(sol_state_t *state, sol_object_t *args) {
67 67
 	sol_obj_free(func);
68 68
 	sol_obj_free(fargs);
69 69
 	if(sol_has_error(state)) {
70
+        sol_clear_error(state);
70 71
 		sol_object_t *err = sol_get_error(state);
71 72
 		sol_object_t *zero = sol_new_int(state, 0);
72 73
 		sol_obj_free(res);
73 74
 		sol_obj_free(one);
74
-		sol_clear_error(state);
75 75
 		sol_list_insert(state, ls, 0, err);
76 76
 		sol_obj_free(err);
77 77
 		sol_list_insert(state, ls, 0, zero);

+ 4
- 0
sol.h Visa fil

@@ -297,4 +297,8 @@ sol_object_t *sol_f_mcell_free(sol_state_t *, sol_object_t *);
297 297
 int sol_validate_list(sol_state_t *, sol_object_t *);
298 298
 int sol_validate_map(sol_state_t *, sol_object_t *);
299 299
 
300
+// util.c
301
+
302
+sol_object_t *sol_util_call(sol_state_t *, sol_object_t *, int, ...)
303
+
300 304
 #endif

+ 30
- 0
util.c Visa fil

@@ -0,0 +1,30 @@
1
+#include "sol.h"
2
+
3
+#include <stdarg.h>
4
+
5
+sol_object_t *sol_util_call(sol_state_t *state, sol_object_t *func, int elems, ...) {
6
+    va_list va;
7
+    sol_object_t *args = sol_new_list(state), *res = NULL;
8
+    int i;
9
+
10
+    if(sol_has_error(state)) return sol_incref(state->None);
11
+
12
+    sol_list_insert(state, args, 0, func);
13
+
14
+    va_start(va, elems);
15
+    for(i=0; i<elems; i++) {
16
+        sol_list_insert(state, args, i+1, va_arg(va, sol_object_t *));
17
+    }
18
+    va_end(va);
19
+
20
+    if(!func->ops->call) return sol_incref(state->None);
21
+    res = func->ops->call(state, args);
22
+    if(!res) res = sol_incref(state->None);
23
+    if(sol_has_error(state)) {
24
+        sol_clear_error(state);
25
+        sol_obj_free(res);
26
+        res = sol_incref(state->None);
27
+    }
28
+
29
+    return res;
30
+}

Laddar…
Avbryt
Spara