Index: arch/typesize.c ================================================================== --- arch/typesize.c +++ arch/typesize.c @@ -27,14 +27,14 @@ found_ofs = 1, sflag(type_offset, "signed " #type); \ } int main() { int found_sz = 0, found_ofs = 0, found_type = 0; - iflag(byte_bits,CHAR_BIT); + iflag(arch_byte_bits,CHAR_BIT); describe_integral(char,char); describe_integral(short,short); describe_integral(int,int); describe_integral(long,long); describe_integral(long long,llong); printf("\n"); return 0; } DELETED grammar/grammar.gpp Index: grammar/grammar.gpp ================================================================== --- grammar/grammar.gpp +++ grammar/grammar.gpp @@ -1,18 +0,0 @@ -#define flag -#1 -#define exec x -#define mode flag(#1)#2 -#define user U -#define meta M -#define add +#1 -#define del -#1 -#define unix_lf z -#define keepnl n -#define tri #1#2#3 -#define comment c -#define string s -#define quote q -#define eval S -#define evalquote Q -#define stack bal_stack bal_unstack -#define meta_grammar meta_start meta_end meta_arg_start meta_sep meta_arg_end stack -#define user_grammar call_start call_end arg_start arg_sep arg_end stack arg_num_char quote_char DELETED grammar/makefile Index: grammar/makefile ================================================================== --- grammar/makefile +++ grammar/makefile @@ -1,2 +0,0 @@ -${TMP}/%: %.gpp grammar.gpp - ${gpp} $< | tr "\n" ' ' > $@ DELETED grammar/precomp.g.gpp Index: grammar/precomp.g.gpp ================================================================== --- grammar/precomp.g.gpp +++ grammar/precomp.g.gpp @@ -1,25 +0,0 @@ -#include grammar.gpp -#mode comment "//" "\n" -// this file defines the "precomp" grammar, the grammar -// that's used to process C code templates -// vim: ft=c -#define call_start "[" -#define call_end "]" -#define arg_start " " -#define arg_sep ",\\w" -#define arg_end "]" -#define bal_stack "\([" -#define bal_unstack "\)]" -#define arg_num_char "\\$" -#define quote_char "|" -#define meta_start "\\w[" -#define meta_end "]\\w" -#define meta_arg_start " " -#define meta_sep "\\w:\\w" -#define meta_arg_end "]\\W" -add(unix_lf) -add(comment "---" "\\n") -add(comment "(*" "*)") -flag(exec) -mode(user, user_grammar) -mode(meta, meta_grammar) Index: kcore/def.h.m ================================================================== --- kcore/def.h.m +++ kcore/def.h.m @@ -1,31 +1,29 @@ ---- kcore/def.h.m → ---- ~ lexi hale ---- this file gathers information on the environment it's ---- being compiled in, setting macros that other headers ---- need. it will be emitted as . ---- vim: ft=c +dnl kcore/def.h.m → +dnl ~ lexi hale +dnl this file gathers information on the environment it's +dnl being compiled in, setting macros that other headers +dnl need. it will be emitted as . +dnl vim: ft=c #ifndef KIdef #define KIdef +define(`def',`#define $1 $2') + +ifdef(`atom_target_bits',` + define(`target',`atom_target_arch.atom_target_os.atom_target_bits') + def(KVbits,atom_target_bits)',` + define(`target',atom_target_arch.atom_target_os)') + +def(KVtarget,target) +def(KVos,atom_target_os) +def(KVarch,atom_target_arch) -[ifdef atom_target_bits] - [define target: [atom_target_arch].[atom_target_os].[atom_target_bits]] - #define KVbits [atom_target_bits] -[else] - [define target: [atom_target_arch].[atom_target_os]] -[endif] -#define KVtarget [target] -#define KVos [atom_target_os] -#define KVarch [atom_target_arch] -[if [target_unix] == yes] - #define KFenv_unix - #define KFenv_posix -[else] - [if [target_posix] == yes] - #define KFenv_posix - [endif] -[endif] +ifelse(target_unix,`yes', + `def(`KFenv_unix',) + def(`KFenv_posix',)',` + ifelse(target_posix,`yes', + `def(KFenv_posix)')') #define Kpragma(p) _Pragma(#p) #if defined(__GNUC__) || defined(__clang__) # define Kerror(msg) Kpragma(GCC error #msg) #else Index: kcore/makefile ================================================================== --- kcore/makefile +++ kcore/makefile @@ -6,11 +6,11 @@ # gen-headers = type.h include ../modmake ${OUT}/k/type.h: type.h.m ${TMP}/typesize.def - $(m-comp) $< $(file < ${TMP}/typesize.def) > $@ + $(m-comp) $(file < ${TMP}/typesize.def) $< > $@ ## the below code predates the introduction of gpp ## to generate these headers from templates instead ## of trying to write one for everypossible arch ## tuple. it is left as a monument to a terrible Index: kcore/type.h.m ================================================================== --- kcore/type.h.m +++ kcore/type.h.m @@ -1,11 +1,12 @@ ---- kcore/type.h.m → ---- ~ lexi hale ---- this file gathers information on the environment it's ---- being compiled in, defining types that our code ---- needs. it will be emitted as . ---- vim: ft=c +dnl kcore/type.h.m → +dnl ~ lexi hale +dnl this file gathers information on the environment it's +dnl being compiled in, defining types that our code +dnl needs. it will be emitted as . +dnl vim: ft=c +changequote(`“',`”') #ifndef KItype #define KItype /* we define 64-bit types first due to an oddity in how * 128-bit types are handled: we want kc_?big to reference @@ -20,111 +21,110 @@ * * once this is done, we can be certain that u128 will * reference the largest available integer type and can * safely define kc_?big by reference to it. */ -[ifdef type_bit64] - typedef unsigned [type_bit64] u64; - typedef signed [type_bit64] s64; - [ifndef type_bit128] + +ifdef(“type_bit64”,“ + typedef unsigned type_bit64 u64; + typedef signed type_bit64 s64; + ifdef(“type_bit128”,,“ /* even if no native type is 128 bits long, clang and * gcc have extensions to support 128 bit arithmetic * on 64-bit hardware */ # if defined(__GNUC__) || defined(__clang__) - typedef unsigned __int128_t u128; - typedef signed __int128_t s128; + typedef __uint128_t u128; + typedef __int128_t s128; # else - /* if we don't have access to that extension + /* if we don`'t have access to that extension * or native 128-bit types, then we just use * the largest native type specified in the * C standard */ typedef unsigned long long u128; typedef signed long long s128; # endif - [endif] -[else] + ”)”,“dnl typedef unsigned long long u64; typedef signed long long s64; typedef u64 u128; typedef s64 s128; -[endif] +”)dnl -[ifdef type_bit128] - typedef unsigned [type_bit128] u128; - typedef signed [type_bit128] s128; -[endif] +ifdef(“type_bit128”,“dnl + typedef unsigned type_bit128 u128; + typedef signed type_bit128 s128; +”)dnl typedef unsigned char ubyte; typedef signed char sbyte; typedef u128 ubig; typedef s128 sbig; -[ifdef type_bit8] - typedef unsigned [type_bit8] u8; - typedef signed [type_bit8] s8; -[else] +ifdef(“type_bit8”,“dnl + typedef unsigned type_bit8 u8; + typedef signed type_bit8 s8; +”,“dnl typedef ubyte u8; typedef sbyte s8; -[endif] +”)dnl -[ifdef type_bit16] - typedef unsigned [type_bit16] u16; - typedef signed [type_bit16] s16; -[else] +ifdef(“type_bit16”,“ + typedef unsigned type_bit16 u16; + typedef signed type_bit16 s16; +”,“ typedef ubig u16; typedef sbig s16; -[endif] +”)dnl -[ifdef type_bit32] - typedef unsigned [type_bit32] u32; - typedef signed [type_bit32] s32; -[else] +ifdef(“type_bit32”,“ + typedef unsigned type_bit32 u32; + typedef signed type_bit32 s32; +”,“ typedef ubig u32; typedef sbig s32; -[endif] +”)dnl enum /* max-min values of each type */ { - byte_bits = [byte_bits], + byte_bits = arch_byte_bits, u8_min = 0, u8_max = ((u8)-1), u16_min = 0, u16_max = ((u16)-1), u32_min = 0, u32_max = ((u32)-1), - u64_min = 0, u32_max = ((u64)-1), + u64_min = 0, u64_max = ((u64)-1), u128_min = 0, u128_max = ((u128)-1), /* assuming two's complement. TODO: check math */ - [define merge: $1$2] - [define [sspec type]: - [merge [type],_min] = 0 - ((1 << sizeof([type]) * kc_byte_bits) / 2), - [merge [type],_max] = (1 << sizeof([type]) * kc_byte_bits) / 2 - 1] + define(“sspec”,“ + $1_min = 0 - ((1 << sizeof($1) * byte_bits) / 2), + $1_max = (1 << sizeof($1) * byte_bits) / 2 - 1”)dnl - [sspec s8], [sspec s16], [sspec s32], - [sspec s64], [sspec s128], + sspec(s8), sspec(s16), sspec(s32), + sspec(s64), sspec(s128), - kc_uchar_min = 0, kc_uchar_max = [type_max_u_char], - kc_ushort_min = 0, kc_ushort_max = [type_max_u_short], - kc_uint_min = 0, kc_uint_max = [type_max_u_int], - kc_ulong_min = 0, kc_ulong_max = [type_max_u_long], - kc_ullong_min = 0, kc_ullong_max = [type_max_u_llong], + kc_uchar_min = 0, kc_uchar_max = type_max_u_char, + kc_ushort_min = 0, kc_ushort_max = type_max_u_short, + kc_uint_min = 0, kc_uint_max = type_max_u_int, + kc_ulong_min = 0, kc_ulong_max = type_max_u_long, + kc_ullong_min = 0, kc_ullong_max = type_max_u_llong, - kc_schar_min = [type_min_s_char], kc_schar_max = [type_max_s_char], - kc_sshort_min = [type_min_s_short], kc_sshort_max = [type_max_s_short], - kc_sint_min = [type_min_s_int], kc_sint_max = [type_max_s_int], - kc_slong_min = [type_min_s_long], kc_slong_max = [type_max_s_long], - kc_sllong_min = [type_min_s_llong], kc_sllong_max = [type_max_s_llong], + kc_schar_min = type_min_s_char, kc_schar_max = type_max_s_char, + kc_sshort_min = type_min_s_short, kc_sshort_max = type_max_s_short, + kc_sint_min = type_min_s_int, kc_sint_max = type_max_s_int, + kc_slong_min = type_min_s_long, kc_slong_max = type_max_s_long, + kc_sllong_min = type_min_s_llong, kc_sllong_max = type_max_s_llong, ubig_min = u128_min, ubig_max = u128_max, sbig_min = s128_min, sbig_max = s128_max, ubyte_min = kc_uchar_min, ubyte_max = kc_uchar_max, sbyte_min = kc_schar_min, sbyte_max = kc_schar_max, }; -[ifdef type_sz] - typedef [type_sz] sz; -[else] +ifdef(“type_sz”,“ + typedef type_sz sz; +”,“dnl # ifdef __cplusplus /* C++ gives us a clean, standardized way to do this */ typedef decltype (sizeof(char)) sz; # else # if defined(__GNUC__) || defined(__clang__) @@ -135,15 +135,15 @@ # warning no authoritative sz (size_t) type definition \ available; defaulting to largest unsigned integer type typedef ubig sz; # endif # endif -[endif] +”)dnl -[ifdef type_offset] - typedef [type_offset] offset; -[else] +ifdef(“type_offset”,“ + typedef type_offset offset; +”,“dnl # ifdef __cplusplus /* C++ gives us a clean, standardized way to do this */ typedef decltype (((void*)-1) - 1) offset; # else # if defined(__GNUC__) || defined(__clang__) @@ -154,29 +154,31 @@ # warning no authoritative offset (ptrdiff_t) type definition \ available; defaulting to largest unsigned integer type typedef sbig offset; # endif # endif -[endif] +”)dnl // exit status integer types - pls use kbad in instead -[if [target_posix] == yes] +ifelse(target_posix,“yes”,“ /* by convention, posix return values are 8-bit, * but note that many modern UNIXes do technically * support higher-bit values. for this reason, * longstat is defined differently under posix. */ typedef u8 stat; typedef u32 stat_long; -[else] - [if ([atom_target_os] == win) || - ([atom_target_os] == vms)] +”,“dnl + ifelse(atom_target_os,“win”,“ + typedef u32 stat; + ”,“dnl + ifelse(atom_target_os,“vms”,“ typedef u32 stat; - [else] + ”,“dnl typedef u8 stat; /* we don't know a specific exit status type * for your arch so we're going with a sane * default. if this is wrong, help us fix it! */ - [endif] + ”)”)dnl typedef stat stat_long; -[endif] +”)dnl #endif Index: libk.md ================================================================== --- libk.md +++ libk.md @@ -33,18 +33,16 @@ ## dependencies libk is designed to be as portable and depedency-free as possible. ideally, it will be possible to compile code against libk using nothing but libk itself. -compiling libk is also designed to be as easy as possible. it has only two external dependencies, the macro processor [gpp], needed for compile-time header generation , and the [GNU make] utility, whose advanced features are needed to perform the relatively complex task of building all of libk from the ground up. +compiling libk is also designed to be as easy as possible. it has only two external dependencies, the macro processor [m4], needed for compile-time header generation, and the [GNU make] utility, whose advanced features are needed to perform the relatively complex task of building all of libk from the ground up. - [gpp]: http://en.nothingisreal.com/wiki/GPP + [m4]: http://www.gnu.org/software/m4 [GNU make]: http://www.gnu.org/software/make -while gpp is a very small program that builds quickly and has no major dependencies of its own, it is an obscure program not likely to be found in any repositories and with an uncertain future. for these reasons, adding m4 translations of the gpp headers should be a long-term priority. being able to be built with both a very small, easily built macro processor, and a very large but extremely well-supported processor, should make libk maximally buildable and future-proof. - -while this project will include gpp tooling and GNU makefiles designed to ease the task of writing and building libk code (as well as tools in many other languages, including native binaries that compile against libk), none of them are required for the task. +a different macro processor, gpp, was used in early versions of libk, however, it was so obscure and took so much overly fragile infrastructure to make it work that the cleaner syntax just wasn't worth it; i've since deleted the gpp infra and ported the macro files to m4. ## naming conventions one of the most frustrating things about libc is its complete and total *lack* of a naming convention. in C, every function and global is injected into a single global namespace, including macros. this means that every libc header you include scatters words all over that namespace, potentially clobbering your function with a macro! Index: makefile ================================================================== --- makefile +++ makefile @@ -10,11 +10,11 @@ export TARGET = $(ARCH).$(OS).$(BITS) else export TARGET = $(ARCH).$(OS) endif -export gpp = gpp +export m4 = m4 export lin-headers = /usr/include/asm export fbsd-headers = /usr/include/sys moddirs = $(wildcard k*) binaries = $(wildcard k*/*.exe.c) @@ -93,28 +93,25 @@ lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX dbg: @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") -%.obj: %/makefile $(TMP)/precomp.g $(TARGET).calls $(OUT) +%.obj: %/makefile $(TARGET).calls $(OUT) cd $* && $(MAKE) obj -%.tool: %/makefile $(TMP)/precomp.g $(OUT) +%.tool: %/makefile $(OUT) cd $* && $(MAKE) tool %.dbg: %/makefile $(OUT) cd $* && $(MAKE) dbg -%.def: %/makefile $(TMP)/precomp.g $(TMP)/typesize.def $(OUT) $(OUT)/k +%.def: %/makefile $(TMP)/typesize.def $(OUT) $(OUT)/k cd $* && $(MAKE) def %.calls: arch/makefile cd arch && $(MAKE) $(TMP)/calls.$*.s -$(TMP)/precomp.g: grammar/precomp.g.gpp $(TMP) - cd grammar && $(MAKE) $@ - $(TMP)/typesize.def: arch/makefile $(TMP) cd arch && $(MAKE) $@ $(OUT)/libk.so: $(fnobjects) ld -shared $(COMPLIB) -o $@ $^ Index: modmake ================================================================== --- modmake +++ modmake @@ -11,11 +11,10 @@ tools = $(filter %.exe.c, $(src)) nontools = $(filter-out %.exe.c, $(src)) cobjects = $(filter %.c, $(nontools)) sobjects = $(filter %.${TARGET}.s, $(nontools)) -gpp = gpp cflags = -std=c11 -isystem ${OUT} -fPIC -nostdlib ${COMPLIB} -L${OUT} m-env = atom_target_arch=${ARCH} m-env += atom_target_os=${OS} ifneq (${BITS},) #!!! ifdef does NOT work with environment variables @@ -22,12 +21,11 @@ m-env += atom_target_bits=${BITS} endif m-env += target_posix=${POSIX} m-env += target_unix=${UNIX} -m-grammar = $(file < ${TMP}/precomp.g) -m-comp = $(gpp) $(m-grammar) $(m-env:%=-D%) +m-comp = ${m4} $(m-env:%=-D%) obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \ $(sobjects:%.s=${OUT}/$(mod).%.o) tool: $(tools:%.exe.c=${OUT}/$(mod).%) \ ${OUT}/libk.a @@ -40,11 +38,10 @@ @echo TARGET = ${TARGET} @echo cobjects = $(cobjects) @echo sobjects = $(sobjects) @echo headers = $(headers) @echo m-comp = $(m-comp) - @echo m-grammar = $(m-grammar) @echo m-env = $(m-env) "$(m-env:%=-D%)" @echo mod = $(mod) ${OUT}/k/%.h: %.h.m $(m-comp) $< > $@