fix: warnings fix (after -Wall -Wextra)
This commit is contained in:
@@ -3,6 +3,12 @@ project(fz-lang
|
||||
LANGUAGES C)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
add_compile_options(-Wall -Wextra -Werror=implicit-function-declaration)
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_compile_options(-fsanitize=address,undefined -g)
|
||||
add_link_options(-fsanitize=address,undefined)
|
||||
endif()
|
||||
|
||||
include_directories(include)
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Constant types
|
||||
typedef enum
|
||||
{
|
||||
FZL_CONSTTYPE_STRING,
|
||||
FZL_CONSTTYPE_NUMBER
|
||||
} fzl_consttype_t;
|
||||
|
||||
// Constant descriptor
|
||||
@@ -34,7 +34,7 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t pool_index;
|
||||
ssize_t pool_index;
|
||||
} fzl_const_hash_slot_t;
|
||||
|
||||
// Constant pool descriptor
|
||||
@@ -53,13 +53,13 @@ typedef struct
|
||||
bool fzl_consts_equal(fzl_const_t a, fzl_const_t b);
|
||||
|
||||
// Get hash of specified constant
|
||||
static uint32_t fzl_hash_const(fzl_const_t c);
|
||||
uint32_t fzl_hash_const(fzl_const_t c);
|
||||
|
||||
// Allocate constants hash pool
|
||||
fzl_const_hash_pool_t *fzl_mkconstpool();
|
||||
|
||||
// Resize the hash table
|
||||
static void fzl_consts_pool_resize_hash(fzl_const_hash_pool_t *pool);
|
||||
void fzl_consts_pool_resize_hash(fzl_const_hash_pool_t *pool);
|
||||
|
||||
// Push constant. Returns unique index
|
||||
size_t fzl_consts_pool_add(fzl_const_hash_pool_t *pool, fzl_const_t c);
|
||||
|
||||
@@ -27,7 +27,6 @@ void print_node(fzl_node_t *node, int level)
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
size_t lvllen = print_level(levelbuf, level);
|
||||
strcpy(printbuf, levelbuf);
|
||||
|
||||
switch (node->type)
|
||||
|
||||
@@ -56,19 +56,6 @@ static fzl_token_t *peek(fzl_parser_t *parser)
|
||||
return parser->cursor->token;
|
||||
}
|
||||
|
||||
// Get token at (cursor + 1)
|
||||
static fzl_token_t *next(fzl_parser_t *parser)
|
||||
{
|
||||
if (!parser || !parser->cursor)
|
||||
return NULL;
|
||||
|
||||
fzl_reader_ll_t *next = parser->cursor->next;
|
||||
if (!next)
|
||||
return NULL;
|
||||
|
||||
return next->token;
|
||||
}
|
||||
|
||||
// Consume token at cursor and move to the next
|
||||
static fzl_token_t *consume(fzl_parser_t *parser)
|
||||
{
|
||||
@@ -205,7 +192,6 @@ fzl_node_t *parse_postfix(fzl_parser_t *parser)
|
||||
return NULL;
|
||||
|
||||
fzl_node_t *left = parse_primary(parser);
|
||||
fzl_node_t *right = NULL;
|
||||
|
||||
if (!left)
|
||||
{
|
||||
@@ -767,6 +753,14 @@ fzl_node_t *parse_function(fzl_parser_t *parser)
|
||||
return NULL;
|
||||
|
||||
fzl_token_t *fn = consume(parser);
|
||||
if (fn->type != FZL_TOKTYPE_FUNCTION)
|
||||
{
|
||||
snprintf(plast_err, sizeof(plast_err),
|
||||
"'%s': expected keyword 'fn' at %ld:%ld", last_known_tok->filename,
|
||||
last_known_tok->ln, last_known_tok->cn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fzl_token_t *name = consume(parser);
|
||||
if (!name || name->type != FZL_TOKTYPE_NAME)
|
||||
{
|
||||
@@ -1131,7 +1125,7 @@ void fzl_freeast(fzl_node_t *root)
|
||||
|
||||
fzl_node_t *next = root->next;
|
||||
free(root);
|
||||
root = root->next;
|
||||
root = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ int fzl_read(fzl_reader_t *reader)
|
||||
token = add_single(reader, FZL_TOKTYPE_PERCENT);
|
||||
else if (curr == '=')
|
||||
token = add_single(reader, FZL_TOKTYPE_EQ);
|
||||
else if (curr >= 'A' && curr <= 'Z' || curr >= 'a' && curr <= 'z' ||
|
||||
else if ((curr >= 'A' && curr <= 'Z') || (curr >= 'a' && curr <= 'z') ||
|
||||
curr == '_')
|
||||
token = parse_name(reader);
|
||||
else if (curr >= '0' && curr <= '9')
|
||||
|
||||
@@ -64,7 +64,7 @@ fzl_walker_t *fzl_mkwalker(fzl_node_t *root)
|
||||
// --- Walking zone ---
|
||||
|
||||
// Convert type token to `fzl_type_t`
|
||||
const fzl_type_t tok_to_type(fzl_token_t *tok)
|
||||
fzl_type_t tok_to_type(fzl_token_t *tok)
|
||||
{
|
||||
if (tok->type == FZL_TOKTYPE_NAME)
|
||||
return FZL_TYPE_OBJECT;
|
||||
@@ -403,7 +403,7 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
|
||||
}
|
||||
|
||||
// NOTE: add sym_top limit check
|
||||
size_t lvl = walker->sym_top;
|
||||
ssize_t lvl = walker->sym_top;
|
||||
walker->syms[walker->sym_top++] = fzl_mksymt();
|
||||
|
||||
fzl_walk_ctx_t *newctx = nest_ctx(walker, FZL_WALK_CTX_TYPE_FN);
|
||||
@@ -939,7 +939,6 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
|
||||
}
|
||||
else if (node->token->type == FZL_TOKTYPE_NULL_LITERAL)
|
||||
{
|
||||
fzl_token_t *tok = node->token;
|
||||
push_op(walker, FZL_OPCODE_PUSHNUM);
|
||||
push_word(walker, 0);
|
||||
push_op(walker, FZL_OPCODE_DEREFERENCE);
|
||||
@@ -1145,7 +1144,7 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
|
||||
if (obj_res.error)
|
||||
return obj_res;
|
||||
|
||||
fzl_ctable_t *ct;
|
||||
fzl_ctable_t *ct = NULL;
|
||||
for (size_t i = 0; i < walker->classes_count; i++)
|
||||
{
|
||||
if (strcmp(obj_res.classname, walker->classes[i]->name) == 0)
|
||||
@@ -1164,7 +1163,7 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
|
||||
return (fzl_walk_res_t){.error = true, .error_msg = wlast_err};
|
||||
}
|
||||
|
||||
fzl_ctable_field_t *ctf;
|
||||
fzl_ctable_field_t *ctf = NULL;
|
||||
for (size_t i = 0; i < ct->fields_count; i++)
|
||||
{
|
||||
if (strcmp(field_node->memb.field->token->value,
|
||||
|
||||
@@ -24,7 +24,7 @@ bool fzl_consts_equal(fzl_const_t a, fzl_const_t b)
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint32_t fzl_hash_const(fzl_const_t c)
|
||||
uint32_t fzl_hash_const(fzl_const_t c)
|
||||
{
|
||||
uint32_t hash = 2166136261u;
|
||||
const uint8_t *data = NULL;
|
||||
@@ -58,20 +58,20 @@ fzl_const_hash_pool_t *fzl_mkconstpool()
|
||||
pool->slots_count = 0;
|
||||
pool->slots_capacity = 16;
|
||||
pool->slots = malloc(pool->slots_capacity * sizeof(fzl_const_hash_slot_t));
|
||||
for (int i = 0; i < pool->slots_capacity; i++)
|
||||
for (size_t i = 0; i < pool->slots_capacity; i++)
|
||||
pool->slots[i].pool_index = -1;
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
static void fzl_consts_pool_resize_hash(fzl_const_hash_pool_t *pool)
|
||||
void fzl_consts_pool_resize_hash(fzl_const_hash_pool_t *pool)
|
||||
{
|
||||
int old_capacity = pool->slots_capacity;
|
||||
fzl_const_hash_slot_t *old_slots = pool->slots;
|
||||
|
||||
pool->slots_capacity = old_capacity * 2;
|
||||
pool->slots = malloc(pool->slots_capacity * sizeof(fzl_const_hash_slot_t));
|
||||
for (int i = 0; i < pool->slots_capacity; i++)
|
||||
for (size_t i = 0; i < pool->slots_capacity; i++)
|
||||
pool->slots[i].pool_index = -1;
|
||||
pool->slots_count = 0;
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ bool fzl_linked_add_files(fzl_linked_t *l, char **files, size_t files_count)
|
||||
.end = current_start + file_sz - 1};
|
||||
|
||||
if (!l->source)
|
||||
l->source = malloc(file_sz);
|
||||
l->source = malloc(file_sz + 1);
|
||||
else
|
||||
l->source = realloc(l->source, current_start + file_sz);
|
||||
l->source = realloc(l->source, current_start + file_sz + 1);
|
||||
|
||||
if (!l->source)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ fzl_options_t *fzl_mkoptions(int argc, char **argv)
|
||||
return opts;
|
||||
}
|
||||
|
||||
size_t i;
|
||||
int i;
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] != '-')
|
||||
@@ -108,7 +108,7 @@ fzl_options_t *fzl_mkoptions(int argc, char **argv)
|
||||
{
|
||||
printf("%sError%s: flags should go before source files list.\n", FZL_CERROR,
|
||||
FZL_CRST);
|
||||
printf("Remain %zu arguments are not handled.\n", argc - 1 - i);
|
||||
printf("Remain %d arguments are not handled.\n", argc - 1 - i);
|
||||
|
||||
free(files);
|
||||
free(opts);
|
||||
|
||||
+10
-1
@@ -650,8 +650,17 @@ int fzl_vm_run(fzl_vm_t *vm)
|
||||
break;
|
||||
|
||||
case FZL_OPCODE_JMP:
|
||||
vm->ip = vm->ops[++vm->ip] - 1;
|
||||
{
|
||||
if (vm->ops_count >= vm->ip)
|
||||
{
|
||||
snprintf(last_err, sizeof(last_err),
|
||||
"runtime error - expected JMP addr");
|
||||
return -1;
|
||||
}
|
||||
uint64_t jmp_ip = vm->ops[++vm->ip];
|
||||
vm->ip = jmp_ip - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case FZL_OPCODE_AND:
|
||||
if (vm->dtop < 2)
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <string.h>
|
||||
#include <vm/fzl_vm_env.h>
|
||||
|
||||
static const fzl_value_t null = {.type = FZL_TYPE_NULL};
|
||||
|
||||
fzl_vm_env_t *fzl_mkenv()
|
||||
{
|
||||
fzl_vm_env_t *env = malloc(sizeof(fzl_vm_env_t));
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ run_args_t *parse_args(int argc, char **argv)
|
||||
args->help = false;
|
||||
args->debug = false;
|
||||
|
||||
for (size_t i = 0; i < argc; i++)
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] != '-')
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user