From 5f0e6200dc25237a1513e6de98d93b34499117ea Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 5 Jan 2019 12:35:18 +0100 Subject: [PATCH] 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. --- include/libmes-mini.h | 6 +++--- lib/libmes.c | 6 +++--- lib/linux/x86-mes-gcc/crt1.c | 6 +++--- lib/linux/x86-mes/crt1.c | 6 +++--- lib/linux/x86_64-mes-gcc/crt1.c | 6 +++--- lib/linux/x86_64-mes/crt1.c | 6 +++--- lib/mes/eputc.c | 2 +- lib/mes/eputs.c | 2 +- lib/mes/oputc.c | 2 +- lib/mes/oputs.c | 2 +- lib/stdio/getchar.c | 2 +- scaffold/cons-mes.c | 12 +++++------ scaffold/read.c | 2 +- scaffold/tiny-mes.c | 4 ++-- src/hash.c | 14 ++++++------ src/lib.c | 16 +++++++------- src/mes.c | 34 ++++++++++++++--------------- src/module.c | 10 ++++----- src/posix.c | 38 ++++++++++++++++----------------- src/strings.c | 6 +++--- 20 files changed, 91 insertions(+), 91 deletions(-) diff --git a/include/libmes-mini.h b/include/libmes-mini.h index b0104d3d..f93c9015 100644 --- a/include/libmes-mini.h +++ b/include/libmes-mini.h @@ -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); diff --git a/lib/libmes.c b/lib/libmes.c index c4add9cf..cdf78d93 100644 --- a/lib/libmes.c +++ b/lib/libmes.c @@ -46,9 +46,9 @@ #include #include // 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, ...) diff --git a/lib/linux/x86-mes-gcc/crt1.c b/lib/linux/x86-mes-gcc/crt1.c index 01eb32ff..859469fe 100644 --- a/lib/linux/x86-mes-gcc/crt1.c +++ b/lib/linux/x86-mes-gcc/crt1.c @@ -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 ( diff --git a/lib/linux/x86-mes/crt1.c b/lib/linux/x86-mes/crt1.c index 07b33e3f..a93b519b 100644 --- a/lib/linux/x86-mes/crt1.c +++ b/lib/linux/x86-mes/crt1.c @@ -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"); diff --git a/lib/linux/x86_64-mes-gcc/crt1.c b/lib/linux/x86_64-mes-gcc/crt1.c index 5a93f81e..89af8e4c 100644 --- a/lib/linux/x86_64-mes-gcc/crt1.c +++ b/lib/linux/x86_64-mes-gcc/crt1.c @@ -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 ( diff --git a/lib/linux/x86_64-mes/crt1.c b/lib/linux/x86_64-mes/crt1.c index ac0add48..d3bce233 100644 --- a/lib/linux/x86_64-mes/crt1.c +++ b/lib/linux/x86_64-mes/crt1.c @@ -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 diff --git a/lib/mes/eputc.c b/lib/mes/eputc.c index ac4cd15e..7164fd74 100644 --- a/lib/mes/eputc.c +++ b/lib/mes/eputc.c @@ -23,5 +23,5 @@ int eputc (int c) { - return fdputc (c, g_stderr); + return fdputc (c, __stderr); } diff --git a/lib/mes/eputs.c b/lib/mes/eputs.c index 7b6896ef..db7b26d5 100644 --- a/lib/mes/eputs.c +++ b/lib/mes/eputs.c @@ -24,6 +24,6 @@ int eputs (char const* s) { int i = strlen (s); - write (g_stderr, s, i); + write (__stderr, s, i); return 0; } diff --git a/lib/mes/oputc.c b/lib/mes/oputc.c index 3b50e27e..ba47365a 100644 --- a/lib/mes/oputc.c +++ b/lib/mes/oputc.c @@ -23,5 +23,5 @@ int oputc (int c) { - return fdputc (c, g_stdout); + return fdputc (c, __stdout); } diff --git a/lib/mes/oputs.c b/lib/mes/oputs.c index f82e3b8d..3f5f4905 100644 --- a/lib/mes/oputs.c +++ b/lib/mes/oputs.c @@ -24,6 +24,6 @@ int oputs (char const* s) { int i = strlen (s); - write (g_stdout, s, i); + write (__stdout, s, i); return 0; } diff --git a/lib/stdio/getchar.c b/lib/stdio/getchar.c index 111655dd..46c30581 100644 --- a/lib/stdio/getchar.c +++ b/lib/stdio/getchar.c @@ -23,5 +23,5 @@ int getchar () { - return fdgetc (g_stdin); + return fdgetc (__stdin); } diff --git a/scaffold/cons-mes.c b/scaffold/cons-mes.c index 99984fb2..09a06691 100644 --- a/scaffold/cons-mes.c +++ b/scaffold/cons-mes.c @@ -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 (); diff --git a/scaffold/read.c b/scaffold/read.c index c58f8aa6..0111a223 100644 --- a/scaffold/read.c +++ b/scaffold/read.c @@ -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; diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c index a04616c8..a7f6566e 100644 --- a/scaffold/tiny-mes.c +++ b/scaffold/tiny-mes.c @@ -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; diff --git a/src/hash.c b/src/hash.c index 1e2c4a81..aa704dae 100644 --- a/src/hash.c +++ b/src/hash.c @@ -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', g_stdout); + fdputc ('>', __stdout); } SCM diff --git a/src/lib.c b/src/lib.c index 94484821..2c86ed6e 100644 --- a/src/lib.c +++ b/src/lib.c @@ -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 diff --git a/src/mes.c b/src/mes.c index 3a36e109..be9133a0 100644 --- a/src/mes.c +++ b/src/mes.c @@ -1939,23 +1939,23 @@ builtin_p (SCM x) SCM builtin_printer (SCM builtin) { - fdputs ("#', 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, ""); + __stdin = open_boot (prefix, 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; } diff --git a/src/module.c b/src/module.c index 79c43dfd..75978dca 100644 --- a/src/module.c +++ b/src/module.c @@ -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 diff --git a/src/posix.c b/src/posix.c index f01002ea..d8316904 100644 --- a/src/posix.c +++ b/src/posix.c @@ -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 (); } diff --git a/src/strings.c b/src/strings.c index 3aec0f9f..b1e17022 100644 --- a/src/strings.c +++ b/src/strings.c @@ -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); }