commit 43c7bd97d2668ab7bbabf4ffdc89b9bf1bb1ee29
parent 991c894888284602f94bdad21f4e1806366cd486
Author: Andres Navarro <canavarro82@gmail.com>
Date: Thu, 17 Mar 2011 14:31:49 -0300
Added object definition, kwrite case and free mem case for Ports.
Diffstat:
3 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/kobject.h b/src/kobject.h
@@ -30,6 +30,7 @@
#include <stdbool.h>
#include <stdint.h>
+#include <stdio.h>
/*
** Union of all collectible objects
@@ -123,6 +124,7 @@ typedef struct __attribute__ ((__packed__)) GCheader {
#define K_TAPPLICATIVE 36
#define K_TENCAPSULATION 37
#define K_TPROMISE 38
+#define K_TPORT 39
#define K_MAKE_VTAG(t) (K_TAG_TAGGED | (t))
@@ -156,6 +158,7 @@ typedef struct __attribute__ ((__packed__)) GCheader {
#define K_TAG_APPLICATIVE K_MAKE_VTAG(K_TAPPLICATIVE)
#define K_TAG_ENCAPSULATION K_MAKE_VTAG(K_TENCAPSULATION)
#define K_TAG_PROMISE K_MAKE_VTAG(K_TPROMISE)
+#define K_TAG_PORT K_MAKE_VTAG(K_TPORT)
/*
@@ -194,6 +197,7 @@ typedef struct __attribute__ ((__packed__)) GCheader {
#define ttiscontinuation(o) (tbasetype_(o) == K_TAG_CONTINUATION)
#define ttisencapsulation(o) (tbasetype_(o) == K_TAG_ENCAPSULATION)
#define ttispromise(o) (tbasetype_(o) == K_TAG_PROMISE)
+#define ttisport(o) (tbasetype_(o) == K_TAG_PORT)
/* macros to easily check boolean values */
#define kis_true(o_) (tv_equal((o_), KTRUE))
@@ -307,6 +311,15 @@ typedef struct __attribute__ ((__packed__)) {
sharing the pair */
} Promise;
+/* input/output direction and open/close status are in flags */
+typedef struct __attribute__ ((__packed__)) {
+ CommonHeader;
+ TValue name;
+ TValue si; /* source code info (either () or (filename line col) */
+ TValue filename;
+ FILE *file;
+} Port;
+
/*
** RATIONALE:
**
@@ -346,6 +359,7 @@ union GCObject {
Applicative app;
Encapsulation enc;
Promise prom;
+ Port port;
};
@@ -407,6 +421,7 @@ const TValue keminf;
#define gc2app(o_) (gc2tv(K_TAG_APPLICATIVE, o_))
#define gc2enc(o_) (gc2tv(K_TAG_ENCAPSULATION, o_))
#define gc2prom(o_) (gc2tv(K_TAG_PROMISE, o_))
+#define gc2port(o_) (gc2tv(K_TAG_PORT, o_))
/* Macro to convert a TValue into a specific heap allocated object */
#define tv2pair(v_) ((Pair *) gcvalue(v_))
@@ -418,6 +433,7 @@ const TValue keminf;
#define tv2app(v_) ((Applicative *) gcvalue(v_))
#define tv2enc(v_) ((Encapsulation *) gcvalue(v_))
#define tv2prom(v_) ((Promise *) gcvalue(v_))
+#define tv2port(v_) ((Port *) gcvalue(v_))
#define tv2gch(v_) ((GCheader *) gcvalue(v_))
#define tv2mgch(v_) ((MGCheader *) gcvalue(v_))
diff --git a/src/kstate.c b/src/kstate.c
@@ -460,6 +460,9 @@ void klisp_close (klisp_State *K)
case K_TPROMISE:
klispM_free(K, (Promise *)obj);
break;
+ case K_TPORT:
+ klispM_free(K, (Port *)obj);
+ break;
default:
/* shouldn't happen */
fprintf(stderr, "Unknown GCObject type: %d\n", type);
diff --git a/src/kwrite.c b/src/kwrite.c
@@ -217,8 +217,13 @@ void kwrite_simple(klisp_State *K, TValue obj)
kw_printf(K, "[encapsulation]");
break;
case K_TPROMISE:
+ /* TODO try to get the name */
kw_printf(K, "[promise]");
break;
+ case K_TPORT:
+ /* TODO try to get the name/ I/O direction / filename */
+ kw_printf(K, "[port]");
+ break;
default:
/* shouldn't happen */
kwrite_error(K, "unknown object type");