On May 16, 2014, at 9:36 AM, Marc Feeley <feeley@iro.umontreal.ca> wrote:
You need to
(declare (extended-bindings) (not safe))
for those procedures to be inlined.
I may change the “safety” of those procedures though because others have had similar problems.
Also I will add tests to avoid JS-level errors when calling an undefined global variable.
Marc
I have now changed the safety to avoid the need for (not safe). Also, the procedures ##inline-host-expression and ##inline-host-statement have been generalized to allow parameters. The Nth parameter after the code string will be inserted where there is a @N@ reference in the code string. Finally the ##inline-host-declaration procedure has been added to allow inserting toplevel host code in the generated code. Below is an example. Note the use of the Gambit_scm2js and Gambit_js2scm functions to convert values between their JavaScript and Scheme representations. Marc (declare (extended-bindings)) ;; to inline the ##inline-host-... procedures (##inline-host-declaration #<<host-code-end function out(x) { console.log(x); } host-code-end ) (define (out x) (##inline-host-statement "out(Gambit_scm2js(@1@));" x)) (define (add x y) (##inline-host-expression "Gambit_js2scm(Gambit_scm2js(@1@) + Gambit_scm2js(@2@))" x y)) (out "hello!") (out #t) (out (add 11 22)) ;; Output: ;; ;; % gsc -c -target js test.scm ;; % node test.js ;; hello! ;; true ;; 33