rexim / ebf

Brainfuck language transpiler to Emacs Lisp
20 stars 3 forks source link

ebf without runtime dependency #14

Closed rexim closed 8 years ago

rexim commented 8 years ago

The result of the ebf macro expansion doesn't require ebf at runtime. So theoretically it's possible to byte-compile a brainfuck program that doesn't require ebf package at runtime. We need to check and document that.

rexim commented 8 years ago

This trick is usually done via eval-when-compile elisp macro.

rexim commented 8 years ago

Can be useful http://www.gnu.org/software/emacs/manual/html_node/elisp/Compiling-Macros.html

rexim commented 8 years ago

Just managed to compile rot13 example:

(eval-when-compile
  (require 'ebf))

(defun rot13 (text)
  (let ((input (mapcar #'identity text))
        (result nil))
    (ebf (lambda () (if (not input) -1 (pop input)))
         (lambda (x) (push x result))
         -\,+
         [-
          [>>++++
           [>++++++++<-]
           <+<-
           [>+>+>-
            [>>>]
            <
            [[>+<-]>>+>]
            <<<<<-]]
          >>>[-]+
          >--
          [-[<->+++[-]]]<
          [++++++++++++<
           [>-
            [>+>>]
            >[+[<+>-]>+>>]
            <<<<<-]
           >>[<+>-]
           >[-[-<<[-]>>]<<[<<->>-]>>]
           <<[<<+>>-]]
          <[-]
          <.[-]
          <-\,+])
    (apply #'string (reverse result))))

(provide 'rot13)

And the resulting module really doesn't require ebf at runtime. It's possible.

rexim commented 8 years ago

But if I want to byte compile without runtime dependency I should not use ebf-input-string in my code.