From: kostasch Date: Fri, 3 Jul 2020 20:27:44 +0300 Subject: [PATCH] pk_struct_type interface for libpoke. 2020-07-03 Kostas Chasialis *libpoke/libpoke.h (pk_make_struct_type): Prototype. (pk_struct_type): Likewise. (pk_allocate_struct_attrs): Likewise. (pk_struct_type_name): Likewise. (pk_struct_type_nfields): Likewise. (pk_struct_type_fname): Likewise. (pk_struct_type_set_fname): Likewise. (pk_struct_type_ftype): Likewise. (pk_struct_type_set_ftype): Likewise. *libpoke/pk-val.c (pk_make_struct_type): Define. (pk_struct_type): Likewise. (pk_allocate_struct_attrs): Likewise. (pk_struct_type_name): Likewise. (pk_struct_type_nfields): Likewise. (pk_struct_type_fname): Likewise. (pk_struct_type_set_fname): Likewise. (pk_struct_type_ftype): Likewise. (pk_struct_type_set_ftype): Likewise. --- ChangeLog | 21 +++++++++++++ libpoke/libpoke.h | 75 +++++++++++++++++++++++++++++++++++++++++++++++ libpoke/pk-val.c | 62 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8acc6882..a36c8ec9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2020-07-03 Kostas Chasialis + + *libpoke/libpoke.h (pk_make_struct_type): Prototype. + (pk_struct_type): Likewise. + (pk_allocate_struct_attrs): Likewise. + (pk_struct_type_name): Likewise. + (pk_struct_type_nfields): Likewise. + (pk_struct_type_fname): Likewise. + (pk_struct_type_set_fname): Likewise. + (pk_struct_type_ftype): Likewise. + (pk_struct_type_set_ftype): Likewise. + *libpoke/pk-val.c (pk_make_struct_type): Define. + (pk_struct_type): Likewise. + (pk_allocate_struct_attrs): Likewise. + (pk_struct_type_name): Likewise. + (pk_struct_type_nfields): Likewise. + (pk_struct_type_fname): Likewise. + (pk_struct_type_set_fname): Likewise. + (pk_struct_type_ftype): Likewise. + (pk_struct_type_set_ftype): Likewise. + 2020-07-02 Kostas Chasialis * libpoke/libpoke.h (pk_make_struct): Prototype. diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h index a0d4c23b..8fb8b48f 100644 --- a/libpoke/libpoke.h +++ b/libpoke/libpoke.h @@ -688,6 +688,80 @@ pk_val pk_offset_type_base_type (pk_val type); pk_val pk_offset_type_unit (pk_val type); +/* Struct types. */ + +/* Build and return a struct type. + + NFIELDS is the number of struct fields on this struct. + + NAME is a string containing the name of a struct type. + + FNAMES is a C array containing the name of each struct field. + + FTYPES is a C array containing the types of each struct field. */ + +pk_val pk_make_struct_type (pk_val nfields, pk_val name, pk_val *fnames, pk_val *ftypes); + +/* Get the type of a struct. */ + +pk_val pk_struct_type (pk_val sct); + +/* Allocate space for struct fields names and field types. */ + +void pk_allocate_struct_attrs (pk_val nfields, pk_val **fnames, pk_val **ftypes); + +/* Get the name of a struct type. */ + +pk_val pk_struct_type_name (pk_val type); + +/* Get the number of fields of a struct type. */ + +pk_val pk_struct_type_nfields (pk_val type); + +/* Get the name of a field in a struct type. + + TYPE is a struct type. + + IDX is the index of the field in a struct type. + + If IDX is invalid, PK_NULL is returned. */ + +pk_val pk_struct_type_fname (pk_val type, uint64_t idx); + +/* Set the name of a field of a struct type. + + TYPE is a struct type. + + IDX is the index of the field in a struct type. + + NAME is a string containing the name of the field in a struct type. + + If IDX is invalid, type remains unchanged. */ + +void pk_struct_type_set_fname (pk_val type, uint64_t idx, pk_val field_name); + +/* Get type of a field in the struct. + + TYPE is a struct type. + + IDX is the index of the struct field. + + If IDX is invalid, PK_NULL is returned. */ + +pk_val pk_struct_type_ftype (pk_val type, uint64_t idx); + +/* Set the type of a field of a struct type. + + TYPE is a struct type. + + IDX is the index of the field in a struct type. + + TYPE is the type of the field in a struct type. + + If IDX is invalid, type remains unchanged. */ + +void pk_struct_type_set_ftype (pk_val type, uint64_t idx, pk_val field_type); + /* Array types. */ /* Build and return an array type. @@ -708,6 +782,7 @@ pk_val pk_array_type_etype (pk_val type); pk_val pk_array_type_bound (pk_val type); + /* Mapped values. */ /* Return a boolean indicating whether the given value is mapped or diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c index e65b6f08..cb70e416 100644 --- a/libpoke/pk-val.c +++ b/libpoke/pk-val.c @@ -290,6 +290,68 @@ pk_make_any_type (void) return pvm_make_any_type (); } +pk_val +pk_make_struct_type (pk_val nfields, pk_val name, pk_val *fnames, pk_val *ftypes) +{ + return pvm_make_struct_type (nfields, name, fnames, ftypes); +} + +pk_val +pk_struct_type (pk_val sct) +{ + return PVM_VAL_SCT_TYPE (sct); +} + +void +pk_allocate_struct_attrs (pk_val nfields, pk_val **fnames, pk_val **ftypes) +{ + pvm_allocate_struct_attrs (nfields, fnames, ftypes); +} + +pk_val +pk_struct_type_name (pk_val type) +{ + return PVM_VAL_TYP_S_NAME (type); +} + +pk_val +pk_struct_type_nfields (pk_val type) +{ + return PVM_VAL_TYP_S_NFIELDS (type); +} + +pk_val +pk_struct_type_fname (pk_val type, uint64_t idx) +{ + if (idx < pk_uint_value (pk_struct_type_nfields (type))) + return PVM_VAL_TYP_S_FNAME (type, idx); + else + return PK_NULL; +} + +void +pk_struct_type_set_fname (pk_val type, uint64_t idx, pk_val field_name) +{ + if (idx < pk_uint_value (pk_struct_type_nfields (type))) + PVM_VAL_TYP_S_FNAME (type, idx) = field_name; +} + +pk_val +pk_struct_type_ftype (pk_val type, uint64_t idx) +{ + if (idx < pk_uint_value (pk_struct_type_nfields (type))) + return PVM_VAL_TYP_S_FTYPE (type, idx); + else + return PK_NULL; +} + +void +pk_struct_type_set_ftype (pk_val type, uint64_t idx, pk_val field_type) +{ + if (idx < pk_uint_value (pk_struct_type_nfields (type))) + PVM_VAL_TYP_S_FTYPE (type, idx) = field_type; +} + pk_val pk_make_array_type (pk_val etype, pk_val bound) { -- 2.17.1