Re: writing an assembler!

telnet@wagner.Princeton.EDU.composers (telnet user)
8 Jul 1998 01:40:01 -0400

          From comp.compilers

Related articles
slightly off topic -- writing an assembler! SAMIGWE@worldnet.att.net (samuel) (1998-06-24)
Re: slightly off topic -- writing an assembler! khays@sequent.com (1998-06-24)
Re: writing an assembler! lindsay-j@rmc.ca (John Lindsay) (1998-06-27)
Re: writing an assembler! henry@spsystems.net (1998-06-28)
Re: writing an assembler! ok@atlas.otago.ac.nz (Dr Richard A. O'Keefe) (1998-07-01)
Re: writing an assembler! nr@labrador.cs.virginia.edu (Norman Ramsey) (1998-07-03)
Re: writing an assembler! telnet@wagner.Princeton.EDU.composers (1998-07-08)
| List of all articles for this month |
From: telnet@wagner.Princeton.EDU.composers (telnet user)
Newsgroups: comp.compilers
Date: 8 Jul 1998 01:40:01 -0400
Organization: Chemistry Department, Princeton University
References: 98-06-126 98-06-144 98-06-160 98-07-005
Keywords: macros, design



In article 98-07-005, "Dr Richard A. O'Keefe" <ok@atlas.otago.ac.nz> writes:
>
> These days, my language of choice for doing this would be Lisp or Ada
> (sensible macros are about *trees*, not strings!) but you can
> certainly use C as an assembler quite effectively.
> [It's a disgusting hack, but it's a great disgusting hack. -John]


You can get away with tree-like behavior in C if you use varargs stuff.
I'll risk my reputation (:-)) by admitting to an even more disgusting hack:
---
void new_section(char *title, char *img_name, int h, int w) {
        emit(html_list,
html_p,
html_hr,
html_br,
                        html_region, "center",
                                html_region, "h1",
html_text, title,
                        html_tag, "img",
html_param, "src", html_string, fname,
html_param, "height", html_text, h,
html_param, "width", html_text, w,
0,
                        0);
}
---


---
typedef void (*html_func)(va_list *);


void emit(html_func first, ...) {
        va_list ap;


        va_start(ap, first);
        (*first)(&ap);
        va_end(ap);
}


void html_list(va_list *ap) {
        html_func f;


        while (1) {
f = va_arg(ap, html_func);
if (f == 0) break;


(*f)(ap);
        }
}


[etc]
---


A disgusting hack? Absolutely.


But it's also an order of magnitude more powerful than any other
dynamic HTML tool I've worked with, and it only took me an hour or so
to implement.


---------------------------------------------------------------------------
Tim Hollebeek
email: tim@wfn-shop.princeton.edu
URL: http://wfn-shop.princeton.edu/~tim
[Wow, that's loathsome. I really like it. -John]




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.