mescc: Mes C Library: Use __ as global internal prefix.

* include/libmes-mini.h (g_stdin, g_stdout, g_stderr): Rename to
__stdin, __stdout, __stderr.  Update users.
This commit is contained in:
Jan Nieuwenhuizen 2019-03-02 12:35:18 +01:00
parent c78a087c38
commit 757d603e4c
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
20 changed files with 106 additions and 91 deletions

View file

@ -75,9 +75,9 @@ int errno;
#endif #endif
char **environ; char **environ;
int g_stdin; int __stdin;
int g_stdout; int __stdout;
int g_stderr; int __stderr;
int eputs (char const* s); int eputs (char const* s);
int puts (char const* s); int puts (char const* s);

View file

@ -43,9 +43,24 @@
#if POSIX #if POSIX
// The Mes C Library defines and initializes these in crt1 // The Mes C Library defines and initializes these in crt1
int g_stdin = STDIN; int __stdin = STDIN;
int g_stdout = STDOUT; int __stdout = STDOUT;
int g_stderr = STDERR; int __stderr = STDERR;
int
mes_open (char const *file_name, int flags, ...)
{
va_list ap;
va_start (ap, flags);
int mask = va_arg (ap, int);
__ungetc_init ();
int r = open (file_name, flags, mask);
if (r > 2)
__ungetc_buf[r] = -1;
va_end (ap);
return r;
}
#include <mes/eputs.c> #include <mes/eputs.c>
#include <mes/oputs.c> #include <mes/oputs.c>
#endif // POSIX #endif // POSIX

View file

@ -27,21 +27,21 @@ _start ()
asm ( asm (
"mov $0,%%eax\n\t" "mov $0,%%eax\n\t"
"mov %%eax,%0\n" "mov %%eax,%0\n"
: "=r" (g_stdin) : "=r" (__stdin)
: //no inputs "" : //no inputs ""
); );
asm ( asm (
"mov $1,%%eax\n\t" "mov $1,%%eax\n\t"
"mov %%eax,%0\n" "mov %%eax,%0\n"
: "=r" (g_stdout) : "=r" (__stdout)
: //no inputs "" : //no inputs ""
); );
asm ( asm (
"mov $2,%%eax\n\t" "mov $2,%%eax\n\t"
"mov %%eax,%0\n" "mov %%eax,%0\n"
: "=r" (g_stderr) : "=r" (__stderr)
: //no inputs "" : //no inputs ""
); );
asm ( asm (

View file

@ -26,13 +26,13 @@ int
_start () _start ()
{ {
asm ("mov____$i8,%eax !0"); asm ("mov____$i8,%eax !0");
asm ("mov____%eax,0x32 &g_stdin"); asm ("mov____%eax,0x32 &__stdin");
asm ("mov____$i8,%eax !1"); asm ("mov____$i8,%eax !1");
asm ("mov____%eax,0x32 &g_stdout"); asm ("mov____%eax,0x32 &__stdout");
asm ("mov____$i8,%eax !2"); asm ("mov____$i8,%eax !2");
asm ("mov____%eax,0x32 &g_stderr"); asm ("mov____%eax,0x32 &__stderr");
asm ("mov____%ebp,%eax"); asm ("mov____%ebp,%eax");
asm ("add____$i8,%eax !4"); asm ("add____$i8,%eax !4");

View file

@ -30,21 +30,21 @@ _start ()
asm ( asm (
"mov $0,%%rax\n\t" "mov $0,%%rax\n\t"
"mov %%rax,%0\n" "mov %%rax,%0\n"
: "=r" (g_stdin) : "=r" (__stdin)
: //no inputs "" : //no inputs ""
); );
asm ( asm (
"mov $1,%%rax\n\t" "mov $1,%%rax\n\t"
"mov %%rax,%0\n" "mov %%rax,%0\n"
: "=r" (g_stdout) : "=r" (__stdout)
: //no inputs "" : //no inputs ""
); );
asm ( asm (
"mov $2,%%rax\n\t" "mov $2,%%rax\n\t"
"mov %%rax,%0\n" "mov %%rax,%0\n"
: "=r" (g_stderr) : "=r" (__stderr)
: //no inputs "" : //no inputs ""
); );
asm ( asm (

View file

@ -25,13 +25,13 @@ int
_start () _start ()
{ {
asm ("mov____$i8,%rax !0"); asm ("mov____$i8,%rax !0");
asm ("mov____%rax,0x32 &g_stdin"); asm ("mov____%rax,0x32 &__stdin");
asm ("mov____$i8,%rax !1"); asm ("mov____$i8,%rax !1");
asm ("mov____%rax,0x32 &g_stdout"); asm ("mov____%rax,0x32 &__stdout");
asm ("mov____$i8,%rax !2"); asm ("mov____$i8,%rax !2");
asm ("mov____%rax,0x32 &g_stderr"); asm ("mov____%rax,0x32 &__stderr");
#if 0 //MES_CCAMD64 #if 0 //MES_CCAMD64
asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu

View file

@ -23,5 +23,5 @@
int int
eputc (int c) eputc (int c)
{ {
return fdputc (c, g_stderr); return fdputc (c, __stderr);
} }

View file

@ -24,6 +24,6 @@ int
eputs (char const* s) eputs (char const* s)
{ {
int i = strlen (s); int i = strlen (s);
write (g_stderr, s, i); write (__stderr, s, i);
return 0; return 0;
} }

View file

@ -23,5 +23,5 @@
int int
oputc (int c) oputc (int c)
{ {
return fdputc (c, g_stdout); return fdputc (c, __stdout);
} }

View file

@ -24,6 +24,6 @@ int
oputs (char const* s) oputs (char const* s)
{ {
int i = strlen (s); int i = strlen (s);
write (g_stdout, s, i); write (__stdout, s, i);
return 0; return 0;
} }

View file

@ -23,5 +23,5 @@
int int
getchar () getchar ()
{ {
return fdgetc (g_stdin); return fdgetc (__stdin);
} }

View file

@ -543,7 +543,7 @@ g_cells[cell_cdr] = scm_cdr;
SCM SCM
bload_env (SCM a) ///((internal)) bload_env (SCM a) ///((internal))
{ {
g_stdin = open ("module/mes/read-0.mo", 0); __stdin = open ("module/mes/read-0.mo", 0);
char *p = (char*)g_cells; char *p = (char*)g_cells;
assert (getchar () == 'M'); assert (getchar () == 'M');
assert (getchar () == 'E'); assert (getchar () == 'E');
@ -559,7 +559,7 @@ bload_env (SCM a) ///((internal))
g_free = (p-(char*)g_cells) / sizeof (struct scm); g_free = (p-(char*)g_cells) / sizeof (struct scm);
gc_peek_frame (); gc_peek_frame ();
g_symbols = r1; g_symbols = r1;
g_stdin = STDIN; __stdin = STDIN;
r0 = mes_builtins (r0); r0 = mes_builtins (r0);
return r2; return r2;
} }
@ -746,8 +746,8 @@ simple_bload_env (SCM a) ///((internal))
char *mo = "module/mes/tiny-0-32.mo"; char *mo = "module/mes/tiny-0-32.mo";
puts (mo); puts (mo);
puts ("\n"); puts ("\n");
g_stdin = open (mo, 0); __stdin = open (mo, 0);
if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} if (__stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;}
char *p = (char*)g_cells; char *p = (char*)g_cells;
int c; int c;
@ -779,7 +779,7 @@ simple_bload_env (SCM a) ///((internal))
g_symbols = 1; g_symbols = 1;
g_stdin = STDIN; __stdin = STDIN;
r0 = mes_builtins (r0); r0 = mes_builtins (r0);
if (g_free != 19) exit (34); if (g_free != 19) exit (34);
@ -826,7 +826,7 @@ main (int argc, char *argv[])
#else #else
if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");return eputs ("0.4");}; if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");return eputs ("0.4");};
#endif #endif
g_stdin = STDIN; __stdin = STDIN;
r0 = mes_environment (); r0 = mes_environment ();

View file

@ -25,7 +25,7 @@
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
g_stdin = open ("scaffold/read.data", 0); __stdin = open ("scaffold/read.data", 0);
int c = getchar (); int c = getchar ();
if (c != 'm') if (c != 'm')
return 1; return 1;

View file

@ -286,8 +286,8 @@ bload_env (SCM a) ///((internal))
char *mo = "module/mes/tiny-0-32.mo"; char *mo = "module/mes/tiny-0-32.mo";
puts (mo); puts (mo);
puts ("\n"); puts ("\n");
g_stdin = open (mo, 0); __stdin = open (mo, 0);
if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} if (__stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;}
// BOOM // BOOM
//char *p = arena; //char *p = arena;

View file

@ -174,27 +174,27 @@ hash_set_x (SCM table, SCM key, SCM value)
SCM SCM
hash_table_printer (SCM table) hash_table_printer (SCM table)
{ {
fdputs ("#<", g_stdout); display_ (struct_ref_ (table, 2)); fdputc (' ', g_stdout); fdputs ("#<", __stdout); display_ (struct_ref_ (table, 2)); fdputc (' ', __stdout);
fdputs ("size: ", g_stdout); display_ (struct_ref_ (table, 3)); fdputc (' ', g_stdout); fdputs ("size: ", __stdout); display_ (struct_ref_ (table, 3)); fdputc (' ', __stdout);
SCM buckets = struct_ref_ (table, 4); SCM buckets = struct_ref_ (table, 4);
fdputs ("buckets: ", g_stdout); fdputs ("buckets: ", __stdout);
for (int i=0; i<LENGTH (buckets); i++) for (int i=0; i<LENGTH (buckets); i++)
{ {
SCM e = vector_ref_ (buckets, i); SCM e = vector_ref_ (buckets, i);
if (e != cell_unspecified) if (e != cell_unspecified)
{ {
fdputc ('[', g_stdout); fdputc ('[', __stdout);
while (TYPE (e) == TPAIR) while (TYPE (e) == TPAIR)
{ {
write_ (CAAR (e)); write_ (CAAR (e));
e = CDR (e); e = CDR (e);
if (TYPE (e) == TPAIR) if (TYPE (e) == TPAIR)
fdputc (' ', g_stdout); fdputc (' ', __stdout);
} }
fdputs ("]\n ", g_stdout); fdputs ("]\n ", __stdout);
} }
} }
fdputc ('>', g_stdout); fdputc ('>', __stdout);
} }
SCM SCM

View file

@ -226,14 +226,14 @@ SCM
display_ (SCM x) display_ (SCM x)
{ {
g_depth = 5; g_depth = 5;
return display_helper (x, 0, "", g_stdout, 0); return display_helper (x, 0, "", __stdout, 0);
} }
SCM SCM
display_error_ (SCM x) display_error_ (SCM x)
{ {
g_depth = 5; g_depth = 5;
return display_helper (x, 0, "", g_stderr, 0); return display_helper (x, 0, "", __stderr, 0);
} }
SCM SCM
@ -247,14 +247,14 @@ SCM
write_ (SCM x) write_ (SCM x)
{ {
g_depth = 5; g_depth = 5;
return display_helper (x, 0, "", g_stdout, 1); return display_helper (x, 0, "", __stdout, 1);
} }
SCM SCM
write_error_ (SCM x) write_error_ (SCM x)
{ {
g_depth = 5; g_depth = 5;
return display_helper (x, 0, "", g_stderr, 1); return display_helper (x, 0, "", __stderr, 1);
} }
SCM SCM
@ -281,10 +281,10 @@ exit_ (SCM x) ///((name . "exit"))
SCM SCM
frame_printer (SCM frame) frame_printer (SCM frame)
{ {
fdputs ("#<", g_stdout); display_ (struct_ref_ (frame, 2)); fdputs ("#<", __stdout); display_ (struct_ref_ (frame, 2));
fdputc (' ', g_stdout); fdputc (' ', __stdout);
fdputs ("procedure: ", g_stdout); display_ (struct_ref_ (frame, 3)); fdputs ("procedure: ", __stdout); display_ (struct_ref_ (frame, 3));
fdputc ('>', g_stdout); fdputc ('>', __stdout);
} }
SCM SCM

View file

@ -1939,23 +1939,23 @@ builtin_p (SCM x)
SCM SCM
builtin_printer (SCM builtin) builtin_printer (SCM builtin)
{ {
fdputs ("#<procedure ", g_stdout); fdputs ("#<procedure ", __stdout);
display_ (builtin_name (builtin)); display_ (builtin_name (builtin));
fdputc (' ', g_stdout); fdputc (' ', __stdout);
int arity = VALUE (builtin_arity (builtin)); int arity = VALUE (builtin_arity (builtin));
if (arity == -1) if (arity == -1)
fdputc ('_', g_stdout); fdputc ('_', __stdout);
else else
{ {
fdputc ('(', g_stdout); fdputc ('(', __stdout);
for (int i = 0; i < arity; i++) for (int i = 0; i < arity; i++)
{ {
if (i) if (i)
fdputc (' ', g_stdout); fdputc (' ', __stdout);
fdputc ('_', g_stdout); fdputc ('_', __stdout);
} }
} }
fdputc ('>', g_stdout); fdputc ('>', __stdout);
} }
SCM SCM
@ -2206,7 +2206,7 @@ open_boot (char *prefix, char const *boot, char const *location)
SCM SCM
read_boot () ///((internal)) read_boot () ///((internal))
{ {
g_stdin = -1; __stdin = -1;
char prefix[1024]; char prefix[1024];
char boot[1024]; char boot[1024];
if (getenv ("MES_BOOT")) if (getenv ("MES_BOOT"))
@ -2218,25 +2218,25 @@ read_boot () ///((internal))
strcpy (prefix, getenv ("MES_PREFIX")); strcpy (prefix, getenv ("MES_PREFIX"));
strcpy (prefix + strlen (prefix), "/module"); strcpy (prefix + strlen (prefix), "/module");
strcpy (prefix + strlen (prefix), "/mes/"); strcpy (prefix + strlen (prefix), "/mes/");
g_stdin = open_boot (prefix, boot, "MES_PREFIX"); __stdin = open_boot (prefix, boot, "MES_PREFIX");
} }
if (g_stdin < 0) if (__stdin < 0)
{ {
char const *p = MODULEDIR "/mes/"; char const *p = MODULEDIR "/mes/";
strcpy (prefix, p); strcpy (prefix, p);
g_stdin = open_boot (prefix, boot, "MODULEDIR"); __stdin = open_boot (prefix, boot, "MODULEDIR");
} }
if (g_stdin < 0) if (__stdin < 0)
{ {
strcpy (prefix, "mes/module/mes/"); strcpy (prefix, "mes/module/mes/");
g_stdin = open_boot (prefix, boot, "."); __stdin = open_boot (prefix, boot, ".");
} }
if (g_stdin < 0) if (__stdin < 0)
{ {
prefix[0] = 0; prefix[0] = 0;
g_stdin = open_boot (prefix, boot, "<boot>"); __stdin = open_boot (prefix, boot, "<boot>");
} }
if (g_stdin < 0) if (__stdin < 0)
{ {
eputs ("mes: boot failed: no such file: "); eputs ("mes: boot failed: no such file: ");
eputs (boot); eputs (boot);
@ -2245,7 +2245,7 @@ read_boot () ///((internal))
} }
r2 = read_input_file_env (r0); r2 = read_input_file_env (r0);
g_stdin = STDIN; __stdin = STDIN;
return r2; return r2;
} }

View file

@ -71,13 +71,13 @@ SCM
module_printer (SCM module) module_printer (SCM module)
{ {
//module = m0; //module = m0;
fdputs ("#<", g_stdout); display_ (struct_ref_ (module, 2)); fdputc (' ', g_stdout); fdputs ("#<", __stdout); display_ (struct_ref_ (module, 2)); fdputc (' ', __stdout);
fdputs ("name: ", g_stdout); display_ (struct_ref_ (module, 3)); fdputc (' ', g_stdout); fdputs ("name: ", __stdout); display_ (struct_ref_ (module, 3)); fdputc (' ', __stdout);
fdputs ("locals: ", g_stdout); display_ (struct_ref_ (module, 4)); fdputc (' ', g_stdout); fdputs ("locals: ", __stdout); display_ (struct_ref_ (module, 4)); fdputc (' ', __stdout);
SCM table = struct_ref_ (module, 5); SCM table = struct_ref_ (module, 5);
fdputs ("globals:\n ", g_stdout); fdputs ("globals:\n ", __stdout);
display_ (table); display_ (table);
fdputc ('>', g_stdout); fdputc ('>', __stdout);
} }
SCM SCM

View file

@ -33,7 +33,7 @@ int unreadchar ();
int int
peekchar () peekchar ()
{ {
if (g_stdin >= 0) if (__stdin >= 0)
{ {
int c = readchar (); int c = readchar ();
unreadchar (c); unreadchar (c);
@ -51,8 +51,8 @@ peekchar ()
int int
readchar () readchar ()
{ {
if (g_stdin >= 0) if (__stdin >= 0)
return fdgetc (g_stdin); return fdgetc (__stdin);
SCM port = current_input_port (); SCM port = current_input_port ();
SCM string = STRING (port); SCM string = STRING (port);
size_t length = LENGTH (string); size_t length = LENGTH (string);
@ -67,8 +67,8 @@ readchar ()
int int
unreadchar (int c) unreadchar (int c)
{ {
if (g_stdin >= 0) if (__stdin >= 0)
return fdungetc (c, g_stdin); return fdungetc (c, __stdin);
SCM port = current_input_port (); SCM port = current_input_port ();
SCM string = STRING (port); SCM string = STRING (port);
size_t length = LENGTH (string); size_t length = LENGTH (string);
@ -109,11 +109,11 @@ peek_char ()
SCM SCM
read_char (SCM port) ///((arity . n)) read_char (SCM port) ///((arity . n))
{ {
int fd = g_stdin; int fd = __stdin;
if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER) if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER)
g_stdin = VALUE (CAR (port)); __stdin = VALUE (CAR (port));
SCM c = MAKE_CHAR (readchar ()); SCM c = MAKE_CHAR (readchar ());
g_stdin = fd; __stdin = fd;
return c; return c;
} }
@ -136,11 +136,11 @@ write_byte (SCM x) ///((arity . n))
{ {
SCM c = car (x); SCM c = car (x);
SCM p = cdr (x); SCM p = cdr (x);
int fd = g_stdout; int fd = __stdout;
if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) != 1) if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) != 1)
fd = VALUE (CAR (p)); fd = VALUE (CAR (p));
if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) == 2) if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER && VALUE (CAR (p)) == 2)
fd = g_stderr; fd = __stderr;
char cc = VALUE (c); char cc = VALUE (c);
write (fd, (char*)&cc, 1); write (fd, (char*)&cc, 1);
#if !__MESC__ #if !__MESC__
@ -175,10 +175,10 @@ access_p (SCM file_name, SCM mode)
SCM SCM
current_input_port () current_input_port ()
{ {
if (g_stdin >= 0) if (__stdin >= 0)
return MAKE_NUMBER (g_stdin); return MAKE_NUMBER (__stdin);
SCM x = g_ports; SCM x = g_ports;
while (x && PORT (CAR (x)) != g_stdin) while (x && PORT (CAR (x)) != __stdin)
x = CDR (x); x = CDR (x);
return CAR (x); return CAR (x);
} }
@ -202,22 +202,22 @@ set_current_input_port (SCM port)
{ {
SCM prev = current_input_port (); SCM prev = current_input_port ();
if (TYPE (port) == TNUMBER) if (TYPE (port) == TNUMBER)
g_stdin = VALUE (port) ? VALUE (port) : STDIN; __stdin = VALUE (port) ? VALUE (port) : STDIN;
else if (TYPE (port) == TPORT) else if (TYPE (port) == TPORT)
g_stdin = PORT (port); __stdin = PORT (port);
return prev; return prev;
} }
SCM SCM
current_output_port () current_output_port ()
{ {
return MAKE_NUMBER (g_stdout); return MAKE_NUMBER (__stdout);
} }
SCM SCM
current_error_port () current_error_port ()
{ {
return MAKE_NUMBER (g_stderr); return MAKE_NUMBER (__stderr);
} }
SCM SCM
@ -234,14 +234,14 @@ open_output_file (SCM x) ///((arity . n))
SCM SCM
set_current_output_port (SCM port) set_current_output_port (SCM port)
{ {
g_stdout = VALUE (port) ? VALUE (port) : STDOUT; __stdout = VALUE (port) ? VALUE (port) : STDOUT;
return current_output_port (); return current_output_port ();
} }
SCM SCM
set_current_error_port (SCM port) set_current_error_port (SCM port)
{ {
g_stderr = VALUE (port) ? VALUE (port) : STDERR; __stderr = VALUE (port) ? VALUE (port) : STDERR;
return current_error_port (); return current_error_port ();
} }

View file

@ -181,9 +181,9 @@ list_to_string (SCM list)
SCM SCM
read_string (SCM port) ///((arity . n)) read_string (SCM port) ///((arity . n))
{ {
int fd = g_stdin; int fd = __stdin;
if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER) if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER)
g_stdin = VALUE (CAR (port)); __stdin = VALUE (CAR (port));
int c = readchar (); int c = readchar ();
size_t i = 0; size_t i = 0;
while (c != -1) while (c != -1)
@ -194,7 +194,7 @@ read_string (SCM port) ///((arity . n))
c = readchar (); c = readchar ();
} }
g_buf[i] = 0; g_buf[i] = 0;
g_stdin = fd; __stdin = fd;
return make_string (g_buf, i); return make_string (g_buf, i);
} }