Last active
July 26, 2017 16:36
-
-
Save shhyou/aa2adaf7e1b7d548783cee352c3230a9 to your computer and use it in GitHub Desktop.
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
#lang my-lang | |
(provide (all-defined-out)) | |
(define (a-binding-to-a-function x) | |
(list "this is in a function with" x "being the first argument")) | |
(printf "In Racket: module instantiated: ~s\n" (a-binding-to-a-function 'arg)) | |
(define a-value 12354) | |
;; By default, this should print 12354 | |
a-value |
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
/* | |
raco ctool --cgc --c-mods base.c ++lib racket/base ++lib racket/runtime-config ++lib my-lang ++lib my-lang/lang/reader | |
g++ -framework Foundation -I<RACKET-HEAD-REPO>/racket/include -L<RACKET-HEAD-REPO>/racket/src/build/racket -L<RACKET-HEAD-REPO>/racket/src/build/rktio custom_dsl.cpp -o custom_dsl -lracket -lmzgc -lrktio -liconv | |
./custom_dsl ./a-module.rkt | |
*/ | |
#include <scheme.h> | |
#include <iostream> | |
#include "base.c" | |
static int run(Scheme_Env *e, int argc, char *argv[]) | |
{ | |
Scheme_Object *curout; | |
int i; | |
Scheme_Thread *th; | |
mz_jmp_buf * volatile save, fresh; | |
/* Declare embedded modules in "base.c": */ | |
declare_modules(e); | |
scheme_namespace_require(scheme_intern_symbol("my-lang")); | |
curout = scheme_get_param(scheme_current_config(), | |
MZCONFIG_OUTPUT_PORT); | |
th = scheme_get_current_thread(); | |
save = th->error_buf; | |
th->error_buf = &fresh; | |
if (scheme_setjmp(*th->error_buf)) { | |
th->error_buf = save; | |
return -1; /* There was an error */ | |
} else { | |
std::cout << "Trying to load file from \"" << argv[1] << "\"\n"; | |
Scheme_Object *custom_dsl_path[2]; | |
custom_dsl_path[0] = scheme_make_pair( | |
scheme_intern_symbol("file"), | |
scheme_make_pair( | |
scheme_make_utf8_string(argv[1]), | |
scheme_make_null())); | |
custom_dsl_path[1] = scheme_make_false(); | |
Scheme_Object *custom_dsl = scheme_dynamic_require(2, custom_dsl_path); | |
th->error_buf = save; | |
} | |
return 0; | |
} | |
int main(int argc, char **argv) { | |
std::cout << "In cpp main\n"; | |
return scheme_main_setup(1, run, argc, argv); | |
} | |
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
$ raco ctool --cgc --c-mods base.c ++lib racket/base ++lib racket/runtime-config ++lib my-lang ++lib my-lang/lang/reader | |
$ g++ -framework Foundation -I<RACKET-HEAD-REPO>/racket/include -L<RACKET-HEAD-REPO>/racket/src/build/racket -L<RACKET-HEAD-REPO>/racket/src/build/rktio custom_dsl.cpp -o custom_dsl -lracket -lmzgc -lrktio -liconv | |
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame | |
$ ./custom_dsl ./a-module.rkt | |
In cpp main | |
Trying to load file from "./a-module.rkt" | |
'(provide (all-defined-out)) | |
'(define (a-binding-to-a-function x) (list "this is in a function with" x "being the first argument")) | |
'(printf "In Racket: module instantiated: ~s\n" (a-binding-to-a-function 'arg)) | |
'(define a-value 12354) | |
'a-value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment