Prims - Implement stop
[clnl] / src / main / main.lisp
index 70be24dfa7f0f2beafe2ce72ab7ae5fdc35f72b5..3acd6e366f193e9fa1e4aaeee248fc24734f7897 100644 (file)
@@ -43,7 +43,12 @@ DESCRIPTION:
   is set so that multiple runs will evaluate to the same.
 
   When FILE is not provided, a default model is used."
- (eval (model->lisp (if file (with-open-file (str file) (clnl-model:read-from-nlogo str)) (clnl-model:default-model)))))
+ (let
+  ((netlogoed-lisp
+    (model->lisp
+     (if file (with-open-file (str file) (clnl-model:read-from-nlogo str)) (clnl-model:default-model))))
+   (*package* *model-package*))
+  (eval netlogoed-lisp)))
 
 (defun run-commands (cmds)
  "RUN-COMMANDS CMDS => RESULT
@@ -57,7 +62,7 @@ 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)))))
+ (clnl-nvm:with-stop-handler (eval (clnl-transpiler:transpile-commands (clnl-parser:parse (clnl-lexer:lex cmds))))))
 
 (defun run-reporter (reporter)
  "RUN-REPORTER REPORTER => RESULT
@@ -77,7 +82,8 @@ DESCRIPTION:
 ; The intention of this method is to generate the common lisp equivalent of a model file,
 ; such that if you decided to no longer use nlogo, you could use the engine without it.
 (defun model->lisp (model)
- `(progn
+ `(let
+   ,(clnl-model:globals model)
    (clnl-random:set-seed 15) ; should the seed always be 15?
-   (clnl-nvm:create-world ,model)
-   (clnl-interface:initialize ,model)))
+   (clnl-nvm:create-world :dims ',(clnl-model:world-dimensions model))
+   (clnl-interface:initialize :dims ',(clnl-model:world-dimensions model))))