X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=ecmalisp.lisp;h=2da30af2fe4fe70538b430772a7a1954937f49bf;hb=def5b23c6aa5146d80f4182f45e2a757fd0a5178;hp=3eec9dd67b3f8b7bc5f70fdcd3fcce62242df701;hpb=d91eeceff8f1d679c935ec473115f72c9b3d6ec7;p=jscl.git diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 3eec9dd..2da30af 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -416,7 +416,20 @@ (car alist)) (defun string= (s1 s2) - (equal s1 s2))) + (equal s1 s2)) + + (defun fdefinition (x) + (cond + ((functionp x) + x) + ((symbolp x) + (symbol-function x)) + (t + (error "Invalid function")))) + + (defun disassemble (function) + (write-line (lambda-code (fdefinition function))) + nil)) ;;; The compiler offers some primitives and special forms which are @@ -1200,9 +1213,10 @@ ;;; Primitives (defmacro define-builtin (name args &body body) - `(define-compilation ,name ,args - (let ,(mapcar (lambda (arg) `(,arg (ls-compile ,arg env))) args) - ,@body))) + `(progn + (define-compilation ,name ,args + (let ,(mapcar (lambda (arg) `(,arg (ls-compile ,arg env))) args) + ,@body)))) ;;; DECLS is a list of (JSVARNAME TYPE LISPFORM) declarations. (defmacro type-check (decls &body body) @@ -1312,6 +1326,9 @@ (define-builtin symbol-plist (x) (concat "((" x ").plist || " (ls-compile nil) ")")) +(define-builtin lambda-code (x) + (concat "(" x ").toString()")) + (define-builtin eq (x y) (js!bool (concat "(" x " === " y ")"))) (define-builtin equal (x y) (js!bool (concat "(" x " == " y ")")))