|
From: Martin R. <ru...@us...> - 2004-08-05 22:38:05
|
Update of /cvsroot/foo/foo/elkfoo/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6206 Modified Files: context.m Log Message: integrated with MacOSX hack (serialization disabled) Index: context.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/context.m,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** context.m 5 Aug 2004 18:58:52 -0000 1.3 --- context.m 5 Aug 2004 22:37:56 -0000 1.4 *************** *** 52,55 **** --- 52,56 ---- SchemeObject V_Context; + static void Check_Context(o) SchemeObject o; *************** *** 60,63 **** --- 61,65 ---- } + SchemeObject Get_Context() { *************** *** 72,75 **** --- 74,78 ---- } + id getCurrentContext() /* used in ../kernel/Context.h */ { *************** *** 84,87 **** --- 87,91 ---- } + static SchemeObject P_Contextp(x) SchemeObject x; *************** *** 90,93 **** --- 94,98 ---- } + static SchemeObject P_Context_Lockedp(context) SchemeObject context; *************** *** 105,110 **** --- 110,117 ---- } + static int Debug_Context = 0; + static SchemeObject P_Debug_Context(flag) SchemeObject flag; *************** *** 119,122 **** --- 126,130 ---- } + static SchemeObject Kill_Context(context) SchemeObject context; *************** *** 126,134 **** fflush(stderr); } ! [CONTEXT_T(context)->pointer free]; CONTEXT_T(context)->pointer = NULL; return True; } static SchemeObject P_Kill_Context(context) SchemeObject context; --- 134,143 ---- fflush(stderr); } ! RELEASE(CONTEXT_T(context)->pointer); CONTEXT_T(context)->pointer = NULL; return True; } + static SchemeObject P_Kill_Context(context) SchemeObject context; *************** *** 140,143 **** --- 149,153 ---- } + static SchemeObject P_Kill_All_Contexts() { *************** *** 146,149 **** --- 156,160 ---- } + SchemeObject A_Make_Context(c) id c; *************** *** 163,166 **** --- 174,178 ---- } + static SchemeObject P_Make_Context(chans) SchemeObject chans; *************** *** 175,178 **** --- 187,191 ---- } + static SchemeObject P_Push_Time_Frame(context, number) SchemeObject context, number; *************** *** 192,195 **** --- 205,209 ---- } + static SchemeObject P_Pop_Time_Frame(context) SchemeObject context; *************** *** 209,212 **** --- 223,227 ---- } + static SchemeObject P_Context_Time(context) SchemeObject context; *************** *** 216,219 **** --- 231,235 ---- } + static SchemeObject P_Context_Time_Frames(context) SchemeObject context; *************** *** 223,226 **** --- 239,243 ---- } + static SchemeObject P_Context_Pointer(context) SchemeObject context; *************** *** 230,390 **** } ! int Write_Context(fp, context) ! FILE *fp; ! id context; ! { ! // NXStream *s; ! TypedStream *ts; ! // if ((s = NXOpenFile(fileno(fp), OBJC_WRITEONLY)) == NULL) ! // return -1; ! // if ((ts = objc_open_typed_stream(s, OBJC_WRITEONLY)) == NULL) { ! if ((ts = objc_open_typed_stream(fp, OBJC_WRITEONLY)) == NULL) { ! // NXClose(s); ! return -2; ! } ! objc_write_root_object(ts, context); ! objc_close_typed_stream(ts); ! // NXClose(s); ! return 1; ! } ! static SchemeObject P_Context_Write(argc, argv) ! int argc; ! SchemeObject *argv; ! { ! // NXStream *s; ! // TypedStream *ts; ! SchemeObject context = argv[0], port; ! if (argc < 2) ! port = Curr_Output_Port; ! else ! port = argv[1]; ! Check_Context(context); ! Check_Type(port, T_Port); ! if (!IS_OUTPUT(port)) ! Primitive_Error("not an output port: ~a", port); ! if (PORT(port)->flags & P_STRING) ! Primitive_Error("not a file port: ~a", port); ! switch (Write_Context(PORT(port)->file, CONTEXT_T(context)->pointer)) { ! case -1: ! Primitive_Error("cannot open stream for: ~a", port); ! case -2: ! // NXClose(s); ! Primitive_Error("cannot open typed stream for: ~a", port); ! } ! return True; ! } ! int Read_Context(fp, context) ! FILE *fp; ! id *context; ! { ! // NXStream *s; ! TypedStream *ts; ! // id c; ! // if ((s = NXOpenFile(fileno(fp), NX_READONLY)) == NULL) ! // return -1; ! // if ((ts = NXOpenTypedStream(s, NX_READONLY)) == NULL) { ! if ((ts = objc_open_typed_stream(fp, OBJC_READONLY)) == NULL) { ! // NXClose(s); ! return -2; ! } ! if (objc_read_object(ts, context) == -1) { ! objc_close_typed_stream(ts); ! // NXClose(s); ! return -3; ! } ! objc_close_typed_stream(ts); ! // NXClose(s); ! // *context = c; ! return 1; ! } ! static SchemeObject P_Context_Read(argc, argv) ! int argc; ! SchemeObject *argv; ! { ! SchemeObject port; ! // NXStream *s; ! // TypedStream *ts; ! id c; ! if (argc < 1) ! port = Curr_Input_Port; ! else ! port = argv[0]; ! Check_Type(port, T_Port); ! if (!IS_INPUT(port)) ! Primitive_Error("not an input port: ~a", port); ! if (PORT(port)->flags & P_STRING) ! Primitive_Error("not a file port: ~a", port); ! switch (Read_Context(PORT(port)->file, &c)) { ! case -1: ! Primitive_Error("cannot open stream for: ~a", port); ! case -2: ! Primitive_Error("cannot open typed stream for: ~a", port); ! case -3: ! Primitive_Error("cannot read from typed stream for: ~a", port); ! } ! return A_Make_Context(c); ! } ! static SchemeObject P_Context_Copy(context) ! SchemeObject context; ! { ! id c; ! // NXStream *ws, *rs; ! FILE *stream; ! TypedStream *ts; ! // char *buffer; ! // int len, maxlen; ! /* use tempfile instead of memory stream (workaround = ugly) */ ! Check_Context(context); ! // if ((ws = NXOpenMemory(NULL, 0, NX_WRITEONLY)) == NULL) ! // Primitive_Error("cannot open memory write stream"); ! // create tempfile ! if (! (stream = tmpfile())) ! { ! Primitive_Error("cannot create temporary file"); ! } ! // create typed stream ! if ((ts = objc_open_typed_stream(stream, OBJC_WRITEONLY)) == NULL) { ! // NXCloseMemory(ws, NX_FREEBUFFER); ! Primitive_Error("cannot open typed write stream"); ! } ! objc_write_root_object(ts, CONTEXT_T(context)->pointer); ! objc_close_typed_stream(ts); ! // NXGetMemoryBuffer(ws, &buffer, &len, &maxlen); ! // if ((rs = NXOpenMemory(buffer, len, NX_READONLY)) == NULL) ! // Primitive_Error("cannot open memory read stream"); ! rewind(stream); ! if ((ts = objc_open_typed_stream(stream, OBJC_READONLY)) == NULL) { ! // NXCloseMemory(ws, NX_FREEBUFFER); ! Primitive_Error("cannot open typed read stream"); ! } ! if (objc_read_object(ts, &c) == -1) ! Primitive_Error("bad context read"); ! objc_close_typed_stream(ts); ! // NXCloseMemory(ws, NX_FREEBUFFER); ! // NXCloseMemory(rs, NX_FREEBUFFER); ! fclose(stream); - return A_Make_Context(c); - } static SchemeObject P_Context_Interval(context) --- 247,413 ---- } ! // commented out so far ! // int Write_Context(fp, context) ! // FILE *fp; ! // id context; ! // { ! // // NXStream *s; ! // TypedStream *ts; ! // // if ((s = NXOpenFile(fileno(fp), OBJC_WRITEONLY)) == NULL) ! // // return -1; ! // // if ((ts = objc_open_typed_stream(s, OBJC_WRITEONLY)) == NULL) { ! // if ((ts = objc_open_typed_stream(fp, OBJC_WRITEONLY)) == NULL) { ! // // NXClose(s); ! // return -2; ! // } ! // objc_write_root_object(ts, context); ! // objc_close_typed_stream(ts); ! // // NXClose(s); ! // return 1; ! // } ! ! // static SchemeObject P_Context_Write(argc, argv) ! // int argc; ! // SchemeObject *argv; ! // { ! // // NXStream *s; ! // // TypedStream *ts; ! // SchemeObject context = argv[0], port; ! // if (argc < 2) ! // port = Curr_Output_Port; ! // else ! // port = argv[1]; ! // Check_Context(context); ! // Check_Type(port, T_Port); ! // if (!IS_OUTPUT(port)) ! // Primitive_Error("not an output port: ~a", port); ! // if (PORT(port)->flags & P_STRING) ! // Primitive_Error("not a file port: ~a", port); ! // switch (Write_Context(PORT(port)->file, CONTEXT_T(context)->pointer)) { ! // case -1: ! // Primitive_Error("cannot open stream for: ~a", port); ! // case -2: ! // // NXClose(s); ! // Primitive_Error("cannot open typed stream for: ~a", port); ! // } ! // return True; ! // } ! ! // int Read_Context(fp, context) ! // FILE *fp; ! // id *context; ! // { ! // // NXStream *s; ! // TypedStream *ts; ! // // id c; ! // // if ((s = NXOpenFile(fileno(fp), NX_READONLY)) == NULL) ! // // return -1; ! // // if ((ts = NXOpenTypedStream(s, NX_READONLY)) == NULL) { ! // if ((ts = objc_open_typed_stream(fp, OBJC_READONLY)) == NULL) { ! // // NXClose(s); ! // return -2; ! // } ! // if (objc_read_object(ts, context) == -1) { ! // objc_close_typed_stream(ts); ! // // NXClose(s); ! // return -3; ! // } ! // objc_close_typed_stream(ts); ! // // NXClose(s); ! // // *context = c; ! // return 1; ! // } ! ! // static SchemeObject P_Context_Read(argc, argv) ! // int argc; ! // SchemeObject *argv; ! // { ! // SchemeObject port; ! // // NXStream *s; ! // // TypedStream *ts; ! // id c; ! // if (argc < 1) ! // port = Curr_Input_Port; ! // else ! // port = argv[0]; ! // Check_Type(port, T_Port); ! // if (!IS_INPUT(port)) ! // Primitive_Error("not an input port: ~a", port); ! // if (PORT(port)->flags & P_STRING) ! // Primitive_Error("not a file port: ~a", port); ! // switch (Read_Context(PORT(port)->file, &c)) { ! // case -1: ! // Primitive_Error("cannot open stream for: ~a", port); ! // case -2: ! // Primitive_Error("cannot open typed stream for: ~a", port); ! // case -3: ! // Primitive_Error("cannot read from typed stream for: ~a", port); ! // } ! // return A_Make_Context(c); ! // } ! ! // static SchemeObject P_Context_Copy(context) ! // SchemeObject context; ! // { ! // id c; ! // // NXStream *ws, *rs; ! // FILE *stream; ! // TypedStream *ts; ! // // char *buffer; ! // // int len, maxlen; ! // /* use tempfile instead of memory stream (workaround = ugly) */ ! // Check_Context(context); ! // // if ((ws = NXOpenMemory(NULL, 0, NX_WRITEONLY)) == NULL) ! // // Primitive_Error("cannot open memory write stream"); ! // // create tempfile ! // if (! (stream = tmpfile())) ! // { ! // Primitive_Error("cannot create temporary file"); ! // } ! // // create typed stream ! // if ((ts = objc_open_typed_stream(stream, OBJC_WRITEONLY)) == NULL) { ! // // NXCloseMemory(ws, NX_FREEBUFFER); ! // Primitive_Error("cannot open typed write stream"); ! // } ! // objc_write_root_object(ts, CONTEXT_T(context)->pointer); ! // objc_close_typed_stream(ts); ! // // NXGetMemoryBuffer(ws, &buffer, &len, &maxlen); ! // // if ((rs = NXOpenMemory(buffer, len, NX_READONLY)) == NULL) ! // // Primitive_Error("cannot open memory read stream"); ! // rewind(stream); ! // if ((ts = objc_open_typed_stream(stream, OBJC_READONLY)) == NULL) { ! // // NXCloseMemory(ws, NX_FREEBUFFER); ! // Primitive_Error("cannot open typed read stream"); ! // } ! // if (objc_read_object(ts, &c) == -1) ! // Primitive_Error("bad context read"); ! // objc_close_typed_stream(ts); ! // // NXCloseMemory(ws, NX_FREEBUFFER); ! // // NXCloseMemory(rs, NX_FREEBUFFER); ! // fclose(stream); ! ! // return A_Make_Context(c); ! // } static SchemeObject P_Context_Interval(context) *************** *** 408,411 **** --- 431,435 ---- } + static int Context_Equal(a, b) SchemeObject a, b; *************** *** 414,417 **** --- 438,442 ---- } + static int Context_Print(x, port, raw, depth, length) SchemeObject x, port; *************** *** 426,429 **** --- 451,455 ---- } + static int Context_Visit(x, f) SchemeObject *x; *************** *** 438,441 **** --- 464,468 ---- } + #define DP Define_Primitive *************** *** 457,463 **** DP(P_Pop_Time_Frame, "foo:context-pop-time-frame", 1, 1, EVAL); DP(P_Context_Time, "foo:context-time", 1, 1, EVAL); ! DP(P_Context_Write, "foo:write-context", 1, 2, VARARGS); ! DP(P_Context_Read, "foo:read-context", 0, 1, VARARGS); ! DP(P_Context_Copy, "foo:copy-context", 1, 1, EVAL); DP(P_Context_Interval, "foo:context-interval", 1, 1, EVAL); --- 484,491 ---- DP(P_Pop_Time_Frame, "foo:context-pop-time-frame", 1, 1, EVAL); DP(P_Context_Time, "foo:context-time", 1, 1, EVAL); ! // serialization stuff commented out so far ! // DP(P_Context_Write, "foo:write-context", 1, 2, VARARGS); ! // DP(P_Context_Read, "foo:read-context", 0, 1, VARARGS); ! // DP(P_Context_Copy, "foo:copy-context", 1, 1, EVAL); DP(P_Context_Interval, "foo:context-interval", 1, 1, EVAL); |