Skip to content

Commit

Permalink
nci: add cstr, pshort/pint/plong
Browse files Browse the repository at this point in the history
the old 't' type as string,
and the pnum types for PMC access to integers (Integer).

fail: only t/pmc/nci_13.pir v (void) special-case
  • Loading branch information
Reini Urban committed Jan 13, 2015
1 parent 26e92ab commit 0cf0c58
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
15 changes: 12 additions & 3 deletions include/parrot/datatypes.h
@@ -1,6 +1,6 @@
/*
* datatypes.h
* Copyright (C) 2002-2012, Parrot Foundation.
* Copyright (C) 2002-2015, Parrot Foundation.
* License: Artistic 2.0, see README.pod and LICENSE for details
* Overview:
* Parrot and native data types enums and type names.
Expand Down Expand Up @@ -40,6 +40,7 @@ typedef enum {
enum_type_float, /* native float types */
enum_type_double,
enum_type_longdouble,
enum_type_float128,

enum_type_int8, /* fixed size types */
enum_type_int16,
Expand All @@ -57,11 +58,14 @@ typedef enum {
enum_type_void,

enum_type_ptr, /* native pointer */
enum_type_cstr, /* c string */
enum_type_cstr, /* 't' c string */
enum_type_struct_ptr, /* pointer to another struct */
enum_type_struct, /* a struct */
enum_type_union, /* a union */
enum_type_func_ptr, /* a function pointer */
enum_type_pshort, /* '2' Integer PMC -> short */
enum_type_pint, /* '3' Integer PMC -> int */
enum_type_plong, /* '4' Integer PMC -> long */

enum_type_sized,

Expand Down Expand Up @@ -122,6 +126,8 @@ const struct _data_types data_types[] = {
{ "longdouble", sizeof (long double), ALIGNOF(longdouble, long double)},
# ifdef PARROT_HAS_FLOAT128
{ "__float128", sizeof (__float128), ALIGNOF1(__float128)},
# else
{ "__float128", 0, 0 },
# endif

/* explicitly sized integer types */
Expand All @@ -146,14 +152,17 @@ const struct _data_types data_types[] = {
{ "uint64", 0, 0 },
# endif

{ "void", 0, 0 },
{ "void", 0, 0 },

{ "ptr", sizeof (void *), ALIGNOF(voidptr, void *) },
{ "cstr", sizeof (char *), ALIGNOF(charptr, char *) },
{ "struct_ptr", sizeof (void *), ALIGNOF(voidptr, void *) },
{ "struct", 0, 0 },
{ "union", 0, 0 },
{ "func_ptr", sizeof (funcptr_t), ALIGNOF1(funcptr_t) },
{ "pshort", sizeof (short), ALIGNOF1(short) },
{ "pint", sizeof (int), ALIGNOF1(int) },
{ "plong", sizeof (long), ALIGNOF1(long) },

{ "sized", 0, 0 },

Expand Down
31 changes: 29 additions & 2 deletions src/nci/libffi.c
@@ -1,4 +1,4 @@
/* Copyright (C) 2010-2014, Parrot Foundation.
/* Copyright (C) 2010-2015, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -417,12 +417,24 @@ prep_pcc_ret_arg(PARROT_INTERP, PARROT_DATA_TYPE t, parrot_var_t *pv, void **rv,
pv->i = *(Parrot_Int4 *)val;
*rv = &pv->i;
break;
case enum_type_pshort:
pv->i = *(short *)val;
*rv = &pv->i;
break;
case enum_type_pint:
pv->i = *(int *)val;
*rv = &pv->i;
break;
#if PARROT_HAS_INT64
case enum_type_int64:
case enum_type_plong:
pv->i = *(Parrot_Int8 *)val;
#else
case enum_type_plong:
pv->i = *(long *)val;
#endif
*rv = &pv->i;
break;
#endif
case enum_type_INTVAL:
pv->i = *(INTVAL *)val;
*rv = &pv->i;
Expand Down Expand Up @@ -618,6 +630,21 @@ call_ffi_thunk(PARROT_INTERP, ARGMOD(PMC *nci_pmc), ARGMOD(PMC *self))
nci_val[i].S = pcc_arg[i].s;
nci_arg_ptr[i] = &nci_val[i].S;
break;
case enum_type_plong:
#if PARROT_HAS_INT64
nci_val[i].i64 = (long)VTABLE_get_integer(interp, pcc_arg[i].p);
nci_arg_ptr[i] = &nci_val[i].i64;
break;
#endif
case enum_type_pint:
nci_val[i].i32 = VTABLE_get_integer(interp, pcc_arg[i].p);
nci_arg_ptr[i] = &nci_val[i].i32;
break;
case enum_type_pshort:
nci_val[i].i16 = (short)VTABLE_get_integer(interp, pcc_arg[i].p);
nci_arg_ptr[i] = &nci_val[i].i16;
break;

case enum_type_PMC:
nci_val[i].P = pcc_arg[i].p;
nci_arg_ptr[i] = &nci_val[i].P;
Expand Down
21 changes: 16 additions & 5 deletions src/nci/signatures.c
Expand Up @@ -7,8 +7,7 @@ src/nci/signatures.c - Native Call Interface signature processing routines
=head1 DESCRIPTION
This file implements functionality for parsing NCI signatures and generating PCC
signatures.
Parse NCI signatures and generate PCC signatures.
=head2 Functions
Expand Down Expand Up @@ -95,6 +94,15 @@ Parrot_nci_parse_signature(PARROT_INTERP, ARGIN(STRING *sig_str))
case 'I': /* INTVAL */
e = enum_type_INTVAL;
break;
case '2': /* short PMC */
e = enum_type_pshort;
break;
case '3': /* int PMC */
e = enum_type_pint;
break;
case '4': /* long PMC */
e = enum_type_plong;
break;

case 'S':
e = enum_type_STRING;
Expand Down Expand Up @@ -153,17 +161,20 @@ ncidt_to_pcc(PARROT_INTERP, PARROT_DATA_TYPE t)
case enum_type_int:
case enum_type_long:
case enum_type_INTVAL:
case enum_type_pshort:
case enum_type_pint:
case enum_type_plong:
return 'I';

case enum_type_STRING:
case enum_type_cstr:
return 'S';

case enum_type_ptr:
case enum_type_PMC:
return 'P';

case enum_type_struct_ptr:
case enum_type_void:
return 'v';
return 'P';

default:
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_KEY_NOT_FOUND,
Expand Down
20 changes: 19 additions & 1 deletion src/pmc/structview.pmc
Expand Up @@ -299,7 +299,6 @@ C<uint16>, C<int32>, C<uint32>, C<int64>(*), and C<uint64>(*)
#if PARROT_HAS_INT64
case enum_type_uint64:
#endif

elt_access = int_access;
break;

Expand All @@ -314,11 +313,15 @@ C<uint16>, C<int32>, C<uint32>, C<int64>(*), and C<uint64>(*)
case enum_type_float:
case enum_type_double:
case enum_type_longdouble:
#ifdef PARROT_HAS_FLOAT128
case enum_type_float128:
#endif
elt_access = num_access;
break;

/* other types */
case enum_type_STRING:
case enum_type_cstr:
elt_access = str_access;
break;
case enum_type_sized:
Expand All @@ -329,6 +332,9 @@ C<uint16>, C<int32>, C<uint32>, C<int64>(*), and C<uint64>(*)
case enum_type_PMC:
case enum_type_ptr:
case enum_type_func_ptr:
case enum_type_pshort:
case enum_type_pint:
case enum_type_plong:
elt_access = pmc_access;
break;

Expand Down Expand Up @@ -665,6 +671,10 @@ Get/Set a float-like element from a struct-pointer PMC.
return *(double *)ptr;
case enum_type_longdouble:
return *(long double *)ptr;
#ifdef PARROT_HAS_FLOAT128
case enum_type_float128:
return *(__float128 *)ptr;
#endif
default:
break;
}
Expand Down Expand Up @@ -692,6 +702,10 @@ Get/Set a float-like element from a struct-pointer PMC.
case enum_type_longdouble:
*(long double *)ptr = n;
return;
#ifdef PARROT_HAS_FLOAT128
case enum_type_float128:
*(__float128 *)ptr = n;
#endif
default:
break;
}
Expand Down Expand Up @@ -721,6 +735,8 @@ Get/Set a string element from a struct-pointer PMC.
switch (elts[i].type) {
case enum_type_STRING:
return *(STRING **)ptr;
case enum_type_cstr:
return Parrot_str_new(interp, *(char **)ptr, 0);
default:
break;
}
Expand All @@ -739,6 +755,8 @@ Get/Set a string element from a struct-pointer PMC.
case enum_type_STRING:
*(STRING **)ptr = s;
return;
case enum_type_cstr:
*(char **)ptr = Parrot_str_to_cstring(interp, s);
default:
break;
}
Expand Down

0 comments on commit 0cf0c58

Please sign in to comment.