diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1996-10-17 09:57:49 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1996-10-17 09:57:49 +0000 |
commit | b379e9a69157fcb8902ac222ab2692d5fb860cf3 (patch) | |
tree | 97eab779dc1ce3b37a44c4c359ce3a3df2ada098 /byterun | |
parent | bc96b0f934117b6d21105c6c97caf19ae3ee3ec3 (diff) | |
download | ocaml-b379e9a69157fcb8902ac222ab2692d5fb860cf3.tar.gz |
interp.c: retour a la division et au modulo de C (non specifies sur
les arguments negatifs)
io, startup: allocation des buffers d'I/O dans le tas majeur, comme
objets finalises.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1077 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun')
-rw-r--r-- | byterun/interp.c | 12 | ||||
-rw-r--r-- | byterun/io.c | 13 | ||||
-rw-r--r-- | byterun/io.h | 1 | ||||
-rw-r--r-- | byterun/startup.c | 20 |
4 files changed, 25 insertions, 21 deletions
diff --git a/byterun/interp.c b/byterun/interp.c index 7316c0e222..487f849d16 100644 --- a/byterun/interp.c +++ b/byterun/interp.c @@ -792,24 +792,16 @@ value interprete(prog, prog_size) Instruct(MULINT): accu = Val_long(Long_val(accu) * Long_val(*sp++)); Next; -#define Abs(x) (unsigned long)(x < 0 ? -x : x) - Instruct(DIVINT): { - long dividend = Long_val(accu); long divisor = Long_val(*sp++); if (divisor == 0) { Setup_for_c_call; raise_zero_divide(); } - accu = Abs(dividend) / Abs(divisor); - if ((dividend ^ divisor) < 0) accu = -accu; - accu = Val_long(accu); + accu = Val_long(Long_val(accu) / divisor); Next; } Instruct(MODINT): { - long dividend = Long_val(accu); long divisor = Long_val(*sp++); if (divisor == 0) { Setup_for_c_call; raise_zero_divide(); } - accu = Abs(dividend) % Abs(divisor); - if (dividend < 0) accu = -accu; - accu = Val_long(accu); + accu = Val_long(Long_val(accu) % divisor); Next; } Instruct(ANDINT): diff --git a/byterun/io.c b/byterun/io.c index 4679f0ee3c..4148dfb898 100644 --- a/byterun/io.c +++ b/byterun/io.c @@ -47,12 +47,21 @@ /* Common functions. */ +static void finalize_channel(vchan) + value vchan; +{ + struct channel * chan = (struct channel *) vchan; + close(chan->fd); +} + struct channel * open_descr(fd) int fd; { struct channel * channel; - channel = (struct channel *) stat_alloc(sizeof(struct channel)); + channel = (struct channel *) + alloc_final(sizeof(struct channel) / sizeof(value), + finalize_channel, 0, 1); channel->fd = fd; channel->offset = 0; channel->end = channel->buff + IO_BUFFER_SIZE; @@ -77,7 +86,7 @@ value close_channel(channel) /* ML */ { /* For output channels, must have flushed before */ close(channel->fd); - stat_free((char *) channel); + channel->fd = -1; return Val_unit; } diff --git a/byterun/io.h b/byterun/io.h index a5bfbecc30..5dae387242 100644 --- a/byterun/io.h +++ b/byterun/io.h @@ -25,6 +25,7 @@ #endif struct channel { + value final_fun; /* Finalization function */ int fd; /* Unix file descriptor */ long offset; /* Absolute position of fd in the file */ char * end; /* Physical end of the buffer */ diff --git a/byterun/startup.c b/byterun/startup.c index aba2bf7826..1388c4a48b 100644 --- a/byterun/startup.c +++ b/byterun/startup.c @@ -209,30 +209,32 @@ void caml_main(argc, argv) if (sigsetjmp(raise_buf.buf, 1) == 0) { external_raise = &raise_buf; - init_gc (minor_heap_init, heap_chunk_init, percent_free_init, verbose_init); init_stack(); init_atoms(); - + /* Load the code */ lseek(fd, - (long) (TRAILER_SIZE + trail.code_size + trail.data_size + trail.symbol_size + trail.debug_size), 2); - code_size = trail.code_size; start_code = (code_t) stat_alloc(code_size); if (read(fd, (char *) start_code, code_size) != code_size) fatal_error("Fatal error: truncated bytecode file.\n"); - #ifdef ARCH_BIG_ENDIAN fixup_endianness(start_code, code_size); #endif - - chan = open_descr(fd); - global_data = input_value(chan); - close_channel(chan); + /* Load the globals */ + { struct channel * chan; + Push_roots(r, 1); + chan = open_descr(fd); + r[0] = (value) chan; + global_data = input_value(chan); + close_channel(chan); + Pop_roots(); + } /* Ensure that the globals are in the major heap. */ oldify(global_data, &global_data); - + /* Run the code */ sys_init(argv + i); interprete(start_code, code_size); |