X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Ftranspile.lisp;h=554e0cdbd07fb348c72825bc411a1ff595449d1f;hb=7a82368afef8428c46d83d7afce51532cb7eb855;hp=5914a592eefbf634ed417a44e16375754fd55038;hpb=5a7fb5cf4e703d4cb8d6b89052265368323edd94;p=clnl diff --git a/src/main/transpile.lisp b/src/main/transpile.lisp index 5914a59..554e0cd 100644 --- a/src/main/transpile.lisp +++ b/src/main/transpile.lisp @@ -13,9 +13,9 @@ (defun find-prim (symb) (when symb - (or - (find symb *prims* :key #'prim-name) - (find-prim (getf (find symb *prim-aliases* :key #'prim-name) :real-symb))))) + (find-if + (lambda (prim-name) (or (eql symb prim-name) (and (listp prim-name) (find symb prim-name)))) + *prims* :key #'prim-name))) ; Let this grow, slowly but surely, eventually taking on calling context, etc. ; For now, it's just a @@ -90,6 +90,7 @@ DESCRIPTION: The Common lisp code that is returned, when run, will return some value." (cond ((numberp reporter) reporter) ; The parser converts to double for us + ((stringp reporter) reporter) ; The parser should have checked that having a symbol here is ok ((symbolp reporter) (intern (symbol-name reporter) clnl:*model-package*)) ((not (listp reporter)) (error "Expected a statement of some sort")) @@ -142,20 +143,23 @@ DESCRIPTION: (defprim :any? :reporter (lambda (agentset) `(> (clnl-nvm:count ,agentset) 0))) (defsimpleprim :ask :command clnl-nvm:ask) (defagentvalueprim :color) +(defsimpleprim '(:clear-all :ca) :command clnl-nvm:clear-all) (defsimpleprim :count :reporter clnl-nvm:count) (defsimpleprim :crt :command clnl-nvm:create-turtles) (defsimpleprim :die :command clnl-nvm:die) (defsimpleprim :fd :command clnl-nvm:forward) +(defsimpleprim :hatch :command clnl-nvm:hatch) (defprim :if :command (lambda (pred a) `(when ,pred ,@(make-command-block-inline a)))) -(defprim :ifelse :command (lambda (pred a b) - `(if ,pred - ,@(make-command-block-inline a) - ,@(make-command-block-inline b)))) +(defprim '(:ifelse :if-else) + :command (lambda (pred a b) + `(if ,pred + ,@(make-command-block-inline a) + ,@(make-command-block-inline b)))) -(defprim-alias :if-else :ifelse) (defagentvalueprim :label) (defagentvalueprim :label-color) (defsimpleprim :lt :command clnl-nvm:turn-left) +(defsimpleprim :not :reporter cl:not) (defkeywordprim :nobody) (defsimpleprim :one-of :reporter clnl-nvm:one-of) (defsimpleprim :of :reporter clnl-nvm:of) @@ -166,15 +170,18 @@ DESCRIPTION: (defsimpleprim :random-float :reporter clnl-nvm:random-float) (defsimpleprim :random-xcor :reporter clnl-nvm:random-xcor) (defsimpleprim :random-ycor :reporter clnl-nvm:random-ycor) +(defprim :round :reporter (lambda (n) `(ffloor (+ ,n 0.5d0)))) (defsimpleprim :rt :command clnl-nvm:turn-right) -(defsimpleprim :show :command clnl-nvm:show) (defsimpleprim :set :command cl:setf) +(defsimpleprim :set-default-shape :command clnl-nvm:set-default-shape) (defsimpleprim :setxy :command clnl-nvm:setxy) +(defsimpleprim :show :command clnl-nvm:show) (defagentvalueprim :size) (defsimpleprim :tick :command clnl-nvm:tick) (defsimpleprim :ticks :reporter clnl-nvm:ticks) (defsimpleprim :turtles :reporter clnl-nvm:turtles) (defagentvalueprim :who) +(defsimpleprim :with :reporter clnl-nvm:with) ; Colors (defmacro defcolorprim (color) `(defprim ,color :reporter (lambda () `(clnl-nvm:lookup-color ,,color))))