From 36424c0fd2890480dde0749d0f4d12d3fa38cb88 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Tue, 7 Apr 2015 21:08:55 +0300 Subject: [PATCH] Removing contexts arguments from Jerry API; introducing jerry_push_ctx and jerry_pop_ctx interfaces; putting context-related API part under #ifdef CONFIG_JERRY_ENABLE_CONTEXTS (supposed to be implemented later, when becomes necessary). --- jerry-core/jerry.cpp | 81 ++++++++++++++++++++++++----------------- jerry-core/jerry.h | 33 ++++++++++++----- main-linux.cpp | 4 +- tests/unit/test_api.cpp | 4 +- 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/jerry-core/jerry.cpp b/jerry-core/jerry.cpp index 39f6bc85f..da65ea91a 100644 --- a/jerry-core/jerry.cpp +++ b/jerry-core/jerry.cpp @@ -767,10 +767,6 @@ jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */ /** * Terminate Jerry engine - * - * Warning: - * All contexts should be freed with jerry_cleanup_ctx - * before calling the cleanup routine. */ void jerry_cleanup (void) @@ -803,35 +799,13 @@ jerry_reg_err_callback (jerry_error_callback_t callback) /**< pointer to callbac JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("Error callback is not implemented", callback); } /* jerry_reg_err_callback */ -/** - * Allocate new run context - */ -jerry_ctx_t* -jerry_new_ctx (void) -{ - JERRY_UNIMPLEMENTED ("Run contexts are not implemented"); -} /* jerry_new_ctx */ - -/** - * Cleanup resources associated with specified run context - */ -void -jerry_cleanup_ctx (jerry_ctx_t* ctx_p) /**< run context */ -{ - JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("Run contexts are not implemented", ctx_p); -} /* jerry_cleanup_ctx */ - /** * Parse script for specified context */ bool -jerry_parse (jerry_ctx_t* ctx_p, /**< run context */ - const char* source_p, /**< script source */ +jerry_parse (const char* source_p, /**< script source */ size_t source_size) /**< script source size */ { - /* FIXME: Remove after implementation of run contexts */ - (void) ctx_p; - bool is_show_opcodes = ((jerry_flags & JERRY_FLAG_SHOW_OPCODES) != 0); parser_init (source_p, source_size, is_show_opcodes); @@ -854,14 +828,10 @@ jerry_parse (jerry_ctx_t* ctx_p, /**< run context */ * @return completion status */ jerry_completion_code_t -jerry_run (jerry_ctx_t* ctx_p) /**< run context */ +jerry_run (void) { - /* FIXME: Remove after implementation of run contexts */ - (void) ctx_p; - return run_int (); } /* jerry_run */ - /** * Simple jerry runner * @@ -876,7 +846,7 @@ jerry_run_simple (const char *script_source, /**< script source */ jerry_completion_code_t ret_code = JERRY_COMPLETION_CODE_OK; - if (!jerry_parse (NULL, script_source, script_source_size)) + if (!jerry_parse (script_source, script_source_size)) { /* unhandled SyntaxError */ ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION; @@ -885,7 +855,7 @@ jerry_run_simple (const char *script_source, /**< script source */ { if ((flags & JERRY_FLAG_PARSE_ONLY) == 0) { - ret_code = jerry_run (NULL); + ret_code = jerry_run (); } } @@ -893,3 +863,46 @@ jerry_run_simple (const char *script_source, /**< script source */ return ret_code; } /* jerry_run_simple */ + +#ifdef CONFIG_JERRY_ENABLE_CONTEXTS +/** + * Allocate new run context + * + * @return run context + */ +jerry_ctx_t* +jerry_new_ctx (void) +{ + JERRY_UNIMPLEMENTED ("Run contexts are not implemented"); +} /* jerry_new_ctx */ + +/** + * Cleanup resources associated with specified run context + */ +void +jerry_cleanup_ctx (jerry_ctx_t* ctx_p) /**< run context */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("Run contexts are not implemented", ctx_p); +} /* jerry_cleanup_ctx */ + +/** + * Activate context and push it to contexts' stack + */ +void +jerry_push_ctx (jerry_ctx_t *ctx_p) /**< run context */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("Run contexts are not implemented", ctx_p); +} /* jerry_push_ctx */ + +/** + * Pop from contexts' stack and activate new stack's top + * + * Note: + * default context (most placed on bottom of stack) cannot be popped + */ +void +jerry_pop_ctx (void) +{ + JERRY_UNIMPLEMENTED ("Run contexts are not implemented"); +} /* jerry_pop_ctx */ +#endif /* CONFIG_JERRY_ENABLE_CONTEXTS */ diff --git a/jerry-core/jerry.h b/jerry-core/jerry.h index 24e54f86f..968488230 100644 --- a/jerry-core/jerry.h +++ b/jerry-core/jerry.h @@ -59,11 +59,6 @@ typedef enum ERR_FAILED_INTERNAL_ASSERTION = 120 } jerry_fatal_code_t; -/** - * Jerry run context - */ -typedef struct jerry_ctx_t jerry_ctx_t; - /** * Jerry engine build date */ @@ -90,17 +85,35 @@ extern EXTERN_C void jerry_cleanup (void); extern EXTERN_C void jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p, size_t *out_stack_limit_p); extern EXTERN_C void jerry_reg_err_callback (jerry_error_callback_t callback); -extern EXTERN_C jerry_ctx_t* jerry_new_ctx (void); -extern EXTERN_C void jerry_cleanup_ctx (jerry_ctx_t*); - -extern EXTERN_C bool jerry_parse (jerry_ctx_t*, const char* source_p, size_t source_size); -extern EXTERN_C jerry_completion_code_t jerry_run (jerry_ctx_t *); +extern EXTERN_C bool jerry_parse (const char* source_p, size_t source_size); +extern EXTERN_C jerry_completion_code_t jerry_run (void); extern EXTERN_C jerry_completion_code_t jerry_run_simple (const char *script_source, size_t script_source_size, jerry_flag_t flags); +#ifdef CONFIG_JERRY_ENABLE_CONTEXTS +/** \addtogroup jerry Jerry run contexts-related interface + * @{ + */ + +/** + * Jerry run context descriptor + */ +typedef struct jerry_ctx_t jerry_ctx_t; + +extern EXTERN_C jerry_ctx_t* jerry_new_ctx (void); +extern EXTERN_C void jerry_cleanup_ctx (jerry_ctx_t* ctx_p); + +extern EXTERN_C void jerry_push_ctx (jerry_ctx_t *ctx_p); +extern EXTERN_C void jerry_pop_ctx (void); + +/** + * @} + */ +#endif /* CONFIG_JERRY_ENABLE_CONTEXTS */ + /** * @} */ diff --git a/main-linux.cpp b/main-linux.cpp index 6e1a07f66..8a49cec64 100644 --- a/main-linux.cpp +++ b/main-linux.cpp @@ -178,7 +178,7 @@ main (int argc, jerry_completion_code_t ret_code = JERRY_COMPLETION_CODE_OK; - if (!jerry_parse (NULL, source_p, source_size)) + if (!jerry_parse (source_p, source_size)) { /* unhandled SyntaxError */ ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION; @@ -187,7 +187,7 @@ main (int argc, { if ((flags & JERRY_FLAG_PARSE_ONLY) == 0) { - ret_code = jerry_run (NULL); + ret_code = jerry_run (); } } diff --git a/tests/unit/test_api.cpp b/tests/unit/test_api.cpp index 27b953d47..fc0000ce2 100644 --- a/tests/unit/test_api.cpp +++ b/tests/unit/test_api.cpp @@ -144,10 +144,10 @@ main (void) jerry_api_value_t res, args [2]; char buffer [32]; - is_ok = jerry_parse (NULL, test_source, strlen (test_source)); + is_ok = jerry_parse (test_source, strlen (test_source)); assert (is_ok); - is_ok = (jerry_run (NULL) == JERRY_COMPLETION_CODE_OK); + is_ok = (jerry_run () == JERRY_COMPLETION_CODE_OK); assert (is_ok); global_obj_p = jerry_api_get_global ();