Author: Gianluca Guida <glguida@tlbflush.org>
Date: Thu Mar 9 00:07:42 UTC 2017
Parent: 6ddebcde2790d334a5c998a1fe2dae286aab9277
Log message:
lac: rationalize interface a bit
1: diff --git a/src/lib/lac.c b/src/lib/lac.c 2: index f0ac653..09cb84c 100644 3: --- a/src/lib/lac.c 4: +++ b/src/lib/lac.c 5: @@ -823,6 +823,11 @@ lac_error_print (FILE * f) 6: fprintf (f, "\")\n"); 7: } 8: 9: +lreg_t 10: +lac_eval (lreg_t lr, lenv_t *env) 11: +{ 12: + return eval (lr, env); 13: +} 14: 15: lenv_t * 16: lac_init (void) 17: diff --git a/src/lib/lac.h b/src/lib/lac.h 18: index 5973ac0..87168c0 100644 19: --- a/src/lib/lac.h 20: +++ b/src/lib/lac.h 21: @@ -146,6 +146,10 @@ static inline void *lac_alloc_fini(size_t size, 22: return obj; 23: } 24: 25: +void lac_error_print (FILE * f); 26: +lreg_t lac_eval (lreg_t lr, lenv_t *env); 27: + 28: + 29: struct cons 30: { 31: lreg_t a; 32: @@ -160,6 +164,11 @@ get_cons(lreg_t lr) 33: raise_exception("not a cons", lr); 34: } 35: 36: +static inline lreg_t lac_string_box(char *s) 37: +{ 38: + return lreg_raw(GC_strdup(s), LREG_STRING); 39: +} 40: + 41: 42: /* 43: * Embedded procedures 44: @@ -283,13 +292,12 @@ extern __thread lreg_t _lac_xcpt_reg; 45: free(p); \ 46: } while(0) 47: 48: -void lac_error_print (FILE * f); 49: - 50: 51: /* 52: * Representations 53: */ 54: 55: +lreg_t sexpr_eval_string(char *s, lenv_t *env); 56: lreg_t sexpr_parse_string(char *s, lreg_t (*fn)(lreg_t,void*), void *opq); 57: lreg_t sexpr_parse_file(FILE *f, lreg_t (*fn)(lreg_t,void*), void *opq); 58: void sexpr_fprint(FILE *f, lreg_t lr); 59: diff --git a/src/lib/lex.l b/src/lib/lex.l 60: index e854b7b..8647c1b 100644 61: --- a/src/lib/lex.l 62: +++ b/src/lib/lex.l 63: @@ -134,6 +134,29 @@ static void _sexpr_parse(yyscan_t yyscan, struct parse_cb *cb) 64: yylex_destroy(yyscan); 65: } 66: 67: +lreg_t sexpr_eval_string(char *s, lenv_t *env) 68: +{ 69: + yyscan_t yyscan; 70: + struct parse_cb cb; 71: + 72: + cb.fn = (lreg_t (*)(lreg_t,void*))eval; 73: + cb.opq = (void *)env; 74: + cb.res = NIL; 75: + 76: + yylex_init(&yyscan); 77: + yy_scan_string(s, yyscan); 78: + 79: + lac_on_error ({ 80: + lac_error_print (stderr); 81: + return NIL; 82: + }); 83: + 84: + _sexpr_parse(yyscan, &cb); 85: + 86: + lac_off_error(); 87: + return cb.res; 88: +} 89: + 90: lreg_t sexpr_parse_string(char *s, lreg_t (*fn)(lreg_t,void*), void *opq) 91: { 92: yyscan_t yyscan; 93: @@ -147,6 +170,7 @@ lreg_t sexpr_parse_string(char *s, lreg_t (*fn)(lreg_t,void*), void *opq) 94: yy_scan_string(s, yyscan); 95: 96: _sexpr_parse(yyscan, &cb); 97: + 98: return cb.res; 99: } 100: 101: diff --git a/src/repl/lac.c b/src/repl/lac.c 102: index 5937d88..e2e4da1 100644 103: --- a/src/repl/lac.c 104: +++ b/src/repl/lac.c 105: @@ -34,7 +34,7 @@ timed_eval (lreg_t lr, void *opq) 106: lenv_t *env = (lenv_t *) opq; 107: 108: gettimeofday (&t1, NULL); 109: - ret = eval (lr, env); 110: + ret = lac_eval (lr, env); 111: gettimeofday (&t2, NULL); 112: 113: fprintf (stderr, "Evaluation took %ld seconds and %ld microseconds.\n",