From owner-freebsd-arch@FreeBSD.ORG Tue Oct 30 17:14:42 2007 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C8B9B16A420; Tue, 30 Oct 2007 17:14:42 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.freebsd.org (Postfix) with ESMTP id 4D75D13C4B8; Tue, 30 Oct 2007 17:14:41 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (unknown [192.168.61.3]) by phk.freebsd.dk (Postfix) with ESMTP id C47C017104; Tue, 30 Oct 2007 17:14:39 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.14.1/8.14.1) with ESMTP id l9UHEcrn001822; Tue, 30 Oct 2007 17:14:39 GMT (envelope-from phk@critter.freebsd.dk) To: Bakul Shah From: "Poul-Henning Kamp" In-Reply-To: Your message of "Tue, 30 Oct 2007 09:36:13 MST." <20071030163613.E70665B30@mail.bitblocks.com> Date: Tue, 30 Oct 2007 17:14:38 +0000 Message-ID: <1821.1193764478@critter.freebsd.dk> Sender: phk@critter.freebsd.dk Cc: Alfred Perlstein , Garance A Drosehn , freebsd-arch@freebsd.org Subject: Re: C++ in the kernel X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2007 17:14:43 -0000 In message <20071030163613.E70665B30@mail.bitblocks.com>, Bakul Shah writes: >Is there a more detailed writeup of Poul's ideas on K >language beyond what is on the wiki.freebsd.org/K? Reading >it brings to mind Brinch Hansen's extensions to Pascal. Knowing that I may regret this, here is my private notes file on K syntax extensions. Preprocessor shell escape ------------------------- #! { ident } ident Generate C/K source with external program. Can be used to generate tables or include firmware files directly from the binary. Public/Private structs ---------------------- public struct foo { ... } Has sizeof() = -1, cannot be assigned. private struct foo { ... } Adds fields to the public struct foo, has sizeof the joint size. Acts like normal struct. Bitmaps ------- bitmap foo { bar, barf, ...}; Like enum, but assigns bit values and allows logical operations. Style/Syntax checks ------------------- Flag misindentation: if (some_cond) do_this(foo); and_that(bar); Style(9) warnings Macros taking code as argument ------------------------------ #define LOCK(a, {}) do { mtx_lock(&a); __CODE__ mtx_unlock(&a); } while (0); XXX: what happens on return/break/etc ? #define LOCK(a, {}) __CODE__( entry { mtx_lock(&a); } return { mtx_unlock(&a); } ) XXX: not happy about syntax Pointer colors -------------- void * "userland" ptr; Cannot be used as regular void *, but must be passed to functions which has same color prototype. Integer ranges -------------- int foo [21...45]; or int foo range [21...45]; Integer endianess ----------------- uint32_t big_endian foo; Atomic variables ---------------- uint32_t atomic foo; Struct offsets and sizes ------------------------ struct foo { sizeof 128; big_endian; align 16; uint8_t foo @0; uint32_t little_endian bar @12; } Multi-loop break ---------------- if (foo != NULL) { TAILQ_FOREACH(foo, &bar, list) { if (foo->idx == idx) break(2); } panic("not found"); } Call identification ------------------- int foo(int barf, void *there, private void **id); The "id" argument points to a call specific, globally unique, static instance of the pointed to type. This can be used for instance to cache a function pointer for lazy binding (KOBJ ?) Alternatively, even faster, go the full length and make run-time resolved function pointers (trouble hunting them down at modunload ?) Sensible jump prediction ------------------------ TAILQ_FOREACH(foo, &bar, list) {{ do_this_alot(foo); }} #include pointlessness warnings ------------------------------- Warn about #includes that have no effect Cross-Referencing ----------------- Generate cross-reference data on joint preproc/C/K level. Function instantiation by prototype ----------------------------------- typedef int foo_f(int arg, void *priv, struct *obj); static foo_f thisfunc(.) { if (arg) { ... } } Argument struct/array building ------------------------------ int foo(struct timeval tv); int bar(int someargs) { foo({.tv_sec = someargs}); } Compile time debugging aids --------------------------- * Look out for 0xdeadc0de+/-256 Check any pointer dereference against the indicated interval * Struct */void * typecheck Give each struct a magic identifier, check after void* transport. * Struct canary insertion Insert canary elements in struct and check their magic values whenever neighbouring elements are tweaked. * Assignment code insertion Insert code "foo" whenever variable "bar" is assigned or changed. Typical values of "foo" would be "mtx_assert_locked(...)" replacement ------------------------- list_head(struct foo, ...) foolist; possible options: single Single linked list double Double linked list tail Tail is accessible from head head Head is accessible from elem member Only allow use with member in target struct. struct foo { list_member list; list_member(opts...) list2; }; list_empty(head) list_next(elem) list_prev(elem) list_first(head) list_last(head) list_insert_head(elem, head) list_insert_tail(elem, tail) list_insert_before(elem, elem {,head ?}) list_insert_after(elem, elem {,head ?}) list_remove(elem {,head ?}) list_init_head(head) list_take_first(head) list_take_last(head) list_foreach(elem, head {,member}) list_foreach_safe(elem, head {,member}) list_foreach_reverse(elem, head {,member}) list_foreach_reverse_safe(elem, head {,member}) -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.