X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Fmain.lisp;h=749c765949ce775f3aa7d99d3d9f9c372d564e50;hb=5c8699f151207953f4029e0fc6c488afce99f756;hp=b9f46707a1a5671c236f9a3ba4821c2bdd1411db;hpb=1ae8c7a0199a4955708c7f5d7a286a12782b5fd2;p=clnl diff --git a/src/main/main.lisp b/src/main/main.lisp index b9f4670..749c765 100644 --- a/src/main/main.lisp +++ b/src/main/main.lisp @@ -1,22 +1,73 @@ -(in-package #:cl-nl) +(in-package #:clnl) (defun e (ast) ast) (defun r (str) (let* - ((lexed-ast (let ((ast (cl-nl.lexer:lex str))) (format t "Via lexing, AST for ~S became ~S~%" str ast) ast)) - (parsed-ast (let ((ast (cl-nl.parser:parse lexed-ast))) (format t "Via parsing, AST for ~S became ~S~%" lexed-ast ast) ast)) - (transpiled-ast (let ((ast (cl-nl.transpiler:transpile-command-block parsed-ast))) (format t "Via transpiling, AST for ~S became ~S~%" parsed-ast ast) ast))) + ((lexed-ast (let ((ast (clnl-lexer:lex str))) + (format t "Via lexing, AST for~%~S~% became~%~S~%~%" str ast) ast)) + (parsed-ast (let ((ast (clnl-parser:parse lexed-ast))) + (format t "Via parsing, AST for~%~S~% became~%~S~%~%" lexed-ast ast) ast)) + (transpiled-ast (let ((ast (clnl-transpiler:transpile-commands parsed-ast))) + (format t "Via transpiling, AST for~%~S~% became~%~S~%" parsed-ast ast) ast))) (eval transpiled-ast))) (defun p (result) result) (defun run () - (loop for str = (progn (format t "> ") (force-output) (read-line)) - while str - do (p (e (r str))))) + "RUN => RESULT -(defun boot ()) +ARGUMENTS AND VALUES: + + RESULT: undefined, the system terminates at the end of the loop + +DESCRIPTION: + + RUN implements a very simple REPL." + (loop + :for str := (progn (format t "> ") (force-output) (read-line)) + :while str + :do (p (e (r str)))) + (sb-ext:exit)) + +(defun boot () + "BOOT => RESULT + +ARGUMENTS AND VALUES: + + RESULT: undefined + +DESCRIPTION: + + BOOT does exactly that, boots the clnl system in a clean state. The seed + is set so that multiple runs will evaluate to the same." + (clnl-random:set-seed 15) + (clnl-nvm:create-world)) (defun run-commands (cmds) - (eval (cl-nl.transpiler:transpile-command-block (cl-nl.parser:parse (cl-nl.lexer:lex cmds))))) + "RUN-COMMANDS CMDS => RESULT + +ARGUMENTS AND VALUES: + + CMDS: A string that may have one more NetLogo commands + RESULT: undefined + +DESCRIPTION: + + RUN-COMMANDS will take NetLogo commands, put them through the various + stages need to turn them into Common Lisp code, and run it." + (eval (clnl-transpiler:transpile-commands (clnl-parser:parse (clnl-lexer:lex cmds))))) + +(defun run-reporter (reporter) + "RUN-REPORTER REPORTER => RESULT + +ARGUMENTS AND VALUES: + + REPORTER: A string that should have only one reporter + RESULT: The value reported by the NVM + +DESCRIPTION: + + RUN-REPORTER will take a NetLogo REPORTER, put it through the various + stages need to turn them into Common Lisp code, run it, and return the RESULT." + (eval (clnl-transpiler:transpile-reporter (car (clnl-parser:parse (clnl-lexer:lex reporter))))))