OSET* and OGET* type-preserving variants and *root* Javascript object
authorDavid Vázquez <davazp@gmail.com>
Tue, 4 Jun 2013 19:23:36 +0000 (20:23 +0100)
committerDavid Vázquez <davazp@gmail.com>
Tue, 4 Jun 2013 19:23:36 +0000 (20:23 +0100)
src/compiler.lisp
src/ffi.lisp

index 0ad7637..c5787c8 100644 (file)
 (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')")))
 
 
 ;;; 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 ")"))
 
index 29862a8..32b9f21 100644 (file)
@@ -32,3 +32,5 @@
       (%define-symbol-macro symbol `(%js-vref ,(string symbol))))))
 
 (setq *intern-hook* #'ffi-intern-hook)
+
+(defvar *root* (%js-vref "window"))