[uim-commit] r999 - branches/r5rs/sigscheme

kzk at freedesktop.org kzk at freedesktop.org
Thu Jul 21 18:46:18 EST 2005


Author: kzk
Date: 2005-07-21 01:46:15 -0700 (Thu, 21 Jul 2005)
New Revision: 999

Modified:
   branches/r5rs/sigscheme/datas.c
   branches/r5rs/sigscheme/io.c
   branches/r5rs/sigscheme/main.c
   branches/r5rs/sigscheme/sigscheme.c
   branches/r5rs/sigscheme/sigscheme.h
   branches/r5rs/sigscheme/sigschemetype.h
Log:
* introduce PortDirection and PortType as follows. Then, I'm going to add
  PORT_STRING related code for eval_c_string function.

/* ScmPort direction */
enum ScmPortDirection {
    PORT_INPUT  = 0,
    PORT_OUTPUT = 1
};

/* ScmPort type */
enum ScmPortType {
    PORT_FILE   = 0,
    PORT_STRING = 1
};

* sigscheme/io.c
  - (ScmOp_open_output_file, ScmOp_open_input_file):
    - use SCM_PORT_PORTDIRECTION instead of SCM_PORT_PORTTYPE
    - fix Scm_NewPort args

* sigscheme/sigscheme.c
  - (SigScm_Initialize): fix Scm_NewPort args
* sigscheme/sigscheme.h
  - (Scm_NewPort): change args
* sigscheme/sigschemetype.h
* sigscheme/datas.c
  - introduce ScmPortDirection and ScmPortType
* sigscheme/main.c
  - (repl): fix Scm_NewPort args and fix indentation



Modified: branches/r5rs/sigscheme/datas.c
===================================================================
--- branches/r5rs/sigscheme/datas.c	2005-07-21 08:19:01 UTC (rev 998)
+++ branches/r5rs/sigscheme/datas.c	2005-07-21 08:46:15 UTC (rev 999)
@@ -416,7 +416,7 @@
     /* get size */
     size = end - start;
 
-    printf("gc_mark_stack() size = %p\n", (void*)start);
+    printf("gc_mark_stack() : size = %d\n", size);
 
     /* mark stack */
     for (i = 0; i < size; i++) {
@@ -668,20 +668,34 @@
     return obj;
 }
 
-ScmObj Scm_NewPort(FILE *file, enum ScmPortType ptype)
+ScmObj Scm_NewPort(FILE *file, enum ScmPortDirection pdirection, enum ScmPortType ptype)
 {
     ScmObj obj = SCM_NIL;
-    ScmPortInfo *pinfo = NULL;
+    ScmPortInfo *pinfo = (ScmPortInfo *)malloc(sizeof(ScmPortInfo));;
 
     SCM_NEW_OBJ_INTERNAL(obj);
 
     SCM_SETPORT(obj);
-    pinfo  = (ScmPortInfo *)malloc(sizeof(ScmPortInfo));
-    pinfo->file         = file;
-    pinfo->line         = 0;
-    pinfo->ungottenchar = 0;
+    SCM_SETPORT_PORTDIRECTION(obj, pdirection);
+    switch (ptype) {
+	case PORT_FILE:
+	    {
+
+		pinfo->file         = file;
+		pinfo->line         = 0;
+		pinfo->ungottenchar = 0;
+	    }
+	    break;
+	case PORT_STRING:
+	    {
+		/* TODO : implemented this immediately! */
+	    }
+	    break;
+	default:
+	    SigScm_Error("Scm_NewPort : invalid port type\n");
+	    break;
+    }
     SCM_SETPORT_PORTINFO(obj, pinfo);
-    SCM_SETPORT_PORTTYPE(obj, ptype);
 
     return obj;
 }

Modified: branches/r5rs/sigscheme/io.c
===================================================================
--- branches/r5rs/sigscheme/io.c	2005-07-21 08:19:01 UTC (rev 998)
+++ branches/r5rs/sigscheme/io.c	2005-07-21 08:46:15 UTC (rev 999)
@@ -114,7 +114,7 @@
 
 ScmObj ScmOp_input_portp(ScmObj obj)
 {
-    if (SCM_PORTP(obj) && SCM_PORT_PORTTYPE(obj) == PORT_INPUT)
+    if (SCM_PORTP(obj) && SCM_PORT_PORTDIRECTION(obj) == PORT_INPUT)
 	return SCM_TRUE;
 
     return SCM_FALSE;
@@ -122,7 +122,7 @@
 
 ScmObj ScmOp_output_portp(ScmObj obj)
 {
-    if (SCM_PORTP(obj) && SCM_PORT_PORTTYPE(obj) == PORT_OUTPUT)
+    if (SCM_PORTP(obj) && SCM_PORT_PORTDIRECTION(obj) == PORT_OUTPUT)
 	return SCM_TRUE;
 
     return SCM_FALSE;
@@ -203,7 +203,7 @@
         SigScm_ErrorObj("open-input-file : cannot open file ", filepath);
 
     /* Allocate ScmPort */
-    return Scm_NewPort(f, PORT_INPUT);
+    return Scm_NewPort(f, PORT_INPUT, PORT_FILE);
 }
 
 ScmObj ScmOp_open_output_file(ScmObj filepath)
@@ -219,7 +219,7 @@
         SigScm_ErrorObj("open-output-file : cannot open file ", filepath);
 
     /* Return new ScmPort */
-    return Scm_NewPort(f, PORT_OUTPUT);
+    return Scm_NewPort(f, PORT_OUTPUT, PORT_FILE);
 }
 
 ScmObj ScmOp_close_input_port(ScmObj port)

Modified: branches/r5rs/sigscheme/main.c
===================================================================
--- branches/r5rs/sigscheme/main.c	2005-07-21 08:19:01 UTC (rev 998)
+++ branches/r5rs/sigscheme/main.c	2005-07-21 08:46:15 UTC (rev 999)
@@ -55,23 +55,23 @@
 /* Very simple repl, please rewrite. */
 static void repl(void)
 {
-  ScmObj stdin_port  = Scm_NewPort(stdin, PORT_INPUT);
-  ScmObj stdout_port = Scm_NewPort(stdout, PORT_INPUT);
-  ScmObj s_exp, result;
+    ScmObj stdin_port  = Scm_NewPort(stdin,  PORT_INPUT, PORT_FILE);
+    ScmObj stdout_port = Scm_NewPort(stdout, PORT_INPUT, PORT_FILE);
+    ScmObj s_exp, result;
 
-  printf("sscm> ");
+    printf("sscm> ");
 
-  for( s_exp = SigScm_Read(stdin_port);
-       !EQ(s_exp, SCM_EOF);
-       s_exp = SigScm_Read(stdin_port))
-  { 
-    result = ScmOp_eval(s_exp, SCM_NIL);
-    SigScm_DisplayToPort(stdout_port, result);
-    printf("\nsscm> ");
-  }
-
-  ScmOp_close_input_port(stdin_port);
-  ScmOp_close_input_port(stdout_port);
+    for( s_exp = SigScm_Read(stdin_port);
+	 !EQ(s_exp, SCM_EOF);
+	 s_exp = SigScm_Read(stdin_port))
+    {
+	result = ScmOp_eval(s_exp, SCM_NIL);
+	SigScm_DisplayToPort(stdout_port, result);
+	printf("\nsscm> ");
+    }
+    
+    ScmOp_close_input_port(stdin_port);
+    ScmOp_close_input_port(stdout_port);
 }
 
 /*=======================================

Modified: branches/r5rs/sigscheme/sigscheme.c
===================================================================
--- branches/r5rs/sigscheme/sigscheme.c	2005-07-21 08:19:01 UTC (rev 998)
+++ branches/r5rs/sigscheme/sigscheme.c	2005-07-21 08:46:15 UTC (rev 999)
@@ -260,9 +260,9 @@
     /*=======================================================================
       Current Input & Output Initialization
     =======================================================================*/
-    current_input_port  = Scm_NewPort(stdin,  PORT_INPUT);
+    current_input_port  = Scm_NewPort(stdin,  PORT_INPUT,  PORT_FILE);
     SigScm_gc_protect(current_input_port);
-    current_output_port = Scm_NewPort(stdout, PORT_OUTPUT);
+    current_output_port = Scm_NewPort(stdout, PORT_OUTPUT, PORT_FILE);
     SigScm_gc_protect(current_output_port);
 
     stack_start_pointer = NULL;

Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h	2005-07-21 08:19:01 UTC (rev 998)
+++ branches/r5rs/sigscheme/sigscheme.h	2005-07-21 08:46:15 UTC (rev 999)
@@ -125,7 +125,7 @@
 ScmObj Scm_NewFunc(enum ScmFuncArgNum num_arg, ScmFuncType func);
 ScmObj Scm_NewClosure(ScmObj exp, ScmObj env);
 ScmObj Scm_NewVector(ScmObj *vec, int len);
-ScmObj Scm_NewPort(FILE *file, enum ScmPortType ptype);
+ScmObj Scm_NewPort(FILE *file, enum ScmPortDirection pdireciton, enum ScmPortType ptype);
 ScmObj Scm_NewContinuation(void);
 ScmObj Scm_NewCPointer(void *data);
 ScmObj Scm_NewCFuncPointer(C_FUNC func);

Modified: branches/r5rs/sigscheme/sigschemetype.h
===================================================================
--- branches/r5rs/sigscheme/sigschemetype.h	2005-07-21 08:19:01 UTC (rev 998)
+++ branches/r5rs/sigscheme/sigschemetype.h	2005-07-21 08:46:15 UTC (rev 999)
@@ -85,12 +85,18 @@
     GC_Marked = 1
 };
 
-/* ScmPort type */
-enum ScmPortType {
+/* ScmPort direction */
+enum ScmPortDirection {
     PORT_INPUT  = 0,
     PORT_OUTPUT = 1
 };
 
+/* ScmPort type */
+enum ScmPortType {
+    PORT_FILE   = 0,
+    PORT_STRING = 1
+};
+
 /* ScmPort Info */
 typedef struct _ScmPortInfo ScmPortInfo;
 struct _ScmPortInfo {
@@ -177,8 +183,9 @@
         } vector;
 
         struct ScmPort {
-            enum ScmPortType port_type;
-            ScmPortInfo     *port_info;
+            enum ScmPortDirection port_direction; /* (PORT_INPUT | PORT_OUTPUT) */
+            enum ScmPortType      port_type;      /* (PORT_FILE  | PORT_STRING) */
+            ScmPortInfo *port_info;
         } port;
 
         struct ScmContinuation {
@@ -292,10 +299,10 @@
 
 #define SCM_PORTP(a) (SCM_GETTYPE(a) == ScmPort)
 #define SCM_PORT(a)  (sigassert(SCM_PORTP(a)), a)
-#define SCM_PORT_PORTTYPE(a) (SCM_PORT(a)->obj.port.port_type)
+#define SCM_PORT_PORTDIRECTION(a) (SCM_PORT(a)->obj.port.port_direction)
 #define SCM_PORT_PORTINFO(a) (SCM_PORT(a)->obj.port.port_info)
 #define SCM_SETPORT(a) (SCM_SETTYPE(a, ScmPort))
-#define SCM_SETPORT_PORTTYPE(a, ptype) (SCM_PORT_PORTTYPE(a) = ptype)
+#define SCM_SETPORT_PORTDIRECTION(a, pdirection) (SCM_PORT_PORTDIRECTION(a) = pdirection)
 #define SCM_SETPORT_PORTINFO(a, pinfo) (SCM_PORT_PORTINFO(a) = pinfo)
 #define SCM_PORTINFO_FILE(a) (SCM_PORT_PORTINFO(a)->file)
 #define SCM_PORTINFO_LINE(a) (SCM_PORT_PORTINFO(a)->line)



More information about the uim-commit mailing list