-
-
Save chrisseaton/6793af738cb10ec8edd001e79ca61b8a to your computer and use it in GitHub Desktop.
Revisions
-
chrisseaton revised this gist
May 22, 2019 . 1 changed file with 19 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,8 +16,7 @@ int main(int argc, char **argv) { if (poly_create_context(thread, NULL, 0, &context) != poly_ok) { fprintf(stderr, "poly_create_context error\n"); goto exit_isolate; } char* language = "js"; @@ -28,7 +27,10 @@ int main(int argc, char **argv) { } else { poly_value result = NULL; if (poly_open_handle_scope(thread) != poly_ok) { fprintf(stderr, "poly_open_handle_scope error\n"); goto exit_context; } if (poly_context_eval(thread, context, language, "eval", argv[n], &result) != poly_ok) { fprintf(stderr, "poly_context_eval error\n"); @@ -52,23 +54,33 @@ int main(int argc, char **argv) { goto exit_scope; } if (poly_close_handle_scope(thread) != poly_ok) { fprintf(stderr, "poly_close_handle_scope error\n"); goto exit_context; } buffer[length] = '\0'; printf("%s\n", buffer); } } if (poly_context_close(thread, context, true) != poly_ok) { fprintf(stderr, "poly_context_close error\n"); goto exit_isolate; } if (poly_tear_down_isolate(thread) != poly_ok) { fprintf(stderr, "poly_tear_down_isolate error\n"); return 1; } return 0; exit_scope: poly_close_handle_scope(thread); exit_context: poly_context_close(thread, context, true); exit_isolate: poly_tear_down_isolate(thread); return 1; } -
chrisseaton revised this gist
May 22, 2019 . 1 changed file with 26 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,18 +4,19 @@ #include <polyglot_api.h> int main(int argc, char **argv) { poly_isolate isolate = NULL; poly_thread thread = NULL; if (poly_create_isolate(NULL, &isolate, &thread) != poly_ok) { fprintf(stderr, "poly_create_isolate error\n"); return 1; } poly_context context = NULL; if (poly_create_context(thread, NULL, 0, &context) != poly_ok) { fprintf(stderr, "poly_create_context error\n"); poly_tear_down_isolate(thread); return 1; } @@ -26,6 +27,8 @@ int main(int argc, char **argv) { language = &argv[n][1]; } else { poly_value result = NULL; poly_open_handle_scope(thread); if (poly_context_eval(thread, context, language, "eval", argv[n], &result) != poly_ok) { fprintf(stderr, "poly_context_eval error\n"); @@ -34,25 +37,38 @@ int main(int argc, char **argv) { if (poly_get_last_error_info(thread, &error) != poly_ok) { fprintf(stderr, "poly_get_last_error_info error\n"); goto exit_scope; } fprintf(stderr, "%s\n", error->error_message); goto exit_scope; } char buffer[1024]; size_t length; if (poly_value_to_string_utf8(thread, result, buffer, sizeof(buffer), &length) != poly_ok) { fprintf(stderr, "poly_value_to_string_utf8 error\n"); goto exit_scope; } poly_close_handle_scope(thread); buffer[length] = '\0'; printf("%s\n", buffer); } } poly_context_close(thread, context, true); poly_tear_down_isolate(thread); return 0; exit_scope: poly_close_handle_scope(thread); exit_context: poly_context_close(thread, context, true); poly_tear_down_isolate(thread); return 1; } -
chrisseaton revised this gist
May 21, 2019 . 1 changed file with 16 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,15 +7,15 @@ int main(int argc, char **argv) { graal_isolate_t *isolate = NULL; graal_isolatethread_t *thread = NULL; if (graal_create_isolate(NULL, &isolate, &thread) != 0) { fprintf(stderr, "graal_create_isolate error\n"); return 1; } poly_context context = NULL; if (poly_create_context(thread, NULL, 0, &context) != poly_ok) { fprintf(stderr, "poly_create_context error\n"); return 1; } @@ -27,23 +27,30 @@ int main(int argc, char **argv) { } else { poly_value result = NULL; if (poly_context_eval(thread, context, language, "eval", argv[n], &result) != poly_ok) { fprintf(stderr, "poly_context_eval error\n"); const poly_extended_error_info *error; if (poly_get_last_error_info(thread, &error) != poly_ok) { fprintf(stderr, "poly_get_last_error_info error\n"); return 1; } fprintf(stderr, "%s\n", error->error_message); return 1; } char buffer[1024]; size_t length; if (poly_value_to_string_utf8(thread, result, buffer, sizeof(buffer), &length) != poly_ok) { fprintf(stderr, "poly_value_to_string_utf8 error\n"); return 1; } printf("%s\n", buffer); } } -
chrisseaton renamed this gist
Apr 25, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
chrisseaton created this gist
Apr 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #include <stdlib.h> #include <stdio.h> #include <polyglot_api.h> int main(int argc, char **argv) { graal_isolate_t *isolate = NULL; graal_isolatethread_t *thread = NULL; if (graal_create_isolate(NULL, &isolate) != 0 || (thread = graal_current_thread(isolate)) == NULL) { fprintf(stderr, "initialization error\n"); return 1; } poly_context context = NULL; if (poly_create_context(thread, NULL, 0, &context) != poly_ok) { fprintf(stderr, "initialization error\n"); return 1; } char* language = "js"; for (int n = 1; n < argc; n++) { if (argv[n][0] == '-') { language = &argv[n][1]; } else { poly_value result = NULL; if (poly_context_eval(thread, context, language, "unicalc", argv[n], &result) != poly_ok) { fprintf(stderr, "eval error\n"); return 1; } char buffer[1024]; size_t length; if (poly_value_to_string_utf8(thread, result, buffer, sizeof(buffer), &length) != poly_ok) { fprintf(stderr, "to string error\n"); return 1; } buffer[length] = '\0'; printf("%s\n", buffer); poly_destroy_handle(thread, result); } } return 0; }