From 2c3190c8bc963f96fcc67c5f12ba406245212be6 Mon Sep 17 00:00:00 2001 From: no Date: Mon, 9 Nov 2020 22:59:09 -0800 Subject: [PATCH 1/3] Fixed enum bitpacking in basic_function. GCC uses unsigned for enum, unless the enum includes explicit negative assignments. MSVC appears to default to signed. Bitpacking here creates errors if the enum is signed because the maximum value for 3 bits is 3, not 7. The easy solution is to add an extra bit for signed/unsigned. I wonder also if bitpacking is necessary? --- src/parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser.c b/src/parser.c index 9a00dde..ab0a4dd 100644 --- a/src/parser.c +++ b/src/parser.c @@ -134,8 +134,8 @@ typedef union typedef struct { token token; - basic_function_type type : 3; - size_t nr_arguments : 3; + basic_function_type type : 4; + size_t nr_arguments : 4; kind kind_1 : 1; kind kind_2 : 1; kind kind_3 : 1; From a9d40bd8e53fd2c9c8316f97e7c391003d9e4cdc Mon Sep 17 00:00:00 2001 From: no Date: Tue, 10 Nov 2020 00:03:40 -0800 Subject: [PATCH 2/3] Fixes to parser, tokenizer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added missing typecasts when using &_dummy. Fixed #if preprocessor that was missing #else and added Windows Sleep() function. In tokenizer, we get: 247:50: error: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess] This can be suppressed as I have done, by converting the source to a char*. --- src/parser.c | 10 ++++------ src/tokenizer.c | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/parser.c b/src/parser.c index ab0a4dd..8877104 100644 --- a/src/parser.c +++ b/src/parser.c @@ -831,7 +831,7 @@ string_term(void) size_t vector[5]; get_vector(vector,5); string = C_STRDUP(variable_array_get_string(var_name, vector)); - if (string == NULL) string = &_dummy; + if (string == NULL) string = (char*)&_dummy; expect(T_RIGHT_BANANA); } @@ -908,7 +908,7 @@ do_print(basic_type* rv) expression(&expr); expression_print(&expr); if (expr.type == expression_type_string){ - if (expr.value.string != &_dummy) + if (expr.value.string != (char*)&_dummy) free(expr.value.string); } } @@ -2066,10 +2066,8 @@ int do_sleep(basic_type* delay, basic_type* rv) nanosleep(&ts, NULL); #endif - struct timespec ts; - ts.tv_sec = milliseconds / 1000; - ts.tv_nsec = (milliseconds % 1000) * 1000000; - nanosleep(&ts, NULL); +#else + Sleep(milliseconds); #endif rv->kind = kind_numeric; diff --git a/src/tokenizer.c b/src/tokenizer.c index 773ef4b..98d5a48 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -244,7 +244,7 @@ char *tokenizer_get_string(void) void tokenizer_get_variable_name(char *name) { - strncpy(name, tokenizer_actual_variable, sizeof(tokenizer_actual_variable)); + strncpy(name, &tokenizer_actual_variable[0], sizeof(tokenizer_actual_variable)); } void From 0a42adf9cca9a7f99d3e855437223ce26a3681e8 Mon Sep 17 00:00:00 2001 From: no Date: Tue, 10 Nov 2020 00:10:41 -0800 Subject: [PATCH 3/3] Updates to Makefile Fixed linker options. Changed gcc-10 to gcc. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dfd2c5d..0222212 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,9 @@ BUILD_FOLDER = build/basic SOURCE_FOLDERS += ./arch/osx ./src -CC = gcc-10 -CFLAGS = -g -Wall -Werror -std=c99 -lreadline -lm -DARCH_OSX=1 -DARCH_XMEGA=2 -DARCH=1 +CC = gcc +CFLAGS = -g -Wall -Werror -std=c99 -DARCH_OSX=1 -DARCH_XMEGA=2 -DARCH=1 +LDFLAGS = -lreadline -lm VPATH = $(SOURCE_FOLDERS)