[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [COMMITTED] pkl: add assertion to `pvm_make_array_type'
From: |
Jose E. Marchesi |
Subject: |
Re: [COMMITTED] pkl: add assertion to `pvm_make_array_type' |
Date: |
Fri, 28 Oct 2022 11:28:24 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> Hi Jose.
>
> On Fri, Oct 28, 2022 at 01:14:46AM +0200, Jose E. Marchesi wrote:
>>
>> Hi Mohammad.
>>
>> > diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
>> > index 641fbd8b..54341761 100644
>> > --- a/libpoke/pvm-val.c
>> > +++ b/libpoke/pvm-val.c
>> > @@ -527,12 +527,14 @@ pvm_make_offset_type (pvm_val base_type, pvm_val
>> > unit)
>> > }
>> >
>> > pvm_val
>> > -pvm_make_array_type (pvm_val type, pvm_val bound)
>> > +pvm_make_array_type (pvm_val type, pvm_val bounder)
>> > {
>> > pvm_val atype = pvm_make_type (PVM_TYPE_ARRAY);
>> >
>> > + assert (bounder);
>>
>> I think this ought to be:
>>
>> assert (bounder != PVM_NULL);
>>
>
> Oops!
> Sorry!
>
> And fixing it leads to a bunch of failure in `poke.pickles' and
> `poke.std' directory!
Consider this:
-------------
diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
index 54341761..0ce493a3 100644
--- a/libpoke/pvm-val.c
+++ b/libpoke/pvm-val.c
@@ -531,7 +531,7 @@ pvm_make_array_type (pvm_val type, pvm_val bounder)
{
pvm_val atype = pvm_make_type (PVM_TYPE_ARRAY);
- assert (bounder);
+ assert (PVM_IS_CLS (bounder));
PVM_VAL_TYP_A_ETYPE (atype) = type;
PVM_VAL_TYP_A_BOUND (atype) = bounder;
diff --git a/poke/poke.c b/poke/poke.c
index 7b258410..6385b26a 100644
--- a/poke/poke.c
+++ b/poke/poke.c
@@ -322,6 +322,7 @@ set_script_args (int argc, char *argv[])
int i, nargs;
uint64_t index;
pk_val argv_array;
+ pk_val array_type_bounder = pk_decl_val (poke_compiler, "_pkl_mkclsn");
/* Look for -L SCRIPT */
for (i = 0; i < argc; ++i)
@@ -333,7 +334,7 @@ set_script_args (int argc, char *argv[])
nargs = argc - i;
argv_array = pk_make_array (pk_make_uint (nargs, 64),
pk_make_array_type (pk_make_string_type (),
- PK_NULL /* bound */));
+ array_type_bounder));
for (index = 0; i < argc; ++i, ++index)
pk_array_insert_elem (argv_array, index,
-------------
This works, but:
1) It makes use of the run-time _pkl_mkclsn, which is supposed to be an
internal detail of the compiler run-time. Also, it is not possible
for libpoke users to denote PVM_NULL, so the poke app cannot define a
bounder function that returns null, by itself.
2) pk_make_array_type in libpoke.h is documented to "at this point"
always get PK_NULL as the `bound' argument.
We could change the documentation of pk_make_array_type to say something
like this:
/* Build and return an array type.
ETYPE is the type of the elements of the array.
BOUNDER is either:
- PVM_NULL to denote an unbounded array.
- An uint<64> to denote an array type bounded by number of
elements.
- An offset<uint<64>,1> to denote an array type bounded by size. */
Then, in libpoke.c:pk_make_array_type we can pk_decl_val and pk_call
_pkl_mkclsn/_pkl_mkclsi/_pkl_mkclso to actually create the real bounder.
This would keep things simpler for libpoke users.
For example, poke.c would remain the same as today.
WDYT?