• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

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

変更サマリ

差分

--- a/sl.mk
+++ b/sl.mk
@@ -42,7 +42,7 @@ relink:
4242 $(AR) $(ARFLAGS) $(AROUT)libsl_s.a $(OBJECTS)
4343 if test ! -z '$(RANLIB)' ; then $(RANLIB) $(RANLIBFLAGS) libsl_s.a ; fi
4444
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
4646
4747 sl_x.o: sl_x.c sl_x.h sl_s.h
4848 $(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
5050 sl_i.o: sl_i.c sl_i.h sl_x.h sl_s.h
5151 $(CC) $(CFLAGS) $(COMPILEFLAG) sl_i.c $(COUT)sl_i.o
5252
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+
5356 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
5457 $(CC) $(CFLAGS) $(COMPILEFLAG) sl_i_main.c $(COUT)sl_i_main.o
5558
--- a/sl_i.c
+++ b/sl_i.c
@@ -18,6 +18,8 @@
1818 */
1919
2020 #include "sl_i.h"
21+
22+#include "sl_i_builtin.h"
2123 #include "sl_x.h"
2224
2325 #define SL_I_BIND_CAP_GROWTH 64
@@ -35,35 +37,6 @@
3537
3638 /*****************************************************************************/
3739
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-
6740 SL_S_FUNC(void) SL_I_InitRuntime(struct SL_I_Runtime *rt){
6841 SL_S_MemSet(rt, 0, sizeof(struct SL_I_Runtime));
6942 rt->frames = &(rt->global);
@@ -74,7 +47,7 @@ SL_S_FUNC(void) SL_I_InitRuntime(struct SL_I_Runtime *rt){
7447
7548 rt->binds[0].name = &sl_i_print_name;
7649 rt->binds[0].is_native = 1;
77- rt->binds[0].bind.native = sl_i_print;
50+ rt->binds[0].bind.native = SL_I_Print;
7851 rt->binds[0].args = SL_S_NIL;
7952 rt->binds[0].arity = 1;
8053 }
--- /dev/null
+++ b/sl_i_builtin.c
@@ -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+/*****************************************************************************/
--- /dev/null
+++ b/sl_i_builtin.h
@@ -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+