[teyjus] r1167 committed - Starting to handle standard streams properly in the C part + new error

1 view
Skip to first unread message

tey...@googlecode.com

unread,
Jan 10, 2015, 1:55:53 PM1/10/15
to teyju...@googlegroups.com
Revision: 1167
Author: fafo...@gmail.com
Date: Sat Jan 10 18:55:30 2015 UTC
Log: Starting to handle standard streams properly in the C part + new
error

https://code.google.com/p/teyjus/source/detail?r=1167

Modified:
/branches/ocaml-builtins/source/front/io.ml
/branches/ocaml-builtins/source/simulator/builtins/builtins.c
/branches/ocaml-builtins/source/simulator/builtins/builtins.h
/branches/ocaml-builtins/source/simulator/builtins/io.c
/branches/ocaml-builtins/source/simulator/builtins/io.h

=======================================
--- /branches/ocaml-builtins/source/front/io.ml Thu Jan 8 13:35:44 2015 UTC
+++ /branches/ocaml-builtins/source/front/io.ml Sat Jan 10 18:55:30 2015 UTC
@@ -71,10 +71,14 @@
(* This should not be reachable since the abstract
machine has checked the type of the argument before
giving it to the OCaml part *)
- ""
+ Printf.eprintf
+ "Teyjus encountered an internal error in inputNChars, please report a
bug\n" ;
+ raise Exit
with
| Not_found ->
- (* Is it possible to reach this point ? *)
+ (* The in_stream exists in the abstract machine but not
+ in the OCaml part:
+ this means that the stream was closed in the meantime. *)
""

let openFile fname mode =
=======================================
--- /branches/ocaml-builtins/source/simulator/builtins/builtins.c Sat Jun
23 10:19:10 2012 UTC
+++ /branches/ocaml-builtins/source/simulator/builtins/builtins.c Sat Jan
10 18:55:30 2015 UTC
@@ -217,6 +217,10 @@
BI_ERROR,
"Substring indexing out of bound.",
EM_NEWLINE, EM_QUERY, 0 },
+ { BI_ERROR_STANDARD_CLOSING,
+ BI_ERROR,
+ "Impossible to close the standard input.",
+ EM_NEWLINE, EM_QUERY, 0 },
};

/* handle the %B switch -- takes no arguments */
=======================================
--- /branches/ocaml-builtins/source/simulator/builtins/builtins.h Mon Sep
8 22:12:17 2008 UTC
+++ /branches/ocaml-builtins/source/simulator/builtins/builtins.h Sat Jan
10 18:55:30 2015 UTC
@@ -89,7 +89,7 @@
* ERROR INFORMATION

*********************************######**************************************/

-#define BI_NUM_ERROR_MESSAGES 28
+#define BI_NUM_ERROR_MESSAGES 29
enum
{
BI_ERROR = BI_FIRST_ERR_INDEX,
@@ -119,7 +119,8 @@
BI_ERROR_FLUSHING_STREAM, /* takes term (stream) */
BI_ERROR_OPENING_STRING, /* takes string */
BI_ERROR_INTEGER_EXPECTED, /* takes term */
- BI_ERROR_SUBSTRING
+ BI_ERROR_SUBSTRING,
+ BI_ERROR_STANDARD_CLOSING
};


=======================================
--- /branches/ocaml-builtins/source/simulator/builtins/io.c Thu Jan 8
13:36:05 2015 UTC
+++ /branches/ocaml-builtins/source/simulator/builtins/io.c Sat Jan 10
18:55:30 2015 UTC
@@ -42,6 +42,21 @@
#include "../../system/stream.h"
#include "../../front/io_c.h"

+static BIIO_finfo BIIO_stdstreams[3] = {
+ {FINFO_STDIN, NULL},
+ {FINFO_STDOUT, NULL},
+ {FINFO_STDERR, NULL}
+};
+
+
+
+WordPtr FINFO_stdin = (WordPtr)&BIIO_stdstreams[0];
+WordPtr FINFO_stdout = (WordPtr)&BIIO_stdstreams[1];
+WordPtr FINFO_stderr = (WordPtr)&BIIO_stdstreams[2];
+
+
+
+
/* unify types */
static void BIIO_typesUnify(DF_TypePtr typ1, DF_TypePtr typ2)
{
@@ -96,9 +111,9 @@
if (DF_isConst(tmPtr)) {
cstInd = DF_constTabIndex(tmPtr);
switch (cstInd) {
- case PERV_STDIN_INDEX: return NULL;
- case PERV_STDOUT_INDEX: return NULL;
- case PERV_STDERR_INDEX: return NULL;
+ case PERV_STDIN_INDEX: return FINFO_stdin;
+ case PERV_STDOUT_INDEX: return FINFO_stdout;
+ case PERV_STDERR_INDEX: return FINFO_stderr;
default: EM_error(BI_ERROR_NON_STREAM_TERM, tmPtr);
}
} else EM_error(BI_ERROR_NON_STREAM_TERM, tmPtr);
@@ -220,6 +235,8 @@
EM_error(BI_ERROR_CANNOT_OPEN_STREAM, fname);

finfo = (BIIO_finfo *)EM_malloc(sizeof(BIIO_finfo));
+ //TODO: modify for standard streams
+ finfo->type = FINFO_FILE;
finfo->name = EM_strdup(fname);

BIIO_bindVarToFinfo(((DF_TermPtr)AM_reg(2)), (WordPtr)finfo);
@@ -240,6 +257,8 @@
if (DF_isFV(tmPtr)) EM_error(BI_ERROR_UNBOUND_VARIABLE, "stream");

finfo = BIIO_getFinfoFromTerm(tmPtr);
+ if (((BIIO_finfo*)finfo)->type != FINFO_FILE)
+ EM_error(BI_ERROR_STANDARD_CLOSING);
fname = ((BIIO_finfo*)finfo)->name;

if (FRONT_IO_close(fname) == -1)
@@ -317,13 +336,12 @@
tmPtr= ((DF_TermPtr)(AM_reg(1)));

finfo = BIIO_getFinfoFromTerm(tmPtr);
- if (finfo != NULL) {
- fname = ((BIIO_finfo*)finfo)->name;
- }
+ //TODO: handle standard streams here
+ fname = ((BIIO_finfo*)finfo)->name;

buffer = FRONT_IO_inputNChars(fname, num);

- if (strcmp(buffer, "") != 0) {
+ if (strcmp(buffer, "") == 0) {
/* There were two kind of errors when IO was managed in C.
* However the BI_ERROR_READING_STREAM was impossible to be thrown
* since it required to input in a stream which didn't have the
=======================================
--- /branches/ocaml-builtins/source/simulator/builtins/io.h Tue Jan 6
18:16:51 2015 UTC
+++ /branches/ocaml-builtins/source/simulator/builtins/io.h Sat Jan 10
18:55:30 2015 UTC
@@ -41,6 +41,7 @@



+
void BIIO_openIn();
void BIIO_openOut();
void BIIO_openApp();
Reply all
Reply to author
Forward
0 new messages