280718460424ada3f7c42cacdee5c393e62db7d6
[clnl] / src / main / clnl / package.lisp
1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3.  See distributed LICENSE.txt.
2 (defpackage #:clnl (:use :common-lisp)
3  (:export
4   #:run #:boot #:run-commands #:run-reporter #:*model-package*
5   #:model->multi-form-lisp #:model->single-form-lisp
6   #:nlogo->lisp)
7  (:documentation
8   "Main CLNL package
9
10 The entry point for general purpose clnl startup, as well as
11 the place that ties all the parts together into a cohesive whole."))
12
13 (defpackage #:clnl-parser
14  (:use :common-lisp)
15  (:export #:parse)
16  (:documentation
17   "CLNL Parser
18
19 All the code to convert the list of tokens coming from the lexer
20 into an ast that can be transpiled later."))
21
22 (defpackage #:clnl-code-parser
23  (:use :common-lisp)
24  (:export #:parse #:globals #:procedures #:turtles-own-vars #:patches-own-vars #:breeds)
25  (:documentation
26   "CLNL Code Parser
27
28 A parser specifically for code from NetLogo models, that turns the lexed
29 ast from an entire structured file into something more defined.
30
31 This is different from the general parser (in clnl-parser) in that
32 it's made for parsing the code section of nlogo files, and so works
33 outside of the constraints.  In NetLogo, I believe this is analagous
34 to the StructureParser, but I'm guessing there's weird overlap with
35 other things."))
36
37 (defpackage #:clnl-random
38  (:use :common-lisp)
39  (:shadow #:export)
40  (:export #:export #:set-seed #:next-int #:next-double #:next-long)
41  (:documentation
42   "Wrapper around mt19937.
43
44 mt19937 implements a merseinne twister that must be adapted a little in
45 order to match the implementation in the main NetLogo codebase which tries
46 to match how java.util.Random works.  Turtles, all the way down."))
47
48 (defpackage #:clnl-transpiler
49  (:use :common-lisp)
50  (:export #:transpile #:reporter-p #:command-list-p)
51  (:documentation
52   "CLNL Transpiler
53
54 The transpiler is responsible for taking an ast and turning it into valid CL code
55 targeting the nvm.  Here is where start to care about commands versus reporters
56 and ensuring that things are in the right place.  The reason we wait until here
57 is because we want to allow someone else to play with the AST before handing it off
58 to us.  For instance, the command center wants to add \"show\" to reporters, and
59 the users dictate based on entry point whether they are expecting a command
60 or a reporter.  So monitors can say \"hey, transpile this reporter\" and we'll check
61 to make sure it actually is.
62
63 Furthermore, the lisp code that any netlogo code would be transpiled to should
64 use exported symbols, such that anyone writing NetLogo code in lisp could use
65 the nvm in the same way that comes out of this transpiler
66 All the code to convert the list of tokens coming from the lexer
67 into an ast that can be transpiled later."))
68
69 (defpackage #:clnl-lexer
70  (:use :common-lisp)
71  (:export #:lex)
72  (:documentation
73   "CLNL Lexer
74
75 The primary code responsible for tokenizing NetLogo code."))
76
77 (defpackage #:clnl-interface
78  (:use :common-lisp)
79  (:export #:run #:export-view #:initialize)
80  (:documentation
81   "CLNL Interface
82
83 The NetLogo view interface using opengl.  This is responsible for taking the
84 current state of the enging and displaying it.  Will not house any interface
85 components."))
86
87 (defpackage #:clnl-model
88  (:use :common-lisp)
89  (:export
90   #:execute-button #:default-model #:read-from-nlogo #:world-dimensions #:widget-globals #:code
91   #:buttons #:textboxes #:forever-button-on #:switches #:sliders #:view #:interface
92   #:set-current-interface #:set-callback)
93  (:documentation
94   "CLNL Model
95
96 The representation, parsing, and serializing of NetLogo model files, including
97 all of the sections, and subsections held within.  This package houses not only
98 the code to read and write .nlogo files, but also the living state of the model
99 as clnl runs."))
100
101 (defpackage #:clnl-extensions
102  (:use :common-lisp)
103  (:export #:load-extension #:prims)
104  (:documentation
105   "CLNL Extensions
106
107 The loading and handling of extensions to CLNL modeled after the way that
108 NetLogo handles extensions.
109
110 Extensions are defined as Common Lisp systems (under asdf) that export
111 the primitive PRIMS.  The name of the asdf system is defined to be the
112 name of the extension prepended by CLNL-EXTENSION-, such that for a hypothetical
113 extension ARRAY, the name of the asdf system would be CLNL-EXTENSION-ARRAY
114 and found through conventional asdf means.  The package that the required
115 functions are symbols in should be the same as the asdf system."))
116
117 (defpackage #:clnl-default-model-package
118  (:use :common-lisp)
119  (:shadow #:go))