Created
December 29, 2010 01:58
-
-
Save kapace/758046 to your computer and use it in GitHub Desktop.
parrot embed/api.c tests
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
c_output_is(linedirective(__LINE__) . <<'CODE', <<'OUTPUT', 'Test Std handles'); | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "parrot/parrot.h" | |
#include "parrot/api.h" | |
#include "parrot/embed.h" | |
#include "parrot/extend.h" | |
static void fail(const char *msg); | |
static Parrot_String createstring(Parrot_Interp interp, const char * value); | |
static void fail(const char *msg) | |
{ | |
fprintf(stderr, "failed: %s\n", msg); | |
exit(EXIT_FAILURE); | |
} | |
static Parrot_String createstring(Parrot_Interp interp, const char * value) | |
{ | |
return Parrot_new_string(interp, value, strlen(value), (const char*)NULL, 0); | |
} | |
int main(int argc, const char **argv) | |
{ | |
/*Parrot_Interp interp; | |
Parrot_String compiler; | |
Parrot_String errstr; | |
Parrot_PMC code; | |
FILE * stdout = fopen("/tmp/stdout", "w"); | |
//FILE * stdin = fopen("/tmp/stdin", "r"); | |
FILE * stderr = fopen("/tmp/stdin", "w"); | |
// Create the interpreter and show a message using parrot io | |
interp = Parrot_new(NULL); | |
Parrot_api_set_stdhandles(interp, stdout, PIO_INVALID_HANDLE, PIO_INVALID_HANDLE); | |
puts("Done"); | |
// Run a simple program that should output something, but not to the screen. | |
// Compile and execute a pir sub | |
compiler = createstring(interp, "PIR"); | |
code = Parrot_compile_string(interp, compiler, | |
".sub main :main\n" | |
" say 'Hello, pir'\n" | |
"\n" | |
".end\n" | |
"\n", | |
&errstr | |
); | |
Parrot_ext_call(interp, code, "->"); | |
Parrot_destroy(interp);*/ | |
char * c_outstr = NULL; | |
Parrot_Init_Args *initargs = NULL; | |
Parrot_PMC interpmc = NULL; | |
Parrot_PMC p_str = NULL, p_keyedstr = NULL; | |
Parrot_String s_teststr = NULL, s_outstr = NULL; | |
FILE * stdout = fopen("/tmp/stdout", "w"); | |
//FILE * stdin = fopen("/tmp/stdin", "r"); | |
FILE * stderr = fopen("/tmp/stdin", "w"); | |
GET_INIT_STRUCT(initargs); | |
Parrot_api_make_interpreter(NULL, 0, initargs, &interpmc); | |
Parrot_api_set_stdhandles(interpmc, stdout, PIO_INVALID_HANDLE, PIO_INVALID_HANDLE); | |
puts("Done"); | |
return 0; | |
} | |
CODE | |
Done | |
OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment