Skip to content

Commit

Permalink
Dags.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoore committed Sep 22, 2015
1 parent 3b4b9f8 commit d64bf9f
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 22 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

![](dags.jpg)

Pikey is a Javascript compiler using Parenscript.

It's work in progress. To build it, you need SBCL and quicklisp.
Then, just `sbcl --load build.lisp`


## Usage

`pikey -i <infile> -o <outfile>`

### Macros

This is really the whole reason for using Pikey.

Pikey will load macros from `macros.lisp` in the current working directory.

So, for instance, if `macros.lisp` contains

``` lisp
(in-package :pikey)
(defmacro+ps dr (&rest body)
`((@ ($ document) ready) (lambda ()
,@body)))
```

and your source file contains

``` lisp
(dr (defvar x 1))
```

`pikey -i source.lisp -o test.js` will produce

``` javascript

$(document).ready(function () {
var x = 1;
});

```

12 changes: 0 additions & 12 deletions README.txt

This file was deleted.

12 changes: 12 additions & 0 deletions build.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

(ql:quickload 'pikey)

(require :asdf)

(defmethod asdf:output-files ((o asdf:program-op) (s (eql (asdf:find-system :pikey))))
(let ((exe-path (uiop/os:getcwd)))
(if exe-path
(values (list (concatenate 'string (directory-namestring exe-path) "pikey")) t)
(call-next-method))))

(asdf:operate :program-op :pikey)
Binary file added dags.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pikey.asd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

:components ((:file "package")
(:file "pikey"))

:build-pathname "pikey"
:entry-point "pikey:main")

26 changes: 17 additions & 9 deletions pikey.lisp
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@

(in-package #:pikey)

(eval-when (:compile-toplevel :load-toplevel)
(defpsmacro gebi (element-id)
`((@ document get-Element-By-Id) ,element-id)))

(defun main ()
(let* ((args (apply-argv:parse-argv (cdr sb-ext:*posix-argv*)))
(in-file (getf args :i))
(out-file (getf args :o))
(load-file (getf args :l)))
(when (probe-file load-file)
(standard (truename
(asdf:system-relative-pathname :pikey "std.lisp"))))

(unless (and in-file out-file)
(format t "Need two files.~%")
(sb-ext:quit))

(when (probe-file "macros.lisp")
(setf *load-verbose* t)
(setf *load-print* t)
(load "macros.lisp"))

(when (probe-file standard)
(setf *load-verbose* t)
(setf *load-print* t)
(load load-file))
(with-open-file (f out-file :if-exists :supersede :direction :output)
(write-string (ps:ps-compile-file in-file) f))))
(load standard))
(ignore-errors
(with-open-file (f out-file :if-exists :supersede :direction :output)
(write-string (ps:ps-compile-file in-file) f)))))
27 changes: 27 additions & 0 deletions std.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(in-package :pikey)

(defmacro+ps -> (&rest body)
`(chain ,@body))

(defmacro+ps _ (function &rest body)
`(-> _ (,function ,@body)))

(defmacro+ps add-entity ()
(with-ps-gensyms (ball)
`(progn
(defvar ,ball (chain game add (sprite 0 0 "balloon")))

(chain game physics (enable ,ball (chain -phaser -physics -a-r-c-a-d-e)))
(setf (@ ,ball check-world-bounds) t)
(chain ,ball body bounce (set 1))

(setf (chain ,ball input-enabled) t)
(chain ,ball events on-input-down (add click-handler ,ball))

(setf (chain ,ball body velocity y) (random-range -20 -50))

(chain all-balloons (push ,ball))
(drop-balloon ,ball))))

(defmacro+ps random-range (min max)
`(+ ,min (-> -math (floor (* (-> -math (random)) (+ 1 (- ,max ,min)))))))

0 comments on commit d64bf9f

Please sign in to comment.