-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
58 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
require_relative "./bytecode_test.rb" | ||
require_relative "./test.rb" | ||
require_relative "./hp_example.rb" |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,68 @@ | ||
#include <ruby.h> | ||
|
||
//! TODO: Is a cleanup maybe possible? For now, the state is kept. | ||
//! TODO: Is a complete cleanup maybe possible? For now, the state is kept. | ||
|
||
extern void* open_interpreter(void) { | ||
|
||
static int already_initialized = 0; | ||
RUBY_INIT_STACK; | ||
ruby_init(); | ||
|
||
if(!already_initialized) { | ||
return (void*) 0; | ||
|
||
//printf("Initializing...\n"); | ||
RUBY_INIT_STACK; | ||
ruby_init(); | ||
//printf("Done initializing.\n"); | ||
already_initialized = 1; | ||
} | ||
|
||
} | ||
extern void close_interpreter(void* rb) { | ||
|
||
return (void*) 0; | ||
ruby_cleanup(0); | ||
|
||
} | ||
|
||
extern void close_interpreter(void* mrb) { | ||
extern void load_script_from_file(void* rb, const char* filename) { | ||
|
||
//printf("Finalizing...\n"); | ||
//ruby_cleanup(0); | ||
//printf("Done finalizing.\n"); | ||
static int first_script = 1; | ||
|
||
} | ||
if(first_script) { | ||
|
||
extern void load_script_from_file(void* mrb, const char* filename) { | ||
ruby_script(filename); | ||
first_script = 0; | ||
|
||
//printf("Running...\n"); | ||
ruby_script(filename); | ||
} | ||
|
||
int error; | ||
|
||
char* args[2] = {"test", (char*) filename}; | ||
|
||
void* options = ruby_options(2, args); | ||
|
||
int return_value = ruby_run_node(options); | ||
//printf("Done running.\n"); | ||
int return_value = ruby_exec_node(options); | ||
|
||
VALUE exception = rb_errinfo(); | ||
if(exception != Qnil) { | ||
|
||
VALUE exception_str = rb_inspect(exception); | ||
|
||
printf("%s\n", rb_string_value_cstr(&exception_str)); | ||
|
||
} | ||
|
||
//! TODO: Fix segfaults at second execution | ||
|
||
} | ||
|
||
extern void execute_script_line(void* rb, const char* text) { | ||
|
||
int status; | ||
rb_eval_string_protect(text, &status); | ||
|
||
if(status) { | ||
|
||
VALUE exception = rb_errinfo(); | ||
VALUE exception_str = rb_inspect(exception); | ||
|
||
//! TODO: Are there any internal methods to print this prettier? | ||
|
||
printf("%s\n", rb_string_value_cstr(&exception_str)); | ||
|
||
} | ||
|
||
} |
This file contains 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 characters
This file contains 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 characters