├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── assets
├── background.png
├── bullet.png
├── bullet.wav
├── font.ttf
├── hud.png
├── janet.png
├── letter-explosion.png
├── letter-explosion.wav
├── music.ogg
├── repository
├── screenshot-1.png
├── screenshot-2.png
├── word-explosion.png
├── word-explosion.wav
└── wrong-letter.wav
├── boot.janet
├── game.make
├── premake5.lua
├── script
├── background.janet
├── colors.janet
├── config.janet
├── engine.janet
├── entities
│ ├── base.janet
│ ├── bullet.janet
│ ├── letter-explosion.janet
│ ├── letter.janet
│ ├── player.janet
│ ├── word-explosion.janet
│ └── word.janet
├── game.janet
├── globals.janet
├── hud.janet
├── keys.janet
├── menu.janet
├── profile.janet
└── utils.janet
└── src
├── cfuncs.h
├── janet.c
├── janet.h
├── janetconf.h
└── main.c
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.sublime*
3 | .vscode
4 | obj/
5 | script/FEEDBACK.md
6 | assets/gfx
7 | assets/music
8 | assets/sfx
9 | launch
10 | game
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # GNU Make workspace makefile autogenerated by Premake
2 |
3 | ifndef config
4 | config=debug
5 | endif
6 |
7 | ifndef verbose
8 | SILENT = @
9 | endif
10 |
11 | ifeq ($(config),debug)
12 | game_config = debug
13 | endif
14 | ifeq ($(config),release)
15 | game_config = release
16 | endif
17 |
18 | PROJECTS := game
19 |
20 | .PHONY: all clean help $(PROJECTS)
21 |
22 | all: $(PROJECTS)
23 |
24 | game:
25 | ifneq (,$(game_config))
26 | @echo "==== Building game ($(game_config)) ===="
27 | @${MAKE} --no-print-directory -C . -f game.make config=$(game_config)
28 | endif
29 |
30 | clean:
31 | @${MAKE} --no-print-directory -C . -f game.make clean
32 |
33 | help:
34 | @echo "Usage: make [config=name] [target]"
35 | @echo ""
36 | @echo "CONFIGURATIONS:"
37 | @echo " debug"
38 | @echo " release"
39 | @echo ""
40 | @echo "TARGETS:"
41 | @echo " all (default)"
42 | @echo " clean"
43 | @echo " game"
44 | @echo ""
45 | @echo "For more information, see https://github.com/premake/premake-core/wiki"
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # super-janet-typist
2 |
3 | a short typing game made with janet lisp
4 |
5 | by [@sepisoad](https://twitter.com/sepisoad)
6 |
7 | ## screenshot(s)
8 |
9 | 
10 | 
11 |
12 | ## how to build
13 |
14 | you need to have raylib installed on your system
15 |
16 | run `make` and it will build the game for you
17 |
18 | ## credits
19 |
20 | all the pixel arts are authored by [surt](http://uninhabitant.com/)
21 |
22 | [raylib](https://github.com/raysan5/raylib) is used as framework
23 |
24 | [rFXGen](https://github.com/raysan5/rfxgen) is used to generate SFXs
25 |
26 | [pixitracker](https://www.warmplace.ru/soft/pixitracker/) is used to make music.
27 |
28 |
--------------------------------------------------------------------------------
/assets/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/background.png
--------------------------------------------------------------------------------
/assets/bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/bullet.png
--------------------------------------------------------------------------------
/assets/bullet.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/bullet.wav
--------------------------------------------------------------------------------
/assets/font.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/font.ttf
--------------------------------------------------------------------------------
/assets/hud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/hud.png
--------------------------------------------------------------------------------
/assets/janet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/janet.png
--------------------------------------------------------------------------------
/assets/letter-explosion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/letter-explosion.png
--------------------------------------------------------------------------------
/assets/letter-explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/letter-explosion.wav
--------------------------------------------------------------------------------
/assets/music.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/music.ogg
--------------------------------------------------------------------------------
/assets/repository:
--------------------------------------------------------------------------------
1 | I
2 | a
3 | as
4 | he
5 | on
6 | be
7 | at
8 | by
9 | is
10 | it
11 | or
12 | of
13 | to
14 | in
15 | we
16 | do
17 | if
18 | an
19 | us
20 | me
21 | up
22 | so
23 | go
24 | no
25 | my
26 | oh
27 | am
28 | his
29 | was
30 | for
31 | are
32 | one
33 | hot
34 | but
35 | you
36 | had
37 | the
38 | and
39 | can
40 | out
41 | how
42 | set
43 | air
44 | end
45 | put
46 | add
47 | big
48 | act
49 | why
50 | ask
51 | men
52 | off
53 | try
54 | any
55 | new
56 | get
57 | man
58 | our
59 | say
60 | low
61 | boy
62 | old
63 | too
64 | she
65 | all
66 | use
67 | way
68 | her
69 | see
70 | him
71 | two
72 | has
73 | day
74 | did
75 | who
76 | may
77 | now
78 | own
79 | sun
80 | eye
81 | let
82 | saw
83 | far
84 | sea
85 | run
86 | few
87 | eat
88 | cut
89 | got
90 | car
91 | red
92 | dog
93 | top
94 | dry
95 | ago
96 | ran
97 | hot
98 | yes
99 | fly
100 | cry
101 | box
102 | six
103 | ten
104 | war
105 | lay
106 | map
107 | bed
108 | egg
109 | art
110 | ice
111 | yet
112 | arm
113 | sit
114 | leg
115 | sky
116 | joy
117 | sat
118 | cow
119 | job
120 | fun
121 | gas
122 | row
123 | die
124 | bad
125 | oil
126 | mix
127 | fit
128 | ear
129 | son
130 | pay
131 | age
132 | lot
133 | key
134 | buy
135 | cat
136 | law
137 | bit
138 | lie
139 | hit
140 | bat
141 | rub
142 | tie
143 | gun
144 | fat
145 | dad
146 | bar
147 | log
148 | fig
149 | led
150 | win
151 | nor
152 | hat
153 | that
154 | with
155 | they
156 | have
157 | this
158 | from
159 | word
160 | what
161 | some
162 | were
163 | time
164 | will
165 | said
166 | each
167 | tell
168 | does
169 | want
170 | well
171 | also
172 | play
173 | home
174 | read
175 | hand
176 | port
177 | even
178 | land
179 | here
180 | must
181 | high
182 | such
183 | went
184 | kind
185 | need
186 | near
187 | self
188 | work
189 | part
190 | take
191 | made
192 | live
193 | back
194 | only
195 | year
196 | came
197 | show
198 | good
199 | give
200 | name
201 | very
202 | just
203 | form
204 | help
205 | line
206 | turn
207 | much
208 | mean
209 | move
210 | same
211 | when
212 | your
213 | many
214 | then
215 | them
216 | like
217 | long
218 | make
219 | look
220 | more
221 | come
222 | most
223 | over
224 | know
225 | than
226 | call
227 | down
228 | side
229 | been
230 | find
231 | head
232 | page
233 | grow
234 | food
235 | four
236 | keep
237 | last
238 | city
239 | tree
240 | farm
241 | hard
242 | draw
243 | left
244 | late
245 | real
246 | life
247 | book
248 | took
249 | room
250 | idea
251 | fish
252 | stop
253 | once
254 | base
255 | hear
256 | sure
257 | face
258 | wood
259 | main
260 | open
261 | seem
262 | next
263 | walk
264 | ease
265 | both
266 | mark
267 | mile
268 | feet
269 | care
270 | girl
271 | ever
272 | list
273 | feel
274 | talk
275 | bird
276 | soon
277 | body
278 | pose
279 | song
280 | door
281 | wind
282 | ship
283 | area
284 | half
285 | rock
286 | fire
287 | told
288 | knew
289 | pass
290 | king
291 | inch
292 | stay
293 | full
294 | blue
295 | deep
296 | moon
297 | foot
298 | busy
299 | test
300 | boat
301 | gold
302 | game
303 | miss
304 | heat
305 | snow
306 | tire
307 | fill
308 | east
309 | unit
310 | town
311 | fine
312 | fall
313 | lead
314 | dark
315 | note
316 | wait
317 | plan
318 | star
319 | noun
320 | rest
321 | able
322 | done
323 | week
324 | gave
325 | warm
326 | free
327 | mind
328 | tail
329 | fact
330 | best
331 | hour
332 | true
333 | five
334 | step
335 | hold
336 | west
337 | fast
338 | verb
339 | sing
340 | less
341 | slow
342 | love
343 | road
344 | rain
345 | rule
346 | pull
347 | cold
348 | hunt
349 | ride
350 | cell
351 | pick
352 | size
353 | vary
354 | pair
355 | felt
356 | ball
357 | wave
358 | drop
359 | wide
360 | sail
361 | race
362 | lone
363 | wall
364 | wish
365 | wild
366 | kept
367 | edge
368 | sign
369 | past
370 | soft
371 | bear
372 | hope
373 | gone
374 | trip
375 | seed
376 | tone
377 | join
378 | lady
379 | yard
380 | rise
381 | blow
382 | grew
383 | cent
384 | team
385 | wire
386 | cost
387 | lost
388 | wear
389 | sent
390 | fell
391 | flow
392 | fair
393 | bank
394 | save
395 | else
396 | case
397 | kill
398 | lake
399 | loud
400 | milk
401 | tiny
402 | cool
403 | poor
404 | iron
405 | flat
406 | skin
407 | hole
408 | jump
409 | baby
410 | meet
411 | root
412 | push
413 | held
414 | hair
415 | cook
416 | burn
417 | hill
418 | safe
419 | type
420 | copy
421 | tall
422 | sand
423 | soil
424 | roll
425 | beat
426 | view
427 | rich
428 | noon
429 | crop
430 | ring
431 | atom
432 | bone
433 | rail
434 | thus
435 | wing
436 | wash
437 | corn
438 | poem
439 | bell
440 | meat
441 | tube
442 | fear
443 | thin
444 | mine
445 | send
446 | dead
447 | spot
448 | suit
449 | lift
450 | rose
451 | post
452 | glad
453 | duck
454 | dear
455 | path
456 | neck
457 | huge
458 | coat
459 | mass
460 | card
461 | band
462 | rope
463 | slip
464 | feed
465 | tool
466 | seat
467 | sell
468 | deal
469 | swim
470 | term
471 | wife
472 | shoe
473 | camp
474 | born
475 | nine
476 | shop
477 | gray
478 | salt
479 | nose
480 | other
481 | which
482 | their
483 | three
484 | small
485 | large
486 | spell
487 | light
488 | house
489 | again
490 | point
491 | world
492 | build
493 | earth
494 | place
495 | where
496 | after
497 | round
498 | every
499 | under
500 | great
501 | think
502 | cause
503 | right
504 | there
505 | about
506 | write
507 | would
508 | these
509 | thing
510 | could
511 | sound
512 | water
513 | first
514 | stand
515 | found
516 | study
517 | still
518 | learn
519 | plant
520 | cover
521 | state
522 | never
523 | cross
524 | start
525 | might
526 | story
527 | while
528 | press
529 | close
530 | night
531 | north
532 | carry
533 | began
534 | horse
535 | watch
536 | color
537 | white
538 | begin
539 | paper
540 | group
541 | music
542 | those
543 | often
544 | until
545 | river
546 | plain
547 | usual
548 | young
549 | ready
550 | above
551 | leave
552 | black
553 | short
554 | class
555 | order
556 | south
557 | piece
558 | since
559 | whole
560 | wheel
561 | force
562 | plane
563 | stead
564 | laugh
565 | check
566 | shape
567 | bring
568 | paint
569 | among
570 | power
571 | field
572 | pound
573 | drive
574 | stood
575 | front
576 | teach
577 | final
578 | green
579 | quick
580 | ocean
581 | clear
582 | space
583 | heard
584 | early
585 | reach
586 | table
587 | vowel
588 | money
589 | serve
590 | voice
591 | count
592 | speak
593 | grand
594 | heart
595 | heavy
596 | dance
597 | store
598 | train
599 | sleep
600 | prove
601 | catch
602 | mount
603 | board
604 | glass
605 | grass
606 | visit
607 | month
608 | happy
609 | trade
610 | mouth
611 | exact
612 | least
613 | shout
614 | wrote
615 | clean
616 | break
617 | blood
618 | touch
619 | brown
620 | equal
621 | quite
622 | broke
623 | scale
624 | child
625 | speed
626 | organ
627 | dress
628 | cloud
629 | quiet
630 | stone
631 | climb
632 | stick
633 | smile
634 | eight
635 | raise
636 | solve
637 | metal
638 | seven
639 | third
640 | shall
641 | floor
642 | coast
643 | value
644 | fight
645 | sense
646 | chair
647 | fruit
648 | thick
649 | party
650 | whose
651 | radio
652 | spoke
653 | human
654 | agree
655 | woman
656 | guess
657 | sharp
658 | crowd
659 | sight
660 | hurry
661 | chief
662 | clock
663 | enter
664 | major
665 | fresh
666 | allow
667 | print
668 | track
669 | shore
670 | sheet
671 | favor
672 | spend
673 | chord
674 | share
675 | bread
676 | offer
677 | slave
678 | chick
679 | enemy
680 | reply
681 | drink
682 | occur
683 | range
684 | steam
685 | meant
686 | teeth
687 | shell
688 | sugar
689 | death
690 | skill
691 | women
692 | thank
693 | match
694 | steel
695 | guide
696 | score
697 | apple
698 | pitch
699 | dream
700 | total
701 | basic
702 | smell
703 | block
704 | chart
705 | event
706 | quart
707 | truck
708 | noise
709 | level
710 | throw
711 | shine
712 | wrong
713 | broad
714 | anger
715 | claim
716 | follow
717 | change
718 | animal
719 | mother
720 | father
721 | little
722 | differ
723 | before
724 | number
725 | people
726 | should
727 | answer
728 | school
729 | friend
730 | always
731 | letter
732 | second
733 | enough
734 | though
735 | family
736 | direct
737 | happen
738 | street
739 | course
740 | object
741 | decide
742 | island
743 | system
744 | record
745 | common
746 | wonder
747 | equate
748 | figure
749 | beauty
750 | minute
751 | strong
752 | behind
753 | better
754 | during
755 | ground
756 | listen
757 | travel
758 | simple
759 | toward
760 | center
761 | person
762 | appear
763 | govern
764 | notice
765 | energy
766 | sudden
767 | square
768 | reason
769 | length
770 | region
771 | settle
772 | weight
773 | matter
774 | circle
775 | divide
776 | engine
777 | forest
778 | window
779 | summer
780 | winter
781 | bright
782 | finish
783 | flower
784 | clothe
785 | melody
786 | office
787 | symbol
788 | except
789 | garden
790 | choose
791 | middle
792 | moment
793 | spring
794 | nation
795 | method
796 | design
797 | bottom
798 | single
799 | twenty
800 | crease
801 | either
802 | result
803 | phrase
804 | silent
805 | finger
806 | excite
807 | danger
808 | doctor
809 | please
810 | modern
811 | corner
812 | supply
813 | locate
814 | insect
815 | caught
816 | period
817 | effect
818 | expect
819 | gentle
820 | create
821 | rather
822 | string
823 | depend
824 | famous
825 | dollar
826 | stream
827 | planet
828 | colony
829 | search
830 | yellow
831 | desert
832 | arrive
833 | master
834 | parent
835 | charge
836 | proper
837 | market
838 | degree
839 | speech
840 | nature
841 | motion
842 | liquid
843 | oxygen
844 | pretty
845 | season
846 | magnet
847 | silver
848 | branch
849 | suffix
850 | afraid
851 | sister
852 | bought
853 | valley
854 | double
855 | spread
856 | invent
857 | cotton
858 | chance
859 | gather
860 | column
861 | select
862 | repeat
863 | plural
864 | picture
865 | through
866 | country
867 | between
868 | thought
869 | dont
870 | science
871 | example
872 | measure
873 | product
874 | numeral
875 | problem
876 | nothing
877 | surface
878 | brought
879 | distant
880 | certain
881 | machine
882 | correct
883 | contain
884 | develop
885 | special
886 | produce
887 | hundred
888 | morning
889 | several
890 | against
891 | pattern
892 | brother
893 | believe
894 | perhaps
895 | subject
896 | general
897 | include
898 | present
899 | written
900 | weather
901 | million
902 | strange
903 | receive
904 | trouble
905 | suggest
906 | collect
907 | control
908 | decimal
909 | observe
910 | section
911 | village
912 | whether
913 | century
914 | natural
915 | capital
916 | wont
917 | soldier
918 | process
919 | operate
920 | protect
921 | element
922 | student
923 | history
924 | imagine
925 | provide
926 | captain
927 | compare
928 | current
929 | connect
930 | station
931 | segment
932 | instant
933 | support
934 | discuss
935 | forward
936 | similar
937 | evening
938 | success
939 | company
940 | arrange
941 | stretch
942 | require
943 | prepare
944 | sentence
945 | mountain
946 | together
947 | children
948 | question
949 | complete
950 | multiply
951 | possible
952 | thousand
953 | language
954 | remember
955 | interest
956 | probable
957 | syllable
958 | position
959 | material
960 | fraction
961 | exercise
962 | straight
963 | surprise
964 | describe
965 | consider
966 | industry
967 | practice
968 | separate
969 | indicate
970 | electric
971 | neighbor
972 | triangle
973 | division
974 | original
975 | populate
976 | quotient
977 | solution
978 | continue
979 | subtract
980 | opposite
981 | shoulder
982 | property
983 | molecule
984 | represent
985 | consonant
986 | paragraph
987 | difficult
988 | character
989 | necessary
990 | substance
991 | condition
992 | determine
993 | continent
994 | instrument
995 | dictionary
996 | experiment
997 | especially
998 | experience
999 | particular
1000 | temperature
--------------------------------------------------------------------------------
/assets/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/screenshot-1.png
--------------------------------------------------------------------------------
/assets/screenshot-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/screenshot-2.png
--------------------------------------------------------------------------------
/assets/word-explosion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/word-explosion.png
--------------------------------------------------------------------------------
/assets/word-explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/word-explosion.wav
--------------------------------------------------------------------------------
/assets/wrong-letter.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sepisoad/super-janet-typist/c5bb443112d82e316e4ec1cb5551280bfa3d8d0a/assets/wrong-letter.wav
--------------------------------------------------------------------------------
/boot.janet:
--------------------------------------------------------------------------------
1 | (import ./script/engine :as engine)
2 |
3 | (engine/start)
--------------------------------------------------------------------------------
/game.make:
--------------------------------------------------------------------------------
1 | # GNU Make project makefile autogenerated by Premake
2 |
3 | ifndef config
4 | config=debug
5 | endif
6 |
7 | ifndef verbose
8 | SILENT = @
9 | endif
10 |
11 | .PHONY: clean prebuild prelink
12 |
13 | ifeq ($(config),debug)
14 | RESCOMP = windres
15 | TARGETDIR = .
16 | TARGET = $(TARGETDIR)/game
17 | OBJDIR = obj/Debug
18 | DEFINES += -DDEBUG
19 | INCLUDES +=
20 | FORCE_INCLUDE +=
21 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
22 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall
23 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g -Wall
24 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
25 | LIBS += -lm -lraylib -ldl
26 | LDDEPS +=
27 | ALL_LDFLAGS += $(LDFLAGS)
28 | LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
29 | define PREBUILDCMDS
30 | endef
31 | define PRELINKCMDS
32 | endef
33 | define POSTBUILDCMDS
34 | endef
35 | all: prebuild prelink $(TARGET)
36 | @:
37 |
38 | endif
39 |
40 | ifeq ($(config),release)
41 | RESCOMP = windres
42 | TARGETDIR = .
43 | TARGET = $(TARGETDIR)/game
44 | OBJDIR = obj/Release
45 | DEFINES += -DNDEBUG
46 | INCLUDES +=
47 | FORCE_INCLUDE +=
48 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
49 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -Wall
50 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2 -Wall
51 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
52 | LIBS += -lm -lraylib -ldl
53 | LDDEPS +=
54 | ALL_LDFLAGS += $(LDFLAGS) -s
55 | LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
56 | define PREBUILDCMDS
57 | endef
58 | define PRELINKCMDS
59 | endef
60 | define POSTBUILDCMDS
61 | endef
62 | all: prebuild prelink $(TARGET)
63 | @:
64 |
65 | endif
66 |
67 | OBJECTS := \
68 | $(OBJDIR)/janet.o \
69 | $(OBJDIR)/main.o \
70 |
71 | RESOURCES := \
72 |
73 | CUSTOMFILES := \
74 |
75 | SHELLTYPE := posix
76 | ifeq (.exe,$(findstring .exe,$(ComSpec)))
77 | SHELLTYPE := msdos
78 | endif
79 |
80 | $(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)
81 | @echo Linking game
82 | $(SILENT) $(LINKCMD)
83 | $(POSTBUILDCMDS)
84 |
85 | $(CUSTOMFILES): | $(OBJDIR)
86 |
87 | $(TARGETDIR):
88 | @echo Creating $(TARGETDIR)
89 | ifeq (posix,$(SHELLTYPE))
90 | $(SILENT) mkdir -p $(TARGETDIR)
91 | else
92 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
93 | endif
94 |
95 | $(OBJDIR):
96 | @echo Creating $(OBJDIR)
97 | ifeq (posix,$(SHELLTYPE))
98 | $(SILENT) mkdir -p $(OBJDIR)
99 | else
100 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR))
101 | endif
102 |
103 | clean:
104 | @echo Cleaning game
105 | ifeq (posix,$(SHELLTYPE))
106 | $(SILENT) rm -f $(TARGET)
107 | $(SILENT) rm -rf $(OBJDIR)
108 | else
109 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
110 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
111 | endif
112 |
113 | prebuild:
114 | $(PREBUILDCMDS)
115 |
116 | prelink:
117 | $(PRELINKCMDS)
118 |
119 | ifneq (,$(PCH))
120 | $(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)
121 | $(GCH): $(PCH) | $(OBJDIR)
122 | @echo $(notdir $<)
123 | $(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
124 | else
125 | $(OBJECTS): | $(OBJDIR)
126 | endif
127 |
128 | $(OBJDIR)/janet.o: src/janet.c
129 | @echo $(notdir $<)
130 | $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
131 | $(OBJDIR)/main.o: src/main.c
132 | @echo $(notdir $<)
133 | $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
134 |
135 | -include $(OBJECTS:%.o=%.d)
136 | ifneq (,$(PCH))
137 | -include $(OBJDIR)/$(notdir $(PCH)).d
138 | endif
--------------------------------------------------------------------------------
/premake5.lua:
--------------------------------------------------------------------------------
1 | workspace "Super Janet Typist"
2 | configurations { "Debug", "Release" }
3 |
4 | project "game"
5 | kind "ConsoleApp"
6 | language "C"
7 | targetdir "."
8 | targetname "game"
9 | files { "src/**.h", "src/**.c" }
10 | links {"m", "raylib", "dl"}
11 | buildoptions { "-Wall" }
12 |
13 | filter "configurations:Debug"
14 | defines { "DEBUG" }
15 | symbols "On"
16 |
17 | filter "configurations:Release"
18 | defines { "NDEBUG" }
19 | optimize "On"
--------------------------------------------------------------------------------
/script/background.janet:
--------------------------------------------------------------------------------
1 | # ____ ___ ________ ____________ ____ __ ___ ______
2 | # / __ )/ | / ____/ //_/ ____/ __ \/ __ \/ / / / | / / __ \
3 | # / __ / /| |/ / / ,< / / __/ /_/ / / / / / / / |/ / / / /
4 | # / /_/ / ___ / /___/ /| / /_/ / _, _/ /_/ / /_/ / /| / /_/ /
5 | # /_____/_/ |_\____/_/ |_\____/_/ |_|\____/\____/_/ |_/_____/
6 |
7 | (import ./colors :as color)
8 |
9 | # __ __ __
10 | # ____/ /___ __ ______ ____/ /___ _/ /____
11 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
12 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
13 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
14 | # /_/
15 |
16 | # (defn do-update [game] nil)
17 |
18 | # __ __
19 | # ____/ /___ ________ ____ ____/ /__ _____
20 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
21 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
22 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
23 |
24 | (defn do-render [game]
25 | (c/draw-texture
26 | (game :background)
27 | 0
28 | 0
29 | color/gray))
30 |
--------------------------------------------------------------------------------
/script/colors.janet:
--------------------------------------------------------------------------------
1 | # __________ __ ____ ____ _____
2 | # / ____/ __ \/ / / __ \/ __ \/ ___/
3 | # / / / / / / / / / / / /_/ /\__ \
4 | # / /___/ /_/ / /___/ /_/ / _, _/___/ /
5 | # \____/\____/_____/\____/_/ |_|/____/
6 |
7 | (def light-gray { :r 200 :g 200 :b 200 :a 255 }) # Light Gray
8 | (def gray { :r 130 :g 130 :b 130 :a 255 }) # Gray
9 | (def dark-gray { :r 80 :g 80 :b 80 :a 255 }) # Dark Gray
10 | (def yellow { :r 253 :g 249 :b 0 :a 255 }) # Yellow
11 | (def gold { :r 255 :g 203 :b 0 :a 255 }) # Gold
12 | (def orange { :r 255 :g 161 :b 0 :a 255 }) # Orange
13 | (def pink { :r 255 :g 109 :b 194 :a 255 }) # Pink
14 | (def red { :r 230 :g 41 :b 55 :a 255 }) # Red
15 | (def maroon { :r 190 :g 33 :b 55 :a 255 }) # Maroon
16 | (def green { :r 0 :g 228 :b 48 :a 255 }) # Green
17 | (def lime { :r 0 :g 158 :b 47 :a 255 }) # Lime
18 | (def dark-green { :r 0 :g 117 :b 44 :a 255 }) # Dark Green
19 | (def sky-blue { :r 102 :g 191 :b 255 :a 255 }) # Sky Blue
20 | (def blue { :r 0 :g 121 :b 241 :a 255 }) # Blue
21 | (def dark-blue { :r 0 :g 82 :b 172 :a 255 }) # Dark Blue
22 | (def purple { :r 200 :g 122 :b 255 :a 255 }) # Purple
23 | (def violet { :r 135 :g 60 :b 190 :a 255 }) # Violet
24 | (def dark-purple { :r 112 :g 31 :b 126 :a 255 }) # Dark Purple
25 | (def beige { :r 211 :g 176 :b 131 :a 255 }) # Beige
26 | (def brown { :r 127 :g 106 :b 79 :a 255 }) # Brown
27 | (def dark-brown { :r 76 :g 63 :b 47 :a 255 }) # Dark Brown
28 | (def white { :r 255 :g 255 :b 255 :a 255 }) # White
29 | (def black { :r 0 :g 0 :b 0 :a 255 }) # Black
30 | (def blank { :r 0 :g 0 :b 0 :a 0 }) # Blank (Transparent)
31 | (def magenta { :r 255 :g 0 :b 255 :a 255 }) # Magenta
32 | (def ray-white { :r 245 :g 245 :b 245 :a 255 }) # My own White (raylib logo)
--------------------------------------------------------------------------------
/script/config.janet:
--------------------------------------------------------------------------------
1 | # __________ _ __________________
2 | # / ____/ __ \/ | / / ____/ _/ ____/
3 | # / / / / / / |/ / /_ / // / __
4 | # / /___/ /_/ / /| / __/ _/ // /_/ /
5 | # \____/\____/_/ |_/_/ /___/\____/
6 |
7 | (def config {:is-fullscreen? false})
8 |
9 |
--------------------------------------------------------------------------------
/script/engine.janet:
--------------------------------------------------------------------------------
1 | # _______ _____________ ________
2 | # / ____/ | / / ____/ _/ | / / ____/
3 | # / __/ / |/ / / __ / // |/ / __/
4 | # / /___/ /| / /_/ // // /| / /___
5 | # /_____/_/ |_/\____/___/_/ |_/_____/
6 |
7 | (import ./config :prefix "")
8 | (import ./globals :as g)
9 | (import ./menu :as menu)
10 | (import ./utils :as u)
11 |
12 | (defn load-repository [path]
13 | (var data (slurp path))
14 | (u/shuffle (string/split "\n" data)))
15 |
16 | (defn start []
17 | (var engine (merge config {}))
18 |
19 | (set (engine :repository) (load-repository g/repository)) # TODO: move it to config
20 | (set (engine :window-width) g/window-width)
21 | (set (engine :window-height) g/window-height)
22 | (set (engine :window-title) g/window-title)
23 | (set (engine :frames-per-second) g/frames-per-second)
24 | (set (engine :font-size) g/default-font-size)
25 | (set (engine :font-spacing) g/default-font-spacing)
26 |
27 | (c/screen-start engine)
28 | (menu/init engine)
29 | (c/screen-end))
30 |
--------------------------------------------------------------------------------
/script/entities/base.janet:
--------------------------------------------------------------------------------
1 | # _____ ___ _____ ______
2 | # / ___/ | / ___// ____/
3 | # / __ / /| | \__ \/ __/
4 | # / /_/ / ___ |___/ / /___
5 | # /_____/_/ |_/____/_____/
6 |
7 |
8 | (def- base
9 | @{:type :BASE
10 | :delete? false
11 | :pos-x 0
12 | :pos-y 0
13 | :speed-x 0
14 | :speed-y 0
15 | :width 0
16 | :height 0
17 | :color @{ :r 0 :g 0 :b 0 :a 0}
18 | # methods
19 | :do-update (fn [self game time] nil)
20 | :do-render (fn [self game] nil)})
21 |
22 | (defn get-ref [] (table/clone base))
--------------------------------------------------------------------------------
/script/entities/bullet.janet:
--------------------------------------------------------------------------------
1 | # ____ __ ____ __ ____________
2 | # / __ )/ / / / / / / / ____/_ __/
3 | # / __ / / / / / / / / __/ / /
4 | # / /_/ / /_/ / /___/ /___/ /___ / /
5 | # /_____/\____/_____/_____/_____/ /_/
6 |
7 | (import ./base :as base)
8 | (import ../globals :as g)
9 | (import ../colors :as color)
10 | (import ./letter-explosion :as letter-explosion)
11 | (import ./word-explosion :as word-explosion)
12 | # __ __ __
13 | # ____/ /___ __ ______ ____/ /___ _/ /____
14 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
15 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
16 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
17 | # /_/
18 |
19 | (defn- do-update [self game time]
20 | (var tar-x (+ ((self :target) :pos-x) (/ ((self :target) :width) 2)))
21 | (var tar-y (+ ((self :target) :pos-y) (/ ((self :target) :height) 2)))
22 |
23 | (var dif-x (- tar-x (self :pos-x)))
24 | (var dif-y (- tar-y (self :pos-y)))
25 | (var dist (math/sqrt (+ (math/pow dif-x 2) (math/pow dif-y 2))))
26 |
27 | (if (> dist 10)
28 | (do
29 | (var dir-x (/ dif-x dist))
30 | (var dir-y (/ dif-y dist))
31 |
32 | (set (self :pos-x) (math/floor (+ (self :pos-x) (* dir-x (self :speed-x)))))
33 | (set (self :pos-y) (math/floor (+ (self :pos-y) (* dir-y (self :speed-y))))))
34 | (do
35 | (when (not (self :exploaded?))
36 | (set (self :exploaded?) true)
37 | (array/concat (game :objects)
38 | (if (self :last?)
39 | (word-explosion/spawn (self :target))
40 | (letter-explosion/spawn (self :target)))))
41 |
42 | (set ((self :target) :delete?) true)
43 | (set (self :delete?) true))))
44 |
45 | # __ __
46 | # ____/ /___ ________ ____ ____/ /__ _____
47 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
48 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
49 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
50 |
51 | (defn- do-render [self game]
52 | (when (not (self :delete?))
53 | (c/draw-texture
54 | (self :gfx)
55 | (self :pos-x)
56 | (self :pos-y)
57 | color/pink)))
58 |
59 | # __ ____ __
60 | # / /_ __ __/ / /__ / /_ ____ _
61 | # / __ \/ / / / / / _ \/ __/_____/ __ `/
62 | # / /_/ / /_/ / / / __/ /_/_____/ /_/ /
63 | # /_.___/\__,_/_/_/\___/\__/ \__,_/
64 |
65 | (def- bullet
66 | @{:width 8
67 | :height 8
68 | :speed-x 15
69 | :speed-y 20
70 | :shooter nil
71 | :target nil
72 | :exploaded? false
73 | :color color/green
74 | #
75 | :do-update do-update
76 | :do-render do-render})
77 |
78 | # _________ ____ __ ______
79 | # / ___/ __ \/ __ `/ | /| / / __ \
80 | # (__ ) /_/ / /_/ /| |/ |/ / / / /
81 | # /____/ .___/\__,_/ |__/|__/_/ /_/
82 | # /_/
83 |
84 | (var gfx nil)
85 | (var sfx nil)
86 |
87 | (defn spawn [shooter target last?]
88 | (when (nil? gfx)
89 | (set gfx (c/load-texture g/bullet-image)))
90 | (when (nil? sfx)
91 | (set sfx (c/load-sound g/bullet-wave)))
92 |
93 | (c/play-sound sfx)
94 |
95 | (merge
96 | (base/get-ref)
97 | (table/clone bullet)
98 | @{:shooter shooter
99 | :target target
100 | :last? last?
101 | :gfx gfx
102 | :pos-x (+ (shooter :pos-x) (/ (shooter :width) 2))
103 | :pos-y (shooter :pos-y)}))
--------------------------------------------------------------------------------
/script/entities/letter-explosion.janet:
--------------------------------------------------------------------------------
1 | # __ ____________________________ _______ __ ____ __ ____ _____ ________ _ __
2 | # / / / ____/_ __/_ __/ ____/ __ \ / ____/ |/ // __ \/ / / __ \/ ___// _/ __ \/ | / /
3 | # / / / __/ / / / / / __/ / /_/ / / __/ | // /_/ / / / / / /\__ \ / // / / / |/ /
4 | # / /___/ /___ / / / / / /___/ _, _/ / /___ / |/ ____/ /___/ /_/ /___/ // // /_/ / /| /
5 | # /_____/_____/ /_/ /_/ /_____/_/ |_| /_____//_/|_/_/ /_____/\____//____/___/\____/_/ |_/
6 |
7 | (import ./base :as base)
8 | (import ../globals :as g)
9 | (import ../colors :as color)
10 |
11 | # __ __ __
12 | # ____/ /___ __ ______ ____/ /___ _/ /____
13 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
14 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
15 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
16 | # /_/
17 |
18 | (defn- do-update [self game time]
19 | (when (not (self :sounded?))
20 | (set (self :sounded?) true)
21 | (c/play-sound (self :sfx)))
22 | (if (>= (self :current-frame) (self :max-frames))
23 | (set (self :delete?) true)
24 | (when (> (- time (self :last-tick)) (self :frames-speed))
25 | (set (self :last-tick) time)
26 | (set (self :current-frame) (+ 1 (self :current-frame))))))
27 | # __ __
28 | # ____/ /___ ________ ____ ____/ /__ _____
29 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
30 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
31 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
32 |
33 | (defn- do-render [self game]
34 | (when (not (self :delete?))
35 | (c/draw-sprite-ex
36 | (self :gfx)
37 | {:x (* (self :current-frame) (self :width))
38 | :y 0
39 | :w (self :width)
40 | :h (self :height)}
41 | {:x ((self :letter) :pos-x)
42 | :y ((self :letter) :pos-y)
43 | :w (* 2.5 (self :width))
44 | :h (* 2.5 (self :height))}
45 | {:x -1 :y -3}
46 | 0
47 | color/purple)))
48 |
49 | # __ __ __ __ _
50 | # / /__ / /_/ /____ _____ ___ _ ______ / /___ _____(_)___ ____
51 | # / / _ \/ __/ __/ _ \/ ___/_____/ _ \| |/_/ __ \/ / __ \/ ___/ / __ \/ __ \
52 | # / / __/ /_/ /_/ __/ / /_____/ __/> /_/ / / /_/ (__ ) / /_/ / / / /
53 | # /_/\___/\__/\__/\___/_/ \___/_/|_/ .___/_/\____/____/_/\____/_/ /_/
54 | # /_/
55 |
56 | (def- letter-explosion
57 | @{:frames-speed 0.02
58 | :current-frame 0
59 | :width 6
60 | :height 6
61 | :max-frames 10
62 | :last-tick 0
63 | :color color/green
64 | #
65 | :do-update do-update
66 | :do-render do-render})
67 |
68 | # _________ ____ __ ______
69 | # / ___/ __ \/ __ `/ | /| / / __ \
70 | # (__ ) /_/ / /_/ /| |/ |/ / / / /
71 | # /____/ .___/\__,_/ |__/|__/_/ /_/
72 | # /_/
73 |
74 | (var gfx nil)
75 | (var sfx nil)
76 |
77 | (defn spawn [letter]
78 | (when (nil? gfx)
79 | (set gfx (c/load-texture g/letter-explosion-image)))
80 | (when (nil? sfx)
81 | (set sfx (c/load-sound g/letter-explosion-wave)))
82 |
83 | (merge
84 | (base/get-ref)
85 | (table/clone letter-explosion)
86 | @{:letter letter
87 | :gfx gfx
88 | :sfx sfx
89 | :sounded? false}))
--------------------------------------------------------------------------------
/script/entities/letter.janet:
--------------------------------------------------------------------------------
1 | # __ ____________________________
2 | # / / / ____/_ __/_ __/ ____/ __ \
3 | # / / / __/ / / / / / __/ / /_/ /
4 | # / /___/ /___ / / / / / /___/ _, _/
5 | # /_____/_____/ /_/ /_/ /_____/_/ |_|
6 |
7 | (import ./base :as base)
8 | (import ../utils :as u)
9 | (import ../colors :as color)
10 |
11 | # __ __
12 | # ____/ /___ ________ ____ ____/ /__ _____
13 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
14 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
15 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
16 |
17 | (defn- do-render [self game]
18 | (when (and (not (self :delete?)) (self :visible))
19 | (if (self :typed?)
20 | (c/draw-text
21 | (game :font)
22 | (self :value)
23 | (self :pos-x)
24 | (self :pos-y)
25 | (self :height)
26 | 1 # spacing !!!
27 | color/gray)
28 | (c/draw-text
29 | (game :font)
30 | (self :value)
31 | (self :pos-x)
32 | (self :pos-y)
33 | (self :height)
34 | 1 # spacing !!!
35 | color/white))))
36 |
37 | # __ __ __
38 | # / /__ / /_/ /____ _____
39 | # / / _ \/ __/ __/ _ \/ ___/
40 | # / / __/ /_/ /_/ __/ /
41 | # /_/\___/\__/\__/\___/_/
42 |
43 | (def- letter
44 | @{:width 15 # is not used !!!
45 | :height 20
46 | :visible true
47 | #
48 | :do-render do-render})
49 |
50 | # _________ ____ __ ______
51 | # / ___/ __ \/ __ `/ | /| / / __ \
52 | # (__ ) /_/ / /_/ /| |/ |/ / / / /
53 | # /____/ .___/\__,_/ |__/|__/_/ /_/
54 | # /_/
55 |
56 | (defn spawn [x y v]
57 | (merge (base/get-ref)
58 | (table/clone letter)
59 | @{:pos-x x
60 | :pos-y y
61 | :typed? false
62 | :value v}))
63 |
--------------------------------------------------------------------------------
/script/entities/player.janet:
--------------------------------------------------------------------------------
1 | # ____ __ _____ ____________
2 | # / __ \/ / / \ \/ / ____/ __ \
3 | # / /_/ / / / /| |\ / __/ / /_/ /
4 | # / ____/ /___/ ___ |/ / /___/ _, _/
5 | # /_/ /_____/_/ |_/_/_____/_/ |_|
6 |
7 | (import ../globals :as g)
8 | (import ../colors :as color)
9 | (import ../keys :as key)
10 | (import ./base :as base)
11 | (import ./bullet :as bullet)
12 |
13 | (var wrong-letter-sfx nil)
14 |
15 | # __ _ __
16 | # ____/ /___ (_)___ ____ __ __/ /_
17 | # / __ / __ \______/ / __ \/ __ \/ / / / __/
18 | # / /_/ / /_/ /_____/ / / / / /_/ / /_/ / /_
19 | # \__,_/\____/ /_/_/ /_/ .___/\__,_/\__/
20 | # /_/
21 |
22 | (defn- do-input [self game]
23 | (when (not (nil? (self :target)))
24 | (var key (c/get-key-pressed))
25 | (var letter (:get-child (game :word)))
26 | (var last? (:last? (game :word)))
27 | (var char (letter :value))
28 | (when (and (not (nil? char)) (not (= -1 key)))
29 | (var ucode (c/u/str-to-code (string/ascii-upper char)))
30 | (var lcode (c/u/str-to-code (string/ascii-lower char)))
31 | (if (or (= key ucode) (= key lcode))
32 | (do
33 | (set (letter :typed?) true)
34 | (set (game :score) (+ 1 (game :score)))
35 | (set (game :streak) (+ 1 (game :streak)))
36 | (array/concat (game :objects)
37 | (bullet/spawn self letter last?)))
38 |
39 | (do
40 | (c/play-sound wrong-letter-sfx)
41 | (when (> (game :streak) (game :best-streak))
42 | (set (game :best-streak) (game :streak)))
43 | (set (game :streak) 0))))))
44 |
45 | # __ __ __
46 | # ____/ /___ __ ______ ____/ /___ _/ /____
47 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
48 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
49 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
50 | # /_/
51 |
52 | (defn- do-update [self game time]
53 | (when (< (self :pos-x) 0)
54 | (set (self :pos-x) 0))
55 | (when (> (+ (self :pos-x) (self :width)) (game :window-width))
56 | (set (self :pos-x) (- (game :window-width) (self :width)))))
57 |
58 | # __ __
59 | # ____/ /___ ________ ____ ____/ /__ _____
60 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
61 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
62 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
63 |
64 | (defn- do-render [self game]
65 | (c/draw-texture
66 | (self :janet)
67 | (self :pos-x)
68 | (self :pos-y)
69 | color/pink))
70 |
71 | # __ __ __
72 | # ________ / /_ / /_____ __________ ____ / /_
73 | # / ___/ _ \/ __/_____/ __/ __ `/ ___/ __ `/ _ \/ __/
74 | # (__ ) __/ /_/_____/ /_/ /_/ / / / /_/ / __/ /_
75 | # /____/\___/\__/ \__/\__,_/_/ \__, /\___/\__/
76 | # /____/
77 |
78 | (defn- set-target [self target]
79 | (pp target)
80 | (set (self :target) target))
81 |
82 | # __
83 | # ____ / /___ ___ _____ _____
84 | # / __ \/ / __ `/ / / / _ \/ ___/
85 | # / /_/ / / /_/ / /_/ / __/ /
86 | # / .___/_/\__,_/\__, /\___/_/
87 | # /_/ /____/
88 |
89 | (def- player
90 | @{:width 16
91 | :height 16
92 | :speed-x 5
93 | :last-fire 0
94 | :color color/maroon
95 | :target nil
96 | #
97 | :do-input do-input
98 | :do-render do-render
99 | #
100 | :set-target set-target})
101 |
102 | # _________ ____ __ ______
103 | # / ___/ __ \/ __ `/ | /| / / __ \
104 | # (__ ) /_/ / /_/ /| |/ |/ / / / /
105 | # /____/ .___/\__,_/ |__/|__/_/ /_/
106 | # /_/
107 |
108 | (defn spawn [x y target]
109 | (when (nil? wrong-letter-sfx)
110 | (set wrong-letter-sfx (c/load-sound g/wrong-letter-wave)))
111 | (merge
112 | (base/get-ref)
113 | (table/clone player)
114 | @{:pos-x (- x (/ (player :width) 2))
115 | :pos-y y
116 | :janet (c/load-texture g/janet-image)
117 | :target target}))
--------------------------------------------------------------------------------
/script/entities/word-explosion.janet:
--------------------------------------------------------------------------------
1 | # _ ______ ____ ____ _______ __ ____ __ ____ _____ ________ _ __
2 | # | | / / __ \/ __ \/ __ \ / ____/ |/ // __ \/ / / __ \/ ___// _/ __ \/ | / /
3 | # | | /| / / / / / /_/ / / / / / __/ | // /_/ / / / / / /\__ \ / // / / / |/ /
4 | # | |/ |/ / /_/ / _, _/ /_/ / / /___ / |/ ____/ /___/ /_/ /___/ // // /_/ / /| /
5 | # |__/|__/\____/_/ |_/_____/ /_____//_/|_/_/ /_____/\____//____/___/\____/_/ |_/
6 |
7 | (import ./base :as base)
8 | (import ../globals :as g)
9 | (import ../colors :as color)
10 |
11 | # __ __ __
12 | # ____/ /___ __ ______ ____/ /___ _/ /____
13 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
14 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
15 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
16 | # /_/
17 |
18 | (defn- do-update [self game time]
19 | (when (not (self :sounded?))
20 | (set (self :sounded?) true)
21 | (c/play-sound (self :sfx)))
22 |
23 | (if (>= (self :current-frame) (self :max-frames))
24 | (set (self :delete?) true)
25 | (when (> (- time (self :last-tick)) (self :frames-speed))
26 | (set (self :last-tick) time)
27 | (set (self :current-frame) (+ 1 (self :current-frame))))))
28 | # __ __
29 | # ____/ /___ ________ ____ ____/ /__ _____
30 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
31 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
32 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
33 |
34 | (defn- do-render [self game]
35 | (when (not (self :delete?))
36 | (c/draw-sprite-ex
37 | (self :gfx)
38 | {:x (* (self :current-frame) (self :width))
39 | :y 0
40 | :w (self :width)
41 | :h (self :height)}
42 | {:x (self :word-x)
43 | :y (self :word-y)
44 | :w (* 3.5 (self :width))
45 | :h (* 3.5 (self :height))}
46 | {:x 20 :y 12}
47 | 0
48 | color/purple)))
49 |
50 | # __ __ _
51 | # _ ______ _________/ / ___ _ ______ / /___ _____(_)___ ____
52 | # | | /| / / __ \/ ___/ __ /_____/ _ \| |/_/ __ \/ / __ \/ ___/ / __ \/ __ \
53 | # | |/ |/ / /_/ / / / /_/ /_____/ __/> /_/ / / /_/ (__ ) / /_/ / / / /
54 | # |__/|__/\____/_/ \__,_/ \___/_/|_/ .___/_/\____/____/_/\____/_/ /_/
55 | # /_/
56 |
57 | (def- word-explosion
58 | @{:frames-speed 0.05
59 | :current-frame 0
60 | :width 16
61 | :height 16
62 | :max-frames 6
63 | :last-tick 0
64 | :color color/green
65 | #
66 | :do-update do-update
67 | :do-render do-render})
68 |
69 | # _________ ____ __ ______
70 | # / ___/ __ \/ __ `/ | /| / / __ \
71 | # (__ ) /_/ / /_/ /| |/ |/ / / / /
72 | # /____/ .___/\__,_/ |__/|__/_/ /_/
73 | # /_/
74 |
75 | (var gfx nil)
76 | (var sfx nil)
77 |
78 | (defn spawn [word]
79 | (when (nil? gfx)
80 | (set gfx (c/load-texture g/word-explosion-image)))
81 | (when (nil? sfx)
82 | (set sfx (c/load-sound g/word-explosion-wave)))
83 |
84 | (merge
85 | (base/get-ref)
86 | (table/clone word-explosion)
87 | @{:word-x (word :pos-x)
88 | :word-y (word :pos-y)
89 | :gfx gfx
90 | :sfx sfx
91 | :sounded? false}))
--------------------------------------------------------------------------------
/script/entities/word.janet:
--------------------------------------------------------------------------------
1 | # _ ______ ____ ____
2 | # | | / / __ \/ __ \/ __ \
3 | # | | /| / / / / / /_/ / / / /
4 | # | |/ |/ / /_/ / _, _/ /_/ /
5 | # |__/|__/\____/_/ |_/_____/
6 |
7 | (import ./base :as base)
8 | (import ./letter :as letter)
9 | (import ../colors :as color)
10 | (import ../utils :as u)
11 |
12 |
13 | (def resize-tick 0)
14 |
15 | # __ __ __
16 | # ____/ /___ __ ______ ____/ /___ _/ /____
17 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
18 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
19 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
20 | # /_/
21 |
22 | (defn- do-update [self game time]
23 | (when (self :locked?)
24 | (when (u/some? (fn [child] (not (child :typed?))) (self :children))
25 | (if (self :grow?)
26 | (do
27 | (set (self :width-ex) (+ (self :width-ex) (self :width-gr)))
28 | (set (self :height-ex) (+ (self :height-ex) (self :height-gr))))
29 | (do
30 | (set (self :width-ex) (- (self :width-ex) (self :width-gr)))
31 | (set (self :height-ex) (- (self :height-ex) (self :height-gr)))))
32 | (when
33 | (or
34 | (>= (self :width-ex) (self :width-max))
35 | (>= (self :height-ex) (self :height-max)))
36 | (set (self :grow?) false))
37 | (when
38 | (or
39 | (< (self :width-ex) (self :width))
40 | (< (self :height-ex) (self :height)))
41 | (set (self :grow?) true))))
42 |
43 | (when
44 | (and
45 | (not (self :dead?))
46 | (u/every? (fn [child] (child :typed?)) (self :children)))
47 | (set (self :locked?) false)
48 | (set (self :dead?) true))
49 |
50 |
51 | (when (> (self :pos-y) (- (game :window-height) (self :height)))
52 | (if (self :dead?)
53 | (each child (self :children)
54 | (set (self :delete?) true)
55 | (set (child :delete?) true))
56 | (set (game :lost?) true)))
57 |
58 | (set (self :pos-y) (+ (self :pos-y) (self :speed-y)))
59 | (each child (self :children)
60 | (set (child :pos-y) (self :pos-y)))
61 |
62 | (when (not (self :produced))
63 | (set (self :produced) true)
64 | (var arr (u/split (self :letters)))
65 | (var idx 0)
66 | (each l arr
67 | (array/push (self :children) (letter/spawn (+ (* 15 idx) (self :pos-x)) (self :pos-y) l))
68 | (++ idx))
69 | (each child (self :children)
70 | (array/push (game :objects) child))))
71 |
72 | # __ __
73 | # ____/ /___ ________ ____ ____/ /__ _____
74 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
75 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
76 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
77 |
78 | (defn- do-render [self game]
79 | (when (and (self :locked?) (not (self :delete?)))
80 | (when (self :grow?)
81 | (var diff (math/floor (/ (- (self :width-ex) (self :width)) 2)))
82 | (c/draw-rect
83 | (- (self :pos-x) diff)
84 | (- (self :pos-y) diff)
85 | (+ (self :width-ex) diff)
86 | (+ (self :height-ex) diff)
87 | (self :color)))
88 | (when (not (self :grow?))
89 | (var diff (math/ceil (/ (- (self :width) (self :width-ex)) 2)))
90 | (c/draw-rect
91 | (+ (self :pos-x) diff)
92 | (+ (self :pos-y) diff)
93 | (- (self :width-ex) diff)
94 | (- (self :height-ex) diff)
95 | (self :color)))))
96 |
97 | # __ __ _ __ __
98 | # ____ ____ / /_ _____/ /_ (_) /___/ /
99 | # / __ `/ _ \/ __/_____/ ___/ __ \/ / / __ /
100 | # / /_/ / __/ /_/_____/ /__/ / / / / / /_/ /
101 | # \__, /\___/\__/ \___/_/ /_/_/_/\__,_/
102 | # /____/
103 |
104 | (defn get-child [self]
105 | (var idx (find-index (fn [child] (not (child :typed?))) (self :children)))
106 |
107 | (if (number? idx)
108 | ((self :children) idx)
109 | -1)) #### WTF WHY I ...
110 |
111 |
112 | (defn last? [self]
113 | (var idx (find-index (fn [child] (not (child :typed?))) (self :children)))
114 |
115 | (if
116 | (or
117 | (nil? idx)
118 | (= (+ 1 idx) (length (self :letters))))
119 | true
120 | false))
121 |
122 | # __
123 | # _ ______ _________/ /
124 | # | | /| / / __ \/ ___/ __ /
125 | # | |/ |/ / /_/ / / / /_/ /
126 | # |__/|__/\____/_/ \__,_/
127 |
128 | (def word
129 | @{:type :WORD
130 | :produced? false
131 | :speed-y 1
132 | :width-gr 2
133 | :height-gr 1
134 | :grow? true
135 | :locked? false
136 | :dead? false
137 | :color color/red
138 | #
139 | :do-update do-update
140 | :do-render do-render
141 | :get-child get-child
142 | :last? last?})
143 |
144 | # _________ ____ __ ______
145 | # / ___/ __ \/ __ `/ | /| / / __ \
146 | # (__ ) /_/ / /_/ /| |/ |/ / / / /
147 | # /____/ .___/\__,_/ |__/|__/_/ /_/
148 | # /_/
149 |
150 | (defn spawn [letters x y w h]
151 | (merge
152 | (base/get-ref)
153 | (table/clone word)
154 | @{:pos-x x
155 | :pos-y y
156 | :width w
157 | :height h
158 | :width-ex w
159 | :height-ex h
160 | :width-max (+ w 10)
161 | :height-max (+ h 10)
162 | :letters letters
163 | :children (array/new 1)}))
--------------------------------------------------------------------------------
/script/game.janet:
--------------------------------------------------------------------------------
1 | # _________ __ _________
2 | # / ____/ | / |/ / ____/
3 | # / / __/ /| | / /|_/ / __/
4 | # / /_/ / ___ |/ / / / /___
5 | # \____/_/ |_/_/ /_/_____/
6 |
7 | (import ./profile :as profile)
8 | (import ./globals :as g)
9 | (import ./utils :as util)
10 | (import ./keys :as key)
11 | (import ./colors :as color)
12 | (import ./background :as background)
13 | (import ./hud :as hud)
14 | (import ./entities/word :as word)
15 | (import ./entities/player :as player)
16 |
17 | (var still-more? true)
18 | (var won? false)
19 | (var cleanup-tick 0)
20 | (var cleanup-time 1)
21 | (var word-tick 0)
22 | (var word-time 2)
23 | (var word-idx 0)
24 | (var seed-flag true)
25 | (var first-word nil)
26 | (var repo-len 0)
27 | (var music nil)
28 | (var game @{})
29 |
30 | # __ _ __
31 | # ____/ /___ (_)___ ____ __ __/ /_
32 | # / __ / __ \______/ / __ \/ __ \/ / / / __/
33 | # / /_/ / /_/ /_____/ / / / / /_/ / /_/ / /_
34 | # \__,_/\____/ /_/_/ /_/ .___/\__,_/\__/
35 | # /_/
36 |
37 | (defn- do-input []
38 | (if (c/is-key-pressed key/exit) (set (game :lost?) true)))
39 |
40 | # __ __ __
41 | # ____/ /___ __ ______ ____/ /___ _/ /____
42 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
43 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
44 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
45 | # /_/
46 |
47 | (defn- do-update [tick]
48 | (when (not (c/music-playing? music))
49 | (c/play-music music))
50 |
51 | (var objects (game :objects))
52 |
53 | (when still-more?
54 | (when (> (- tick word-tick) word-time)
55 | (set word-tick tick)
56 |
57 | (if seed-flag
58 | (math/seedrandom (math/floor (os/clock)))
59 | (math/seedrandom (math/floor tick)))
60 |
61 | (set seed-flag (not seed-flag))
62 |
63 | (var pos-x (math/floor (* (game :window-width) (math/random))))
64 | (var text ((game :repository) word-idx))
65 | (var size (c/text-size (game :font) text (game :font-size) (game :font-spacing)))
66 |
67 | (when (>= (+ pos-x (size :x)) (game :window-width))
68 | (-= pos-x (size :x)))
69 |
70 | (array/concat objects (word/spawn text pos-x -15 (size :x) (size :y)))
71 | (++ word-idx)
72 | (when (>= word-idx repo-len)
73 | (set still-more? false))))
74 |
75 | (set first-word
76 | (find-index
77 | (fn [obj]
78 | (and
79 | (not (obj :dead?))
80 | (= (obj :type) :WORD)))
81 | objects))
82 |
83 |
84 | (when (not (nil? first-word))
85 | (set (game :word) (objects first-word))
86 | (set ((game :word) :locked?) true)
87 | (set ((game :player) :target) (game :word)))
88 |
89 |
90 | (when (> (- tick cleanup-tick) cleanup-time)
91 | (set cleanup-tick tick)
92 | (var idx (- (length objects) 1))
93 | (while (>= idx 0)
94 | (when (= ((objects idx) :delete?) true)
95 | (array/remove objects idx))
96 | (-- idx))))
97 |
98 | # _ _ __
99 | # (_)___ (_) /_
100 | # / / __ \/ / __/
101 | # / / / / / / /_
102 | # /_/_/ /_/_/\__/
103 |
104 | (defn init [eng]
105 | (when (nil? music)
106 | (set music (c/load-music g/music)))
107 |
108 | (set still-more? true)
109 | (set won? false)
110 | (set cleanup-tick 0)
111 | (set cleanup-time 1)
112 | (set word-tick 0)
113 | (set word-time 2)
114 | (set word-idx 0)
115 | (set seed-flag true)
116 | (set first-word nil)
117 | (set repo-len 0)
118 | (set game @{})
119 |
120 | (set game
121 | @{:won? false
122 | :lost? false
123 | :score 0
124 | :streak 0
125 | :best-streak 0
126 | :hud-height 50
127 | :player nil
128 | :objects (array/new 1)
129 | :word nil})
130 |
131 | (set game (merge eng game))
132 | (set (game :font) (c/load-font g/default-font g/default-font-size))
133 | (set (game :background) (c/load-texture g/background-image))
134 | (set (game :hud) (c/load-texture g/hud-image))
135 | (var objects (game :objects))
136 | (set repo-len (length (game :repository)))
137 |
138 | (var plyr (player/spawn (/ (game :window-width) 2) 1000 nil))
139 | (set (game :player) plyr)
140 | (set (plyr :pos-y) (- (game :window-height) (plyr :height) 9))
141 |
142 | (var time (c/get-time))
143 |
144 | (while (and (not (game :won?)) (not (game :lost?)))
145 | (set time (c/get-time))
146 |
147 | (do-input)
148 | (:do-input plyr game)
149 |
150 |
151 | (do-update time)
152 | (:do-update plyr game time)
153 | (each obj objects (:do-update obj game time))
154 |
155 | (util/render
156 | (background/do-render game)
157 | (each obj objects (:do-render obj game))
158 | (:do-render plyr game)
159 | (hud/do-render game)))
160 |
161 | (when (> (game :streak) (game :best-streak))
162 | (set (game :best-streak) (game :streak)))
163 |
164 | (profile/update (game :score) (game :best-streak))
165 |
166 | (when (game :won?)
167 | (while (not (c/is-key-released key/select))
168 | (util/render
169 | (c/draw-text (game :font) "You Win" 140 100 20 1 color/red))))
170 |
171 | (when (game :lost?)
172 | (while (not (c/is-key-released key/select))
173 | (when (not (c/music-playing? music))
174 | (c/play-music music))
175 | (util/render
176 | (c/draw-text (game :font) "You Lost" 140 100 20 1 color/red)
177 | (c/draw-text (game :font) "You Scored: " 40 400 20 1 color/light-gray)
178 | (c/draw-text (game :font) (string (game :score)) 60 420 20 1 color/gold)
179 | (c/draw-text (game :font) "Your best Streak: " 40 440 20 1 color/light-gray)
180 | (c/draw-text (game :font) (string (game :best-streak)) 60 460 20 1 color/gold)
181 | (c/draw-text (game :font) "press enter to continue" 40 600 20 1 color/sky-blue)))))
182 |
--------------------------------------------------------------------------------
/script/globals.janet:
--------------------------------------------------------------------------------
1 | (def window-width 400)
2 | (def window-height 650)
3 | (def window-title "super janet typist")
4 | (def frames-per-second 60)
5 | (def repository "assets/repository")
6 | (def default-font "assets/font.ttf")
7 | (def background-image "assets/background.png")
8 | (def hud-image "assets/hud.png")
9 | (def janet-image "assets/janet.png")
10 |
11 | (def bullet-image "assets/bullet.png")
12 | (def bullet-wave "assets/bullet.wav")
13 |
14 | (def letter-explosion-image "assets/letter-explosion.png")
15 | (def letter-explosion-wave "assets/letter-explosion.wav")
16 |
17 | (def word-explosion-image "assets/word-explosion.png")
18 | (def word-explosion-wave "assets/word-explosion.wav")
19 |
20 | (def wrong-letter-wave "assets/wrong-letter.wav")
21 | (def music "assets/music.ogg")
22 |
23 | (def default-font-size 20)
24 | (def default-font-spacing 1)
--------------------------------------------------------------------------------
/script/hud.janet:
--------------------------------------------------------------------------------
1 | # __ ____ ______
2 | # / / / / / / / __ \
3 | # / /_/ / / / / / / /
4 | # / __ / /_/ / /_/ /
5 | # /_/ /_/\____/_____/
6 |
7 | (import ./colors :as color)
8 |
9 | # __ __ __
10 | # ____/ /___ __ ______ ____/ /___ _/ /____
11 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
12 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
13 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
14 | # /_/
15 |
16 | # (defn do-update [game] nil)
17 |
18 | # __ __
19 | # ____/ /___ ________ ____ ____/ /__ _____
20 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
21 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
22 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
23 |
24 | (defn do-render [game]
25 | (c/draw-texture
26 | (game :hud)
27 | 0
28 | 0
29 | color/gray)
30 | (c/draw-text
31 | (game :font)
32 | (string/format "score: %d" (game :score))
33 | 35
34 | 10
35 | 20
36 | 1
37 | color/white)
38 | (c/draw-text
39 | (game :font)
40 | (string/format "streak: %d" (game :streak))
41 | 210
42 | 10
43 | 20
44 | 1
45 | color/white))
46 |
--------------------------------------------------------------------------------
/script/keys.janet:
--------------------------------------------------------------------------------
1 | # __ __ ________ _______
2 | # / //_// ____/\ \/ / ___/
3 | # / ,< / __/ \ /\__ \
4 | # / /| |/ /___ / /___/ /
5 | # /_/ |_/_____/ /_//____/
6 |
7 | (def left 263)
8 | (def right 262)
9 | (def jump 88) # x
10 | (def crawl 90) # z
11 | (def fire 88) # x
12 | (def pause 80) # p
13 | (def continue 256) # esc
14 | (def exit 256) # esc
15 | (def select 257) # enter
16 |
--------------------------------------------------------------------------------
/script/menu.janet:
--------------------------------------------------------------------------------
1 | # __ __________ ____ __
2 | # / |/ / ____/ | / / / / /
3 | # / /|_/ / __/ / |/ / / / /
4 | # / / / / /___/ /| / /_/ /
5 | # /_/ /_/_____/_/ |_/\____/
6 |
7 | (import ./globals :as g)
8 | (import ./profile :as profile)
9 | (import ./utils :as util)
10 | (import ./keys :as key)
11 | (import ./colors :as color)
12 | (import ./game :as game)
13 | (import ./background :as background)
14 |
15 | # __ _ __
16 | # ____/ /___ (_)___ ____ __ __/ /_
17 | # / __ / __ \______/ / __ \/ __ \/ / / / __/
18 | # / /_/ / /_/ /_____/ / / / / /_/ / /_/ / /_
19 | # \__,_/\____/ /_/_/ /_/ .___/\__,_/\__/
20 | # /_/
21 |
22 | (defn- do-input [menu]
23 | (if (c/is-key-pressed key/select) (set (menu :start?) true))
24 | (if (c/is-key-pressed key/exit) (set (menu :quit?) true)))
25 |
26 | # __ __ __
27 | # ____/ /___ __ ______ ____/ /___ _/ /____
28 | # / __ / __ \______/ / / / __ \/ __ / __ `/ __/ _ \
29 | # / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/
30 | # \__,_/\____/ \__,_/ .___/\__,_/\__,_/\__/\___/
31 | # /_/
32 |
33 | (defn- do-update [tick] nil)
34 |
35 | # __ __
36 | # ____/ /___ ________ ____ ____/ /__ _____
37 | # / __ / __ \______/ ___/ _ \/ __ \/ __ / _ \/ ___/
38 | # / /_/ / /_/ /_____/ / / __/ / / / /_/ / __/ /
39 | # \__,_/\____/ /_/ \___/_/ /_/\__,_/\___/_/
40 |
41 | (defn- do-render [menu]
42 | (util/render
43 | (background/do-render menu)
44 | (c/draw-text (menu :font) "a game made for\n lisp game jam\n (GPLv3)" 100 10 16 1 color/dark-gray)
45 | (c/draw-text (menu :font) "press to start" 60 100 20 1 color/white)
46 | (c/draw-text (menu :font) " enter " 60 100 20 1 color/sky-blue)
47 | (c/draw-text (menu :font) "press to quit" 60 140 20 1 color/white)
48 | (c/draw-text (menu :font) " escape " 60 140 20 1 color/red)
49 | (c/draw-text (menu :font) "A game by:" 60 200 20 1 color/light-gray)
50 | (c/draw-text (menu :font) " @sepisoad" 60 220 20 1 color/gold)
51 | (c/draw-text (menu :font) "GFX by:" 60 240 20 1 color/light-gray)
52 | (c/draw-text (menu :font) " @surt" 60 260 20 1 color/gold)
53 | (c/draw-text (menu :font) "SFX and Music by:" 60 280 20 1 color/light-gray)
54 | (c/draw-text (menu :font) " @sepisoad" 60 300 20 1 color/gold)
55 |
56 | (c/draw-text (menu :font) "Follow me on twitter:" 60 340 20 1 color/gray)
57 | (c/draw-text (menu :font) " @sepisoad" 60 360 20 1 color/dark-gray)
58 | (c/draw-text (menu :font) "Follow me on github:" 60 380 20 1 color/gray)
59 | (c/draw-text (menu :font) " @sepisoad" 60 400 20 1 color/dark-gray)
60 |
61 | (c/draw-text (menu :font) "License: GPLv3" 60 620 20 1 color/purple)
62 | (when (not (empty? (menu :info)))
63 | (c/draw-text (menu :font) (string "best score: " ((menu :info) :best-score)) 60 480 20 1 color/dark-gray)
64 | (c/draw-text (menu :font) (string "best streak: " ((menu :info) :best-streak)) 60 500 20 1 color/dark-gray)
65 | (c/draw-text (menu :font) (string "last score: " ((menu :info) :last-score)) 60 520 20 1 color/dark-gray)
66 | (c/draw-text (menu :font) (string "last streak: " ((menu :info) :last-streak)) 60 540 20 1 color/dark-gray))))
67 |
68 | # ____ ___ ___ ____ __ __
69 | # / __ `__ \/ _ \/ __ \/ / / /
70 | # / / / / / / __/ / / / /_/ /
71 | # /_/ /_/ /_/\___/_/ /_/\__,_/
72 |
73 | (var menu nil)
74 |
75 | # _ _ __
76 | # (_)___ (_) /_
77 | # / / __ \/ / __/
78 | # / / / / / / /_
79 | # /_/_/ /_/_/\__/
80 |
81 | (defn init [eng]
82 | (when (nil? menu)
83 | (set menu @{})
84 | (set (menu :start?) false)
85 | (set (menu :quit?) false)
86 | (set (menu :font) (c/load-font g/default-font g/default-font-size))
87 | (set (menu :background) (c/load-texture g/background-image)))
88 |
89 | (var time 0)
90 |
91 | (while (not (menu :quit?))
92 | (set (menu :info) (profile/load))
93 | (while (and (not (menu :start?)) (not (menu :quit?)))
94 | (set time (c/get-time))
95 | (do-input menu)
96 | (do-update time)
97 | (do-render menu))
98 | (when (menu :start?)
99 | (set (menu :quit?) false)
100 | (set (menu :start?) false)
101 | (game/init eng))))
--------------------------------------------------------------------------------
/script/profile.janet:
--------------------------------------------------------------------------------
1 | (def- profile-dir (string (os/getenv "HOME") "/.super-janet-typist"))
2 | (def- best-score (string profile-dir "/best-score"))
3 | (def- best-streak (string profile-dir "/best-streak"))
4 | (def- last-score (string profile-dir "/last-score"))
5 | (def- last-streak (string profile-dir "/last-streak"))
6 | (def- top-scores (string profile-dir "/top-scores"))
7 |
8 | (defn- make-sure-profile-exists []
9 | (when (nil? (os/stat profile-dir))
10 | (when (not (os/mkdir profile-dir))
11 | (error "cannot create profile directory")))
12 |
13 | (when (nil? (os/stat best-score))
14 | (let [file (file/open best-score :wb)]
15 | (when (nil? file)
16 | (error "cannot open/create best score file"))
17 | (file/close file)))
18 |
19 | (when (nil? (os/stat best-streak))
20 | (let [file (file/open best-streak :wb)]
21 | (when (nil? file)
22 | (error "cannot open/create best streak file"))
23 | (file/close file)))
24 |
25 | (when (nil? (os/stat last-score))
26 | (let [file (file/open last-score :wb)]
27 | (when (nil? file)
28 | (error "cannot open/create last score file"))
29 | (file/close file)))
30 |
31 | (when (nil? (os/stat last-streak))
32 | (let [file (file/open last-streak :wb)]
33 | (when (nil? file)
34 | (error "cannot open/create last streak file"))
35 | (file/close file)))
36 |
37 | (when (nil? (os/stat top-scores))
38 | (let [file (file/open top-scores :wb)]
39 | (when (nil? file)
40 | (error "cannot open/create top scores file"))
41 | (file/close file))))
42 |
43 |
44 | (defn load []
45 | (make-sure-profile-exists)
46 | (var res @{})
47 | (let [last-score-file (file/open last-score :rb)
48 | last-streak-file (file/open last-streak :rb)
49 | best-score-file (file/open best-score :rb)
50 | best-streak-file (file/open best-streak :rb)]
51 |
52 | (when (not (nil? last-score-file))
53 | (var buf @"")
54 | (file/read last-score-file :all buf)
55 | (when (empty? buf) (set buf @"0"))
56 | (set (res :last-score) (scan-number buf))
57 | (file/close last-score-file))
58 |
59 | (when (not (nil? last-streak-file))
60 | (var buf @"")
61 | (file/read last-streak-file :all buf)
62 | (when (empty? buf) (set buf @"0"))
63 | (set (res :last-streak) (scan-number buf))
64 | (file/close last-streak-file))
65 |
66 | (when (not (nil? best-score-file))
67 | (var buf @"")
68 | (file/read best-score-file :all buf)
69 | (when (empty? buf) (set buf @"0"))
70 | (set (res :best-score) (scan-number buf))
71 | (file/close best-score-file))
72 |
73 | (when (not (nil? best-streak-file))
74 | (var buf @"")
75 | (file/read best-streak-file :all buf)
76 | (when (empty? buf) (set buf @"0"))
77 | (set (res :best-streak) (scan-number buf))
78 | (file/close best-streak-file)))
79 |
80 | (pp "====load====")
81 | (pp res)
82 | (pp "============")
83 |
84 | res)
85 |
86 | (defn update [score streak]
87 | (make-sure-profile-exists)
88 |
89 | (var last-score-val 0)
90 | (var last-streak-val 0)
91 | (var best-score-val 0)
92 | (var best-streak-val 0)
93 |
94 | (let [file (file/open last-score :rb)]
95 | (when (not (nil? file))
96 | (set last-score-val (scan-number (file/read file :all)))
97 | (when (nil? last-score-val) (set last-score-val 0))
98 | (file/close file)))
99 |
100 | (let [file (file/open last-streak :rb)]
101 | (when (not (nil? file))
102 | (set last-streak-val (scan-number (file/read file :all)))
103 | (when (nil? last-streak-val) (set last-streak-val 0))
104 | (file/close file)))
105 |
106 | (let [file (file/open best-score :rb)]
107 | (when (not (nil? file))
108 | (set best-score-val (scan-number (file/read file :all)))
109 | (when (nil? best-score-val) (set best-score-val 0))
110 | (file/close file)))
111 |
112 | (let [file (file/open best-streak :rb)]
113 | (when (not (nil? file))
114 | (set best-streak-val (scan-number (file/read file :all)))
115 | (when (nil? best-streak-val) (set best-streak-val 0))
116 | (file/close file)))
117 |
118 | #
119 |
120 | (pp "====update====[input]")
121 | (pp score)
122 | (pp streak)
123 | (pp "====update====[last]")
124 | (pp last-score-val)
125 | (pp last-streak-val)
126 | (pp "====update====[best]")
127 | (pp best-score-val)
128 | (pp best-streak-val)
129 | (pp "============")
130 |
131 | (let [file (file/open last-score :wb)]
132 | (when (not (nil? file))
133 | (file/write file (string score))
134 | (file/close file)))
135 |
136 | (let [file (file/open last-streak :wb)]
137 | (when (not (nil? file))
138 | (file/write file (string streak))
139 | (file/close file)))
140 |
141 | (when (> score best-score-val)
142 | (let [file (file/open best-score :wb)]
143 | (when (not (nil? file))
144 | (file/write file (string score))
145 | (file/close file))))
146 |
147 | (when (> streak best-streak-val)
148 | (let [file (file/open best-streak :wb)]
149 | (when (not (nil? file))
150 | (file/write file (string streak))
151 | (file/close file)))))
152 |
--------------------------------------------------------------------------------
/script/utils.janet:
--------------------------------------------------------------------------------
1 | # __ ______________ _____
2 | # / / / /_ __/ _/ / / ___/
3 | # / / / / / / / // / \__ \
4 | # / /_/ / / / _/ // /______/ /
5 | # \____/ /_/ /___/_____/____/
6 |
7 | # __
8 | # ________ ____ ____/ /__ _____
9 | # / ___/ _ \/ __ \/ __ / _ \/ ___/
10 | # / / / __/ / / / /_/ / __/ /
11 | # /_/ \___/_/ /_/\__,_/\___/_/
12 |
13 | (defmacro render [& commands]
14 | "renders multiple commands within the same begin and end render pair"
15 | ~(do
16 | (c/begin-draw)
17 | ,;commands
18 | (c/end-draw)))
19 |
20 | # ___
21 | # ___ _ _____ _______ _/__ \
22 | # / _ \ | / / _ \/ ___/ / / // _/
23 | # / __/ |/ / __/ / / /_/ //_/
24 | # \___/|___/\___/_/ \__, /(_)
25 | # /____/
26 |
27 | (defmacro every? [pred ind]
28 | ~(if (and (indexed? ,ind) (not (empty? ,ind)))
29 | (true? (reduce (fn [iv nv] (and iv nv)) true (map ,pred ,ind)))
30 | false))
31 |
32 | # ___
33 | # _________ ____ ___ ___/__ \
34 | # / ___/ __ \/ __ `__ \/ _ \/ _/
35 | # (__ ) /_/ / / / / / / __/_/
36 | # /____/\____/_/ /_/ /_/\___(_)
37 |
38 | (defmacro some? [pred ind]
39 | ~(if (and (indexed? ,ind) (not (empty? ,ind)))
40 | (true? (reduce (fn [iv nv] (or iv nv)) false (map ,pred ,ind)))
41 | false))
42 |
43 | # ____
44 | # ____ ____ ____ / __/________ _____ ___ ___ _____
45 | # / __ `/ _ \/ __ \______/ /_/ ___/ __ `/ __ `__ \/ _ \/ ___/
46 | # / /_/ / __/ / / /_____/ __/ / / /_/ / / / / / / __(__ )
47 | # \__, /\___/_/ /_/ /_/ /_/ \__,_/_/ /_/ /_/\___/____/
48 | # /____/
49 |
50 | (defn gen-frames [& numbers] ## todo: convert this to a macro
51 | (if (or (= (length numbers) 0)
52 | (not (= (% (length numbers) 4) 0)))
53 | (error "gen-frames wrong input arguments count"))
54 | (var numbers-x numbers)
55 | (var frames-array @[])
56 | (var frame nil)
57 | (while (> (length numbers-x) 0)
58 | (set frame (take 4 numbers-x))
59 | (set numbers-x (array/slice numbers-x 4))
60 | (if (= nil frame) (break)
61 | (array/concat frames-array
62 | {:x (frame 0) :y (frame 1) :w (frame 2) :h (frame 3)})))
63 | frames-array)
64 |
65 | # __ __
66 | # / /_____ _____/ /_ ____ ___________
67 | # / __/ __ \______/ ___/ __ \/ __ `/ ___/ ___/
68 | # / /_/ /_/ /_____/ /__/ / / / /_/ / / (__ )
69 | # \__/\____/ \___/_/ /_/\__,_/_/ /____/
70 |
71 | (defn split [str]
72 | (var len (length str))
73 | (var idx 0)
74 | (var res @[])
75 | (while (< idx len)
76 | (array/push res (string/slice str idx (+ idx 1)))
77 | (++ idx))
78 | res)
79 |
80 | # __ _ __
81 | # _________ _____ ____/ /___ ____ ___ (_)___ / /_
82 | # / ___/ __ `/ __ \/ __ / __ \/ __ `__ \______/ / __ \/ __/
83 | # / / / /_/ / / / / /_/ / /_/ / / / / / /_____/ / / / / /_
84 | # /_/ \__,_/_/ /_/\__,_/\____/_/ /_/ /_/ /_/_/ /_/\__/
85 |
86 | (defn random-int [num]
87 | (math/floor (* num (math/random))))
88 |
89 | # __ __________
90 | # _____/ /_ __ __/ __/ __/ /__
91 | # / ___/ __ \/ / / / /_/ /_/ / _ \
92 | # (__ ) / / / /_/ / __/ __/ / __/
93 | # /____/_/ /_/\__,_/_/ /_/ /_/\___/
94 |
95 | (defn shuffle [input]
96 | (when (not (indexed? input))
97 | (error "input value must be an array or tuple"))
98 | (var occupied 0)
99 | (var array-length (length input))
100 | (var index-array (array/new array-length))
101 |
102 | (math/seedrandom (os/time))
103 |
104 | (var index (random-int array-length))
105 | (while (not (>= occupied array-length))
106 | (while (not (nil? (index-array index)))
107 | (set index (random-int array-length)))
108 | (set (index-array index) (input occupied))
109 | (set occupied (+ 1 occupied)))
110 |
111 | (if (array? input)
112 | index-array
113 | (tuple ;index-array)))
--------------------------------------------------------------------------------
/src/cfuncs.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "janet.h"
3 |
4 | //==============================================================================
5 |
6 | JanetAbstractType jt_image =
7 | {"jt/image", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
8 |
9 | JanetAbstractType jt_texture2d =
10 | {"jt/texture2d", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
11 |
12 | JanetAbstractType jt_font =
13 | {"jt/font", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
14 |
15 | JanetAbstractType jt_wave =
16 | {"jt/wave", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
17 |
18 | JanetAbstractType jt_sound =
19 | {"jt/sound", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
20 |
21 | //==============================================================================
22 |
23 | static Janet c_screen_start(int32_t argc, Janet *argv) {
24 | janet_fixarity(argc, 1);
25 |
26 | JanetTable *config = janet_gettable(argv, 0);
27 | int window_width =
28 | janet_unwrap_integer(
29 | janet_table_get(config,
30 | janet_ckeywordv("window-width")));
31 |
32 | int window_height =
33 | janet_unwrap_integer(
34 | janet_table_get(config,
35 | janet_ckeywordv("window-height")));
36 |
37 | int frames_per_second =
38 | janet_unwrap_integer(
39 | janet_table_get(config,
40 | janet_ckeywordv("frames-per-second")));
41 |
42 | const uint8_t *window_title =
43 | janet_unwrap_string(
44 | janet_table_get(config,
45 | janet_ckeywordv("window-title")));
46 |
47 | bool is_fullscreen =
48 | janet_unwrap_boolean(
49 | janet_table_get(config,
50 | janet_ckeywordv("is-fullscreen?")));
51 |
52 | InitWindow(window_width, window_height, (const char *)window_title);
53 | InitAudioDevice();
54 |
55 | if (is_fullscreen) {
56 | ToggleFullscreen();
57 | }
58 |
59 | SetTargetFPS(frames_per_second);
60 | SetExitKey(KEY_F10);
61 |
62 | return janet_wrap_true();
63 | }
64 |
65 | //==============================================================================
66 |
67 | static Janet c_screen_end(int32_t argc, Janet *argv) {
68 | janet_fixarity(argc, 0);
69 | CloseAudioDevice();
70 | CloseWindow();
71 | return janet_wrap_true();
72 | }
73 |
74 | //==============================================================================
75 |
76 | static Janet c_begin_draw(int32_t argc, Janet *argv) {
77 | janet_fixarity(argc, 0);
78 | BeginDrawing();
79 | ClearBackground(BLACK); // TODO: harcoded!!!
80 | // DrawFPS(10, 10);
81 | return janet_wrap_nil();
82 | }
83 |
84 | //==============================================================================
85 |
86 | static Janet c_end_draw(int32_t argc, Janet *argv) {
87 | janet_fixarity(argc, 0);
88 | EndDrawing();
89 | return janet_wrap_nil();
90 | }
91 |
92 | //==============================================================================
93 |
94 | static Janet c_get_time(int32_t argc, Janet *argv) {
95 | janet_fixarity(argc, 0);
96 | return janet_wrap_number(GetTime());
97 | }
98 |
99 | //==============================================================================
100 |
101 | static Janet c_draw_text(int32_t argc, Janet *argv) {
102 | janet_fixarity(argc, 7);
103 |
104 | Font *font = (Font *) janet_getabstract(argv, 0, &jt_font);
105 | const char *text = janet_getcstring(argv, 1);
106 | int x = janet_getinteger(argv, 2);
107 | int y = janet_getinteger(argv, 3);
108 | double size = janet_getnumber(argv, 4);
109 | double spacing = janet_getnumber(argv, 5);
110 | const JanetKV *color_kv = janet_getstruct(argv, 6);
111 | Color color = (Color) {
112 | .r = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("r"))),
113 | .g = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("g"))),
114 | .b = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("b"))),
115 | .a = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("a"))),
116 | };
117 |
118 | DrawTextEx(*font, text, (Vector2){.x=x,.y=y}, size, spacing, color);
119 | return janet_wrap_nil();
120 | }
121 |
122 | //==============================================================================
123 |
124 | static Janet c_draw_texture(int32_t argc, Janet *argv) {
125 | janet_fixarity(argc, 4);
126 |
127 | Texture2D *texture = (Texture2D*) janet_getabstract(argv, 0, &jt_texture2d);
128 | int x = janet_getinteger(argv, 1);
129 | int y = janet_getinteger(argv, 2);
130 | const JanetKV *color_kv = janet_getstruct(argv, 3);
131 | Color color = (Color) {
132 | .r = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("r"))),
133 | .g = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("g"))),
134 | .b = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("b"))),
135 | .a = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("a"))),
136 | };
137 |
138 | DrawTexture(
139 | *texture,
140 | x,
141 | y,
142 | color);
143 | return janet_wrap_nil();
144 | }
145 |
146 | //==============================================================================
147 |
148 | static Janet c_draw_sprite(int32_t argc, Janet *argv) {
149 | janet_fixarity(argc, 4);
150 |
151 | Texture2D *texture = (Texture2D*) janet_getabstract(argv, 0, &jt_texture2d);
152 | const JanetKV *jrect = janet_getstruct(argv, 1);
153 | const JanetKV *jpos = janet_getstruct(argv, 2);
154 | const JanetKV *color_kv = janet_getstruct(argv, 3);
155 |
156 | Rectangle rect = (Rectangle) {
157 | .x = janet_unwrap_integer(janet_struct_get(jrect, janet_ckeywordv("x"))),
158 | .y = janet_unwrap_integer(janet_struct_get(jrect, janet_ckeywordv("y"))),
159 | .width = janet_unwrap_integer(janet_struct_get(jrect, janet_ckeywordv("w"))),
160 | .height = janet_unwrap_integer(janet_struct_get(jrect, janet_ckeywordv("h")))
161 | };
162 |
163 | Vector2 pos = (Vector2) {
164 | .x = janet_unwrap_integer(janet_struct_get(jpos, janet_ckeywordv("x"))),
165 | .y = janet_unwrap_integer(janet_struct_get(jpos, janet_ckeywordv("y"))),
166 | };
167 |
168 | Color color = (Color) {
169 | .r = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("r"))),
170 | .g = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("g"))),
171 | .b = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("b"))),
172 | .a = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("a"))),
173 | };
174 |
175 | DrawTextureRec(
176 | *texture,
177 | rect,
178 | pos,
179 | color);
180 | return janet_wrap_nil();
181 | }
182 |
183 | //==============================================================================
184 |
185 | static Janet c_draw_sprite_ex(int32_t argc, Janet *argv) {
186 | janet_fixarity(argc, 6);
187 |
188 | Texture2D *texture = (Texture2D*) janet_getabstract(argv, 0, &jt_texture2d);
189 | const JanetKV *jrect_src = janet_getstruct(argv, 1);
190 | const JanetKV *jrect_dst = janet_getstruct(argv, 2);
191 | const JanetKV *jorigin = janet_getstruct(argv, 3);
192 | const double rotation = janet_getnumber(argv, 4);
193 | const JanetKV *color_kv = janet_getstruct(argv, 5);
194 |
195 | Rectangle rect_src = (Rectangle) {
196 | .x = janet_unwrap_integer(janet_struct_get(jrect_src, janet_ckeywordv("x"))),
197 | .y = janet_unwrap_integer(janet_struct_get(jrect_src, janet_ckeywordv("y"))),
198 | .width = janet_unwrap_integer(janet_struct_get(jrect_src, janet_ckeywordv("w"))),
199 | .height = janet_unwrap_integer(janet_struct_get(jrect_src, janet_ckeywordv("h")))
200 | };
201 |
202 | Rectangle rect_dst = (Rectangle) {
203 | .x = janet_unwrap_integer(janet_struct_get(jrect_dst, janet_ckeywordv("x"))),
204 | .y = janet_unwrap_integer(janet_struct_get(jrect_dst, janet_ckeywordv("y"))),
205 | .width = janet_unwrap_integer(janet_struct_get(jrect_dst, janet_ckeywordv("w"))),
206 | .height = janet_unwrap_integer(janet_struct_get(jrect_dst, janet_ckeywordv("h")))
207 | };
208 |
209 | Vector2 origin = (Vector2) {
210 | .x = janet_unwrap_integer(janet_struct_get(jorigin, janet_ckeywordv("x"))),
211 | .y = janet_unwrap_integer(janet_struct_get(jorigin, janet_ckeywordv("y"))),
212 | };
213 |
214 | Color color = (Color) {
215 | .r = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("r"))),
216 | .g = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("g"))),
217 | .b = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("b"))),
218 | .a = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("a"))),
219 | };
220 |
221 | DrawTexturePro(
222 | *texture,
223 | rect_src,
224 | rect_dst,
225 | origin,
226 | rotation,
227 | color);
228 | return janet_wrap_nil();
229 | }
230 |
231 | //==============================================================================
232 |
233 | static Janet c_draw_pixel(int32_t argc, Janet *argv) {
234 | janet_fixarity(argc, 2);
235 |
236 | int x = janet_getinteger(argv, 0);
237 | int y = janet_getinteger(argv, 1);
238 |
239 | DrawPixel(x, y, WHITE);
240 | return janet_wrap_nil();
241 | }
242 |
243 | //==============================================================================
244 |
245 | static Janet c_draw_rect(int32_t argc, Janet *argv) {
246 | janet_fixarity(argc, 5);
247 |
248 | int x = janet_getinteger(argv, 0);
249 | int y = janet_getinteger(argv, 1);
250 | int w = janet_getinteger(argv, 2);
251 | int h = janet_getinteger(argv, 3);
252 |
253 | const JanetKV *color_kv = janet_getstruct(argv, 4);
254 | Color color = (Color) {
255 | .r = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("r"))),
256 | .g = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("g"))),
257 | .b = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("b"))),
258 | .a = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("a"))),
259 | };
260 |
261 | DrawRectangle(x, y, w, h, color);
262 | return janet_wrap_nil();
263 | }
264 |
265 | //==============================================================================
266 |
267 | static Janet c_draw_rect_lines(int32_t argc, Janet *argv) {
268 | janet_fixarity(argc, 5);
269 |
270 | int x = janet_getinteger(argv, 0);
271 | int y = janet_getinteger(argv, 1);
272 | int w = janet_getinteger(argv, 2);
273 | int h = janet_getinteger(argv, 3);
274 |
275 | const JanetKV *color_kv = janet_getstruct(argv, 4);
276 | Color color = (Color) {
277 | .r = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("r"))),
278 | .g = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("g"))),
279 | .b = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("b"))),
280 | .a = janet_unwrap_integer(janet_struct_get(color_kv, janet_ckeywordv("a"))),
281 | };
282 |
283 | DrawRectangleLines(x, y, w, h, color);
284 | return janet_wrap_nil();
285 | }
286 |
287 | //==============================================================================
288 |
289 | static Janet c_load_image(int32_t argc, Janet *argv) {
290 | janet_fixarity(argc, 1);
291 |
292 | const char *path = janet_getcstring(argv, 0);
293 | Image *image = janet_abstract(&jt_image, sizeof(Image));
294 | *image = LoadImage(path);
295 | return janet_wrap_abstract(image);
296 | }
297 |
298 | //==============================================================================
299 |
300 | static Janet c_load_sprite(int32_t argc, Janet *argv) {
301 | janet_fixarity(argc, 1);
302 |
303 | const char *path = janet_getcstring(argv, 0);
304 |
305 | Image image = LoadImage(path);
306 | Texture2D *texture = janet_abstract(&jt_texture2d, sizeof(Texture2D));
307 | *texture = LoadTextureFromImage(image);
308 | return janet_wrap_abstract(texture);
309 | }
310 |
311 | //==============================================================================
312 |
313 | static Janet c_load_texture(int32_t argc, Janet *argv) {
314 | janet_fixarity(argc, 1);
315 |
316 | const char *path = janet_getcstring(argv, 0);
317 | Texture2D *texture = janet_abstract(&jt_texture2d, sizeof(Texture2D));
318 | *texture = LoadTexture(path);
319 | return janet_wrap_abstract(texture);
320 | }
321 |
322 | //==============================================================================
323 |
324 | static Janet c_load_sound(int32_t argc, Janet *argv) {
325 | janet_fixarity(argc, 1);
326 |
327 | const char *path = janet_getcstring(argv, 0);
328 | Sound *sound = janet_abstract(&jt_sound, sizeof(Sound));
329 | *sound = LoadSoundFromWave(LoadWave(path));
330 | return janet_wrap_abstract(sound);
331 | }
332 |
333 | //==============================================================================
334 |
335 | static Janet c_play_sound(int32_t argc, Janet *argv) {
336 | janet_fixarity(argc, 1);
337 |
338 | Sound *sound = (Sound*) janet_getabstract(argv, 0, &jt_sound);
339 | PlaySound(*sound);
340 |
341 | return janet_wrap_nil();
342 | }
343 |
344 | //==============================================================================
345 |
346 | static Janet c_load_music(int32_t argc, Janet *argv) {
347 | janet_fixarity(argc, 1);
348 |
349 | const char *path = janet_getcstring(argv, 0);
350 | Sound *sound = janet_abstract(&jt_sound, sizeof(Sound));
351 | *sound = LoadSound(path);
352 | return janet_wrap_abstract(sound);
353 | }
354 |
355 | //==============================================================================
356 |
357 | static Janet c_play_music(int32_t argc, Janet *argv) {
358 | janet_fixarity(argc, 1);
359 |
360 | Sound *sound = (Sound*) janet_getabstract(argv, 0, &jt_sound);
361 | PlaySound(*sound);
362 |
363 | return janet_wrap_nil();
364 | }
365 |
366 | //==============================================================================
367 |
368 | static Janet c_pause_music(int32_t argc, Janet *argv) {
369 | janet_fixarity(argc, 1);
370 |
371 | Sound *sound = (Sound*) janet_getabstract(argv, 0, &jt_sound);
372 | PauseSound(*sound);
373 |
374 | return janet_wrap_nil();
375 | }
376 |
377 | //==============================================================================
378 |
379 | static Janet c_resume_music(int32_t argc, Janet *argv) {
380 | janet_fixarity(argc, 1);
381 |
382 | Sound *sound = (Sound*) janet_getabstract(argv, 0, &jt_sound);
383 | ResumeSound(*sound);
384 |
385 | return janet_wrap_nil();
386 | }
387 |
388 | //==============================================================================
389 |
390 | static Janet c_is_music_playing(int32_t argc, Janet *argv) {
391 | janet_fixarity(argc, 1);
392 |
393 | Sound *sound = (Sound*) janet_getabstract(argv, 0, &jt_sound);
394 |
395 | return janet_wrap_boolean(IsSoundPlaying(*sound));
396 | }
397 |
398 | //==============================================================================
399 |
400 | static Janet c_stop_music(int32_t argc, Janet *argv) {
401 | janet_fixarity(argc, 1);
402 |
403 | Sound *sound = (Sound*) janet_getabstract(argv, 0, &jt_sound);
404 | StopSound(*sound);
405 |
406 | return janet_wrap_nil();
407 | }
408 |
409 | //==============================================================================
410 |
411 | static Janet c_is_key_pressed(int32_t argc, Janet *argv) {
412 | janet_fixarity(argc, 1);
413 |
414 | int key = janet_getinteger(argv, 0);
415 | return janet_wrap_boolean(IsKeyPressed(key));
416 | }
417 |
418 | //==============================================================================
419 |
420 | static Janet c_is_key_down(int32_t argc, Janet *argv) {
421 | janet_fixarity(argc, 1);
422 |
423 | int key = janet_getinteger(argv, 0);
424 | return janet_wrap_boolean(IsKeyDown(key));
425 | }
426 |
427 | //==============================================================================
428 |
429 | static Janet c_is_key_released(int32_t argc, Janet *argv) {
430 | janet_fixarity(argc, 1);
431 |
432 | int key = janet_getinteger(argv, 0);
433 | return janet_wrap_boolean(IsKeyReleased(key));
434 | }
435 |
436 | //==============================================================================
437 |
438 | static Janet c_is_key_up(int32_t argc, Janet *argv) {
439 | janet_fixarity(argc, 1);
440 |
441 | int key = janet_getinteger(argv, 0);
442 | return janet_wrap_boolean(IsKeyUp(key));
443 | }
444 |
445 | //==============================================================================
446 |
447 | static Janet c_get_key_pressed(int32_t argc, Janet *argv) {
448 | janet_fixarity(argc, 0);
449 | return janet_wrap_integer(GetKeyPressed());
450 | }
451 |
452 | //==============================================================================
453 |
454 | static Janet c_load_font(int32_t argc, Janet *argv) {
455 | janet_fixarity(argc, 2);
456 |
457 | const char *path = janet_getcstring(argv, 0);
458 | const int size = janet_getinteger(argv, 1);
459 |
460 | Font *font = janet_abstract(&jt_font, sizeof(Font));
461 | *font = LoadFontEx(path, size, 0, 0);
462 | return janet_wrap_abstract(font);
463 | }
464 |
465 | //==============================================================================
466 |
467 | static Janet c_text_size(int32_t argc, Janet *argv) {
468 | janet_fixarity(argc, 4);
469 |
470 | Font *font = (Font *) janet_getabstract(argv, 0, &jt_font);
471 | const char *text = janet_getcstring(argv, 1);
472 | int size = janet_getinteger(argv, 2);
473 | int spacing = janet_getinteger(argv, 3);
474 |
475 | Vector2 vec = MeasureTextEx(*font, text, size, spacing);
476 | JanetKV *jvec = janet_struct_begin(2);
477 | janet_struct_put(jvec, janet_ckeywordv("x"), janet_wrap_integer(vec.x));
478 | janet_struct_put(jvec, janet_ckeywordv("y"), janet_wrap_integer(vec.y));
479 |
480 | return janet_wrap_struct(janet_struct_end(jvec));
481 | }
482 |
483 | //==============================================================================
484 |
485 | static Janet c_u_str_to_code(int32_t argc, Janet *argv) {
486 | janet_fixarity(argc, 1);
487 |
488 | const char *strchar = janet_getcstring(argv, 0);
489 | return janet_wrap_integer((int8_t)strchar[0]);
490 | }
491 |
492 | //==============================================================================
493 |
494 | void inject_engine_symbols(JanetTable *jenv) {
495 |
496 | JanetReg cfuns[] = {
497 | {"c/screen-start", c_screen_start, ""},
498 | {"c/screen-end", c_screen_end, ""},
499 | {"c/get-time", c_get_time, ""},
500 | {"c/begin-draw", c_begin_draw, ""},
501 | {"c/end-draw", c_end_draw, ""},
502 | {"c/draw-text", c_draw_text, ""},
503 | {"c/draw-texture", c_draw_texture, ""},
504 | {"c/draw-sprite", c_draw_sprite, ""},
505 | {"c/draw-sprite-ex", c_draw_sprite_ex, ""},
506 | {"c/draw-pixel", c_draw_pixel, ""},
507 | {"c/draw-rect", c_draw_rect, ""},
508 | {"c/draw-rect-lines", c_draw_rect_lines, ""},
509 | {"c/load-image", c_load_image, ""},
510 | {"c/load-sprite", c_load_sprite, ""},
511 | {"c/load-texture", c_load_texture, ""},
512 | {"c/load-sound", c_load_sound, ""},
513 | {"c/play-sound", c_play_sound, ""},
514 | {"c/load-music", c_load_music, ""},
515 | {"c/play-music", c_play_music, ""},
516 | {"c/pause-music", c_pause_music, ""},
517 | {"c/resume-music", c_resume_music, ""},
518 | {"c/music-playing?", c_is_music_playing, ""},
519 | {"c/stop-music", c_stop_music, ""},
520 | {"c/is-key-pressed", c_is_key_pressed, ""},
521 | {"c/is-key-down", c_is_key_down, ""},
522 | {"c/is-key-released", c_is_key_released, ""},
523 | {"c/is-key-up", c_is_key_up, ""},
524 | {"c/get-key-pressed", c_get_key_pressed, ""},
525 | {"c/load-font", c_load_font, ""},
526 | {"c/text-size", c_text_size, ""},
527 |
528 | {"c/u/str-to-code", c_u_str_to_code, ""},
529 |
530 | {NULL, NULL, NULL}
531 | };
532 |
533 | janet_cfuns(jenv, "c", cfuns);
534 | }
535 |
536 |
--------------------------------------------------------------------------------
/src/janet.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019 Calvin Rose
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to
6 | * deal in the Software without restriction, including without limitation the
7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 | * sell copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 | * IN THE SOFTWARE.
21 | */
22 |
23 | #ifndef JANET_H_defined
24 | #define JANET_H_defined
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | /***** START SECTION CONFIG *****/
31 |
32 | #include "janetconf.h"
33 |
34 | #ifndef JANET_VERSION
35 | #define JANET_VERSION "latest"
36 | #endif
37 |
38 | #ifndef JANET_BUILD
39 | #define JANET_BUILD "local"
40 | #endif
41 |
42 | /*
43 | * Detect OS and endianess.
44 | * From webkit source. There is likely some extreneous
45 | * detection for unsupported platforms
46 | */
47 |
48 | /* Check Unix */
49 | #if defined(_AIX) \
50 | || defined(__APPLE__) /* Darwin */ \
51 | || defined(__FreeBSD__) || defined(__DragonFly__) \
52 | || defined(__FreeBSD_kernel__) \
53 | || defined(__GNU__) /* GNU/Hurd */ \
54 | || defined(__HAIKU__) \
55 | || defined(__linux__) \
56 | || defined(__NetBSD__) \
57 | || defined(__OpenBSD__) \
58 | || defined(__QNXNTO__) \
59 | || defined(sun) || defined(__sun) /* Solaris */ \
60 | || defined(unix) || defined(__unix) || defined(__unix__)
61 | #define JANET_UNIX 1
62 | /* Enable certain posix features */
63 | #ifndef _POSIX_C_SOURCE
64 | #define _POSIX_C_SOURCE 200112L
65 | #endif
66 | #elif defined(__EMSCRIPTEN__)
67 | #define JANET_WEB 1
68 | #elif defined(WIN32) || defined(_WIN32)
69 | #define JANET_WINDOWS 1
70 | #endif
71 |
72 | /* Check 64-bit vs 32-bit */
73 | #if ((defined(__x86_64__) || defined(_M_X64)) \
74 | && (defined(JANET_UNIX) || defined(JANET_WINDOWS))) \
75 | || (defined(_WIN64)) /* Windows 64 bit */ \
76 | || (defined(__ia64__) && defined(__LP64__)) /* Itanium in LP64 mode */ \
77 | || defined(__alpha__) /* DEC Alpha */ \
78 | || (defined(__sparc__) && defined(__arch64__) || defined (__sparcv9)) /* BE */ \
79 | || defined(__s390x__) /* S390 64-bit (BE) */ \
80 | || (defined(__ppc64__) || defined(__PPC64__)) \
81 | || defined(__aarch64__) /* ARM 64-bit */
82 | #define JANET_64 1
83 | #else
84 | #define JANET_32 1
85 | #endif
86 |
87 | /* Check big endian */
88 | #if defined(__MIPSEB__) /* MIPS 32-bit */ \
89 | || defined(__ppc__) || defined(__PPC__) /* CPU(PPC) - PowerPC 32-bit */ \
90 | || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) \
91 | || defined(_M_PPC) || defined(__PPC) \
92 | || defined(__ppc64__) || defined(__PPC64__) /* PowerPC 64-bit */ \
93 | || defined(__sparc) /* Sparc 32bit */ \
94 | || defined(__sparc__) /* Sparc 64-bit */ \
95 | || defined(__s390x__) /* S390 64-bit */ \
96 | || defined(__s390__) /* S390 32-bit */ \
97 | || defined(__ARMEB__) /* ARM big endian */ \
98 | || ((defined(__CC_ARM) || defined(__ARMCC__)) /* ARM RealView compiler */ \
99 | && defined(__BIG_ENDIAN))
100 | #define JANET_BIG_ENDIAN 1
101 | #else
102 | #define JANET_LITTLE_ENDIAN 1
103 | #endif
104 |
105 | /* Check emscripten */
106 | #ifdef __EMSCRIPTEN__
107 | #define JANET_NO_DYNAMIC_MODULES
108 | #endif
109 |
110 | /* Define how global janet state is declared */
111 | #ifdef JANET_SINGLE_THREADED
112 | #define JANET_THREAD_LOCAL
113 | #elif defined(__GNUC__)
114 | #define JANET_THREAD_LOCAL __thread
115 | #elif defined(_MSC_BUILD)
116 | #define JANET_THREAD_LOCAL __declspec(thread)
117 | #else
118 | #define JANET_THREAD_LOCAL
119 | #endif
120 |
121 | /* Enable or disable dynamic module loading. Enabled by default. */
122 | #ifndef JANET_NO_DYNAMIC_MODULES
123 | #define JANET_DYNAMIC_MODULES
124 | #endif
125 |
126 | /* Enable or disable the assembler. Enabled by default. */
127 | #ifndef JANET_NO_ASSEMBLER
128 | #define JANET_ASSEMBLER
129 | #endif
130 |
131 | /* Enable or disable the peg module */
132 | #ifndef JANET_NO_PEG
133 | #define JANET_PEG
134 | #endif
135 |
136 | /* Enable or disable the typedarray module */
137 | #ifndef JANET_NO_TYPED_ARRAY
138 | #define JANET_TYPED_ARRAY
139 | #endif
140 |
141 | /* Enable or disable large int types (for now 64 bit, maybe 128 / 256 bit integer types) */
142 | #ifndef JANET_NO_INT_TYPES
143 | #define JANET_INT_TYPES
144 | #endif
145 |
146 | /* How to export symbols */
147 | #ifndef JANET_API
148 | #ifdef JANET_WINDOWS
149 | #define JANET_API __declspec(dllexport)
150 | #else
151 | #define JANET_API __attribute__((visibility ("default")))
152 | #endif
153 | #endif
154 |
155 | /* Tell complier some functions don't return */
156 | #ifndef JANET_NO_RETURN
157 | #ifdef JANET_WINDOWS
158 | #define JANET_NO_RETURN __declspec(noreturn)
159 | #else
160 | #define JANET_NO_RETURN __attribute__ ((noreturn))
161 | #endif
162 | #endif
163 |
164 | /* Prevent some recursive functions from recursing too deeply
165 | * ands crashing (the parser). Instead, error out. */
166 | #define JANET_RECURSION_GUARD 1024
167 |
168 | /* Maximum depth to follow table prototypes before giving up and returning nil. */
169 | #define JANET_MAX_PROTO_DEPTH 200
170 |
171 | /* Maximum depth to follow table prototypes before giving up and returning nil. */
172 | #define JANET_MAX_MACRO_EXPAND 200
173 |
174 | /* Define default max stack size for stacks before raising a stack overflow error.
175 | * This can also be set on a per fiber basis. */
176 | #ifndef JANET_STACK_MAX
177 | #define JANET_STACK_MAX 0x7fffffff
178 | #endif
179 |
180 | /* Use nanboxed values - uses 8 bytes per value instead of 12 or 16.
181 | * To turn of nanboxing, for debugging purposes or for certain
182 | * architectures (Nanboxing only tested on x86 and x64), comment out
183 | * the JANET_NANBOX define.*/
184 | #ifndef JANET_NO_NANBOX
185 | #ifdef JANET_32
186 | #define JANET_NANBOX_32
187 | #elif defined(__x86_64__) || defined(_WIN64)
188 | /* We will only enable nanboxing by default on 64 bit systems
189 | * on x86. This is mainly because the approach is tied to the
190 | * implicit 47 bit address space. */
191 | #define JANET_NANBOX_64
192 | #endif
193 | #endif
194 |
195 | /* Runtime config constants */
196 | #ifdef JANET_NO_NANBOX
197 | #define JANET_NANBOX_BIT 0
198 | #else
199 | #define JANET_NANBOX_BIT 0x1
200 | #endif
201 |
202 | #ifdef JANET_SINGLE_THREADED
203 | #define JANET_SINGLE_THREADED_BIT 0x2
204 | #else
205 | #define JANET_SINGLE_THREADED_BIT 0
206 | #endif
207 |
208 | #define JANET_CURRENT_CONFIG_BITS \
209 | (JANET_SINGLE_THREADED_BIT | \
210 | JANET_NANBOX_BIT)
211 |
212 | /* Represents the settings used to compile Janet, as well as the version */
213 | typedef struct {
214 | unsigned major;
215 | unsigned minor;
216 | unsigned patch;
217 | unsigned bits;
218 | } JanetBuildConfig;
219 |
220 | /* Get config of current compilation unit. */
221 | #define janet_config_current() ((JanetBuildConfig){ \
222 | JANET_VERSION_MAJOR, \
223 | JANET_VERSION_MINOR, \
224 | JANET_VERSION_PATCH, \
225 | JANET_CURRENT_CONFIG_BITS })
226 |
227 | /***** END SECTION CONFIG *****/
228 |
229 | /***** START SECTION TYPES *****/
230 |
231 | #include
232 | #include
233 | #include
234 | #include
235 | #include
236 | #include
237 | #include
238 |
239 | /* Names of all of the types */
240 | JANET_API extern const char *const janet_type_names[16];
241 | JANET_API extern const char *const janet_signal_names[14];
242 | JANET_API extern const char *const janet_status_names[16];
243 |
244 | /* Fiber signals */
245 | typedef enum {
246 | JANET_SIGNAL_OK,
247 | JANET_SIGNAL_ERROR,
248 | JANET_SIGNAL_DEBUG,
249 | JANET_SIGNAL_YIELD,
250 | JANET_SIGNAL_USER0,
251 | JANET_SIGNAL_USER1,
252 | JANET_SIGNAL_USER2,
253 | JANET_SIGNAL_USER3,
254 | JANET_SIGNAL_USER4,
255 | JANET_SIGNAL_USER5,
256 | JANET_SIGNAL_USER6,
257 | JANET_SIGNAL_USER7,
258 | JANET_SIGNAL_USER8,
259 | JANET_SIGNAL_USER9
260 | } JanetSignal;
261 |
262 | /* Fiber statuses - mostly corresponds to signals. */
263 | typedef enum {
264 | JANET_STATUS_DEAD,
265 | JANET_STATUS_ERROR,
266 | JANET_STATUS_DEBUG,
267 | JANET_STATUS_PENDING,
268 | JANET_STATUS_USER0,
269 | JANET_STATUS_USER1,
270 | JANET_STATUS_USER2,
271 | JANET_STATUS_USER3,
272 | JANET_STATUS_USER4,
273 | JANET_STATUS_USER5,
274 | JANET_STATUS_USER6,
275 | JANET_STATUS_USER7,
276 | JANET_STATUS_USER8,
277 | JANET_STATUS_USER9,
278 | JANET_STATUS_NEW,
279 | JANET_STATUS_ALIVE
280 | } JanetFiberStatus;
281 |
282 | #ifdef JANET_NANBOX_64
283 | typedef union Janet Janet;
284 | #elif defined(JANET_NANBOX_32)
285 | typedef union Janet Janet;
286 | #else
287 | typedef struct Janet Janet;
288 | #endif
289 |
290 | /* Use type punning for GC objects */
291 | typedef struct JanetGCObject JanetGCObject;
292 |
293 | /* All of the primary Janet GCed types */
294 | typedef struct JanetFunction JanetFunction;
295 | typedef struct JanetArray JanetArray;
296 | typedef struct JanetBuffer JanetBuffer;
297 | typedef struct JanetTable JanetTable;
298 | typedef struct JanetFiber JanetFiber;
299 |
300 | /* Prefixed Janet types */
301 | typedef struct JanetTupleHead JanetTupleHead;
302 | typedef struct JanetStructHead JanetStructHead;
303 | typedef struct JanetStringHead JanetStringHead;
304 | typedef struct JanetAbstractHead JanetAbstractHead;
305 |
306 | /* Other structs */
307 | typedef struct JanetFuncDef JanetFuncDef;
308 | typedef struct JanetFuncEnv JanetFuncEnv;
309 | typedef struct JanetKV JanetKV;
310 | typedef struct JanetStackFrame JanetStackFrame;
311 | typedef struct JanetAbstractType JanetAbstractType;
312 | typedef struct JanetReg JanetReg;
313 | typedef struct JanetMethod JanetMethod;
314 | typedef struct JanetSourceMapping JanetSourceMapping;
315 | typedef struct JanetView JanetView;
316 | typedef struct JanetByteView JanetByteView;
317 | typedef struct JanetDictView JanetDictView;
318 | typedef struct JanetRange JanetRange;
319 | typedef Janet(*JanetCFunction)(int32_t argc, Janet *argv);
320 |
321 | /* Basic types for all Janet Values */
322 | typedef enum JanetType {
323 | JANET_NUMBER,
324 | JANET_NIL,
325 | JANET_BOOLEAN,
326 | JANET_FIBER,
327 | JANET_STRING,
328 | JANET_SYMBOL,
329 | JANET_KEYWORD,
330 | JANET_ARRAY,
331 | JANET_TUPLE,
332 | JANET_TABLE,
333 | JANET_STRUCT,
334 | JANET_BUFFER,
335 | JANET_FUNCTION,
336 | JANET_CFUNCTION,
337 | JANET_ABSTRACT,
338 | JANET_POINTER
339 | } JanetType;
340 |
341 | #define JANET_COUNT_TYPES (JANET_POINTER + 1)
342 |
343 | /* Type flags */
344 | #define JANET_TFLAG_NIL (1 << JANET_NIL)
345 | #define JANET_TFLAG_BOOLEAN (1 << JANET_BOOLEAN)
346 | #define JANET_TFLAG_FIBER (1 << JANET_FIBER)
347 | #define JANET_TFLAG_NUMBER (1 << JANET_NUMBER)
348 | #define JANET_TFLAG_STRING (1 << JANET_STRING)
349 | #define JANET_TFLAG_SYMBOL (1 << JANET_SYMBOL)
350 | #define JANET_TFLAG_KEYWORD (1 << JANET_KEYWORD)
351 | #define JANET_TFLAG_ARRAY (1 << JANET_ARRAY)
352 | #define JANET_TFLAG_TUPLE (1 << JANET_TUPLE)
353 | #define JANET_TFLAG_TABLE (1 << JANET_TABLE)
354 | #define JANET_TFLAG_STRUCT (1 << JANET_STRUCT)
355 | #define JANET_TFLAG_BUFFER (1 << JANET_BUFFER)
356 | #define JANET_TFLAG_FUNCTION (1 << JANET_FUNCTION)
357 | #define JANET_TFLAG_CFUNCTION (1 << JANET_CFUNCTION)
358 | #define JANET_TFLAG_ABSTRACT (1 << JANET_ABSTRACT)
359 | #define JANET_TFLAG_POINTER (1 << JANET_POINTER)
360 |
361 | #define JANET_TFLAG_BYTES (JANET_TFLAG_STRING | JANET_TFLAG_SYMBOL | JANET_TFLAG_BUFFER | JANET_TFLAG_KEYWORD)
362 | #define JANET_TFLAG_INDEXED (JANET_TFLAG_ARRAY | JANET_TFLAG_TUPLE)
363 | #define JANET_TFLAG_DICTIONARY (JANET_TFLAG_TABLE | JANET_TFLAG_STRUCT)
364 | #define JANET_TFLAG_LENGTHABLE (JANET_TFLAG_BYTES | JANET_TFLAG_INDEXED | JANET_TFLAG_DICTIONARY)
365 | #define JANET_TFLAG_CALLABLE (JANET_TFLAG_FUNCTION | JANET_TFLAG_CFUNCTION | \
366 | JANET_TFLAG_LENGTHABLE | JANET_TFLAG_ABSTRACT)
367 |
368 | /* We provide three possible implementations of Janets. The preferred
369 | * nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
370 | * application must interact through exposed interface. */
371 |
372 | /* Required interface for Janet */
373 | /* wrap and unwrap for all types */
374 | /* Get type quickly */
375 | /* Check against type quickly */
376 | /* Small footprint */
377 | /* 32 bit integer support */
378 |
379 | /* janet_type(x)
380 | * janet_checktype(x, t)
381 | * janet_wrap_##TYPE(x)
382 | * janet_unwrap_##TYPE(x)
383 | * janet_truthy(x)
384 | * janet_memclear(p, n) - clear memory for hash tables to nils
385 | * janet_u64(x) - get 64 bits of payload for hashing
386 | */
387 |
388 | /***** START SECTION NON-C API *****/
389 |
390 | /* Some janet types use offset tricks to make operations easier in C. For
391 | * external bindings, we should prefer using the Head structs directly, and
392 | * use the host language to add sugar around the manipulation of the Janet types. */
393 |
394 | JANET_API JanetStructHead *janet_struct_head(const JanetKV *st);
395 | JANET_API JanetAbstractHead *janet_abstract_head(const void *abstract);
396 | JANET_API JanetStringHead *janet_string_head(const uint8_t *s);
397 | JANET_API JanetTupleHead *janet_tuple_head(const Janet *tuple);
398 |
399 | /* Some language bindings won't have access to the macro versions. */
400 |
401 | JANET_API JanetType janet_type(Janet x);
402 | JANET_API int janet_checktype(Janet x, JanetType type);
403 | JANET_API int janet_checktypes(Janet x, int typeflags);
404 | JANET_API int janet_truthy(Janet x);
405 |
406 | JANET_API const JanetKV *janet_unwrap_struct(Janet x);
407 | JANET_API const Janet *janet_unwrap_tuple(Janet x);
408 | JANET_API JanetFiber *janet_unwrap_fiber(Janet x);
409 | JANET_API JanetArray *janet_unwrap_array(Janet x);
410 | JANET_API JanetTable *janet_unwrap_table(Janet x);
411 | JANET_API JanetBuffer *janet_unwrap_buffer(Janet x);
412 | JANET_API const uint8_t *janet_unwrap_string(Janet x);
413 | JANET_API const uint8_t *janet_unwrap_symbol(Janet x);
414 | JANET_API const uint8_t *janet_unwrap_keyword(Janet x);
415 | JANET_API void *janet_unwrap_abstract(Janet x);
416 | JANET_API void *janet_unwrap_pointer(Janet x);
417 | JANET_API JanetFunction *janet_unwrap_function(Janet x);
418 | JANET_API JanetCFunction janet_unwrap_cfunction(Janet x);
419 | JANET_API int janet_unwrap_boolean(Janet x);
420 | JANET_API double janet_unwrap_number(Janet x);
421 | JANET_API int32_t janet_unwrap_integer(Janet x);
422 |
423 | JANET_API Janet janet_wrap_nil(void);
424 | JANET_API Janet janet_wrap_number(double x);
425 | JANET_API Janet janet_wrap_true(void);
426 | JANET_API Janet janet_wrap_false(void);
427 | JANET_API Janet janet_wrap_boolean(int x);
428 | JANET_API Janet janet_wrap_string(const uint8_t *x);
429 | JANET_API Janet janet_wrap_symbol(const uint8_t *x);
430 | JANET_API Janet janet_wrap_keyword(const uint8_t *x);
431 | JANET_API Janet janet_wrap_array(JanetArray *x);
432 | JANET_API Janet janet_wrap_tuple(const Janet *x);
433 | JANET_API Janet janet_wrap_struct(const JanetKV *x);
434 | JANET_API Janet janet_wrap_fiber(JanetFiber *x);
435 | JANET_API Janet janet_wrap_buffer(JanetBuffer *x);
436 | JANET_API Janet janet_wrap_function(JanetFunction *x);
437 | JANET_API Janet janet_wrap_cfunction(JanetCFunction x);
438 | JANET_API Janet janet_wrap_table(JanetTable *x);
439 | JANET_API Janet janet_wrap_abstract(void *x);
440 | JANET_API Janet janet_wrap_pointer(void *x);
441 | JANET_API Janet janet_wrap_integer(int32_t x);
442 |
443 | /***** END SECTION NON-C API *****/
444 |
445 | #ifdef JANET_NANBOX_64
446 |
447 | #include
448 |
449 | /* 64 Nanboxed Janet value */
450 | union Janet {
451 | uint64_t u64;
452 | int64_t i64;
453 | double number;
454 | void *pointer;
455 | };
456 | #define janet_u64(x) ((x).u64)
457 |
458 | #define JANET_NANBOX_TAGBITS 0xFFFF800000000000llu
459 | #define JANET_NANBOX_PAYLOADBITS 0x00007FFFFFFFFFFFllu
460 | #define janet_nanbox_lowtag(type) ((uint64_t)(type) | 0x1FFF0)
461 | #define janet_nanbox_tag(type) (janet_nanbox_lowtag(type) << 47)
462 | #define janet_type(x) \
463 | (isnan((x).number) \
464 | ? (((x).u64 >> 47) & 0xF) \
465 | : JANET_NUMBER)
466 |
467 | #define janet_nanbox_checkauxtype(x, type) \
468 | (((x).u64 & JANET_NANBOX_TAGBITS) == janet_nanbox_tag((type)))
469 |
470 | #define janet_nanbox_isnumber(x) \
471 | (!isnan((x).number) || janet_nanbox_checkauxtype((x), JANET_NUMBER))
472 |
473 | #define janet_checktype(x, t) \
474 | (((t) == JANET_NUMBER) \
475 | ? janet_nanbox_isnumber(x) \
476 | : janet_nanbox_checkauxtype((x), (t)))
477 |
478 | JANET_API void *janet_nanbox_to_pointer(Janet x);
479 | JANET_API Janet janet_nanbox_from_pointer(void *p, uint64_t tagmask);
480 | JANET_API Janet janet_nanbox_from_cpointer(const void *p, uint64_t tagmask);
481 | JANET_API Janet janet_nanbox_from_double(double d);
482 | JANET_API Janet janet_nanbox_from_bits(uint64_t bits);
483 |
484 | #define janet_truthy(x) \
485 | (!janet_checktype((x), JANET_NIL) && \
486 | (!janet_checktype((x), JANET_BOOLEAN) || ((x).u64 & 0x1)))
487 |
488 | #define janet_nanbox_from_payload(t, p) \
489 | janet_nanbox_from_bits(janet_nanbox_tag(t) | (p))
490 |
491 | #define janet_nanbox_wrap_(p, t) \
492 | janet_nanbox_from_pointer((p), janet_nanbox_tag(t))
493 |
494 | #define janet_nanbox_wrap_c(p, t) \
495 | janet_nanbox_from_cpointer((p), janet_nanbox_tag(t))
496 |
497 | /* Wrap the simple types */
498 | #define janet_wrap_nil() janet_nanbox_from_payload(JANET_NIL, 1)
499 | #define janet_wrap_true() janet_nanbox_from_payload(JANET_BOOLEAN, 1)
500 | #define janet_wrap_false() janet_nanbox_from_payload(JANET_BOOLEAN, 0)
501 | #define janet_wrap_boolean(b) janet_nanbox_from_payload(JANET_BOOLEAN, !!(b))
502 | #define janet_wrap_number(r) janet_nanbox_from_double(r)
503 |
504 | /* Unwrap the simple types */
505 | #define janet_unwrap_boolean(x) ((x).u64 & 0x1)
506 | #define janet_unwrap_number(x) ((x).number)
507 |
508 | /* Wrap the pointer types */
509 | #define janet_wrap_struct(s) janet_nanbox_wrap_c((s), JANET_STRUCT)
510 | #define janet_wrap_tuple(s) janet_nanbox_wrap_c((s), JANET_TUPLE)
511 | #define janet_wrap_fiber(s) janet_nanbox_wrap_((s), JANET_FIBER)
512 | #define janet_wrap_array(s) janet_nanbox_wrap_((s), JANET_ARRAY)
513 | #define janet_wrap_table(s) janet_nanbox_wrap_((s), JANET_TABLE)
514 | #define janet_wrap_buffer(s) janet_nanbox_wrap_((s), JANET_BUFFER)
515 | #define janet_wrap_string(s) janet_nanbox_wrap_c((s), JANET_STRING)
516 | #define janet_wrap_symbol(s) janet_nanbox_wrap_c((s), JANET_SYMBOL)
517 | #define janet_wrap_keyword(s) janet_nanbox_wrap_c((s), JANET_KEYWORD)
518 | #define janet_wrap_abstract(s) janet_nanbox_wrap_((s), JANET_ABSTRACT)
519 | #define janet_wrap_function(s) janet_nanbox_wrap_((s), JANET_FUNCTION)
520 | #define janet_wrap_cfunction(s) janet_nanbox_wrap_((s), JANET_CFUNCTION)
521 | #define janet_wrap_pointer(s) janet_nanbox_wrap_((s), JANET_POINTER)
522 |
523 | /* Unwrap the pointer types */
524 | #define janet_unwrap_struct(x) ((const JanetKV *)janet_nanbox_to_pointer(x))
525 | #define janet_unwrap_tuple(x) ((const Janet *)janet_nanbox_to_pointer(x))
526 | #define janet_unwrap_fiber(x) ((JanetFiber *)janet_nanbox_to_pointer(x))
527 | #define janet_unwrap_array(x) ((JanetArray *)janet_nanbox_to_pointer(x))
528 | #define janet_unwrap_table(x) ((JanetTable *)janet_nanbox_to_pointer(x))
529 | #define janet_unwrap_buffer(x) ((JanetBuffer *)janet_nanbox_to_pointer(x))
530 | #define janet_unwrap_string(x) ((const uint8_t *)janet_nanbox_to_pointer(x))
531 | #define janet_unwrap_symbol(x) ((const uint8_t *)janet_nanbox_to_pointer(x))
532 | #define janet_unwrap_keyword(x) ((const uint8_t *)janet_nanbox_to_pointer(x))
533 | #define janet_unwrap_abstract(x) (janet_nanbox_to_pointer(x))
534 | #define janet_unwrap_pointer(x) (janet_nanbox_to_pointer(x))
535 | #define janet_unwrap_function(x) ((JanetFunction *)janet_nanbox_to_pointer(x))
536 | #define janet_unwrap_cfunction(x) ((JanetCFunction)janet_nanbox_to_pointer(x))
537 |
538 | #elif defined(JANET_NANBOX_32)
539 |
540 | /* 32 bit nanboxed janet */
541 | union Janet {
542 | struct {
543 | #ifdef JANET_BIG_ENDIAN
544 | uint32_t type;
545 | union {
546 | int32_t integer;
547 | void *pointer;
548 | } payload;
549 | #else
550 | union {
551 | int32_t integer;
552 | void *pointer;
553 | } payload;
554 | uint32_t type;
555 | #endif
556 | } tagged;
557 | double number;
558 | uint64_t u64;
559 | };
560 |
561 | #define JANET_DOUBLE_OFFSET 0xFFFF
562 |
563 | #define janet_u64(x) ((x).u64)
564 | #define janet_type(x) (((x).tagged.type < JANET_DOUBLE_OFFSET) ? (x).tagged.type : JANET_NUMBER)
565 | #define janet_checktype(x, t) ((t) == JANET_NUMBER \
566 | ? (x).tagged.type >= JANET_DOUBLE_OFFSET \
567 | : (x).tagged.type == (t))
568 | #define janet_truthy(x) \
569 | ((x).tagged.type != JANET_NIL && ((x).tagged.type != JANET_BOOLEAN || ((x).tagged.payload.integer & 0x1)))
570 |
571 | JANET_API Janet janet_nanbox32_from_tagi(uint32_t tag, int32_t integer);
572 | JANET_API Janet janet_nanbox32_from_tagp(uint32_t tag, void *pointer);
573 |
574 | #define janet_wrap_nil() janet_nanbox32_from_tagi(JANET_NIL, 0)
575 | #define janet_wrap_true() janet_nanbox32_from_tagi(JANET_BOOLEAN, 1)
576 | #define janet_wrap_false() janet_nanbox32_from_tagi(JANET_BOOLEAN, 0)
577 | #define janet_wrap_boolean(b) janet_nanbox32_from_tagi(JANET_BOOLEAN, !!(b))
578 |
579 | /* Wrap the pointer types */
580 | #define janet_wrap_struct(s) janet_nanbox32_from_tagp(JANET_STRUCT, (void *)(s))
581 | #define janet_wrap_tuple(s) janet_nanbox32_from_tagp(JANET_TUPLE, (void *)(s))
582 | #define janet_wrap_fiber(s) janet_nanbox32_from_tagp(JANET_FIBER, (void *)(s))
583 | #define janet_wrap_array(s) janet_nanbox32_from_tagp(JANET_ARRAY, (void *)(s))
584 | #define janet_wrap_table(s) janet_nanbox32_from_tagp(JANET_TABLE, (void *)(s))
585 | #define janet_wrap_buffer(s) janet_nanbox32_from_tagp(JANET_BUFFER, (void *)(s))
586 | #define janet_wrap_string(s) janet_nanbox32_from_tagp(JANET_STRING, (void *)(s))
587 | #define janet_wrap_symbol(s) janet_nanbox32_from_tagp(JANET_SYMBOL, (void *)(s))
588 | #define janet_wrap_keyword(s) janet_nanbox32_from_tagp(JANET_KEYWORD, (void *)(s))
589 | #define janet_wrap_abstract(s) janet_nanbox32_from_tagp(JANET_ABSTRACT, (void *)(s))
590 | #define janet_wrap_function(s) janet_nanbox32_from_tagp(JANET_FUNCTION, (void *)(s))
591 | #define janet_wrap_cfunction(s) janet_nanbox32_from_tagp(JANET_CFUNCTION, (void *)(s))
592 | #define janet_wrap_pointer(s) janet_nanbox32_from_tagp(JANET_POINTER, (void *)(s))
593 |
594 | #define janet_unwrap_struct(x) ((const JanetKV *)(x).tagged.payload.pointer)
595 | #define janet_unwrap_tuple(x) ((const Janet *)(x).tagged.payload.pointer)
596 | #define janet_unwrap_fiber(x) ((JanetFiber *)(x).tagged.payload.pointer)
597 | #define janet_unwrap_array(x) ((JanetArray *)(x).tagged.payload.pointer)
598 | #define janet_unwrap_table(x) ((JanetTable *)(x).tagged.payload.pointer)
599 | #define janet_unwrap_buffer(x) ((JanetBuffer *)(x).tagged.payload.pointer)
600 | #define janet_unwrap_string(x) ((const uint8_t *)(x).tagged.payload.pointer)
601 | #define janet_unwrap_symbol(x) ((const uint8_t *)(x).tagged.payload.pointer)
602 | #define janet_unwrap_keyword(x) ((const uint8_t *)(x).tagged.payload.pointer)
603 | #define janet_unwrap_abstract(x) ((x).tagged.payload.pointer)
604 | #define janet_unwrap_pointer(x) ((x).tagged.payload.pointer)
605 | #define janet_unwrap_function(x) ((JanetFunction *)(x).tagged.payload.pointer)
606 | #define janet_unwrap_cfunction(x) ((JanetCFunction)(x).tagged.payload.pointer)
607 | #define janet_unwrap_boolean(x) ((x).tagged.payload.integer)
608 |
609 | #else
610 |
611 | /* A general janet value type for more standard C */
612 | struct Janet {
613 | union {
614 | uint64_t u64;
615 | double number;
616 | int32_t integer;
617 | void *pointer;
618 | const void *cpointer;
619 | } as;
620 | JanetType type;
621 | };
622 |
623 | #define janet_u64(x) ((x).as.u64)
624 | #define janet_type(x) ((x).type)
625 | #define janet_checktype(x, t) ((x).type == (t))
626 | #define janet_truthy(x) \
627 | ((x).type != JANET_NIL && ((x).type != JANET_BOOLEAN || ((x).as.integer & 0x1)))
628 |
629 | #define janet_unwrap_struct(x) ((const JanetKV *)(x).as.pointer)
630 | #define janet_unwrap_tuple(x) ((const Janet *)(x).as.pointer)
631 | #define janet_unwrap_fiber(x) ((JanetFiber *)(x).as.pointer)
632 | #define janet_unwrap_array(x) ((JanetArray *)(x).as.pointer)
633 | #define janet_unwrap_table(x) ((JanetTable *)(x).as.pointer)
634 | #define janet_unwrap_buffer(x) ((JanetBuffer *)(x).as.pointer)
635 | #define janet_unwrap_string(x) ((const uint8_t *)(x).as.pointer)
636 | #define janet_unwrap_symbol(x) ((const uint8_t *)(x).as.pointer)
637 | #define janet_unwrap_keyword(x) ((const uint8_t *)(x).as.pointer)
638 | #define janet_unwrap_abstract(x) ((x).as.pointer)
639 | #define janet_unwrap_pointer(x) ((x).as.pointer)
640 | #define janet_unwrap_function(x) ((JanetFunction *)(x).as.pointer)
641 | #define janet_unwrap_cfunction(x) ((JanetCFunction)(x).as.pointer)
642 | #define janet_unwrap_boolean(x) ((x).as.u64 & 0x1)
643 | #define janet_unwrap_number(x) ((x).as.number)
644 |
645 | /* End of tagged union implementation */
646 | #endif
647 |
648 | JANET_API int janet_checkint(Janet x);
649 | JANET_API int janet_checkint64(Janet x);
650 | JANET_API int janet_checksize(Janet x);
651 | #define janet_checkintrange(x) ((x) == (int32_t)(x))
652 | #define janet_checkint64range(x) ((x) == (int64_t)(x))
653 | #define janet_unwrap_integer(x) ((int32_t) janet_unwrap_number(x))
654 | #define janet_wrap_integer(x) janet_wrap_number((int32_t)(x))
655 |
656 | #define janet_checktypes(x, tps) ((1 << janet_type(x)) & (tps))
657 |
658 | /* GC Object type pun. The lower 16 bits of flags are reserved for the garbage collector,
659 | * but the upper 16 can be used per type for custom flags. The current collector is a linked
660 | * list of blocks, which is naive but works. */
661 | struct JanetGCObject {
662 | int32_t flags;
663 | JanetGCObject *next;
664 | };
665 |
666 | /* Fiber signal masks. */
667 | #define JANET_FIBER_MASK_ERROR 2
668 | #define JANET_FIBER_MASK_DEBUG 4
669 | #define JANET_FIBER_MASK_YIELD 8
670 |
671 | #define JANET_FIBER_MASK_USER0 (16 << 0)
672 | #define JANET_FIBER_MASK_USER1 (16 << 1)
673 | #define JANET_FIBER_MASK_USER2 (16 << 2)
674 | #define JANET_FIBER_MASK_USER3 (16 << 3)
675 | #define JANET_FIBER_MASK_USER4 (16 << 4)
676 | #define JANET_FIBER_MASK_USER5 (16 << 5)
677 | #define JANET_FIBER_MASK_USER6 (16 << 6)
678 | #define JANET_FIBER_MASK_USER7 (16 << 7)
679 | #define JANET_FIBER_MASK_USER8 (16 << 8)
680 | #define JANET_FIBER_MASK_USER9 (16 << 9)
681 |
682 | #define JANET_FIBER_MASK_USERN(N) (16 << (N))
683 | #define JANET_FIBER_MASK_USER 0x3FF0
684 |
685 | #define JANET_FIBER_STATUS_MASK 0xFF0000
686 | #define JANET_FIBER_STATUS_OFFSET 16
687 |
688 | /* A lightweight green thread in janet. Does not correspond to
689 | * operating system threads. */
690 | struct JanetFiber {
691 | JanetGCObject gc; /* GC Object stuff */
692 | int32_t flags; /* More flags */
693 | int32_t frame; /* Index of the stack frame */
694 | int32_t stackstart; /* Beginning of next args */
695 | int32_t stacktop; /* Top of stack. Where values are pushed and popped from. */
696 | int32_t capacity;
697 | int32_t maxstack; /* Arbitrary defined limit for stack overflow */
698 | JanetTable *env; /* Dynamic bindings table (usually current environment). */
699 | Janet *data;
700 | JanetFiber *child; /* Keep linked list of fibers for restarting pending fibers */
701 | };
702 |
703 | /* Mark if a stack frame is a tail call for debugging */
704 | #define JANET_STACKFRAME_TAILCALL 1
705 |
706 | /* Mark if a stack frame is an entrance frame */
707 | #define JANET_STACKFRAME_ENTRANCE 2
708 |
709 | /* A stack frame on the fiber. Is stored along with the stack values. */
710 | struct JanetStackFrame {
711 | JanetFunction *func;
712 | uint32_t *pc;
713 | JanetFuncEnv *env;
714 | int32_t prevframe;
715 | int32_t flags;
716 | };
717 |
718 | /* Number of Janets a frame takes up in the stack */
719 | #define JANET_FRAME_SIZE ((sizeof(JanetStackFrame) + sizeof(Janet) - 1) / sizeof(Janet))
720 |
721 | /* A dynamic array type. */
722 | struct JanetArray {
723 | JanetGCObject gc;
724 | int32_t count;
725 | int32_t capacity;
726 | Janet *data;
727 | };
728 |
729 | /* A byte buffer type. Used as a mutable string or string builder. */
730 | struct JanetBuffer {
731 | JanetGCObject gc;
732 | int32_t count;
733 | int32_t capacity;
734 | uint8_t *data;
735 | };
736 |
737 | /* A mutable associative data type. Backed by a hashtable. */
738 | struct JanetTable {
739 | JanetGCObject gc;
740 | int32_t count;
741 | int32_t capacity;
742 | int32_t deleted;
743 | JanetKV *data;
744 | JanetTable *proto;
745 | };
746 |
747 | /* A key value pair in a struct or table */
748 | struct JanetKV {
749 | Janet key;
750 | Janet value;
751 | };
752 |
753 | /* Prefix for a tuple */
754 | struct JanetTupleHead {
755 | JanetGCObject gc;
756 | int32_t length;
757 | int32_t hash;
758 | int32_t sm_start;
759 | int32_t sm_end;
760 | const Janet data[];
761 | };
762 |
763 | /* Prefix for a struct */
764 | struct JanetStructHead {
765 | JanetGCObject gc;
766 | int32_t length;
767 | int32_t hash;
768 | int32_t capacity;
769 | const JanetKV data[];
770 | };
771 |
772 | /* Prefix for a string */
773 | struct JanetStringHead {
774 | JanetGCObject gc;
775 | int32_t length;
776 | int32_t hash;
777 | const uint8_t data[];
778 | };
779 |
780 | /* Prefix for an abstract value */
781 | struct JanetAbstractHead {
782 | JanetGCObject gc;
783 | const JanetAbstractType *type;
784 | size_t size;
785 | long long data[]; /* Use long long to ensure most general alignment */
786 | };
787 |
788 | /* Some function definition flags */
789 | #define JANET_FUNCDEF_FLAG_VARARG 0x10000
790 | #define JANET_FUNCDEF_FLAG_NEEDSENV 0x20000
791 | #define JANET_FUNCDEF_FLAG_HASNAME 0x80000
792 | #define JANET_FUNCDEF_FLAG_HASSOURCE 0x100000
793 | #define JANET_FUNCDEF_FLAG_HASDEFS 0x200000
794 | #define JANET_FUNCDEF_FLAG_HASENVS 0x400000
795 | #define JANET_FUNCDEF_FLAG_HASSOURCEMAP 0x800000
796 | #define JANET_FUNCDEF_FLAG_STRUCTARG 0x1000000
797 | #define JANET_FUNCDEF_FLAG_TAG 0xFFFF
798 |
799 | /* Source mapping structure for a bytecode instruction */
800 | struct JanetSourceMapping {
801 | int32_t start;
802 | int32_t end;
803 | };
804 |
805 | /* A function definition. Contains information needed to instantiate closures. */
806 | struct JanetFuncDef {
807 | JanetGCObject gc;
808 | int32_t *environments; /* Which environments to capture from parent. */
809 | Janet *constants;
810 | JanetFuncDef **defs;
811 | uint32_t *bytecode;
812 |
813 | /* Various debug information */
814 | JanetSourceMapping *sourcemap;
815 | const uint8_t *source;
816 | const uint8_t *name;
817 |
818 | int32_t flags;
819 | int32_t slotcount; /* The amount of stack space required for the function */
820 | int32_t arity; /* Not including varargs */
821 | int32_t min_arity; /* Including varargs */
822 | int32_t max_arity; /* Including varargs */
823 | int32_t constants_length;
824 | int32_t bytecode_length;
825 | int32_t environments_length;
826 | int32_t defs_length;
827 | };
828 |
829 | /* A function environment */
830 | struct JanetFuncEnv {
831 | JanetGCObject gc;
832 | union {
833 | JanetFiber *fiber;
834 | Janet *values;
835 | } as;
836 | int32_t length; /* Size of environment */
837 | int32_t offset; /* Stack offset when values still on stack. If offset is <= 0, then
838 | environment is no longer on the stack. */
839 | };
840 |
841 | #define JANET_FUNCFLAG_TRACE (1 << 16)
842 |
843 | /* A function */
844 | struct JanetFunction {
845 | JanetGCObject gc;
846 | JanetFuncDef *def;
847 | JanetFuncEnv *envs[];
848 | };
849 |
850 | typedef struct JanetParseState JanetParseState;
851 | typedef struct JanetParser JanetParser;
852 |
853 | enum JanetParserStatus {
854 | JANET_PARSE_ROOT,
855 | JANET_PARSE_ERROR,
856 | JANET_PARSE_PENDING,
857 | JANET_PARSE_DEAD
858 | };
859 |
860 | /* A janet parser */
861 | struct JanetParser {
862 | Janet *args;
863 | const char *error;
864 | JanetParseState *states;
865 | uint8_t *buf;
866 | size_t argcount;
867 | size_t argcap;
868 | size_t statecount;
869 | size_t statecap;
870 | size_t bufcount;
871 | size_t bufcap;
872 | size_t offset;
873 | size_t pending;
874 | int lookback;
875 | int flag;
876 | };
877 |
878 | typedef struct {
879 | void *m_state; /* void* to not expose MarshalState ?*/
880 | void *u_state;
881 | int flags;
882 | const uint8_t *data;
883 | } JanetMarshalContext;
884 |
885 | /* Defines an abstract type */
886 | struct JanetAbstractType {
887 | const char *name;
888 | int (*gc)(void *data, size_t len);
889 | int (*gcmark)(void *data, size_t len);
890 | Janet(*get)(void *data, Janet key);
891 | void (*put)(void *data, Janet key, Janet value);
892 | void (*marshal)(void *p, JanetMarshalContext *ctx);
893 | void (*unmarshal)(void *p, JanetMarshalContext *ctx);
894 | void (*tostring)(void *p, JanetBuffer *buffer);
895 | };
896 |
897 | struct JanetReg {
898 | const char *name;
899 | JanetCFunction cfun;
900 | const char *documentation;
901 | };
902 |
903 | struct JanetMethod {
904 | const char *name;
905 | JanetCFunction cfun;
906 | };
907 |
908 | struct JanetView {
909 | const Janet *items;
910 | int32_t len;
911 | };
912 |
913 | struct JanetByteView {
914 | const uint8_t *bytes;
915 | int32_t len;
916 | };
917 |
918 | struct JanetDictView {
919 | const JanetKV *kvs;
920 | int32_t len;
921 | int32_t cap;
922 | };
923 |
924 | struct JanetRange {
925 | int32_t start;
926 | int32_t end;
927 | };
928 |
929 | /***** END SECTION TYPES *****/
930 |
931 | /***** START SECTION OPCODES *****/
932 |
933 | /* Bytecode op argument types */
934 | enum JanetOpArgType {
935 | JANET_OAT_SLOT,
936 | JANET_OAT_ENVIRONMENT,
937 | JANET_OAT_CONSTANT,
938 | JANET_OAT_INTEGER,
939 | JANET_OAT_TYPE,
940 | JANET_OAT_SIMPLETYPE,
941 | JANET_OAT_LABEL,
942 | JANET_OAT_FUNCDEF
943 | };
944 |
945 | /* Various types of instructions */
946 | enum JanetInstructionType {
947 | JINT_0, /* No args */
948 | JINT_S, /* Slot(3) */
949 | JINT_L, /* Label(3) */
950 | JINT_SS, /* Slot(1), Slot(2) */
951 | JINT_SL, /* Slot(1), Label(2) */
952 | JINT_ST, /* Slot(1), Slot(2) */
953 | JINT_SI, /* Slot(1), Immediate(2) */
954 | JINT_SD, /* Slot(1), Closure(2) */
955 | JINT_SU, /* Slot(1), Unsigned Immediate(2) */
956 | JINT_SSS, /* Slot(1), Slot(1), Slot(1) */
957 | JINT_SSI, /* Slot(1), Slot(1), Immediate(1) */
958 | JINT_SSU, /* Slot(1), Slot(1), Unsigned Immediate(1) */
959 | JINT_SES, /* Slot(1), Environment(1), Far Slot(1) */
960 | JINT_SC /* Slot(1), Constant(2) */
961 | };
962 |
963 | /* All opcodes for the bytecode interpreter. */
964 | enum JanetOpCode {
965 | JOP_NOOP,
966 | JOP_ERROR,
967 | JOP_TYPECHECK,
968 | JOP_RETURN,
969 | JOP_RETURN_NIL,
970 | JOP_ADD_IMMEDIATE,
971 | JOP_ADD,
972 | JOP_SUBTRACT,
973 | JOP_MULTIPLY_IMMEDIATE,
974 | JOP_MULTIPLY,
975 | JOP_DIVIDE_IMMEDIATE,
976 | JOP_DIVIDE,
977 | JOP_BAND,
978 | JOP_BOR,
979 | JOP_BXOR,
980 | JOP_BNOT,
981 | JOP_SHIFT_LEFT,
982 | JOP_SHIFT_LEFT_IMMEDIATE,
983 | JOP_SHIFT_RIGHT,
984 | JOP_SHIFT_RIGHT_IMMEDIATE,
985 | JOP_SHIFT_RIGHT_UNSIGNED,
986 | JOP_SHIFT_RIGHT_UNSIGNED_IMMEDIATE,
987 | JOP_MOVE_FAR,
988 | JOP_MOVE_NEAR,
989 | JOP_JUMP,
990 | JOP_JUMP_IF,
991 | JOP_JUMP_IF_NOT,
992 | JOP_GREATER_THAN,
993 | JOP_GREATER_THAN_IMMEDIATE,
994 | JOP_LESS_THAN,
995 | JOP_LESS_THAN_IMMEDIATE,
996 | JOP_EQUALS,
997 | JOP_EQUALS_IMMEDIATE,
998 | JOP_COMPARE,
999 | JOP_LOAD_NIL,
1000 | JOP_LOAD_TRUE,
1001 | JOP_LOAD_FALSE,
1002 | JOP_LOAD_INTEGER,
1003 | JOP_LOAD_CONSTANT,
1004 | JOP_LOAD_UPVALUE,
1005 | JOP_LOAD_SELF,
1006 | JOP_SET_UPVALUE,
1007 | JOP_CLOSURE,
1008 | JOP_PUSH,
1009 | JOP_PUSH_2,
1010 | JOP_PUSH_3,
1011 | JOP_PUSH_ARRAY,
1012 | JOP_CALL,
1013 | JOP_TAILCALL,
1014 | JOP_RESUME,
1015 | JOP_SIGNAL,
1016 | JOP_PROPAGATE,
1017 | JOP_GET,
1018 | JOP_PUT,
1019 | JOP_GET_INDEX,
1020 | JOP_PUT_INDEX,
1021 | JOP_LENGTH,
1022 | JOP_MAKE_ARRAY,
1023 | JOP_MAKE_BUFFER,
1024 | JOP_MAKE_STRING,
1025 | JOP_MAKE_STRUCT,
1026 | JOP_MAKE_TABLE,
1027 | JOP_MAKE_TUPLE,
1028 | JOP_MAKE_BRACKET_TUPLE,
1029 | JOP_NUMERIC_LESS_THAN,
1030 | JOP_NUMERIC_LESS_THAN_EQUAL,
1031 | JOP_NUMERIC_GREATER_THAN,
1032 | JOP_NUMERIC_GREATER_THAN_EQUAL,
1033 | JOP_NUMERIC_EQUAL,
1034 | JOP_INSTRUCTION_COUNT
1035 | };
1036 |
1037 | /* Info about all instructions */
1038 | extern enum JanetInstructionType janet_instructions[JOP_INSTRUCTION_COUNT];
1039 |
1040 | /***** END SECTION OPCODES *****/
1041 |
1042 | /***** START SECTION MAIN *****/
1043 |
1044 | /* Parsing */
1045 | JANET_API void janet_parser_init(JanetParser *parser);
1046 | JANET_API void janet_parser_deinit(JanetParser *parser);
1047 | JANET_API void janet_parser_consume(JanetParser *parser, uint8_t c);
1048 | JANET_API enum JanetParserStatus janet_parser_status(JanetParser *parser);
1049 | JANET_API Janet janet_parser_produce(JanetParser *parser);
1050 | JANET_API const char *janet_parser_error(JanetParser *parser);
1051 | JANET_API void janet_parser_flush(JanetParser *parser);
1052 | JANET_API void janet_parser_eof(JanetParser *parser);
1053 | JANET_API int janet_parser_has_more(JanetParser *parser);
1054 |
1055 | /* Assembly */
1056 | #ifdef JANET_ASSEMBLER
1057 | typedef struct JanetAssembleResult JanetAssembleResult;
1058 | enum JanetAssembleStatus {
1059 | JANET_ASSEMBLE_OK,
1060 | JANET_ASSEMBLE_ERROR
1061 | };
1062 | struct JanetAssembleResult {
1063 | JanetFuncDef *funcdef;
1064 | const uint8_t *error;
1065 | enum JanetAssembleStatus status;
1066 | };
1067 | JANET_API JanetAssembleResult janet_asm(Janet source, int flags);
1068 | JANET_API Janet janet_disasm(JanetFuncDef *def);
1069 | JANET_API Janet janet_asm_decode_instruction(uint32_t instr);
1070 | #endif
1071 |
1072 | /* Compilation */
1073 | typedef struct JanetCompileResult JanetCompileResult;
1074 | enum JanetCompileStatus {
1075 | JANET_COMPILE_OK,
1076 | JANET_COMPILE_ERROR
1077 | };
1078 | struct JanetCompileResult {
1079 | JanetFuncDef *funcdef;
1080 | const uint8_t *error;
1081 | JanetFiber *macrofiber;
1082 | JanetSourceMapping error_mapping;
1083 | enum JanetCompileStatus status;
1084 | };
1085 | JANET_API JanetCompileResult janet_compile(Janet source, JanetTable *env, const uint8_t *where);
1086 |
1087 | /* Get the default environment for janet */
1088 | JANET_API JanetTable *janet_core_env(JanetTable *replacements);
1089 |
1090 | JANET_API int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath, Janet *out);
1091 | JANET_API int janet_dostring(JanetTable *env, const char *str, const char *sourcePath, Janet *out);
1092 |
1093 | /* Number scanning */
1094 | JANET_API int janet_scan_number(const uint8_t *str, int32_t len, double *out);
1095 | JANET_API int janet_scan_int64(const uint8_t *str, int32_t len, int64_t *out);
1096 | JANET_API int janet_scan_uint64(const uint8_t *str, int32_t len, uint64_t *out);
1097 |
1098 | /* Debugging */
1099 | JANET_API void janet_debug_break(JanetFuncDef *def, int32_t pc);
1100 | JANET_API void janet_debug_unbreak(JanetFuncDef *def, int32_t pc);
1101 | JANET_API void janet_debug_find(
1102 | JanetFuncDef **def_out, int32_t *pc_out,
1103 | const uint8_t *source, int32_t offset);
1104 |
1105 | /* Array functions */
1106 | JANET_API JanetArray *janet_array(int32_t capacity);
1107 | JANET_API JanetArray *janet_array_n(const Janet *elements, int32_t n);
1108 | JANET_API void janet_array_ensure(JanetArray *array, int32_t capacity, int32_t growth);
1109 | JANET_API void janet_array_setcount(JanetArray *array, int32_t count);
1110 | JANET_API void janet_array_push(JanetArray *array, Janet x);
1111 | JANET_API Janet janet_array_pop(JanetArray *array);
1112 | JANET_API Janet janet_array_peek(JanetArray *array);
1113 |
1114 | /* Buffer functions */
1115 | JANET_API JanetBuffer *janet_buffer(int32_t capacity);
1116 | JANET_API JanetBuffer *janet_buffer_init(JanetBuffer *buffer, int32_t capacity);
1117 | JANET_API void janet_buffer_deinit(JanetBuffer *buffer);
1118 | JANET_API void janet_buffer_ensure(JanetBuffer *buffer, int32_t capacity, int32_t growth);
1119 | JANET_API void janet_buffer_setcount(JanetBuffer *buffer, int32_t count);
1120 | JANET_API void janet_buffer_extra(JanetBuffer *buffer, int32_t n);
1121 | JANET_API void janet_buffer_push_bytes(JanetBuffer *buffer, const uint8_t *string, int32_t len);
1122 | JANET_API void janet_buffer_push_string(JanetBuffer *buffer, const uint8_t *string);
1123 | JANET_API void janet_buffer_push_cstring(JanetBuffer *buffer, const char *cstring);
1124 | JANET_API void janet_buffer_push_u8(JanetBuffer *buffer, uint8_t x);
1125 | JANET_API void janet_buffer_push_u16(JanetBuffer *buffer, uint16_t x);
1126 | JANET_API void janet_buffer_push_u32(JanetBuffer *buffer, uint32_t x);
1127 | JANET_API void janet_buffer_push_u64(JanetBuffer *buffer, uint64_t x);
1128 |
1129 | /* Tuple */
1130 |
1131 | #define JANET_TUPLE_FLAG_BRACKETCTOR 0x10000
1132 |
1133 | #define janet_tuple_head(t) ((JanetTupleHead *)((char *)t - offsetof(JanetTupleHead, data)))
1134 | #define janet_tuple_length(t) (janet_tuple_head(t)->length)
1135 | #define janet_tuple_hash(t) (janet_tuple_head(t)->hash)
1136 | #define janet_tuple_sm_start(t) (janet_tuple_head(t)->sm_start)
1137 | #define janet_tuple_sm_end(t) (janet_tuple_head(t)->sm_end)
1138 | #define janet_tuple_flag(t) (janet_tuple_head(t)->gc.flags)
1139 | JANET_API Janet *janet_tuple_begin(int32_t length);
1140 | JANET_API const Janet *janet_tuple_end(Janet *tuple);
1141 | JANET_API const Janet *janet_tuple_n(const Janet *values, int32_t n);
1142 | JANET_API int janet_tuple_equal(const Janet *lhs, const Janet *rhs);
1143 | JANET_API int janet_tuple_compare(const Janet *lhs, const Janet *rhs);
1144 |
1145 | /* String/Symbol functions */
1146 | #define janet_string_head(s) ((JanetStringHead *)((char *)s - offsetof(JanetStringHead, data)))
1147 | #define janet_string_length(s) (janet_string_head(s)->length)
1148 | #define janet_string_hash(s) (janet_string_head(s)->hash)
1149 | JANET_API uint8_t *janet_string_begin(int32_t length);
1150 | JANET_API const uint8_t *janet_string_end(uint8_t *str);
1151 | JANET_API const uint8_t *janet_string(const uint8_t *buf, int32_t len);
1152 | JANET_API const uint8_t *janet_cstring(const char *cstring);
1153 | JANET_API int janet_string_compare(const uint8_t *lhs, const uint8_t *rhs);
1154 | JANET_API int janet_string_equal(const uint8_t *lhs, const uint8_t *rhs);
1155 | JANET_API int janet_string_equalconst(const uint8_t *lhs, const uint8_t *rhs, int32_t rlen, int32_t rhash);
1156 | JANET_API const uint8_t *janet_description(Janet x);
1157 | JANET_API const uint8_t *janet_to_string(Janet x);
1158 | JANET_API void janet_to_string_b(JanetBuffer *buffer, Janet x);
1159 | JANET_API void janet_description_b(JanetBuffer *buffer, Janet x);
1160 | #define janet_cstringv(cstr) janet_wrap_string(janet_cstring(cstr))
1161 | #define janet_stringv(str, len) janet_wrap_string(janet_string((str), (len)))
1162 | JANET_API const uint8_t *janet_formatc(const char *format, ...);
1163 | JANET_API void janet_formatb(JanetBuffer *bufp, const char *format, va_list args);
1164 |
1165 | /* Symbol functions */
1166 | JANET_API const uint8_t *janet_symbol(const uint8_t *str, int32_t len);
1167 | JANET_API const uint8_t *janet_csymbol(const char *str);
1168 | JANET_API const uint8_t *janet_symbol_gen(void);
1169 | #define janet_symbolv(str, len) janet_wrap_symbol(janet_symbol((str), (len)))
1170 | #define janet_csymbolv(cstr) janet_wrap_symbol(janet_csymbol(cstr))
1171 |
1172 | /* Keyword functions */
1173 | #define janet_keyword janet_symbol
1174 | #define janet_ckeyword janet_csymbol
1175 | #define janet_keywordv(str, len) janet_wrap_keyword(janet_keyword((str), (len)))
1176 | #define janet_ckeywordv(cstr) janet_wrap_keyword(janet_ckeyword(cstr))
1177 |
1178 | /* Structs */
1179 | #define janet_struct_head(t) ((JanetStructHead *)((char *)t - offsetof(JanetStructHead, data)))
1180 | #define janet_struct_length(t) (janet_struct_head(t)->length)
1181 | #define janet_struct_capacity(t) (janet_struct_head(t)->capacity)
1182 | #define janet_struct_hash(t) (janet_struct_head(t)->hash)
1183 | JANET_API JanetKV *janet_struct_begin(int32_t count);
1184 | JANET_API void janet_struct_put(JanetKV *st, Janet key, Janet value);
1185 | JANET_API const JanetKV *janet_struct_end(JanetKV *st);
1186 | JANET_API Janet janet_struct_get(const JanetKV *st, Janet key);
1187 | JANET_API JanetTable *janet_struct_to_table(const JanetKV *st);
1188 | JANET_API int janet_struct_equal(const JanetKV *lhs, const JanetKV *rhs);
1189 | JANET_API int janet_struct_compare(const JanetKV *lhs, const JanetKV *rhs);
1190 | JANET_API const JanetKV *janet_struct_find(const JanetKV *st, Janet key);
1191 |
1192 | /* Table functions */
1193 | JANET_API JanetTable *janet_table(int32_t capacity);
1194 | JANET_API JanetTable *janet_table_init(JanetTable *table, int32_t capacity);
1195 | JANET_API void janet_table_deinit(JanetTable *table);
1196 | JANET_API Janet janet_table_get(JanetTable *t, Janet key);
1197 | JANET_API Janet janet_table_get_ex(JanetTable *t, Janet key, JanetTable **which);
1198 | JANET_API Janet janet_table_rawget(JanetTable *t, Janet key);
1199 | JANET_API Janet janet_table_remove(JanetTable *t, Janet key);
1200 | JANET_API void janet_table_put(JanetTable *t, Janet key, Janet value);
1201 | JANET_API const JanetKV *janet_table_to_struct(JanetTable *t);
1202 | JANET_API void janet_table_merge_table(JanetTable *table, JanetTable *other);
1203 | JANET_API void janet_table_merge_struct(JanetTable *table, const JanetKV *other);
1204 | JANET_API JanetKV *janet_table_find(JanetTable *t, Janet key);
1205 | JANET_API JanetTable *janet_table_clone(JanetTable *table);
1206 |
1207 | /* Fiber */
1208 | JANET_API JanetFiber *janet_fiber(JanetFunction *callee, int32_t capacity, int32_t argc, const Janet *argv);
1209 | JANET_API JanetFiber *janet_fiber_reset(JanetFiber *fiber, JanetFunction *callee, int32_t argc, const Janet *argv);
1210 | JANET_API JanetFiberStatus janet_fiber_status(JanetFiber *fiber);
1211 | JANET_API JanetFiber *janet_current_fiber(void);
1212 |
1213 | /* Treat similar types through uniform interfaces for iteration */
1214 | JANET_API int janet_indexed_view(Janet seq, const Janet **data, int32_t *len);
1215 | JANET_API int janet_bytes_view(Janet str, const uint8_t **data, int32_t *len);
1216 | JANET_API int janet_dictionary_view(Janet tab, const JanetKV **data, int32_t *len, int32_t *cap);
1217 | JANET_API Janet janet_dictionary_get(const JanetKV *data, int32_t cap, Janet key);
1218 | JANET_API const JanetKV *janet_dictionary_next(const JanetKV *kvs, int32_t cap, const JanetKV *kv);
1219 |
1220 | /* Abstract */
1221 | #define janet_abstract_head(u) ((JanetAbstractHead *)((char *)u - offsetof(JanetAbstractHead, data)))
1222 | #define janet_abstract_type(u) (janet_abstract_head(u)->type)
1223 | #define janet_abstract_size(u) (janet_abstract_head(u)->size)
1224 | JANET_API void *janet_abstract_begin(const JanetAbstractType *type, size_t size);
1225 | JANET_API void *janet_abstract_end(void *);
1226 | JANET_API void *janet_abstract(const JanetAbstractType *type, size_t size); /* begin and end in one call */
1227 |
1228 | /* Native */
1229 | typedef void (*JanetModule)(JanetTable *);
1230 | typedef JanetBuildConfig(*JanetModconf)(void);
1231 | JANET_API JanetModule janet_native(const char *name, const uint8_t **error);
1232 |
1233 | /* Marshaling */
1234 | JANET_API void janet_marshal(
1235 | JanetBuffer *buf,
1236 | Janet x,
1237 | JanetTable *rreg,
1238 | int flags);
1239 | JANET_API Janet janet_unmarshal(
1240 | const uint8_t *bytes,
1241 | size_t len,
1242 | int flags,
1243 | JanetTable *reg,
1244 | const uint8_t **next);
1245 | JANET_API JanetTable *janet_env_lookup(JanetTable *env);
1246 | JANET_API void janet_env_lookup_into(JanetTable *renv, JanetTable *env, const char *prefix, int recurse);
1247 |
1248 | /* GC */
1249 | JANET_API void janet_mark(Janet x);
1250 | JANET_API void janet_sweep(void);
1251 | JANET_API void janet_collect(void);
1252 | JANET_API void janet_clear_memory(void);
1253 | JANET_API void janet_gcroot(Janet root);
1254 | JANET_API int janet_gcunroot(Janet root);
1255 | JANET_API int janet_gcunrootall(Janet root);
1256 | JANET_API int janet_gclock(void);
1257 | JANET_API void janet_gcunlock(int handle);
1258 |
1259 | /* Functions */
1260 | JANET_API JanetFuncDef *janet_funcdef_alloc(void);
1261 | JANET_API JanetFunction *janet_thunk(JanetFuncDef *def);
1262 | JANET_API int janet_verify(JanetFuncDef *def);
1263 |
1264 | /* Pretty printing */
1265 | #define JANET_PRETTY_COLOR 1
1266 | #define JANET_PRETTY_ONELINE 2
1267 | JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x);
1268 |
1269 | /* Misc */
1270 | JANET_API int janet_equals(Janet x, Janet y);
1271 | JANET_API int32_t janet_hash(Janet x);
1272 | JANET_API int janet_compare(Janet x, Janet y);
1273 | JANET_API int janet_cstrcmp(const uint8_t *str, const char *other);
1274 | JANET_API Janet janet_get(Janet ds, Janet key);
1275 | JANET_API Janet janet_getindex(Janet ds, int32_t index);
1276 | JANET_API int32_t janet_length(Janet x);
1277 | JANET_API Janet janet_lengthv(Janet x);
1278 | JANET_API void janet_put(Janet ds, Janet key, Janet value);
1279 | JANET_API void janet_putindex(Janet ds, int32_t index, Janet value);
1280 | JANET_API uint64_t janet_getflags(const Janet *argv, int32_t n, const char *flags);
1281 | #define janet_flag_at(F, I) ((F) & ((1ULL) << (I)))
1282 | JANET_API Janet janet_wrap_number_safe(double x);
1283 |
1284 | /* VM functions */
1285 | JANET_API int janet_init(void);
1286 | JANET_API void janet_deinit(void);
1287 | JANET_API JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out);
1288 | JANET_API JanetSignal janet_pcall(JanetFunction *fun, int32_t argn, const Janet *argv, Janet *out, JanetFiber **f);
1289 | JANET_API Janet janet_call(JanetFunction *fun, int32_t argc, const Janet *argv);
1290 | JANET_API Janet janet_mcall(const char *name, int32_t argc, Janet *argv);
1291 | JANET_API void janet_stacktrace(JanetFiber *fiber, Janet err);
1292 |
1293 | /* Scratch Memory API */
1294 | JANET_API void *janet_smalloc(size_t size);
1295 | JANET_API void *janet_srealloc(void *mem, size_t size);
1296 | JANET_API void janet_sfree(void *mem);
1297 |
1298 | /* C Library helpers */
1299 | typedef enum {
1300 | JANET_BINDING_NONE,
1301 | JANET_BINDING_DEF,
1302 | JANET_BINDING_VAR,
1303 | JANET_BINDING_MACRO
1304 | } JanetBindingType;
1305 | JANET_API void janet_def(JanetTable *env, const char *name, Janet val, const char *documentation);
1306 | JANET_API void janet_var(JanetTable *env, const char *name, Janet val, const char *documentation);
1307 | JANET_API void janet_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns);
1308 | JANET_API JanetBindingType janet_resolve(JanetTable *env, const uint8_t *sym, Janet *out);
1309 | JANET_API void janet_register(const char *name, JanetCFunction cfun);
1310 |
1311 | /* New C API */
1312 |
1313 | /* Allow setting entry name for static libraries */
1314 | #ifndef JANET_ENTRY_NAME
1315 | #define JANET_ENTRY_NAME _janet_init
1316 | #endif
1317 |
1318 | #define JANET_MODULE_ENTRY \
1319 | JANET_API JanetBuildConfig _janet_mod_config(void) { \
1320 | return janet_config_current(); \
1321 | } \
1322 | JANET_API void JANET_ENTRY_NAME
1323 |
1324 | JANET_NO_RETURN JANET_API void janet_panicv(Janet message);
1325 | JANET_NO_RETURN JANET_API void janet_panic(const char *message);
1326 | JANET_NO_RETURN JANET_API void janet_panics(const uint8_t *message);
1327 | JANET_NO_RETURN JANET_API void janet_panicf(const char *format, ...);
1328 | JANET_API void janet_printf(const char *format, ...);
1329 | JANET_NO_RETURN JANET_API void janet_panic_type(Janet x, int32_t n, int expected);
1330 | JANET_NO_RETURN JANET_API void janet_panic_abstract(Janet x, int32_t n, const JanetAbstractType *at);
1331 | JANET_API void janet_arity(int32_t arity, int32_t min, int32_t max);
1332 | JANET_API void janet_fixarity(int32_t arity, int32_t fix);
1333 |
1334 | JANET_API Janet janet_getmethod(const uint8_t *method, const JanetMethod *methods);
1335 | JANET_API double janet_getnumber(const Janet *argv, int32_t n);
1336 | JANET_API JanetArray *janet_getarray(const Janet *argv, int32_t n);
1337 | JANET_API const Janet *janet_gettuple(const Janet *argv, int32_t n);
1338 | JANET_API JanetTable *janet_gettable(const Janet *argv, int32_t n);
1339 | JANET_API const JanetKV *janet_getstruct(const Janet *argv, int32_t n);
1340 | JANET_API const uint8_t *janet_getstring(const Janet *argv, int32_t n);
1341 | JANET_API const char *janet_getcstring(const Janet *argv, int32_t n);
1342 | JANET_API const uint8_t *janet_getsymbol(const Janet *argv, int32_t n);
1343 | JANET_API const uint8_t *janet_getkeyword(const Janet *argv, int32_t n);
1344 | JANET_API JanetBuffer *janet_getbuffer(const Janet *argv, int32_t n);
1345 | JANET_API JanetFiber *janet_getfiber(const Janet *argv, int32_t n);
1346 | JANET_API JanetFunction *janet_getfunction(const Janet *argv, int32_t n);
1347 | JANET_API JanetCFunction janet_getcfunction(const Janet *argv, int32_t n);
1348 | JANET_API int janet_getboolean(const Janet *argv, int32_t n);
1349 | JANET_API void *janet_getpointer(const Janet *argv, int32_t n);
1350 |
1351 | JANET_API int32_t janet_getinteger(const Janet *argv, int32_t n);
1352 | JANET_API int64_t janet_getinteger64(const Janet *argv, int32_t n);
1353 | JANET_API size_t janet_getsize(const Janet *argv, int32_t n);
1354 | JANET_API JanetView janet_getindexed(const Janet *argv, int32_t n);
1355 | JANET_API JanetByteView janet_getbytes(const Janet *argv, int32_t n);
1356 | JANET_API JanetDictView janet_getdictionary(const Janet *argv, int32_t n);
1357 | JANET_API void *janet_getabstract(const Janet *argv, int32_t n, const JanetAbstractType *at);
1358 | JANET_API JanetRange janet_getslice(int32_t argc, const Janet *argv);
1359 | JANET_API int32_t janet_gethalfrange(const Janet *argv, int32_t n, int32_t length, const char *which);
1360 | JANET_API int32_t janet_getargindex(const Janet *argv, int32_t n, int32_t length, const char *which);
1361 |
1362 | JANET_API Janet janet_dyn(const char *name);
1363 | JANET_API void janet_setdyn(const char *name, Janet value);
1364 |
1365 | JANET_API FILE *janet_getfile(const Janet *argv, int32_t n, int *flags);
1366 | JANET_API FILE *janet_dynfile(const char *name, FILE *def);
1367 |
1368 | /* Marshal API */
1369 | JANET_API void janet_marshal_size(JanetMarshalContext *ctx, size_t value);
1370 | JANET_API void janet_marshal_int(JanetMarshalContext *ctx, int32_t value);
1371 | JANET_API void janet_marshal_int64(JanetMarshalContext *ctx, int64_t value);
1372 | JANET_API void janet_marshal_byte(JanetMarshalContext *ctx, uint8_t value);
1373 | JANET_API void janet_marshal_bytes(JanetMarshalContext *ctx, const uint8_t *bytes, size_t len);
1374 | JANET_API void janet_marshal_janet(JanetMarshalContext *ctx, Janet x);
1375 |
1376 | JANET_API size_t janet_unmarshal_size(JanetMarshalContext *ctx);
1377 | JANET_API int32_t janet_unmarshal_int(JanetMarshalContext *ctx);
1378 | JANET_API int64_t janet_unmarshal_int64(JanetMarshalContext *ctx);
1379 | JANET_API uint8_t janet_unmarshal_byte(JanetMarshalContext *ctx);
1380 | JANET_API void janet_unmarshal_bytes(JanetMarshalContext *ctx, uint8_t *dest, size_t len);
1381 | JANET_API Janet janet_unmarshal_janet(JanetMarshalContext *ctx);
1382 |
1383 | JANET_API void janet_register_abstract_type(const JanetAbstractType *at);
1384 | JANET_API const JanetAbstractType *janet_get_abstract_type(Janet key);
1385 |
1386 | #ifdef JANET_TYPED_ARRAY
1387 |
1388 | typedef enum {
1389 | JANET_TARRAY_TYPE_U8,
1390 | JANET_TARRAY_TYPE_S8,
1391 | JANET_TARRAY_TYPE_U16,
1392 | JANET_TARRAY_TYPE_S16,
1393 | JANET_TARRAY_TYPE_U32,
1394 | JANET_TARRAY_TYPE_S32,
1395 | JANET_TARRAY_TYPE_U64,
1396 | JANET_TARRAY_TYPE_S64,
1397 | JANET_TARRAY_TYPE_F32,
1398 | JANET_TARRAY_TYPE_F64
1399 | } JanetTArrayType;
1400 |
1401 | typedef struct {
1402 | uint8_t *data;
1403 | size_t size;
1404 | int32_t flags;
1405 | } JanetTArrayBuffer;
1406 |
1407 | typedef struct {
1408 | union {
1409 | void *pointer;
1410 | uint8_t *u8;
1411 | int8_t *s8;
1412 | uint16_t *u16;
1413 | int16_t *s16;
1414 | uint32_t *u32;
1415 | int32_t *s32;
1416 | uint64_t *u64;
1417 | int64_t *s64;
1418 | float *f32;
1419 | double *f64;
1420 | } as;
1421 | JanetTArrayBuffer *buffer;
1422 | size_t size;
1423 | size_t stride;
1424 | JanetTArrayType type;
1425 | } JanetTArrayView;
1426 |
1427 | JANET_API JanetTArrayBuffer *janet_tarray_buffer(size_t size);
1428 | JANET_API JanetTArrayView *janet_tarray_view(JanetTArrayType type, size_t size, size_t stride, size_t offset, JanetTArrayBuffer *buffer);
1429 | JANET_API int janet_is_tarray_view(Janet x, JanetTArrayType type);
1430 | JANET_API JanetTArrayBuffer *janet_gettarray_buffer(const Janet *argv, int32_t n);
1431 | JANET_API JanetTArrayView *janet_gettarray_view(const Janet *argv, int32_t n, JanetTArrayType type);
1432 | JanetTArrayView *janet_gettarray_any(const Janet *argv, int32_t n);
1433 |
1434 | #endif
1435 |
1436 | #ifdef JANET_INT_TYPES
1437 |
1438 | typedef enum {
1439 | JANET_INT_NONE,
1440 | JANET_INT_S64,
1441 | JANET_INT_U64
1442 | } JanetIntType;
1443 |
1444 | JANET_API JanetIntType janet_is_int(Janet x);
1445 | JANET_API Janet janet_wrap_s64(int64_t x);
1446 | JANET_API Janet janet_wrap_u64(uint64_t x);
1447 | JANET_API int64_t janet_unwrap_s64(Janet x);
1448 | JANET_API uint64_t janet_unwrap_u64(Janet x);
1449 | JANET_API int janet_scan_int64(const uint8_t *str, int32_t len, int64_t *out);
1450 | JANET_API int janet_scan_uint64(const uint8_t *str, int32_t len, uint64_t *out);
1451 |
1452 | #endif
1453 |
1454 | /***** END SECTION MAIN *****/
1455 |
1456 | #ifdef __cplusplus
1457 | }
1458 | #endif
1459 |
1460 | #endif /* JANET_H_defined */
1461 |
--------------------------------------------------------------------------------
/src/janetconf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019 Calvin Rose
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to
6 | * deal in the Software without restriction, including without limitation the
7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 | * sell copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 | * IN THE SOFTWARE.
21 | */
22 |
23 | /* This is an example janetconf.h file. This will be usually generated
24 | * by the build system. */
25 |
26 | #ifndef JANETCONF_H
27 | #define JANETCONF_H
28 |
29 | #define JANET_VERSION_MAJOR 1
30 | #define JANET_VERSION_MINOR 2
31 | #define JANET_VERSION_PATCH 0
32 | #define JANET_VERSION_EXTRA ""
33 | #define JANET_VERSION "1.2.0"
34 |
35 | /* #define JANET_BUILD "local" */
36 |
37 | /* These settings all affect linking, so use cautiously. */
38 | /* #define JANET_SINGLE_THREADED */
39 | /* #define JANET_NO_DYNAMIC_MODULES */
40 | /* #define JANET_NO_NANBOX */
41 | /* #define JANET_API __attribute__((visibility ("default"))) */
42 |
43 | /* These settings should be specified before amalgamation is
44 | * built. */
45 | /* #define JANET_NO_DOCSTRINGS */
46 | /* #define JANET_NO_SOURCEMAPS */
47 | /* #define JANET_REDUCED_OS */
48 |
49 | /* Other settings */
50 | /* #define JANET_NO_ASSEMBLER */
51 | /* #define JANET_NO_PEG */
52 | /* #define JANET_NO_TYPED_ARRAY */
53 | /* #define JANET_NO_INT_TYPES */
54 | /* #define JANET_OUT_OF_MEMORY do { printf("janet out of memory\n"); exit(1); } while (0) */
55 | /* #define JANET_RECURSION_GUARD 1024 */
56 | /* #define JANET_MAX_PROTO_DEPTH 200 */
57 | /* #define JANET_MAX_MACRO_EXPAND 200 */
58 | /* #define JANET_STACK_MAX 16384 */
59 | /* #define JANET_OS_NAME my-custom-os */
60 | /* #define JANET_ARCH_NAME pdp-8 */
61 |
62 | #endif /* end of include guard: JANETCONF_H */
63 |
--------------------------------------------------------------------------------
/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "cfuncs.h"
4 |
5 | //==============================================================================
6 |
7 | #define BOOTSCRIPT "./boot.janet"
8 | static char bootBuffer[128] = {0};
9 |
10 | //==============================================================================
11 |
12 | bool load_script(char *buffer, const char *path) {
13 | FILE *bootFile = fopen(path, "r");
14 | if (NULL == bootFile) {
15 | fprintf(stderr, "failed to open boot script!");
16 | return false;
17 | }
18 |
19 | fseek(bootFile, 0, SEEK_END);
20 | size_t size = ftell(bootFile);
21 | rewind(bootFile);
22 | if(0 >= size) {
23 | fprintf(stderr, "boot script is empty or broken!");
24 | return false;
25 | }
26 |
27 | fread(buffer, sizeof(char), size, bootFile);
28 |
29 | return true;
30 | }
31 |
32 | //==============================================================================
33 |
34 | int main(int argc, char **argv) {
35 | if (0 != janet_init()) {
36 | fprintf(stderr, "failed to bring up lisp machine!");
37 | return EXIT_FAILURE;
38 | }
39 |
40 | JanetTable *jenv = janet_core_env(NULL);
41 | if (NULL == jenv) {
42 | fprintf(stderr, "failed to set up lisp machine!");
43 | return EXIT_FAILURE;
44 | }
45 |
46 | inject_engine_symbols(jenv);
47 |
48 | if (!load_script(bootBuffer, BOOTSCRIPT)) {
49 | return EXIT_SUCCESS;
50 | }
51 |
52 | Janet res;
53 | janet_dostring(jenv, bootBuffer, NULL, &res);
54 |
55 | janet_deinit();
56 | return EXIT_SUCCESS;
57 | }
--------------------------------------------------------------------------------