9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] UTF and the preprocessor
@ 2009-03-30 15:30 hugo rivera
  2009-03-30 15:45 ` andrey mirtchovski
  2009-03-30 18:55 ` erik quanstrom
  0 siblings, 2 replies; 3+ messages in thread
From: hugo rivera @ 2009-03-30 15:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hi there,
I just found out that the preprocessor on plan 9 doesn't like utf. I
hope I am wrong, but just try to compile something like

# include <u.h>
# include <libc.h>

# define ΓVAL 12

void main(void);

void
main()
{
	int β;

	β = ΓVAL;
	while(β < 15)
		print("%d\n", β++);
	exits(nil);
}

and you get a "syntax in #define" error that points to the define
line. Remove (or replace) the utf character and everything works as
expected.
-- 
Hugo



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] UTF and the preprocessor
  2009-03-30 15:30 [9fans] UTF and the preprocessor hugo rivera
@ 2009-03-30 15:45 ` andrey mirtchovski
  2009-03-30 18:55 ` erik quanstrom
  1 sibling, 0 replies; 3+ messages in thread
From: andrey mirtchovski @ 2009-03-30 15:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

until somebody gives you a proper explanation of this you can use the
ansi C preprocessor (-p) to compile this particular code. e.g:

% 8c -p t.c; 8l t.8
% 8.out
12
13
14
% cat t.c
#include <u.h>
#include <libc.h>

#define ΓVAL 12
...



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] UTF and the preprocessor
  2009-03-30 15:30 [9fans] UTF and the preprocessor hugo rivera
  2009-03-30 15:45 ` andrey mirtchovski
@ 2009-03-30 18:55 ` erik quanstrom
  1 sibling, 0 replies; 3+ messages in thread
From: erik quanstrom @ 2009-03-30 18:55 UTC (permalink / raw)
  To: 9fans

others more qualified may disagree, but in this
case i think an enum would be preferred.  however,
there are some cases where an enum will not do.
for example,
#define prγ(γ, fmt, ...) if(γ >1.) print(fmt, __VA_ARGS__)

i think that this patch will do the trick.  i continued the
assumption that the the ctype macros are valid for any c,
even if !isascii(c).  this diff is hard to read, the source is
also at http://www.quanstro.net/plan9/macbody

/n/dump/2009/0330/sys/src/cmd/cc/lex.c:1029,1035 - lex.c:1029,1035
  	} else
  		c = GETC();
  	for(;;) {
- 		if(!isspace(c))
+ 		if(c >= Runeself || !isspace(c))
  			return c;
  		if(c == '\n') {
  			lineno++;
; diffy -c macbody
/n/dump/2009/0330/sys/src/cmd/cc/macbody:18,39 - macbody:18,44
  	return n;
  }

- Sym*
- getsym(void)
+ static void
+ nextsym(int c)
  {
- 	int c;
+ 	int c1;
  	char *cp;

- 	c = getnsc();
- 	if(!isalpha(c) && c != '_') {
- 		unget(c);
- 		return S;
- 	}
  	for(cp = symb;;) {
- 		if(cp <= symb+NSYMB-4)
- 			*cp++ = c;
+ 		if(c >= Runeself) {
+ 			for(c1=0;;) {
+ 				if(cp <= symb+NSYMB-4)
+ 					cp[c1++] = c;
+ 				if(fullrune(cp, c1))
+ 					break;
+ 				c = getc();
+ 			}
+ 			cp += c1;
+ 		}else
+ 			if(cp <= symb+NSYMB-4)
+ 				*cp++ = c;
  		c = getc();
- 		if(isalnum(c) || c == '_')
+ 		if(c >= Runeself || isalnum(c) || c == '_')
  			continue;
  		unget(c);
  		break;
/n/dump/2009/0330/sys/src/cmd/cc/macbody:41,46 - macbody:46,64
  	*cp = 0;
  	if(cp > symb+NSYMB-4)
  		yyerror("symbol too large: %s", symb);
+ }
+
+ Sym*
+ getsym(void)
+ {
+ 	int c;
+
+ 	c = getnsc();
+ 	if(c < Runeself && !isalpha(c) && c != '_') {
+ 		unget(c);
+ 		return S;
+ 	}
+ 	nextsym(c);
  	return lookup();
  }

/n/dump/2009/0330/sys/src/cmd/cc/macbody:193,199 - macbody:211,217
  macdef(void)
  {
  	Sym *s, *a;
- 	char *args[NARG], *np, *base;
+ 	char *args[NARG], *base;
  	int n, i, c, len, dots;
  	int ischr;

/n/dump/2009/0330/sys/src/cmd/cc/macbody:235,249 - macbody:253,261
  	len = 1;
  	ischr = 0;
  	for(;;) {
- 		if(isalpha(c) || c == '_') {
- 			np = symb;
- 			*np++ = c;
+ 		if(c >= Runeself || isalpha(c) || c == '_') {
+ 			nextsym(c);
  			c = getc();
- 			while(isalnum(c) || c == '_') {
- 				*np++ = c;
- 				c = getc();
- 			}
- 			*np = 0;
  			for(i=0; i<n; i++)
  				if(strcmp(symb, args[i]) == 0)
  					break;
/n/dump/2009/0330/sys/src/cmd/cc/macbody:660,666 - macbody:672,678
  	for(;;) {
  		c = getc();
  		if(c != '#') {
- 			if(!isspace(c))
+ 			if(c >= Runeself || !isspace(c))
  				bol = 0;
  			if(c == '\n')
  				bol = 1;



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-30 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-30 15:30 [9fans] UTF and the preprocessor hugo rivera
2009-03-30 15:45 ` andrey mirtchovski
2009-03-30 18:55 ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).