diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6342066 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2011 Sami Samhuri - sami.samhuri@gmail.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Readme.md b/Readme.md index a5fc184..a599bce 100644 --- a/Readme.md +++ b/Readme.md @@ -20,11 +20,11 @@ Hooray! It parses (reads), evaluates, and then prints things back. Lake needs: - * booleans - * chars + * dotted lists * functions * flesh out eval, write apply - * dotted lists + * booleans + * chars * primitives (especially define) * define and friends * branching @@ -41,3 +41,15 @@ Lake needs: * sugar such as '... -> (quote ...) I don't think I'll need any other numeric types, but they are easy to implement anyway when performance is no concern and they're all boxed. + +Contributors +============ + +None of them want any credit. + +License +======= + +Copyright 2011 Sami Samhuri + +MIT License, see included [LICENSE](blob/master/LICENSE) file \ No newline at end of file diff --git a/bool.c b/bool.c index fcbdba2..c7fc0dd 100644 --- a/bool.c +++ b/bool.c @@ -1,3 +1,12 @@ +/** + * bool.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include "bool.h" #include "lake.h" #include "sym.h" diff --git a/bool.h b/bool.h index 0e521d3..30216e7 100644 --- a/bool.h +++ b/bool.h @@ -1,3 +1,12 @@ +/** + * bool.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_BOOL_H #define _LAKE_BOOL_H 1 diff --git a/env.c b/env.c index c02079e..7423e79 100644 --- a/env.c +++ b/env.c @@ -1,3 +1,12 @@ +/** + * env.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include #include #include diff --git a/env.h b/env.h index 802835b..bbaba6d 100644 --- a/env.h +++ b/env.h @@ -1,3 +1,12 @@ +/** + * env.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_ENV_H #define _LAKE_ENV_H 1 diff --git a/int.c b/int.c index 72cff0b..3583871 100644 --- a/int.c +++ b/int.c @@ -1,3 +1,12 @@ +/** + * int.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include #include #include "bool.h" diff --git a/int.h b/int.h index 09056c3..7458da9 100644 --- a/int.h +++ b/int.h @@ -1,3 +1,12 @@ +/** + * int.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_INT_H #define _LAKE_INT_H 1 diff --git a/lake.c b/lake.c index d0d0994..37e793b 100644 --- a/lake.c +++ b/lake.c @@ -15,6 +15,7 @@ #include #include "env.h" #include "lake.h" +#include "list.h" #include "parse.h" #include "string.h" @@ -92,27 +93,6 @@ void run_one_then_repl(int argc, char const *args[]) run_repl_with_env(env); } -static char *list_repr(LakeList *list) -{ - char s[1024]; - size_t n = 0; - s[n++] = '('; - int i; - char *s2; - size_t len; - for (i = 0; i < LIST_N(list); ++i) { - s2 = repr(LIST_VAL(list, i)); - len = strlen(s2); - memcpy(s + n, s2, len); - n += len; - free(s2); - if (i != LIST_N(list) - 1) s[n++] = ' '; - } - s[n++] = ')'; - s[n] = 0; - return strdup(s); -} - char *repr(LakeVal *expr) { char *s = NULL; diff --git a/lake.h b/lake.h index dda8ec3..3df5d3d 100644 --- a/lake.h +++ b/lake.h @@ -1,3 +1,12 @@ +/** + * lake.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_LAKE_H #define _LAKE_LAKE_H 1 diff --git a/list.c b/list.c index 8fa419b..c4c1451 100644 --- a/list.c +++ b/list.c @@ -1,3 +1,12 @@ +/** + * list.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include #include "int.h" #include "lake.h" @@ -104,6 +113,29 @@ LakeSym *list_eq(LakeList *a, LakeList *b) LakeStr *list_to_str(LakeList *list) { - /* TODO */ - return str_from_c("[TODO]"); + char *s = list_repr(list); + LakeStr *str = str_from_c(s); + free(s); + return str; +} + +char *list_repr(LakeList *list) +{ + char s[1024]; + size_t n = 0; + s[n++] = '('; + int i; + char *s2; + size_t len; + for (i = 0; i < LIST_N(list); ++i) { + s2 = repr(LIST_VAL(list, i)); + len = strlen(s2); + memcpy(s + n, s2, len); + n += len; + free(s2); + if (i != LIST_N(list) - 1) s[n++] = ' '; + } + s[n++] = ')'; + s[n] = 0; + return strdup(s); } diff --git a/list.h b/list.h index d8173d7..9dea4c5 100644 --- a/list.h +++ b/list.h @@ -1,3 +1,12 @@ +/** + * list.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_LIST_H #define _LAKE_LIST_H 1 @@ -16,5 +25,6 @@ LakeVal *list_get(LakeList *list, LakeInt *li); LakeInt *list_cmp(LakeList *a, LakeList *b); LakeSym *list_eq(LakeList *a, LakeList *b); LakeStr *list_to_str(LakeList *list); +char *list_repr(LakeList *list); #endif diff --git a/parse.c b/parse.c index f6e41e3..eb473e7 100644 --- a/parse.c +++ b/parse.c @@ -1,3 +1,12 @@ +/** + * parse.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include #include #include diff --git a/parse.h b/parse.h index 043e7a5..6c4b4e3 100644 --- a/parse.h +++ b/parse.h @@ -1,3 +1,12 @@ +/** + * parse.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_PARSE_H #define _LAKE_PARSE_H 1 diff --git a/string.c b/string.c index b9f4817..7c40ad7 100644 --- a/string.c +++ b/string.c @@ -1,3 +1,12 @@ +/** + * string.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include #include #include "int.h" diff --git a/string.h b/string.h index f504868..0e72019 100644 --- a/string.h +++ b/string.h @@ -1,3 +1,12 @@ +/** + * string.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_STRING_H #define _LAKE_STRING_H 1 diff --git a/sym.c b/sym.c index b0b2801..0e70567 100644 --- a/sym.c +++ b/sym.c @@ -1,3 +1,12 @@ +/** + * sym.c + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #include #include #include diff --git a/sym.h b/sym.h index 9fc4ef9..25dea23 100644 --- a/sym.h +++ b/sym.h @@ -1,3 +1,12 @@ +/** + * sym.h + * Lake Scheme + * + * Copyright 2011 Sami Samhuri + * MIT License + * + */ + #ifndef _LAKE_SYM_H #define _LAKE_SYM_H 1