From: David Vázquez Date: Tue, 4 Jun 2013 19:23:36 +0000 (+0100) Subject: OSET* and OGET* type-preserving variants and *root* Javascript object X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=bc239e6931441439be5afd9c6221a532340e5eb1;p=jscl.git OSET* and OGET* type-preserving variants and *root* Javascript object --- diff --git a/src/compiler.lisp b/src/compiler.lisp index 0ad7637..c5787c8 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1242,35 +1242,6 @@ (define-builtin %throw (string) (js!selfcall "throw " string ";" *newline*)) -(define-builtin new () "{}") - -(define-builtin objectp (x) - (js!bool (code "(typeof (" x ") === 'object')"))) - -(define-builtin lisp-to-js (x) (code "lisp_to_js(" x ")")) -(define-builtin js-to-lisp (x) (code "js_to_lisp(" x ")")) - -(define-builtin oget (object key) - (js!selfcall - "var tmp = " "(" object ")[xstring(" key ")];" *newline* - "return tmp == undefined? " (ls-compile nil) ": tmp ;" *newline*)) - -(define-builtin oset (object key value) - (code "((" object ")[xstring(" key ")] = " value ")")) - -(define-builtin in (key object) - (js!bool (code "(xstring(" key ") in (" object "))"))) - -(define-builtin map-for-in (function object) - (js!selfcall - "var f = " function ";" *newline* - "var g = (typeof f === 'function' ? f : f.fvalue);" *newline* - "var o = " object ";" *newline* - "for (var key in o){" *newline* - (indent "g(" (if *multiple-value-p* "values" "pv") ", 1, o[key]);" *newline*) - "}" - " return " (ls-compile nil) ";" *newline*)) - (define-builtin functionp (x) (js!bool (code "(typeof " x " == 'function')"))) @@ -1336,6 +1307,45 @@ ;;; Javascript FFI +(define-builtin new () "{}") + +(define-builtin oget* (object key) + (js!selfcall + "var tmp = " "(" object ")[xstring(" key ")];" *newline* + "return tmp == undefined? " (ls-compile nil) ": tmp ;" *newline*)) + +(define-builtin oset* (object key value) + (code "((" object ")[xstring(" key ")] = " value ")")) + +(define-builtin oget (object key) + (js!selfcall + "var tmp = " "(" object ")[xstring(" key ")];" *newline* + "return tmp == undefined? " (ls-compile nil) ": js_to_lisp(tmp);" *newline*)) + +(define-builtin oset (object key value) + (code "((" object ")[xstring(" key ")] = lisp_to_js(" value "))")) + + +(define-builtin objectp (x) + (js!bool (code "(typeof (" x ") === 'object')"))) + +(define-builtin lisp-to-js (x) (code "lisp_to_js(" x ")")) +(define-builtin js-to-lisp (x) (code "js_to_lisp(" x ")")) + + +(define-builtin in (key object) + (js!bool (code "(xstring(" key ") in (" object "))"))) + +(define-builtin map-for-in (function object) + (js!selfcall + "var f = " function ";" *newline* + "var g = (typeof f === 'function' ? f : f.fvalue);" *newline* + "var o = " object ";" *newline* + "for (var key in o){" *newline* + (indent "g(" (if *multiple-value-p* "values" "pv") ", 1, o[key]);" *newline*) + "}" + " return " (ls-compile nil) ";" *newline*)) + (define-compilation %js-vref (var) (code "js_to_lisp(" var ")")) diff --git a/src/ffi.lisp b/src/ffi.lisp index 29862a8..32b9f21 100644 --- a/src/ffi.lisp +++ b/src/ffi.lisp @@ -32,3 +32,5 @@ (%define-symbol-macro symbol `(%js-vref ,(string symbol)))))) (setq *intern-hook* #'ffi-intern-hook) + +(defvar *root* (%js-vref "window"))