(defmacro named-lambda (name args &rest body)
(let ((x (gensym "FN")))
`(let ((,x (lambda ,args ,@body)))
- (set ,x "fname" ,name)
+ (oset ,x "fname" ,name)
,x)))
(defmacro %defun (name args &rest body)
(defvar *package* (new))
(defvar nil (make-symbol "NIL"))
- (set *package* "NIL" nil)
+ (oset *package* "NIL" nil)
(defvar t (make-symbol "T"))
- (set *package* "T" t)
+ (oset *package* "T" t)
(defun null (x)
(eq x nil))
(defun intern (name)
(if (internp name)
- (get *package* name)
- (set *package* name (make-symbol name))))
+ (oget *package* name)
+ (oset *package* name (make-symbol name))))
(defun find-symbol (name)
- (get *package* name))
+ (oget *package* name))
(defvar *gensym-counter* 0)
(defun gensym (&optional (prefix "G"))
((integerp form) (integer-to-string form))
((stringp form) (concat "\"" (escape-string form) "\""))
((functionp form)
- (let ((name (get form "fname")))
+ (let ((name (oget form "fname")))
(if name
(concat "#<FUNCTION " name ">")
(concat "#<FUNCTION>"))))
" = "
(ls-compile val env)))
+
;;; Literals
(defun escape-string (string)
(let ((output "")
(define-builtin symbol-name (x)
(concat "(" x ").name"))
+(define-builtin set (symbol value)
+ (concat "(" symbol ").value =" value))
+
+(define-builtin symbol-value (x)
+ (concat "(" x ").value"))
+
+(define-builtin symbol-function (x)
+ (concat "(" x ").function"))
+
(define-builtin eq (x y) (js!bool (concat "(" x " === " y ")")))
(define-builtin equal (x y) (js!bool (concat "(" x " == " y ")")))
(define-builtin new () "{}")
-(define-builtin get (object key)
+(define-builtin oget (object key)
(js!selfcall
"var tmp = " "(" object ")[" key "];" *newline*
"return tmp == undefined? " (ls-compile nil) ": tmp ;" *newline*))
-(define-builtin set (object key value)
+(define-builtin oset (object key value)
(concat "((" object ")[" key "] = " value ")"))
(define-builtin in (key object)