Skip to content

Commit

Permalink
[js] add js_eval_noret() helper
Browse files Browse the repository at this point in the history
Some applications need to run JS code, but don't care about the
resulting values.
  • Loading branch information
ebirger committed Apr 4, 2016
1 parent c59726d commit 2d7463b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 1 addition & 7 deletions apps/file_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
#include "util/tstr.h"
#include "util/debug.h"
#include "fs/vfs.h"
#include "js/js_types.h"
#include "js/js_eval.h"
#include "js/js.h"

void app_start(int argc, char *argv[])
{
obj_t *o = NULL;
tstr_t code, file;

if (argc != 2)
Expand All @@ -44,11 +41,8 @@ void app_start(int argc, char *argv[])
if (js_eval_rank(code))
tp_crit("Invalid code, cannot execute\n");

if (js_eval(&o, &code) == COMPLETION_THROW)
tp_crit("Evaluation resulted in exception %o\n", o);
js_eval_noret(&code);

obj_put(o);
js_gc_run();
tstr_free(&code);
tstr_free(&file);
}
9 changes: 2 additions & 7 deletions apps/static_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@
#include "util/tstr.h"
#include "util/debug.h"
#include "js/js_eval.h"
#include "js/js.h"
#include "js/js_types.h"

extern char *static_file;

void app_start(int argc, char *argv[])
{
obj_t *o;
tstr_t code;

tp_out("TinkerPal Application - static file\n");

tstr_init(&code, static_file, strlen(static_file), 0);
if (js_eval(&o, &code) == COMPLETION_THROW)
tp_crit("Evaluation resulted in exception %o\n", o);

obj_put(o);
js_gc_run();
js_eval_noret(&code);

tstr_free(&code);
}
3 changes: 0 additions & 3 deletions js/js.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
void js_uninit(void);
void js_init(void);

#include "js/js_gc.h"

#else

static inline void js_uninit(void) { }
static inline void js_init(void) { }
static inline void js_gc_run(void) { }

#endif

Expand Down
12 changes: 12 additions & 0 deletions js/js_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "util/debug.h"
#include "js/js_eval.h"
#include "js/js_eval_common.h"
#include "js/js_gc.h"
#include "js/js_scan.h"
#include "js/js_types.h"
#include "js/js_obj.h"
Expand Down Expand Up @@ -1911,6 +1912,17 @@ int js_eval_obj(obj_t **ret, obj_t *obj)
return rc;
}

void js_eval_noret(tstr_t *code)
{
obj_t *o = NULL;

if (js_eval(&o, code) == COMPLETION_THROW)
tp_err("Evaluation resulted in exception %o\n", o);

obj_put(o);
js_gc_run();
}

static inline char open_char_recip(char c)
{
switch (c)
Expand Down
2 changes: 2 additions & 0 deletions js/js_eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
int js_eval(obj_t **ret, tstr_t *code);
int js_eval_module(obj_t **ret, tstr_t *code);
int js_eval_obj(obj_t **ret, obj_t *obj);
void js_eval_noret(tstr_t *code);

/* Return 'rank' of code - used for multiline edit:
* Examples:
* function f() { => 1
Expand Down

0 comments on commit 2d7463b

Please sign in to comment.