From c59b01fe00da9ce23432d9882bd683e471f63037 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 22 Mar 2016 21:54:32 -0400 Subject: [PATCH] Beginning to add u8vector type --- include/cyclone/runtime.h | 2 ++ include/cyclone/types.h | 6 ++++++ runtime.c | 14 ++++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index c7816d71..e956d9ae 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -29,6 +29,7 @@ #define Cyc_check_str(d,obj) Cyc_check_type(d,Cyc_is_string, string_tag, obj); #define Cyc_check_sym(d,obj) Cyc_check_type(d,Cyc_is_symbol, symbol_tag, obj); #define Cyc_check_vec(d,obj) Cyc_check_type(d,Cyc_is_vector, vector_tag, obj); +#define Cyc_check_bvec(d,obj) Cyc_check_type(d,Cyc_is_bytevector, bytevector_tag, obj); #define Cyc_check_port(d,obj) Cyc_check_type(d,Cyc_is_port, port_tag, obj); #define Cyc_check_mutex(d,obj) Cyc_check_type(d,Cyc_is_mutex, mutex_tag, obj); #define Cyc_check_cond_var(d,obj) Cyc_check_type(d,Cyc_is_cond_var, cond_var_tag, obj); @@ -198,6 +199,7 @@ object Cyc_is_number(object o); object Cyc_is_real(object o); object Cyc_is_integer(object o); object Cyc_is_vector(object o); +object Cyc_is_bytevector(object o); object Cyc_is_port(object o); object Cyc_is_mutex(object o); object Cyc_is_cond_var(object o); diff --git a/include/cyclone/types.h b/include/cyclone/types.h index a8ec4499..c1090913 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -185,6 +185,7 @@ typedef long tag_type; #define macro_tag 18 #define mutex_tag 19 #define cond_var_tag 20 +#define bytevector_tag 21 #define nil NULL #define eq(x,y) (x == y) @@ -297,6 +298,11 @@ typedef vector_type *vector; #define make_empty_vector(v) vector_type v; v.hdr.mark = gc_color_red; v.hdr.grayed = 0; v.tag = vector_tag; v.num_elt = 0; v.elts = NULL; +/* Bytevector type */ + +typedef struct {gc_header_type hdr; tag_type tag; int len; char *data;} bytevector_type; +typedef bytevector_type *bytevector; + /* Define cons type. */ typedef struct {gc_header_type hdr; tag_type tag; object cons_car,cons_cdr;} cons_type; diff --git a/runtime.c b/runtime.c index ab7957ec..18988eb6 100644 --- a/runtime.c +++ b/runtime.c @@ -27,15 +27,15 @@ object Cyc_global_set(void *thd, object *glo, object value) /* Error checking section - type mismatch, num args, etc */ /* Type names to use for error messages */ -const char *tag_names[22] = { \ +const char *tag_names[23] = { \ "pair" \ , "symbol" \ , "" \ , "procedure" \ , "procedure" \ - , "procedure" \ - , "procedure" \ - , "procedure" \ + , "" \ + , "" \ + , "" \ , "procedure" \ , "number" \ , "number" \ @@ -49,6 +49,7 @@ const char *tag_names[22] = { \ , "macro" \ , "mutex" \ , "condition variable" \ + , "bytevector" \ , "Reserved for future use" }; void Cyc_invalid_type_error(void *data, int tag, object found) { @@ -840,6 +841,11 @@ object Cyc_is_vector(object o){ return boolean_t; return boolean_f;} +object Cyc_is_bytevector(object o){ + if (!nullp(o) && !is_value_type(o) && ((list)o)->tag == bytevector_tag) + return boolean_t; + return boolean_f;} + object Cyc_is_port(object o){ if (!nullp(o) && !is_value_type(o) && ((list)o)->tag == port_tag) return boolean_t;