Baremetal Lisp interpreter and compiler for low-resource devices
リビジョン | 342e19e6ceaaa91a71fe623b54896027301784b9 (tree) |
---|---|
日時 | 2020-09-13 06:58:55 |
作者 | AlaskanEmily <emily@alas...> |
コミッター | AlaskanEmily |
Move builtins to a separate file
@@ -42,7 +42,7 @@ relink: | ||
42 | 42 | $(AR) $(ARFLAGS) $(AROUT)libsl_s.a $(OBJECTS) |
43 | 43 | if test ! -z '$(RANLIB)' ; then $(RANLIB) $(RANLIBFLAGS) libsl_s.a ; fi |
44 | 44 | |
45 | -IOBJECTS=sl_i.o sl_x.o sl_i_main.o | |
45 | +IOBJECTS=sl_i.o sl_i_builtin.o sl_x.o sl_i_main.o | |
46 | 46 | |
47 | 47 | sl_x.o: sl_x.c sl_x.h sl_s.h |
48 | 48 | $(CC) $(CFLAGS) $(COMPILEFLAG) sl_x.c $(COUT)sl_x.o |
@@ -50,6 +50,9 @@ sl_x.o: sl_x.c sl_x.h sl_s.h | ||
50 | 50 | sl_i.o: sl_i.c sl_i.h sl_x.h sl_s.h |
51 | 51 | $(CC) $(CFLAGS) $(COMPILEFLAG) sl_i.c $(COUT)sl_i.o |
52 | 52 | |
53 | +sl_i_builtin.o: sl_i_builtin.c sl_i_builtin.h sl_i.h sl_s.h | |
54 | + $(CC) $(CFLAGS) $(COMPILEFLAG) sl_i_builtin.c $(COUT)sl_i_builtin.o | |
55 | + | |
53 | 56 | sl_i_main.o: sl_i_main.c sl_i.h sl_s.h sl_s_parse.h sl_x.h sl_x_io.h |
54 | 57 | $(CC) $(CFLAGS) $(COMPILEFLAG) sl_i_main.c $(COUT)sl_i_main.o |
55 | 58 |
@@ -18,6 +18,8 @@ | ||
18 | 18 | */ |
19 | 19 | |
20 | 20 | #include "sl_i.h" |
21 | + | |
22 | +#include "sl_i_builtin.h" | |
21 | 23 | #include "sl_x.h" |
22 | 24 | |
23 | 25 | #define SL_I_BIND_CAP_GROWTH 64 |
@@ -35,35 +37,6 @@ | ||
35 | 37 | |
36 | 38 | /*****************************************************************************/ |
37 | 39 | |
38 | -SL_S_FUNC(void) *sl_i_print(struct SL_I_Runtime *rt, | |
39 | - const struct SL_S_List *args){ | |
40 | - | |
41 | - struct SL_S_Atom *atom; | |
42 | - struct SL_S_List *list; | |
43 | - if(SL_S_IS_NIL(args->head)){ | |
44 | - rt->io.write(rt->io.x_stdout, "nil", 3); | |
45 | - } | |
46 | - if(SL_S_IS_LIST(args->head)){ | |
47 | - rt->io.write(rt->io.x_stdout, "( ", 2); | |
48 | - for(list = SL_S_PTR_FROM_TAG(args->head); | |
49 | - list != SL_S_NIL; | |
50 | - list = list->tail){ | |
51 | - | |
52 | - sl_i_print(rt, list); | |
53 | - rt->io.write(rt->io.x_stdout, " ", 1); | |
54 | - } | |
55 | - rt->io.write(rt->io.x_stdout, ")", 1); | |
56 | - } | |
57 | - else{ | |
58 | - atom = SL_S_PTR_FROM_TAG(args->head); | |
59 | - rt->io.write(rt->io.x_stdout, atom->text, atom->len); | |
60 | - } | |
61 | - return SL_S_NIL; | |
62 | -} | |
63 | -const struct SL_S_Atom sl_i_print_name = SL_S_STATIC_ATOM("print"); | |
64 | - | |
65 | -/*****************************************************************************/ | |
66 | - | |
67 | 40 | SL_S_FUNC(void) SL_I_InitRuntime(struct SL_I_Runtime *rt){ |
68 | 41 | SL_S_MemSet(rt, 0, sizeof(struct SL_I_Runtime)); |
69 | 42 | rt->frames = &(rt->global); |
@@ -74,7 +47,7 @@ SL_S_FUNC(void) SL_I_InitRuntime(struct SL_I_Runtime *rt){ | ||
74 | 47 | |
75 | 48 | rt->binds[0].name = &sl_i_print_name; |
76 | 49 | rt->binds[0].is_native = 1; |
77 | - rt->binds[0].bind.native = sl_i_print; | |
50 | + rt->binds[0].bind.native = SL_I_Print; | |
78 | 51 | rt->binds[0].args = SL_S_NIL; |
79 | 52 | rt->binds[0].arity = 1; |
80 | 53 | } |
@@ -0,0 +1,57 @@ | ||
1 | +/* Copyright (c) 2020 AlaskanEmily | |
2 | + * | |
3 | + * This software is provided 'as-is', without any express or implied warranty. | |
4 | + * In no event will the authors be held liable for any damages arising from | |
5 | + * the use of this software. | |
6 | + * | |
7 | + * Permission is granted to anyone to use this software for any purpose, | |
8 | + * including commercial applications, and to alter it and redistribute it | |
9 | + * freely, subject to the following restrictions: | |
10 | + * | |
11 | + * 1. The origin of this software must not be misrepresented; you must not | |
12 | + * claim that you wrote the original software. If you use this software in a | |
13 | + * product, an acknowledgment in the product documentation would be | |
14 | + * appreciated but is not required. | |
15 | + * 2. Altered source versions must be plainly marked as such, and must not be | |
16 | + * misrepresented as being the original software. | |
17 | + * 3. This notice may not be removed or altered from any source distribution. | |
18 | + */ | |
19 | + | |
20 | +#include "sl_i_builtin.h" | |
21 | + | |
22 | +#include "sl_i.h" | |
23 | +#include "sl_x.h" | |
24 | + | |
25 | +/*****************************************************************************/ | |
26 | + | |
27 | +const struct SL_S_Atom sl_i_print_name = SL_S_STATIC_ATOM("print"); | |
28 | + | |
29 | +/*****************************************************************************/ | |
30 | + | |
31 | +SL_S_FUNC(void) *SL_I_Print(struct SL_I_Runtime *rt, | |
32 | + const struct SL_S_List *args){ | |
33 | + | |
34 | + struct SL_S_Atom *atom; | |
35 | + struct SL_S_List *list; | |
36 | + if(SL_S_IS_NIL(args->head)){ | |
37 | + rt->io.write(rt->io.x_stdout, "nil", 3); | |
38 | + } | |
39 | + if(SL_S_IS_LIST(args->head)){ | |
40 | + rt->io.write(rt->io.x_stdout, "( ", 2); | |
41 | + for(list = SL_S_PTR_FROM_TAG(args->head); | |
42 | + list != SL_S_NIL; | |
43 | + list = list->tail){ | |
44 | + | |
45 | + SL_I_Print(rt, list); | |
46 | + rt->io.write(rt->io.x_stdout, " ", 1); | |
47 | + } | |
48 | + rt->io.write(rt->io.x_stdout, ")", 1); | |
49 | + } | |
50 | + else{ | |
51 | + atom = SL_S_PTR_FROM_TAG(args->head); | |
52 | + rt->io.write(rt->io.x_stdout, atom->text, atom->len); | |
53 | + } | |
54 | + return SL_S_NIL; | |
55 | +} | |
56 | + | |
57 | +/*****************************************************************************/ |
@@ -0,0 +1,55 @@ | ||
1 | +#ifndef SAPPHIRE_LISP_INTERPRETER_BUILTIN_H | |
2 | +#define SAPPHIRE_LISP_INTERPRETER_BUILTIN_H | |
3 | + | |
4 | +/* Copyright (c) 2020 AlaskanEmily | |
5 | + * | |
6 | + * This software is provided 'as-is', without any express or implied warranty. | |
7 | + * In no event will the authors be held liable for any damages arising from | |
8 | + * the use of this software. | |
9 | + * | |
10 | + * Permission is granted to anyone to use this software for any purpose, | |
11 | + * including commercial applications, and to alter it and redistribute it | |
12 | + * freely, subject to the following restrictions: | |
13 | + * | |
14 | + * 1. The origin of this software must not be misrepresented; you must not | |
15 | + * claim that you wrote the original software. If you use this software in a | |
16 | + * product, an acknowledgment in the product documentation would be | |
17 | + * appreciated but is not required. | |
18 | + * 2. Altered source versions must be plainly marked as such, and must not be | |
19 | + * misrepresented as being the original software. | |
20 | + * 3. This notice may not be removed or altered from any source distribution. | |
21 | + */ | |
22 | + | |
23 | +#include "sl_i_builtin.h" | |
24 | + | |
25 | +#include "sl_s.h" | |
26 | + | |
27 | +/*****************************************************************************/ | |
28 | + | |
29 | +#ifdef __cplusplus | |
30 | +extern "C"{ | |
31 | +#endif | |
32 | + | |
33 | +/*****************************************************************************/ | |
34 | + | |
35 | +struct SL_I_Runtime; | |
36 | + | |
37 | +/*****************************************************************************/ | |
38 | + | |
39 | +const extern struct SL_S_Atom sl_i_print_name; | |
40 | + | |
41 | +/*****************************************************************************/ | |
42 | + | |
43 | +SL_S_FUNC(void) *SL_I_Print(struct SL_I_Runtime *rt, | |
44 | + const struct SL_S_List *args); | |
45 | + | |
46 | +/*****************************************************************************/ | |
47 | + | |
48 | +#ifdef __cplusplus | |
49 | +} // extern "C" | |
50 | +#endif | |
51 | + | |
52 | +/*****************************************************************************/ | |
53 | + | |
54 | +#endif /* SAPPHIRE_LISP_INTERPRETER_BUILTIN_H */ | |
55 | + |