From 3bfffff5e35a4c62b1439b5ffc32010593b9621a Mon Sep 17 00:00:00 2001 From: nishi Date: Tue, 23 Apr 2024 12:15:18 +0000 Subject: [PATCH] better targets git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@19 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- Makefile | 5 +++++ Serenade/Makefile | 2 +- Serenade/main.c | 4 ++-- Serenade/parser.c | 9 +++++---- Serenade/run.c | 33 +++++++++++++++++++++++++++++++++ Serenade/run.h | 38 ++++++++++++++++++++++++++++++++++++++ Serenade/util.c | 4 +++- Tool/configgen.c | 4 ++-- 8 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 Serenade/run.c create mode 100644 Serenade/run.h diff --git a/Makefile b/Makefile index a1b4d92..84f60dd 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,11 @@ LDFLAGS = LIBS = SUFFIX = +.if "$(PLATFORM)" != "" +.include "platforms/${PLATFORM}.mk" +.else .include "platform.mk" +.endif .PHONY: all ./Serenade ./Tool replace format @@ -16,6 +20,7 @@ all: ./Tool ./config.h ./Serenade $(MAKE) -C ./Tool CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)" ./config.h: + if [ ! -e ./Tool/configgen ]; then $(MAKE) ./Tool ; fi ./Tool/configgen $@ ./Serenade:: diff --git a/Serenade/Makefile b/Serenade/Makefile index 9a8de38..06a890c 100644 --- a/Serenade/Makefile +++ b/Serenade/Makefile @@ -1,6 +1,6 @@ # $Id$ -SERENADE_OBJS = main.o parser.o util.o +SERENADE_OBJS = main.o parser.o util.o run.o .PHONY: all clean .SUFFIXES: .o .c diff --git a/Serenade/main.c b/Serenade/main.c index b4f8d16..7a20a71 100644 --- a/Serenade/main.c +++ b/Serenade/main.c @@ -46,7 +46,7 @@ int main(int argc, char** argv) { if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) { printf("Serenade LISP %s\n", SERENADE_VERSION); printf("Support: %s\n", SUPPORT); - printf("Stack size: %d\n", STACK_SIZE); + printf("Parser stack size: %d\n", PARSER_STACK_SIZE); return 1; } else { fprintf(stderr, "%s: %s: invalid option\n", argv[0], argv[i]); @@ -84,7 +84,7 @@ int main(int argc, char** argv) { if(!loaded) { printf("Welcome to Serenade LISP %s\n", SERENADE_VERSION); printf("Support: %s\n", SUPPORT); - printf("Stack size: %d\n", STACK_SIZE); + printf("Parser stack size: %d\n", PARSER_STACK_SIZE); } return 0; #else diff --git a/Serenade/parser.c b/Serenade/parser.c index 2638bc2..8197970 100644 --- a/Serenade/parser.c +++ b/Serenade/parser.c @@ -82,14 +82,15 @@ struct sn_generic* sn_expr_parse(char* data, unsigned long long size) { int i; int br = 0; bool dq = false; - struct sn_generic** gn_stack = malloc(sizeof(*gn_stack) * STACK_SIZE); - int* index_stack = malloc(sizeof(int) * STACK_SIZE); + struct sn_generic** gn_stack = malloc(sizeof(*gn_stack) * PARSER_STACK_SIZE); + int* index_stack = malloc(sizeof(int) * PARSER_STACK_SIZE); char* argbuf = malloc(1); argbuf[0] = 0; int argbufmode = SN_TYPE_VOID; for(i = 0; i < size; i++) { char c = data[i]; - if(c == '"') { + if(c == '\r') { + } else if(c == '"') { dq = !dq; } else if(dq) { char cbuf[2] = {c, 0}; @@ -121,7 +122,7 @@ struct sn_generic* sn_expr_parse(char* data, unsigned long long size) { } br--; } else { - if(c == ' ') { + if(c == ' ' || c == '\n') { if(strlen(argbuf) > 0) { push_stack(gn_stack[br - 1], argbuf, argbufmode); index_stack[br - 1]++; diff --git a/Serenade/run.c b/Serenade/run.c new file mode 100644 index 0000000..23dc6ca --- /dev/null +++ b/Serenade/run.c @@ -0,0 +1,33 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Serenade is a Lisp Dialect */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#include "run.h" + +int sn_run(struct sn_generic* gen) { return 0; } diff --git a/Serenade/run.h b/Serenade/run.h new file mode 100644 index 0000000..16addcb --- /dev/null +++ b/Serenade/run.h @@ -0,0 +1,38 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Serenade is a Lisp Dialect */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#ifndef __SERENADE_RUN_H__ +#define __SERENADE_RUN_H__ + +#include "parser.h" + +int sn_run(struct sn_generic* gen); + +#endif diff --git a/Serenade/util.c b/Serenade/util.c index 29b7f26..a544c7b 100644 --- a/Serenade/util.c +++ b/Serenade/util.c @@ -54,6 +54,7 @@ void _sn_print_generic(struct sn_generic* gen, int n) { fprintf(stderr, "[%2d]", gen->type); for(i = 0; i < n; i++) fprintf(stderr, " "); if(gen->type == SN_TYPE_TREE) { + fprintf(stderr, "(Tree)\n"); if(gen->tree->args != NULL) { for(i = 0; gen->tree->args[i] != NULL; i++) { _sn_print_generic(gen->tree->args[i], n + 1); @@ -61,10 +62,11 @@ void _sn_print_generic(struct sn_generic* gen, int n) { } } else if(gen->type == SN_TYPE_DOUBLE) { fprintf(stderr, "%f", gen->number); + fprintf(stderr, "\n"); } else if(gen->type == SN_TYPE_STRING || gen->type == SN_TYPE_FUNCTION) { fwrite(gen->string, 1, gen->string_length, stderr); + fprintf(stderr, "\n"); } - fprintf(stderr, "\n"); } void sn_print_generic(struct sn_generic* gen) { _sn_print_generic(gen, 0); } diff --git a/Tool/configgen.c b/Tool/configgen.c index 5ad2698..1b6ac5f 100644 --- a/Tool/configgen.c +++ b/Tool/configgen.c @@ -82,10 +82,10 @@ int main(int argc, char** argv) { } } int stack_size = 1024; - fprintf(stderr, "[recommended: 1024] Stack size? "); + fprintf(stderr, "[recommended: 1024] Parser stack size? "); fflush(stderr); scanf("%d", &stack_size); - fprintf(out, "#define STACK_SIZE %d\n", stack_size); + fprintf(out, "#define PARSER_STACK_SIZE %d\n", stack_size); fprintf(out, "#define SUPPORT \""); for(n = 0; asks[n * 4] != NULL; n++) { if(n > 0) fprintf(out, " "); -- 2.43.0