Aria

A low-level systems programming language
git clone git://git.m21c.me/Aria.git
Log | Files | Refs | LICENSE

commit 5220505b31fc359c629bfec08b519d54afbc8cee
parent aea94da4800cedfc179539b45fc8c425f2dc7591
Author: m21c <ho*******@gmail.com>
Date:   Sun, 28 Mar 2021 17:18:58 +0200

changed coding-style for better searchability

Diffstat:
Maria.c | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 99 insertions(+), 49 deletions(-)

diff --git a/aria.c b/aria.c @@ -8,7 +8,8 @@ #include <string.h> -static int mystrncasecmp(const char *str1, const char *str2, size_t max_len) +static int +mystrncasecmp(const char *str1, const char *str2, size_t max_len) { char tmp1[] = {'\0', '\0'}; char tmp2[] = {'\0', '\0'}; @@ -36,7 +37,8 @@ static int mystrncasecmp(const char *str1, const char *str2, size_t max_len) return 0; } -static int mystrcasecmp(const char *str1, const char *str2) +static int +mystrcasecmp(const char *str1, const char *str2) { char tmp1[] = {'\0', '\0'}; char tmp2[] = {'\0', '\0'}; @@ -60,7 +62,8 @@ static int mystrcasecmp(const char *str1, const char *str2) /* - forward declarations - */ -typedef struct Node Node; +typedef +struct Node Node; /* - type struct - */ @@ -95,7 +98,8 @@ enum { #define TSSIZE TS64 /* TODO(m21c): maybe add long double type ? */ -typedef struct Type Type; +typedef +struct Type Type; struct Type { int kind; @@ -136,7 +140,8 @@ Type prim[] = { Type typebuf[4096]; int typetop; -Type *maketype(void) { +Type * +maketype(void) { return typebuf + typetop++; } @@ -146,7 +151,8 @@ char line[4096]; int currline, lastline; long linepos; -bool mygetline(FILE *in) { +bool +mygetline(FILE *in) { int i, l, c = getc(in); linepos = ftell(in); @@ -238,7 +244,8 @@ enum { PSTART = 0 }; -typedef struct Op { +typedef +struct Op { const char *debugstr; const char *str; @@ -308,7 +315,8 @@ const Op ops[] = { #define lengthof(array) ((int) sizeof(array) / (int) sizeof (*(array))) -typedef struct Keyword { +typedef +struct Keyword { const char *str; int len; @@ -345,7 +353,7 @@ enum { KFOR, KLOOP, KWHILE, KUNTIL }; -struct Keyword keywords[] = { +Keyword keywords[] = { {"void", 0, false, 0, true, TVOID}, {"bool", 0, false, 0, true, TBOOL}, @@ -408,14 +416,16 @@ struct Keyword keywords[] = { const char *keywordkeys[KEYWORD_MAP_SIZE]; int keywordvals[KEYWORD_MAP_SIZE]; -int strnhash(const char *str, int n) { +int +strnhash(const char *str, int n) { int hash = 5381, i; for (i = 0; i < n && str[i]; ++i) hash = (hash << 5) + hash + str[i]; return hash; } -void initkeywords(void) { +void +initkeywords(void) { int i, j, h; for (i = 0; i < lengthof(keywords); ++i) { int n = keywords[i].len = strlen(keywords[i].str); @@ -441,7 +451,8 @@ void initkeywords(void) { */ } -int getkeyword(const char *str, int n) { +int +getkeyword(const char *str, int n) { int i, h = strnhash(str, n) & (lengthof(keywordkeys) - 8); for (i = 0; i < 8; ++i, ++h) { @@ -455,12 +466,14 @@ int getkeyword(const char *str, int n) { return -1; } -typedef struct StringEntry { +typedef +struct StringEntry { int len; const char *str; } StringEntry; -typedef struct StringMap { +typedef +struct StringMap { int *keys; int keyscap; @@ -471,7 +484,8 @@ typedef struct StringMap { StringMap idents; StringMap strings; -void initstrmap(StringMap *map) +void +initstrmap(StringMap *map) { map->keys = calloc(32, sizeof(int)); map->keyscap = 32; @@ -483,7 +497,8 @@ void initstrmap(StringMap *map) assert(map->vals); } -void disposestrmap(StringMap *map) +void +disposestrmap(StringMap *map) { int i; for (i = map->valslen - 1; i >= 0; --i) { @@ -494,7 +509,8 @@ void disposestrmap(StringMap *map) free(map->keys); } -static void putstringkey(StringMap *map, int key, int hash) +static void +putstringkey(StringMap *map, int key, int hash) { int *keys = map->keys; StringEntry *vals = map->vals; @@ -523,7 +539,8 @@ redo: int auxthen; -int getstringkey(StringMap *map, const char *str, int n) +int +getstringkey(StringMap *map, const char *str, int n) { int *keys = map->keys; StringEntry *vals = map->vals; @@ -654,7 +671,8 @@ char stringbuf[1024]; int currcol, lastcol, lastindent, lastkind; Node tok; -int warn(const char *fmt, ...) { +int +warn(const char *fmt, ...) { va_list ap; int n; @@ -668,7 +686,8 @@ int warn(const char *fmt, ...) { return n; } -int error(const char *fmt, ...) { +int +error(const char *fmt, ...) { va_list ap; int n; @@ -685,7 +704,8 @@ int error(const char *fmt, ...) { #define nextindent(indent) \ ((indent) + tabwidth - ((indent) % tabwidth)) -int gettok(bool haslhs) { +int +gettok(bool haslhs) { register int c0 = line[currcol]; static bool hasnewline = false; @@ -1038,7 +1058,8 @@ skipwhite: /* - environment & declaration */ -typedef enum DeclKind { +typedef +enum DeclKind { DMODULE = 0, DTYPE, /* NOTE(m21c): maybe be the same as void-module ? */ DVAR, @@ -1049,8 +1070,11 @@ typedef enum DeclKind { */ } DeclKind; -typedef struct Decl Decl; -typedef struct Env Env; +typedef +struct Decl Decl; + +typedef +struct Env Env; struct Decl { DeclKind kind; @@ -1062,7 +1086,8 @@ struct Decl { Decl *prev, *next; }; -typedef enum EnvKind { +typedef +enum EnvKind { STOPLEVEL = 0, SFUNCTION, SSCOPE, @@ -1090,7 +1115,8 @@ int envtop; Env *currenv; -Decl *makedecl(int key, DeclKind kind) +Decl * +makedecl(int key, DeclKind kind) { const int cacheindex = (key >> 3) & 0x3f; const int cachebit = 1 << (key & 0x03); @@ -1118,7 +1144,8 @@ Decl *makedecl(int key, DeclKind kind) return decl; } -Decl *finddeclaration(int key) +Decl * +finddeclaration(int key) { const int cacheindex = (key >> 3) & 0x3f; const int cachebit = 1 << (key & 0x03); @@ -1140,7 +1167,8 @@ Decl *finddeclaration(int key) return NULL; } -Env *pushenv(EnvKind kind) +Env * +pushenv(EnvKind kind) { Env *env = envbuf + envtop++; @@ -1152,7 +1180,8 @@ Env *pushenv(EnvKind kind) return env; } -Env *popenv(void) +Env * +popenv(void) { Env *env = currenv; @@ -1162,7 +1191,8 @@ Env *popenv(void) return env; } -Env *getfuncenv(void) +Env * +getfuncenv(void) { Env *env; @@ -1179,7 +1209,8 @@ Env *getfuncenv(void) Node nodebuf[4096]; int nodetop; -Node *makenode(Node *lhs) +Node * +makenode(Node *lhs) { Node *node = nodebuf + nodetop++; *node = tok; @@ -1188,7 +1219,8 @@ Node *makenode(Node *lhs) return node; } -int printnode(FILE *out, Node *node) { +int +printnode(FILE *out, Node *node) { int n = 0, len, i; const char *str; @@ -1251,7 +1283,8 @@ int printnode(FILE *out, Node *node) { return n; } -int printast(Node *node, int indent) { +int +printast(Node *node, int indent) { int n, i; bool newline = false; @@ -1329,7 +1362,8 @@ int printast(Node *node, int indent) { /* - parser - */ -bool expect(int kind, bool nexthaslhs, const char *fmt, ...) +bool +expect(int kind, bool nexthaslhs, const char *fmt, ...) { va_list ap; @@ -1365,7 +1399,8 @@ enum { QINFER = QVAR, }; -int qualifiers(int allowmask) { +int +qualifiers(int allowmask) { int flags = 0, mask = allowmask; while (tok.kind == 'K') { @@ -1411,9 +1446,11 @@ finish: return flags; } -Node *expr(int minprec); +Node * +expr(int minprec); -Node *getbasetype(int flags) { +Node * +getbasetype(int flags) { Node *result; if (tok.kind == 'I') { @@ -1431,7 +1468,8 @@ Node *getbasetype(int flags) { return result; } -Node *gettype(Node *basetype) { +Node * +gettype(Node *basetype) { int flags; Type *ty; @@ -1468,10 +1506,14 @@ advance: return basetype; } -Node *exprlist(bool isparam, Node *paramtype); -Node *stmtlist(int indent); +Node * +exprlist(bool isparam, Node *paramtype); + +Node * +stmtlist(int indent); -Node *declaration(Node *typenode) { +Node * +declaration(Node *typenode) { bool has_self_param = false; Node *result = typenode; @@ -1529,13 +1571,15 @@ Node *declaration(Node *typenode) { return result; } -Node *tailof(Node *head) { +Node * +tailof(Node *head) { while (head->next) head = head->next; return head; } -bool isatom(void) { +bool +isatom(void) { switch (tok.kind) { case 0: case '\n': case ';': @@ -1558,7 +1602,8 @@ bool isatom(void) { return true; } -Node *stmtlist(int indent) { +Node * +stmtlist(int indent) { Node *result = NULL, *lhs = NULL; int needindent = nextindent(indent); /* printf("needident: %d, currindent: %d, lastindent: %d\n", needindent, currindent, lastindent); */ @@ -1610,7 +1655,8 @@ Node *stmtlist(int indent) { Node *lastis; -Node *atom(int flags) { +Node * +atom(int flags) { Node *lhs = NULL, *savedis = lastis; int indent; /* int flags; */ @@ -1862,7 +1908,8 @@ Node *atom(int flags) { return lhs; } -Node *expr(int minprec) { +Node * +expr(int minprec) { Node *lhs = atom(0), *last = NULL; /* only binary expr */ @@ -1900,7 +1947,8 @@ Node *expr(int minprec) { return lhs; } -Node *todeclaration(Node *curr, Node **ty) { +Node * +todeclaration(Node *curr, Node **ty) { if (*ty) { if (curr->kind == 'I') { Node *decl = makenode(*ty); @@ -1925,7 +1973,8 @@ Node *todeclaration(Node *curr, Node **ty) { return curr; } -Node *exprlist(bool isparam, Node *paramtype) { +Node * +exprlist(bool isparam, Node *paramtype) { Node *head, *tail; bool isdeclaration, typetuple; @@ -1974,7 +2023,8 @@ Node *exprlist(bool isparam, Node *paramtype) { /* - main-routine - */ -int main(int argc, char **argv) { +int +main(int argc, char **argv) { initkeywords(); initstrmap(&idents); initstrmap(&strings);