libk  Check-in [0c20d256a6]

Overview
Comment:port header macro files to m4; delete gpp infra; fix glaring syntax errors in kcore/type.h
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0c20d256a6feb4d2fc5394b0f4e215c6cbbeaf6ed6fe7c114aca01981db9839c
User & Date: lexi on 2019-07-27 05:28:14
Other Links: manifest | tags
Context
2019-08-18
10:20
fix kmheapa() and add kmheapf() check-in: 5279674525 user: lexi tags: trunk
2019-07-27
05:28
port header macro files to m4; delete gpp infra; fix glaring syntax errors in kcore/type.h check-in: 0c20d256a6 user: lexi tags: trunk
03:59
fix typo check-in: 85bec55157 user: lexi tags: trunk
Changes

Modified arch/typesize.c from [9ee84449d7] to [71add081ad].

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
		found_sz = 1, sflag(type_sz, "unsigned " #type); \
	if (!found_ofs && sizeof(type) == sizeof(ptrdiff_t)) \
		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);
	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;
}







|








25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
		found_sz = 1, sflag(type_sz, "unsigned " #type); \
	if (!found_ofs && sizeof(type) == sizeof(ptrdiff_t)) \
		found_ofs = 1, sflag(type_offset, "signed " #type); \
}

int main() {
	int found_sz = 0, found_ofs = 0, found_type = 0;
	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 version [89005aac7c].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#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 version [8c2d1af7ce].

1
2
${TMP}/%: %.gpp grammar.gpp
	${gpp} $< | tr "\n" ' ' > $@
<
<




Deleted grammar/precomp.g.gpp version [d33952f39e].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


















































Modified kcore/def.h.m from [9c53671363] to [694c1d32cc].

1
2
3
4
5
6
7
8

9
10
11

12
13
14
15

16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--- kcore/def.h.m → <k/def.h>
--- ~ lexi hale <lexi@hale.su>
--- this file gathers information on the environment it's
--- being compiled in, setting macros that other headers
--- need. it will be emitted as <k/def.h>.
--- vim: ft=c
#ifndef KIdef
#define KIdef


[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]

#define Kpragma(p) _Pragma(#p)
#if defined(__GNUC__) || defined(__clang__)
#   define Kerror(msg) Kpragma(GCC error #msg) 
#else
#   define Kerror(msg) Kpragma(message #msg)
#endif
#define Knoimpl(fn) Kerror(no implementation of fn for platform [target])

#endif
|
|
|
|
|
|


>

|
<
>
|
<
|
<
>
|
|
|
>
|
|
|
<
|
|
<
<










1
2
3
4
5
6
7
8
9
10
11

12
13

14

15
16
17
18
19
20
21
22

23
24


25
26
27
28
29
30
31
32
33
34
dnl kcore/def.h.m → <k/def.h>
dnl ~ lexi hale <lexi@hale.su>
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 <k/def.h>.
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)

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
#   define Kerror(msg) Kpragma(message #msg)
#endif
#define Knoimpl(fn) Kerror(no implementation of fn for platform [target])

#endif

Modified kcore/makefile from [f9fefae3d1] to [e2db22ecce].

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# so we're generating it at build time.

# gen-headers = type.h

include ../modmake

${OUT}/k/type.h: type.h.m ${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
## and now blissfully forgotten past.
#







|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# so we're generating it at build time.

# gen-headers = type.h

include ../modmake

${OUT}/k/type.h: type.h.m ${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
## and now blissfully forgotten past.
#

Modified kcore/type.h.m from [def2d33e25] to [6926347ff4].

1
2
3
4
5
6

7
8
9
10
11
12
13
..
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173


174
175
176
177
178
179
180
181
182
--- kcore/type.h.m → <k/type.h>
--- ~ lexi hale <lexi@hale.su>
--- this file gathers information on the environment it's
--- being compiled in, defining types that our code
--- needs. it will be emitted as <k/type.h>.
--- vim: ft=c

#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
 * the absolute largest type available to the compiler,
 * but in some cases, 128-bits may not be among the
................................................................................
 * that supports the 128-bit extension - but only if a
 * native 128-bit type is not available.
 * 
 * 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]
	/* 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;
#		else
			/* 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]
	typedef unsigned long long u64;
	typedef   signed long long s64;

	typedef u64 u128;
	typedef	s64 s128;
[endif]

[ifdef type_bit128]
	typedef unsigned [type_bit128] u128;
	typedef   signed [type_bit128] s128;
[endif]

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]

	typedef ubyte u8;
	typedef	sbyte s8;
[endif]

[ifdef type_bit16]
	typedef unsigned [type_bit16] u16;
	typedef   signed [type_bit16] s16;
[else]

	typedef ubig u16;
	typedef	sbig s16;
[endif]

[ifdef type_bit32]
	typedef unsigned [type_bit32] u32;
	typedef   signed [type_bit32] s32;
[else]

	typedef ubig u32;
	typedef	sbig s32;
[endif]

enum /* max-min values of each type */ {
	byte_bits = [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),
	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]


	[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_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 __cplusplus
 	   /* C++ gives us a clean, standardized way to do this */
 	   typedef decltype (sizeof(char)) sz;
#	else
#		if defined(__GNUC__) || defined(__clang__)
			typedef __typeof__ (sizeof(char)) sz;
#		else
................................................................................
			/* we're stumped - set sz to the safest possible value under
			 * the circumstances, and warn the user. */
#			warning no authoritative sz (size_t) type definition \
			        available; defaulting to largest unsigned integer type
			typedef ubig sz;
#		endif
#	endif
[endif]

[ifdef type_offset]
	typedef [type_offset] offset;
[else]

#	ifdef __cplusplus
 	   /* C++ gives us a clean, standardized way to do this */
		typedef decltype (((void*)-1) - 1) offset;
#	else
#		if defined(__GNUC__) || defined(__clang__)
			typedef __typeof__ (((void*)10) - ((void*)5)) offset;
#		else
................................................................................
			/* no dice - set offset to the safest possible value under
			 * the circumstances, and warn the user. */
#			warning no authoritative offset (ptrdiff_t) type definition \
			        available; defaulting to largest unsigned integer type
			typedef sbig offset;
#		endif
#	endif
[endif]

// exit status integer types - pls use kbad in <k/magic.h> instead
[if [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)]
		typedef u32 stat;
	[else]


		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]
	typedef stat stat_long;
[endif]

#endif
|
|
|
|
|
|
>







 







>
|
|
|
|




|
|

|






|
<





|

|
|
|
|






|
|
|
<
>


|

|
|
|
<
>


|

|
|
|
<
>


|


|




|



|
|
|
<

>
|
<

|
|
|
|
|

>
|
|
|
|
<








|
|
|







 







|

|
|
<
>







 







|


|






|
|
|
|
|
>
>




|

|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102

103
104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
dnl kcore/type.h.m → <k/type.h>
dnl ~ lexi hale <lexi@hale.su>
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 <k/type.h>.
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
 * the absolute largest type available to the compiler,
 * but in some cases, 128-bits may not be among the
................................................................................
 * that supports the 128-bit extension - but only if a
 * native 128-bit type is not available.
 * 
 * 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;
	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 __uint128_t u128;
			typedef  __int128_t s128;
#		else
			/* 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
	”)”,“dnl

	typedef unsigned long long u64;
	typedef   signed long long s64;

	typedef u64 u128;
	typedef	s64 s128;
”)dnl

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”,“dnl
	typedef unsigned type_bit8 u8;
	typedef   signed type_bit8 s8;

”,“dnl
	typedef ubyte u8;
	typedef	sbyte s8;
”)dnl

ifdef(“type_bit16”,“
	typedef unsigned type_bit16 u16;
	typedef   signed type_bit16 s16;

”,“
	typedef ubig u16;
	typedef	sbig s16;
”)dnl

ifdef(“type_bit32”,“
	typedef unsigned type_bit32 u32;
	typedef   signed type_bit32 s32;

”,“
	typedef ubig u32;
	typedef	sbig s32;
”)dnl

enum /* max-min values of each type */ {
	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,  u64_max = ((u64)-1),
	u128_min = 0, u128_max = ((u128)-1),

	/* assuming two's complement. TODO: check math */
	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),


	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,


	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;
”,“dnl
#	ifdef __cplusplus
 	   /* C++ gives us a clean, standardized way to do this */
 	   typedef decltype (sizeof(char)) sz;
#	else
#		if defined(__GNUC__) || defined(__clang__)
			typedef __typeof__ (sizeof(char)) sz;
#		else
................................................................................
			/* we're stumped - set sz to the safest possible value under
			 * the circumstances, and warn the user. */
#			warning no authoritative sz (size_t) type definition \
			        available; defaulting to largest unsigned integer type
			typedef ubig sz;
#		endif
#	endif
”)dnl

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__)
			typedef __typeof__ (((void*)10) - ((void*)5)) offset;
#		else
................................................................................
			/* no dice - set offset to the safest possible value under
			 * the circumstances, and warn the user. */
#			warning no authoritative offset (ptrdiff_t) type definition \
			        available; defaulting to largest unsigned integer type
			typedef sbig offset;
#		endif
#	endif
”)dnl

// exit status integer types - pls use kbad in <k/magic.h> instead
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;
”,“dnl
	ifelse(atom_target_os,“win”,“
		typedef u32 stat;
	”,“dnl
	ifelse(atom_target_os,“vms”,“
		typedef u32 stat;
	”,“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! */
	”)”)dnl
	typedef stat stat_long;
”)dnl

#endif

Modified libk.md from [3181eecb08] to [7bf377a763].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 9. **compatibility.** code that links against libk should be able to compile and run on any operating system. in the ideal case (Linux or FreeBSD) it will be able to do so without touching any other system libraries; for less ideal environments like Windows, libk will when necessary abstract over system libraries or libc itself.
 10. **sane error-handling.** every time you type `errno` god murders a puppy.

## 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. 

 [gpp]: http://en.nothingisreal.com/wiki/GPP
 [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.

## 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!

libk is designed to fix this (in hindsight) glaring error.








|

|


|
<
<







31
32
33
34
35
36
37
38
39
40
41
42
43


44
45
46
47
48
49
50
 9. **compatibility.** code that links against libk should be able to compile and run on any operating system. in the ideal case (Linux or FreeBSD) it will be able to do so without touching any other system libraries; for less ideal environments like Windows, libk will when necessary abstract over system libraries or libc itself.
 10. **sane error-handling.** every time you type `errno` god murders a puppy.

## 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 [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. 

 [m4]: http://www.gnu.org/software/m4
 [GNU make]: http://www.gnu.org/software/make

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!

libk is designed to fix this (in hindsight) glaring error.

Modified makefile from [ce9c7792cb] to [7c13625dc8].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

ifneq ($(BITS),)
    export TARGET = $(ARCH).$(OS).$(BITS)
else
    export TARGET = $(ARCH).$(OS)
endif

export gpp = gpp
export lin-headers = /usr/include/asm
export fbsd-headers = /usr/include/sys

moddirs = $(wildcard k*)
binaries = $(wildcard k*/*.exe.c)
functions = $(wildcard k*/*.fn.c) 
assemblies = $(wildcard k*/*.fn.$(TARGET).s)
................................................................................
uninstall: $(header-dir)/k $(lib-dir)/k
	rm -rf $^

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)
	cd $* && $(MAKE) obj

%.tool: %/makefile $(TMP)/precomp.g $(OUT)
	cd $* && $(MAKE) tool

%.dbg: %/makefile $(OUT)
	cd $* && $(MAKE) dbg

%.def: %/makefile $(TMP)/precomp.g $(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 $@ $^
	@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o








|







 







|


|





|





<
<
<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112



113
114
115
116
117
118
119

ifneq ($(BITS),)
    export TARGET = $(ARCH).$(OS).$(BITS)
else
    export TARGET = $(ARCH).$(OS)
endif

export m4 = m4
export lin-headers = /usr/include/asm
export fbsd-headers = /usr/include/sys

moddirs = $(wildcard k*)
binaries = $(wildcard k*/*.exe.c)
functions = $(wildcard k*/*.fn.c) 
assemblies = $(wildcard k*/*.fn.$(TARGET).s)
................................................................................
uninstall: $(header-dir)/k $(lib-dir)/k
	rm -rf $^

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 $(TARGET).calls $(OUT)
	cd $* && $(MAKE) obj

%.tool: %/makefile $(OUT)
	cd $* && $(MAKE) tool

%.dbg: %/makefile $(OUT)
	cd $* && $(MAKE) dbg

%.def: %/makefile $(TMP)/typesize.def $(OUT) $(OUT)/k
	cd $* && $(MAKE) def

%.calls: arch/makefile
	cd arch && $(MAKE) $(TMP)/calls.$*.s




$(TMP)/typesize.def: arch/makefile $(TMP)
	cd arch && $(MAKE) $@

$(OUT)/libk.so: $(fnobjects) 
	ld -shared $(COMPLIB) -o $@ $^
	@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o

Modified modmake from [eb2aedd9b1] to [4d2e5850b0].

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
headers = $(wildcard *.h) $(gen-headers) $(patsubst %.m,%,$(wildcard *.h.m))

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
    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%)

obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \
	 $(sobjects:%.s=${OUT}/$(mod).%.o)
tool: $(tools:%.exe.c=${OUT}/$(mod).%) \
	  ${OUT}/libk.a

def: $(headers:%=${OUT}/k/%)
................................................................................
	@echo src = $(src)
	@echo tools = $(tools)
	@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) $< > $@

.PRECIOUS: ${TMP}/$(mod).%







<










<
|







 







<







9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
..
36
37
38
39
40
41
42

43
44
45
46
47
48
49
headers = $(wildcard *.h) $(gen-headers) $(patsubst %.m,%,$(wildcard *.h.m))

tools    = $(filter     %.exe.c,   $(src))
nontools = $(filter-out %.exe.c,   $(src))
cobjects = $(filter     %.c,       $(nontools))
sobjects = $(filter %.${TARGET}.s, $(nontools))


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
    m-env += atom_target_bits=${BITS}
endif
m-env += target_posix=${POSIX}
m-env += target_unix=${UNIX}


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

def: $(headers:%=${OUT}/k/%)
................................................................................
	@echo src = $(src)
	@echo tools = $(tools)
	@echo TARGET = ${TARGET}
	@echo cobjects = $(cobjects)
	@echo sobjects = $(sobjects)
	@echo headers = $(headers)
	@echo m-comp = $(m-comp)

	@echo m-env = $(m-env) "$(m-env:%=-D%)"
	@echo mod = $(mod)

${OUT}/k/%.h: %.h.m
	$(m-comp) $< > $@

.PRECIOUS: ${TMP}/$(mod).%