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
char **environ;
int g_stdin;
int g_stdout;
int g_stderr;
int __stdin;
int __stdout;
int __stderr;
int eputs (char const* s);
int puts (char const* s);

View File

@ -43,9 +43,24 @@
#if POSIX
// The Mes C Library defines and initializes these in crt1
int g_stdin = STDIN;
int g_stdout = STDOUT;
int g_stderr = STDERR;
int __stdin = STDIN;
int __stdout = STDOUT;
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/oputs.c>
#endif // POSIX

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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