diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-01-01 19:31:12 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-01-01 19:31:12 +0100 |
commit | 69fe7b182a1eedfb75c611f7dd35fa60200426f4 (patch) | |
tree | 329a0c6cc9b06c23d8782ece09f0f7dfa9b16b13 /minic | |
download | compilertests-69fe7b182a1eedfb75c611f7dd35fa60200426f4.tar.gz compilertests-69fe7b182a1eedfb75c611f7dd35fa60200426f4.tar.bz2 |
initial checkin
Diffstat (limited to 'minic')
-rw-r--r-- | minic/README | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/minic/README b/minic/README new file mode 100644 index 0000000..56ac241 --- /dev/null +++ b/minic/README @@ -0,0 +1,159 @@ +mission +------- + +minimal C to program the kernel. + +design desicions +---------------- + +Do we allow structs, functions etc. We could go with global variables +only and basic types, makes the compiler simpler, but the code maybe +not so well-structured. + +The kind of C dialect we use is a simplified version, so we +rather write i = i + 1 than i++, ++i + +Constructs we need +------------------ + +From CPP +-------- + +In principle we would like to avoid having to implement CPP +funtionality, but.. + +header file includes +-------------------- + +#include "filename.h" (but we can go without preprocessor and make it +a special command in the language itself. We don't want and need +preprocessor tricks (we think). + +include guards +-------------- + +#import "a.h" is deprectated in gcc, was Microsoft extension and +Objective-C. + +ok, no go then. + +#pragma once in a.h + +very simple to implement, avoids clashes of names of guard macros, +which is very good. + +instead of + +#ifndef XXXX +#define XXXX +#include "a.h" +#endif + +We could implement a simple preprocessor functionality which only +works with defined symbols (names and no values). + +platform switches +----------------- + +#ifdef HOSTED +#define print(X) puts(X) +#else +// our own function print to our kernel +#endif + +alternatives? + +Linking to specific implementation files io-host.c vs io-minios.c + +debug code +---------- + +#ifdef DEBUG +#endif + +constants +--------- + +for array dimentions mainly. + +#define ACONSTANT 5 +int b[ACONSTANT]; + +constants can be done with 'enum { ACONSTANT = 5 };' + +No this is really a problem when parts of standard C require a macro +processor just to define things like NULL: + +#if !defined(NULL) + #define NULL ((void*)0) +#endif + +runtime +------- + +We need a minimalistic runtime (basically the functions needed to write +the self-compiling first-stage compiler). + +crt0 type entry points: + +raise +_start +_exit + +testing +------- + +From the simplest test program on, make sure we generate some output +and verify it! Even if this means we must write special bootstrap test +code.. + +Make sure we can output all phases of the compiler, lexing/parsing, +semantics, code generation, etc. + +Have a pseudo code generator like "cucu", or maybe better something +which even runs (Jasmin, Java byte-code), cucu has a Python interpreter +for the pseudo assembler. The real target we should postpone, as it +involves linking, ELF, GPT, Intel assembly code and other things which +complicate issues in the beginning. + +Also having a small virtual CPU as in Oberon (where the virtual CPU +actually can get real :-) ) or as in +http://schweigi.github.io/assembler-simulator/instruction-set.html +is an idea. +The idea is even usable for a running system like +erlm.github.io/OberonEmulator/ + +header files +------------ + +Generate them, later make the compiler self-aware of source files +in Oberon-style. For bootstrapping via another C compiler we +need simple header file (#pragma once only, #include only in the +C file. For including things which are prerequisites either: +- the program can define a global series of includes +- the library or component (like minilib) defines a facade header + file + +generating header files: +http://www.hwaci.com/sw/mkhdr/ + +But, we would like the minic compiler to do this, not yet another +tool in the chain. + +makeheaders plays too many tricks with preprocessors. Another possibility +is to have a modified C with other constructs which then first gets +converted into plain C89 with full-preprocessor support. + +io.c: + +typedef struct Io { +} Io; + +implicit +-> #include "io.h" + +declaration gets moved into io.h + +user of a module uses: + +import io; |