diff --git a/TODO b/TODO --- a/TODO +++ b/TODO @@ -1,9 +1,5 @@ -* Use Parenscript's packages -* Use Parenscript's minifier -* Remove dots * MENU with async/await -* Find a way to minify syntax (extra returns at least) * Special locations * Special variables * CLI build for Linux diff --git a/src/api.ps b/src/api.ps --- a/src/api.ps +++ b/src/api.ps @@ -125,7 +125,7 @@ (defun enable-frame (key enable) (let ((obj (get-frame key))) (setf (@ obj style display) (if enable "block" "none")) - (values))) + (void))) ;;; Actions @@ -167,7 +167,7 @@ (setf (@ this indexes) (create)) ;; From numbers to {num: 0, str: ""} objects (setf (@ this values) (list)) - (values)) + (void)) (defun new-value () (create :num 0 :str "")) @@ -202,7 +202,7 @@ (setf (getprop (@ this values) (chain this (index-num index)) slot) value) - (values))) + (void))) (setf (@ *var prototype kill) (lambda (index) @@ -220,7 +220,7 @@ (defun ensure-var (name) (let ((store (var-ref name))) (unless store - (setf store (new (-var name))) + (setf store (new (*var name))) (setf (getprop (root vars) name) store)) store)) @@ -237,7 +237,7 @@ (defun set-var (name index slot value) (chain (ensure-var name) (set index slot value)) - (values)) + (void)) (defun get-array (name) (var-ref name)) @@ -246,13 +246,13 @@ (let ((store (var-ref name))) (setf (@ store values) (@ value values)) (setf (@ store indexes) (@ value indexes))) - (values)) + (void)) (defun kill-var (name &optional index) (if (and index (not (= 0 index))) (chain (getprop (root vars) name) (kill index)) (delete (getprop (root vars) name))) - (values)) + (void)) (defun array-size (name) (getprop (var-ref name) 'length)) @@ -261,11 +261,11 @@ (defun push-local-frame () (chain (root locals) (push (create))) - (values)) + (void)) (defun pop-local-frame () (chain (root locals) (pop)) - (values)) + (void)) (defun current-local-frame () (elt (root locals) (1- (length (root locals))))) @@ -274,7 +274,7 @@ (let ((frame (current-local-frame))) (unless (in name frame) (setf (getprop frame name) (create))) - (values))) + (void))) ;;; Objects @@ -357,35 +357,37 @@ (call-serv-loc "ONGSAVE") (setf (root state-stash) (chain *j-s-o-n (stringify - (create vars (root vars) - objs (root objs) - loc-args args - msecs (- (chain *date (now)) (root started-at)) - main-html (inner-html - (by-id :qsp-main)) - stat-html (inner-html - (by-id :qsp-stat)) - next-location (root current-location))))) - (values)) + (create :vars (root vars) + :objs (root objs) + :loc-args args + :msecs (- (chain *date (now)) (root started-at)) + :timer-interval (root timer-interval) + :main-html (inner-html + (by-id :qsp-main)) + :stat-html (inner-html + (by-id :qsp-stat)) + :next-location (root current-location))))) + (void)) (defun unstash-state () (let ((data (chain *j-s-o-n (parse (root state-stash))))) (clear-act) - (setf (root vars) (@ data vars)) + (setf (root vars) (@ data :vars)) (loop :for k :in (chain *object (keys (root vars))) :do (chain *object (set-prototype-of (getprop (root vars) k) (@ *var prototype)))) - (setf (root started-at) (- (chain *date (now)) (@ data msecs))) - (setf (root objs) (@ data objs)) - (setf (root current-location) (@ data next-location)) + (setf (root started-at) (- (chain *date (now)) (@ data :msecs))) + (setf (root objs) (@ data :objs)) + (setf (root current-location) (@ data :next-location)) (setf (inner-html (by-id :qsp-main)) - (@ data main-html)) + (@ data :main-html)) (setf (inner-html (by-id :qsp-stat)) - (@ data stat-html)) + (@ data :stat-html)) (update-objs) + (set-timer (@ data :timer-interval)) (call-serv-loc "ONGLOAD") - (call-loc (root current-location) (@ data loc-args)) - (values))) + (call-loc (root current-location) (@ data :loc-args)) + (void))) (defun state-to-base64 () (btoa (encode-u-r-i-component (root state-stash)))) diff --git a/src/intrinsics.ps b/src/intrinsics.ps --- a/src/intrinsics.ps +++ b/src/intrinsics.ps @@ -10,7 +10,7 @@ (defun goto (target args) (api:clear-text :main) (funcall xgoto target (or args (list))) - (values)) + (void)) (defun xgoto (target args) (api:clear-act) @@ -18,7 +18,7 @@ (api:stash-state args) (funcall (getprop (root locs) (root current-location)) (or args (list))) - (values)) + (void)) ;;; 2var @@ -100,7 +100,7 @@ (defun gosub (target &rest args) (funcall (getprop (root locs) target) args) - (values)) + (void)) (defun func (target &rest args) (funcall (getprop (root locs) target) args)) @@ -111,14 +111,14 @@ (defun dynamic (block &rest args) (when (stringp block) - (api:report-error "DYNAMIC can't evaluate arbitrary strings.\nUse {braces} to create blocks for DYNAMIC.")) + (api:report-error "DYNAMIC can't evaluate arbitrary strings.\\nUse {braces} to create blocks for DYNAMIC.")) (api:with-call-args args (funcall block args)) - (values)) + (void)) (defun dyneval (block &rest args) (when (stringp block) - (api:report-error "DYNEVAL can't evaluate arbitrary strings.\nUse {braces} to create blocks for DYNEVAL.")) + (api:report-error "DYNEVAL can't evaluate arbitrary strings.\\nUse {braces} to create blocks for DYNEVAL.")) (api:with-call-args args (funcall block args))) @@ -126,21 +126,21 @@ (defun main-p (s) (api:add-text :main s) - (values)) + (void)) (defun main-pl (s) (api:add-text :main s) (api:newline :main) - (values)) + (void)) (defun main-nl (s) (api:newline :main) (api:add-text :main s) - (values)) + (void)) (defun maintxt (s) (api:get-text :main) - (values)) + (void)) ;; For clarity (it leaves a lib.desc() call in JS) (defun desc (s) @@ -148,38 +148,38 @@ (defun main-clear () (api:clear-text :main) - (values)) + (void)) ;;; 12stat (defun stat-p (s) (api:add-text :stat s) - (values)) + (void)) (defun stat-pl (s) (api:add-text :stat s) (api:newline :stat) - (values)) + (void)) (defun stat-nl (s) (api:newline :stat) (api:add-text :stat s) - (values)) + (void)) (defun stattxt (s) (api:get-text :stat) - (values)) + (void)) (defun stat-clear () (api:clear-text :stat) - (values)) + (void)) (defun cls () (stat-clear) (main-clear) (cla) (cmdclear) - (values)) + (void)) ;;; 13diag @@ -189,27 +189,27 @@ (let ((acts (root acts))) (lambda () (setf (root acts) acts) - (values)))) + (void)))) ;;; 15objs (defun addobj (name) (chain (root objs) (push name)) (api:update-objs) - (values)) + (void)) (defun delobj (name) (let ((index (chain (root objs) (index-of name)))) (when (> index -1) (killobj (1+ index)))) - (values)) + (void)) (defun killobj (&optional (num nil)) (if (eq nil num) (setf (root objs) (list)) (chain (root objs) (splice (1- num) 1))) (api:update-objs) - (values)) + (void)) ;;; 16menu @@ -232,7 +232,7 @@ loc loc icon icon)))))))) (api:menu menu-data) - (values))) + (void))) ;;; 17sound @@ -244,7 +244,8 @@ (defun close (filename) (funcall (root playing filename) stop) - (delete (root playing filename))) + (delete (root playing filename)) + (void)) (defun closeall () (loop :for k :in (chain *object (keys (root playing))) diff --git a/src/patches.lisp b/src/patches.lisp --- a/src/patches.lisp +++ b/src/patches.lisp @@ -58,3 +58,12 @@ (ps-print body)) (cl:export '=>) + +;;; Actually return nothing (with no empty return) +(defvar *old-return-result-of* (function return-result-of)) + +(defun return-result-of (tag form) + (if (equal form '(void)) + nil + (funcall *old-return-result-of* tag form))) +(export 'void) diff --git a/src/ps-macros.lisp b/src/ps-macros.lisp --- a/src/ps-macros.lisp +++ b/src/ps-macros.lisp @@ -9,16 +9,14 @@ ;;; Common -(defpsmacro label-block ((&key (locals t)) &body body) +(defpsmacro label-block (() &body body) (let ((has-labels (some #'keywordp body))) `(block nil ,@(when has-labels '((defvar __labels))) - ,@(if locals - `((tagbody - ,@body)) - `((tagbody - ,@body)))))) + (tagbody + ,@body + (void))))) (defpsmacro str (&rest forms) (cond ((zerop (length forms)) @@ -130,7 +128,7 @@ `(api-call add-act ,name ,img (async-lambda () (label-block () - ,@body)))) + ,@body)))) ;;; 12aux