commit 57e454b408baa58afa805b79fc34a9771630c4d2
parent f437a5f5768026fb458cb71cdf2ffd2cce3b2e0c
Author: m21c <ho*******@gmail.com>
Date: Fri, 8 Mar 2024 10:24:38 +0100
changed section comments
Diffstat:
| M | compiler.c | | | 144 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
1 file changed, 119 insertions(+), 25 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -7,6 +7,8 @@
#include <stdbool.h>
#include <string.h>
+// @section forward declarations {{{
+
typedef unsigned char uchar;
typedef unsigned int uint;
@@ -64,7 +66,9 @@ struct Block Block;
-/* SECTION: - node kind table - */
+// }}}
+
+// @section node kind table {{{
#define SENDOFFILE "end-of-file"
#define SINVALID "invalide token"
@@ -232,7 +236,9 @@ struct Block Block;
-/* SECTION: - type kind table - */
+// }}}
+
+// @section type kind table {{{
#define TYPETAB \
/* tag , size , align*/ \
@@ -298,7 +304,9 @@ struct Block Block;
-/* SECTION: - enumerations & constants - */
+// }}}
+
+// @section enumerations & constants {{{
typedef
enum Flags {
@@ -442,7 +450,9 @@ enum ConductKind {
-/* SECTION: - type definitions - */
+// }}}
+
+// @section type definitions {{{
typedef
struct SrcLoc {
@@ -742,14 +752,17 @@ struct Analysis {
+// }}}
-/* SECTION: - global-vars - */
+// @section global-vars {{{
Source testsource;
-/* SECTION: - look-up tables - */
+// }}}
+
+// @section look-up tables {{{
#define defaultloc {0, 1, "<builtin>"}
@@ -811,7 +824,10 @@ const uint8_t opinfo[] = {
-/* SECTION: - utility functions - */
+// }}}
+
+// @section utility functions {{{
+
#ifndef lengthof
#define lengthof(array) ((int) sizeof(array) / (int) sizeof(*(array)))
@@ -871,7 +887,9 @@ mystrcasecmp(const char *str1, const char *str2)
-/* SECTION: - pre-lexer - */
+// }}}
+
+// @section pre-lexer {{{
static void
tryprompt(Source *source, const char ch);
@@ -955,7 +973,9 @@ advance:
-/* SECTION: - keyword map - */
+// }}}
+
+// @section keyword map {{{
#define KEYWORD_MAP_SIZE 128
const char *keywordkeys[KEYWORD_MAP_SIZE];
@@ -1016,7 +1036,9 @@ getkeyword(const char *str, int n)
-/* SECTION: - string map - */
+// }}}
+
+// @section string map {{{
typedef
struct StringEntry {
@@ -1141,7 +1163,9 @@ getstringkey(StringMap *map, const char *str, int n)
-/* SECTION: - error reporting - */
+// }}}
+
+// @section error reporting {{{
static int
warn(SrcLoc *loc, const char *fmt, ...)
@@ -1185,7 +1209,9 @@ error(SrcLoc *loc, const char *fmt, ...)
-/* SECTION: - lexer - */
+// }}}
+
+// @section lexer {{{
#define nextindent(source, indent) \
((indent) + (source)->tabwidth - ((indent) % (source)->tabwidth))
@@ -1199,6 +1225,8 @@ error(SrcLoc *loc, const char *fmt, ...)
#define nextchar(source) \
((source)->line[++(source)->currloc.column])
+// @sub-section tokenize keyword / identifier {{{
+
static int
tokenizealphanumeric(Source *source, register int ch)
{
@@ -1240,6 +1268,10 @@ tokenizealphanumeric(Source *source, register int ch)
return source->tok.kind = IDENT;
}
+// }}}
+
+// @sub-section tokenize number {{{
+
static Type *
suffixfloattype(Source *source, const char *end)
{
@@ -1413,6 +1445,10 @@ advancenum:
return source->tok.kind = NUMBER;
}
+// }}}
+
+// @sub-section tokenize string {{{
+
static int
tokenizestring(Source *source, register int ch)
{
@@ -1486,6 +1522,10 @@ tokenizestring(Source *source, register int ch)
return source->tok.kind = STRING;
}
+// }}}
+
+// @sub-section tokenizer {{{
+
static int
gettok(Source *source)
{
@@ -1656,6 +1696,10 @@ skipwhite:
#undef select
}
+// }}}
+
+// @sub-section tokenizer utilities {{{
+
static void
pushbacktok(Source *source, Node *tok)
{
@@ -1738,8 +1782,13 @@ getunarysuffix(Source *source)
}
}
+// }}}
+
+
-/* SECTION: - ast-node */
+// }}}
+
+// @section ast-node {{{
Node *poolednodes;
Node nodebuf[4096];
@@ -1820,7 +1869,9 @@ deletenode(Node *node)
-/* SECTION: - type-struct - */
+// }}}
+
+// @section type-struct {{{
Type typebuf[4096];
int typetop;
@@ -1839,7 +1890,9 @@ maketype(SrcLoc *loc, Type *orig, Type *target)
-/* SECTION: - annotation - */
+// }}}
+
+// @section annotation {{{
Annot annotbuf[4096];
int annottop;
@@ -1880,7 +1933,9 @@ makedocket(Node *node)
-/* SECTION: - environment - */
+// }}}
+
+// @section environment {{{
Env envbuf[4096];
int envtop;
@@ -2069,7 +2124,9 @@ deleteenv(Env *env)
-/* SECTION: - declaration - */
+// }}}
+
+// @section declaration {{{
Decl declbuf[4096];
int decltop;
@@ -2182,7 +2239,9 @@ defertypedeclaration(Source *source, int key)
-/* SECTION: - parser - */
+// }}}
+
+// @section parser {{{
#define getkind(source) \
((source)->tok.kind)
@@ -2214,6 +2273,8 @@ expect(Source *source, int kind, const char *fmt, ...)
return true;
}
+// @sub-section read annotations {{{
+
static AnnotParam *
readannotparam(Source *source)
{
@@ -2325,6 +2386,10 @@ readannots(Source *source)
}
}
+// }}}
+
+// @sub-section read statement list {{{
+
static bool
checkend(Source *source, bool hastail, int needindent,
const char *expecterrmsg)
@@ -2445,6 +2510,10 @@ stmtlist(Source *source, int indent, EnvKind envkind,
return head;
}
+// }}}
+
+// @sub-section read declaration {{{
+
static int
qualifiers(Source *source, int allowmask)
{
@@ -2765,6 +2834,10 @@ finish:
return result;
}
+// }}}
+
+// @sub-section read atom {{{
+
static Node *
readident(Source *source, int flags)
{
@@ -3252,6 +3325,10 @@ readatom(Source *source, int flags)
return lhs;
}
+// }}}
+
+// @sub-section read expression {{{
+
static Node *
readexpr(Source *source, int minprec)
{
@@ -3394,9 +3471,13 @@ exprlist(Source *source, bool isparam, Type *paramtype)
return lhs;
}
+// }}}
-/* SECTION: - type-checking & folding - */
+
+// }}}
+
+// @section type-checking & folding {{{
static bool
isinttype(Type *ty)
@@ -4339,7 +4420,9 @@ foldexpr(Env *env, Node *expr)
-/* SECTION: - data-flow analysis - */
+// }}}
+
+// @section data-flow analysis {{{
/*
In order to do DFA, we divide the code of a scope into sections.
@@ -4780,7 +4863,7 @@ dataflow(Block *block, Node *expr)
-/* SECTION: - data-flow analysis version 2 */
+/* @section data-flow analysis version 2 */
static void
fetchsections(Analysis *analysis, Node *expr)
@@ -4802,11 +4885,16 @@ dataflow2(Analysis *analysis, Node *expr)
-/* SECTION: - intermediate code generation - */
+// }}}
+// @section intermediate code generation {{{
-/* SECTION: - print ast - */
+
+
+// }}}
+
+// @section print ast {{{
static void
promptenvpath(Env* currenv)
@@ -5695,7 +5783,9 @@ printexpr(FILE *out, Node *expr, int indent)
-/* SECTION: - init source - */
+// }}}
+
+// @section init source {{{
static void
initsource(Source *source, const char *filename, FILE *file)
@@ -5714,7 +5804,9 @@ initsource(Source *source, const char *filename, FILE *file)
-/* SECTION: - main-routine - */
+// }}}
+
+// @section main-routine {{{
const char *
isolatecommand(char **string)
@@ -5950,3 +6042,5 @@ main(int argc, char **argv)
return 0;
}
+
+// }}}