# HG changeset patch # User # Date 2020-03-24 09:32:42 # Node ID 77d821545d073b1cb41767cae8dffb2bf37bcbcf # Parent 944c8b3e3b136906aebfd7ea9fcffe583e9a0bb3 Fix labels diff --git a/TODO b/TODO --- a/TODO +++ b/TODO @@ -1,12 +1,14 @@ +* Duplicate label error (in the parser) +* Reporting error lines in the parser * MENU with async/await * Special locations * Special variables * CLI build for Linux * CLI build for Windows +* Storing error lines in the parser to report it in runtime errors * Build Istreblenie * Windows GUI (for the compiler) * Save-load game in slots * Resizable frames -** modifying it to suit compiler specifics diff --git a/examples/9loops.txt b/examples/9loops.txt --- a/examples/9loops.txt +++ b/examples/9loops.txt @@ -6,22 +6,23 @@ p 'Это сообщение не будет выведено' p 'А это сообщение пользователь увидит' s=0 -:loop +:loop1 if s<9: s=s+1 pl s - jump 'loop' + jump 'loop1' end p 'Всё!' -:loop +:loop2 if y y0: exit end - diff --git a/src/package.lisp b/src/package.lisp --- a/src/package.lisp +++ b/src/package.lisp @@ -40,7 +40,7 @@ (:use :cl :ps :sugar-qsp.main :sugar-qsp.js) (:local-nicknames (#:api :sugar-qsp.api)) (:export #:str #:exec #:qspblock #:qspfor #:location - #:qspcond #:qspvar #:set #:local + #:qspcond #:qspvar #:set #:local #:jump #:killvar #:killall #:obj #:loc #:no diff --git a/src/ps-macros.lisp b/src/ps-macros.lisp --- a/src/ps-macros.lisp +++ b/src/ps-macros.lisp @@ -13,7 +13,7 @@ (let ((has-labels (some #'keywordp body))) `(block nil ,@(when has-labels - '((defvar __labels))) + '((defvar _labels))) (tagbody ,@body (void))))) @@ -88,15 +88,15 @@ ;;; Yep, that's a huge kludge since Javascript doesn't support arbitrary labels (defpsmacro jump (target) - `(return-from ,(intern (string-upcase (second target))) - (funcall (getprop __labels ,target)))) + `(return-from label-body + (funcall (getprop _labels ,(string-upcase (second target)))))) (defpsmacro tagbody (&body body) - (let ((funcs (list nil :__nil))) + (let ((funcs (list nil "_nil"))) (dolist (form body) (cond ((keywordp form) (setf (first funcs) (reverse (first funcs))) - (push form funcs) + (push (string-upcase form) funcs) (push nil funcs)) (t (push form (first funcs))))) @@ -106,14 +106,15 @@ `(progn ,@body) `(progn - (setf ,@(loop :for f :on funcs :by #'cddr - :append `((@ __labels ,(first f)) - (block ,(intern (string-upcase (string (first f)))) - ,@(second f) - ,@(when (third f) - `((funcall - (getprop __labels ,(third f))))))))) - (jump (str "__nil")))))) + (setf ,@(loop :for (label code . rest-labels) :on funcs :by #'cddr + :append `((@ _labels ,label) + (block label-body + (block ,(intern label) + ,@code + ,@(when rest-labels + `((funcall + (getprop _labels ,(first rest-labels)))))))))) + (funcall (getprop _labels "_nil")))))) ;;; 10dynamic