sic

The sic programming language, compiler and tools (WIP)
Log | Files | Refs

commit c0e066466b66293808a97943b1c8bd6018c1025c
parent 43cf39ebd945e897f872040f6ffec6f39560f6c3
Author: citbl <citbl@citbl.org>
Date:   Sat,  9 May 2026 21:18:03 +1000

reformat

Diffstat:
M.clang-format | 6+++---
Mmakefile | 4+++-
Msrc/common.h | 14+++++++-------
Msrc/lexer.c | 7+++----
Msrc/lexer.h | 2+-
Msrc/main.c | 11+++++++----
Msrc/utils.c | 18++++++++++--------
Msrc/utils.h | 4++--
8 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/.clang-format b/.clang-format @@ -1,8 +1,8 @@ UseTab: Never IndentWidth: 4 TabWidth: 4 -ColumnLimit: 0 +ColumnLimit: 150 SpacesBeforeTrailingComments: 2 -PointerAlignment: Left +PointerAlignment: Right AlignArrayOfStructures: Right -#AlignConsecutiveAssignments: Consecutive +AlignConsecutiveAssignments: Consecutive diff --git a/makefile b/makefile @@ -2,7 +2,9 @@ cmp = clang warn = -Wall -Wextra pedantic = -Werror release = -02 +std = -std=c99 sane = -fsanitize=address +silly = -Wdeclaration-after-statement -Werror=declaration-after-statement cfiles = src/**.c includes = -i src/**.h out = -o sicc @@ -10,4 +12,4 @@ out = -o sicc export ASAN_OPTIONS := allocator_may_return_null=1 default: - $(cmp) $(warn) $(out) $(cfiles) + $(cmp) $(warn) $(std) $(silly) $(out) $(cfiles) diff --git a/src/common.h b/src/common.h @@ -51,23 +51,23 @@ typedef enum Keyword { typedef struct Token { TokenType type; union Value { - char* as_string; + char *as_string; char as_char; size_t as_int; bool as_bool; } value; - const char* path; - const char* filename; + const char *path; + const char *filename; size_t line; size_t col; } Token; typedef struct Lexer { - const char* code; - const char* path; - const char* filename; + const char *code; + const char *path; + const char *filename; size_t pos; - Token* tokens; + Token *tokens; size_t count; size_t cap; } Lexer; diff --git a/src/lexer.c b/src/lexer.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <stdlib.h> -static void add_token(Lexer* l, Token t) { +static void add_token(Lexer *l, Token t) { if (l->count >= l->cap) { l->cap *= 2; l->tokens = realloc(l->tokens, l->cap * sizeof(Token)); @@ -11,10 +11,9 @@ static void add_token(Lexer* l, Token t) { l->tokens[l->count++] = t; } -Lexer* lexer_lex(Lexer* l) { - l->tokens = calloc(250, sizeof(Token)); - +Lexer *lexer_lex(Lexer *l) { Token tok = {0}; + l->tokens = calloc(250, sizeof(Token)); add_token(l, tok); return l; } diff --git a/src/lexer.h b/src/lexer.h @@ -2,4 +2,4 @@ #include "common.h" -Lexer* lexer_lex(Lexer* lexer); +Lexer *lexer_lex(Lexer *lexer); diff --git a/src/main.c b/src/main.c @@ -2,22 +2,25 @@ #include "utils.h" #include <stdio.h> -int main(int argc, char** args) { +int main(int argc, char **args) { + char *filename; + char *contents; + Lexer lexer = {0}; + if (argc < 1) return 1; - char* filename = args[1]; + filename = args[1]; if (filename == NULL) return 1; - char* contents = read_file(filename); + contents = read_file(filename); if (contents == NULL) return 1; printf("%s\n", contents); - Lexer lexer = {0}; lexer = *lexer_lex(&lexer); return 0; diff --git a/src/utils.c b/src/utils.c @@ -2,10 +2,10 @@ #include <stdlib.h> #include <string.h> -char* read_file(const char* filename) { - FILE* fp = fopen(filename, "r"); +char *read_file(const char *filename) { + FILE *fp = fopen(filename, "r"); if (fp == NULL) { - // Handle file not found + fprintf(stderr, "file not found\n"); return NULL; } @@ -13,7 +13,7 @@ char* read_file(const char* filename) { long fsize = ftell(fp); fseek(fp, 0, SEEK_SET); - char* source = malloc(fsize + 1); + char *source = malloc(fsize + 1); fread(source, fsize, 1, fp); fclose(fp); @@ -21,16 +21,18 @@ char* read_file(const char* filename) { return source; } -void separate_file_from_path(const char* fullpath, char** out_path, char** out_filename) { - char* path = strdup(fullpath); - char* filename = strrchr(path, '/'); +void separate_file_from_path(const char *fullpath, char **out_path, char **out_filename) { + char *path = strdup(fullpath); + char *filename = strrchr(path, '/'); + if (filename == NULL) { printf("No path found\n"); exit(1); } + *filename = '\0'; filename++; - *out_path = strdup(path); + *out_path = strdup(path); *out_filename = strdup(filename); free(path); } diff --git a/src/utils.h b/src/utils.h @@ -1,5 +1,5 @@ #pragma once -char* read_file(const char* filename); +char *read_file(const char *filename); -void separate_file_from_path(const char* fullpath, char** out_path, char** out_filename); +void separate_file_from_path(const char *fullpath, char **out_path, char **out_filename);