
  Emotinomicon code generation helper

(defgeneric translate (cmd))

(defmethod translate ((cmd list))
  (ecase (first cmd)
    (push0 "😀")
    (push1 "😅")
    (push2 "😉")
    (push3 "😍")
    (push4 "😒")
    (push5 "😗")
    (push6 "😜")
    (push7 "😡")
    (push8 "😁")
    (push9 "😆")
    (push10 "🔟")
    (push100 "💯")
    (add "➕")
    (sub "➖")
    (div "➗")
    (mul "✖")
    (input-char "⏫")
    (output-char "⏬")
    (open-loop "⏪")
    (close-loop "⏩")
    (dup "🆙")
    (drop "😊")
    (reverse-stack "😎")
    (reverse-n "😓") ; DOESN'T WORK IN THE REFERENCE IMPLEMENTATION !!
    (pow "😘")
    (log "😝")
    (negate "😢")
    (abs "😂")
    (2n "😇")
    (3n "☺️")
    (4n "😏")
    (n/2 "😔")
    (n/3 "😙")
    (n/4 "😞")
    (n^2 "😣")
    (n^3 "😃")
    (n^4 "😈")
    (sqrt "😋")
    (cbrt "😐")
    (4rt "😕")
    (floor "😚")
    (ceil "😟")
    (round "😤")
    (n+1 "😄")
    (n-1 "👿")
    (mod "😌")
    (2^n "😑")
    (3^n "😖")
    (4^n "😛")
    (fibo "😠")
    (lucas "😥")
    (pi "😦")
    (e "😫")
    (phi "😰")
    (ln "😵")
    (log10 "😺")
    (e^n "😿")
    (10^n "😧")
    (pop-and-goto "😬")
    (pop-and-modify-code "😱")
    (pop-and-get-code "😶")
    (n%2 "😻")
    (rand "🙀")
    (output-num "😨")
    (begin-quote "😭")
    (end-quote "😲")
    (factorial "️❗")
    (if-then-else "️❓")
    (skip "❕")
    (skip-if-true "❔")
    (double-factorial "‼")
    (skip-if-false "⁉")))

(defmethod translate ((cmd string))
  cmd)

(defmethod translate-all (cmd)
  (mapcar #'translate cmd))

(defun lit-string (body)
  `((begin-string)
    ,@body
    (end-string)))

(defun do-loop (body)
  `((open-loop)
    ,@body
    (close-loop)))

(defun do-while (body)
  (do-loop
    `(,@body
      (skip-if-false))))

  Only supports numbers from 0 to 100
(defun push-num (n)
  (case n
    (0 '((push0)))
    (1 '((push1)))
    (2 '((push2)))
    (3 '((push3)))
    (4 '((push4)))
    (5 '((push5)))
    (6 '((push6)))
    (7 '((push7)))
    (8 '((push8)))
    (9 '((push9)))
    (10 '((push10)))
    (100 '((push100)))
    (t `((push10) ,@(push-num (- n 10)) (add)))))

  Copies the Nth element on the stack
;;
;; (copy-nth 0) is equivalent to (dup)
;; (defun copy-nth (n)
    ` ( ,    n )
;;     (reverse-n)
;;     (dup)
      ,    ( 1 + n ) )
;;     (reverse-n)
      ,    n )
;;     (reverse-n)
      ,    ( 1 + n ) )
;;     (reverse-n)))

(defun padding (n)
  (loop for i = 1 to n
        collect '(reverse-stack)))

(format t "~{~A~}~%"
        (translate-all `(,@(padding 20)
                         (

;; (format t "~{~A~}~%"
          ( translate - all ` ( , @(push - num 10 )
                           , @(push - num 20 )
                           , @(push - num 30 )
                           , @(push - num 40 )
                           , @(push - num 50 )
                           , @(push - num 60 )
                           , @(copy - nth 2 )
;;                          (output-num)
;;                          (output-num)
;;                          (output-num)
;;                          (output-num)
;;                          (output-num)
;;                          (output-num))))

 DOESN'T WORK IN THE REFERENCE IMPLEMENTATION !!

 (copy-nth 0) is equivalent to (dup)
 (defun copy-nth (n)
     (reverse-n)
     (dup)
     (reverse-n)
     (reverse-n)
     (reverse-n)))
 (format t "~{~A~}~%"
                          (output-num)
                          (output-num)
                          (output-num)
                          (output-num)
                          (output-num)
                          (output-num))))

  Emotinomicon code generation helper

(defgeneric translate (cmd))

(defmethod translate ((cmd list))
  (ecase (first cmd)
    (push0 "😀")
    (push1 "😅")
    (push2 "😉")
    (push3 "😍")
    (push4 "😒")
    (push5 "😗")
    (push6 "😜")
    (push7 "😡")
    (push8 "😁")
    (push9 "😆")
    (push10 "🔟")
    (push100 "💯")
    (add "➕")
    (sub "➖")
    (div "➗")
    (mul "✖")
    (input-char "⏫")
    (output-char "⏬")
    (open-loop "⏪")
    (close-loop "⏩")
    (dup "🆙")
    (drop "😊")
    (reverse-stack "😎")
    (pow "😘")
    (log "😝")
    (negate "😢")
    (abs "😂")
    (2n "😇")
    (3n "☺️")
    (4n "😏")
    (n/2 "😔")
    (n/3 "😙")
    (n/4 "😞")
    (n^2 "😣")
    (n^3 "😃")
    (n^4 "😈")
    (sqrt "😋")
    (cbrt "😐")
    (4rt "😕")
    (floor "😚")
    (ceil "😟")
    (round "😤")
    (n+1 "😄")
    (n-1 "👿")
    (mod "😌")
    (2^n "😑")
    (3^n "😖")
    (4^n "😛")
    (fibo "😠")
    (lucas "😥")
    (pi "😦")
    (e "😫")
    (phi "😰")
    (ln "😵")
    (log10 "😺")
    (e^n "😿")
    (10^n "😧")
    (pop-and-goto "😬")
    (pop-and-modify-code "😱")
    (pop-and-get-code "😶")
    (n%2 "😻")
    (rand "🙀")
    (output-num "😨")
    (begin-quote "😭")
    (end-quote "😲")
    (factorial "️❗")
    (if-then-else "️❓")
    (skip "❕")
    (skip-if-true "❔")
    (double-factorial "‼")
    (skip-if-false "⁉")))

(defmethod translate ((cmd string))
  cmd)

(defmethod translate-all (cmd)
  (mapcar #'translate cmd))

(defun lit-string (body)
  `((begin-string)
    ,@body
    (end-string)))

(defun do-loop (body)
  `((open-loop)
    ,@body
    (close-loop)))

(defun do-while (body)
  (do-loop
    `(,@body
      (skip-if-false))))

  Only supports numbers from 0 to 100
(defun push-num (n)
  (case n
    (0 '((push0)))
    (1 '((push1)))
    (2 '((push2)))
    (3 '((push3)))
    (4 '((push4)))
    (5 '((push5)))
    (6 '((push6)))
    (7 '((push7)))
    (8 '((push8)))
    (9 '((push9)))
    (10 '((push10)))
    (100 '((push100)))
    (t `((push10) ,@(push-num (- n 10)) (add)))))

  Copies the Nth element on the stack
    ` ( ,    n )
      ,    ( 1 + n ) )
      ,    n )
      ,    ( 1 + n ) )

(defun padding (n)
  (loop for i = 1 to n
        collect '(reverse-stack)))

(format t "~{~A~}~%"
        (translate-all `(,@(padding 20)
                         (

          ( translate - all ` ( , @(push - num 10 )
                           , @(push - num 20 )
                           , @(push - num 30 )
                           , @(push - num 40 )
                           , @(push - num 50 )
                           , @(push - num 60 )
                           , @(copy - nth 2 )
