adding initial untyped "cpointer" data type

This commit is contained in:
Alex Shinn 2009-08-11 01:14:39 +09:00
parent c6499c8b62
commit 8ba102c5c4
2 changed files with 18 additions and 0 deletions

View file

@ -14,6 +14,9 @@
#ifdef PLAN9 #ifdef PLAN9
#include <u.h> #include <u.h>
#include <libc.h> #include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
typedef unsigned long size_t; typedef unsigned long size_t;
#else #else
#include <stddef.h> #include <stddef.h>
@ -66,6 +69,7 @@ enum sexp_types {
SEXP_VECTOR, SEXP_VECTOR,
SEXP_FLONUM, SEXP_FLONUM,
SEXP_BIGNUM, SEXP_BIGNUM,
SEXP_CPOINTER,
SEXP_IPORT, SEXP_IPORT,
SEXP_OPORT, SEXP_OPORT,
SEXP_EXCEPTION, SEXP_EXCEPTION,
@ -163,6 +167,9 @@ struct sexp_struct {
sexp_uint_t length; sexp_uint_t length;
sexp_uint_t data[]; sexp_uint_t data[];
} bignum; } bignum;
struct {
void *value;
} cpointer;
/* runtime types */ /* runtime types */
struct { struct {
char flags; char flags;
@ -341,6 +348,7 @@ sexp sexp_make_flonum(sexp ctx, double f);
#define sexp_iportp(x) (sexp_check_tag(x, SEXP_IPORT)) #define sexp_iportp(x) (sexp_check_tag(x, SEXP_IPORT))
#define sexp_oportp(x) (sexp_check_tag(x, SEXP_OPORT)) #define sexp_oportp(x) (sexp_check_tag(x, SEXP_OPORT))
#define sexp_bignump(x) (sexp_check_tag(x, SEXP_BIGNUM)) #define sexp_bignump(x) (sexp_check_tag(x, SEXP_BIGNUM))
#define sexp_cpointerp(x) (sexp_check_tag(x, SEXP_CPOINTER))
#define sexp_exceptionp(x) (sexp_check_tag(x, SEXP_EXCEPTION)) #define sexp_exceptionp(x) (sexp_check_tag(x, SEXP_EXCEPTION))
#define sexp_procedurep(x) (sexp_check_tag(x, SEXP_PROCEDURE)) #define sexp_procedurep(x) (sexp_check_tag(x, SEXP_PROCEDURE))
#define sexp_envp(x) (sexp_check_tag(x, SEXP_ENV)) #define sexp_envp(x) (sexp_check_tag(x, SEXP_ENV))
@ -420,6 +428,8 @@ sexp sexp_make_flonum(sexp ctx, double f);
#define sexp_exception_procedure(p) ((p)->value.exception.procedure) #define sexp_exception_procedure(p) ((p)->value.exception.procedure)
#define sexp_exception_source(p) ((p)->value.exception.source) #define sexp_exception_source(p) ((p)->value.exception.source)
#define sexp_cpointer_value(p) ((p)->value.cpointer.value)
#define sexp_bytecode_length(x) ((x)->value.bytecode.length) #define sexp_bytecode_length(x) ((x)->value.bytecode.length)
#define sexp_bytecode_name(x) ((x)->value.bytecode.name) #define sexp_bytecode_name(x) ((x)->value.bytecode.name)
#define sexp_bytecode_literals(x) ((x)->value.bytecode.literals) #define sexp_bytecode_literals(x) ((x)->value.bytecode.literals)
@ -606,6 +616,7 @@ SEXP_API sexp sexp_intern(sexp ctx, char *str);
SEXP_API sexp sexp_string_to_symbol(sexp ctx, sexp str); SEXP_API sexp sexp_string_to_symbol(sexp ctx, sexp str);
SEXP_API sexp sexp_make_vector(sexp ctx, sexp len, sexp dflt); SEXP_API sexp sexp_make_vector(sexp ctx, sexp len, sexp dflt);
SEXP_API sexp sexp_list_to_vector(sexp ctx, sexp ls); SEXP_API sexp sexp_list_to_vector(sexp ctx, sexp ls);
SEXP_API sexp sexp_make_cpointer(sexp ctx, void* value);
SEXP_API void sexp_write(sexp ctx, sexp obj, sexp out); SEXP_API void sexp_write(sexp ctx, sexp obj, sexp out);
SEXP_API sexp sexp_read_string(sexp ctx, sexp in); SEXP_API sexp sexp_read_string(sexp ctx, sexp in);
SEXP_API sexp sexp_read_symbol(sexp ctx, sexp in, int init, int internp); SEXP_API sexp sexp_read_symbol(sexp ctx, sexp in, int init, int internp);

7
sexp.c
View file

@ -74,6 +74,7 @@ static struct sexp_struct sexp_type_specs[] = {
_DEF_TYPE(SEXP_VECTOR, sexp_offsetof(vector, data), 0, sexp_offsetof(vector, length), 1, sexp_sizeof(vector), sexp_offsetof(vector, length), 4, "vector"), _DEF_TYPE(SEXP_VECTOR, sexp_offsetof(vector, data), 0, sexp_offsetof(vector, length), 1, sexp_sizeof(vector), sexp_offsetof(vector, length), 4, "vector"),
_DEF_TYPE(SEXP_FLONUM, 0, 0, 0, 0, sexp_sizeof(flonum), 0, 0, "flonum"), _DEF_TYPE(SEXP_FLONUM, 0, 0, 0, 0, sexp_sizeof(flonum), 0, 0, "flonum"),
_DEF_TYPE(SEXP_BIGNUM, 0, 0, 0, 0, sexp_sizeof(bignum), sexp_offsetof(bignum, length), 4, "bignum"), _DEF_TYPE(SEXP_BIGNUM, 0, 0, 0, 0, sexp_sizeof(bignum), sexp_offsetof(bignum, length), 4, "bignum"),
_DEF_TYPE(SEXP_CPOINTER, 0, 0, 0, 0, sexp_sizeof(cpointer), 0, 0, "cpointer"),
_DEF_TYPE(SEXP_IPORT, sexp_offsetof(port, name), 2, 0, 0, sexp_sizeof(port), 0, 0, "input-port"), _DEF_TYPE(SEXP_IPORT, sexp_offsetof(port, name), 2, 0, 0, sexp_sizeof(port), 0, 0, "input-port"),
_DEF_TYPE(SEXP_OPORT, sexp_offsetof(port, name), 2, 0, 0, sexp_sizeof(port), 0, 0, "output-port"), _DEF_TYPE(SEXP_OPORT, sexp_offsetof(port, name), 2, 0, 0, sexp_sizeof(port), 0, 0, "output-port"),
_DEF_TYPE(SEXP_EXCEPTION, sexp_offsetof(exception, kind), 6, 0, 0, sexp_sizeof(exception), 0, 0, "exception"), _DEF_TYPE(SEXP_EXCEPTION, sexp_offsetof(exception, kind), 6, 0, 0, sexp_sizeof(exception), 0, 0, "exception"),
@ -554,6 +555,12 @@ sexp sexp_list_to_vector(sexp ctx, sexp ls) {
return vec; return vec;
} }
sexp sexp_make_cpointer (sexp ctx, void *value) {
sexp ptr = sexp_alloc_type(ctx, port, SEXP_CPOINTER);
sexp_cpointer_value(ptr) = value;
return ptr;
}
/************************ reading and writing *************************/ /************************ reading and writing *************************/
#if USE_BIGNUMS #if USE_BIGNUMS