poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] libpoke,poke,poked,pokefmt,testsuite: add `pk_compiler' to `


From: Jose E. Marchesi
Subject: Re: [PATCH] libpoke,poke,poked,pokefmt,testsuite: add `pk_compiler' to `pk_make_*'
Date: Mon, 27 Nov 2023 05:06:05 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Mohammad.
OK.  Thanks.

> In order to have multiple Poke incremental compilers to co-exist,
> all the `pk_make_*' functions should get the compiler instance.
>
> 2023-11-26  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>
>       * libpoke/libpoke.h (pk_make_int): Add new param of type `pk_compiler'.
>       (pk_make_uint): Likewise.
>       (pk_make_string): Likewise.
>       (pk_make_offset): Likewise.
>       (pk_make_struct): Likewise.
>       (pk_make_array): Likewise.
>       (pk_make_integral_type): Likewise.
>       (pk_make_string_type): Likewise.
>       (pk_make_any_type): Likewise.
>       (pk_make_offset_type): Likewise.
>       (pk_make_struct_type): Likewise.
>       (pk_make_array_type): Likewise.
>       * libpoke/pk-val.c (pk_make_int): Likewise.
>       (pk_make_uint): Likewise.
>       (pk_make_string): Likewise.
>       (pk_make_offset): Likewise.
>       (pk_make_struct): Likewise.
>       (pk_make_array): Likewise.
>       (pk_make_integral_type): Likewise.
>       (pk_make_string_type): Likewise.
>       (pk_make_any_type): Likewise.
>       (pk_make_offset_type): Likewise.
>       (pk_make_struct_type): Likewise.
>       (pk_make_array_type): Likewise.
>       (pk_val_offset): Update.
>       * poke/pk-cmd-help (pk_cmd_help): Likewise.
>       (pk_cmd_set): Likewise.
>       * poke/pk-hserver.c (pk_hserver_token_p): Likewise.
>       (pk_hserver_token_kind): Likewise.
>       (pk_hserver_cmd): Likewise.
>       (pk_hserver_function): Likewise.
>       (pk_hserver_init): Likewise.
>       (pk_hserver_start): Likewise.
>       (pk_hserver_make_hyperlink): Likewise.
>       * poke/poke.c (pk_set_var_int): Likewise.
>       (set_script_args): Likewise.
>       (initialize): Likewise.
>       * poked/poked.c (poked_init): Likewise.
>       * pokefmt/pokefmt.l (poke_init): Likewise.
>       * testsuite/poke.libpoke/values.c (test_simple_values): Likewise.
>       (test_simple_values_mapping): Likewise.
>       (test_pk_typeof): Likewise.
>       (main): Pass `pk_compiler' to `test_simple_values',
>       `test_simple_values_mapping' and `test_pk_typeof'.
> ---
>
> Hi Jose,
>
> Another boring patch :)
>
>
>  ChangeLog                       | 47 ++++++++++++++++++++
>  libpoke/libpoke.h               | 32 ++++++++------
>  libpoke/pk-val.c                | 34 +++++++++------
>  poke/pk-cmd-help.c              |  2 +-
>  poke/pk-cmd-set.c               | 12 +++---
>  poke/pk-hserver.c               | 19 +++++----
>  poke/poke.c                     | 24 ++++++-----
>  poked/poked.c                   |  8 ++--
>  pokefmt/pokefmt.l               |  3 +-
>  testsuite/poke.libpoke/values.c | 76 +++++++++++++++++++--------------
>  10 files changed, 167 insertions(+), 90 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index aa2e9e81..e671faa6 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,50 @@
> +2023-11-26  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * libpoke/libpoke.h (pk_make_int): Add new param of type `pk_compiler'.
> +     (pk_make_uint): Likewise.
> +     (pk_make_string): Likewise.
> +     (pk_make_offset): Likewise.
> +     (pk_make_struct): Likewise.
> +     (pk_make_array): Likewise.
> +     (pk_make_integral_type): Likewise.
> +     (pk_make_string_type): Likewise.
> +     (pk_make_any_type): Likewise.
> +     (pk_make_offset_type): Likewise.
> +     (pk_make_struct_type): Likewise.
> +     (pk_make_array_type): Likewise.
> +     * libpoke/pk-val.c (pk_make_int): Likewise.
> +     (pk_make_uint): Likewise.
> +     (pk_make_string): Likewise.
> +     (pk_make_offset): Likewise.
> +     (pk_make_struct): Likewise.
> +     (pk_make_array): Likewise.
> +     (pk_make_integral_type): Likewise.
> +     (pk_make_string_type): Likewise.
> +     (pk_make_any_type): Likewise.
> +     (pk_make_offset_type): Likewise.
> +     (pk_make_struct_type): Likewise.
> +     (pk_make_array_type): Likewise.
> +     (pk_val_offset): Update.
> +     * poke/pk-cmd-help (pk_cmd_help): Likewise.
> +     (pk_cmd_set): Likewise.
> +     * poke/pk-hserver.c (pk_hserver_token_p): Likewise.
> +     (pk_hserver_token_kind): Likewise.
> +     (pk_hserver_cmd): Likewise.
> +     (pk_hserver_function): Likewise.
> +     (pk_hserver_init): Likewise.
> +     (pk_hserver_start): Likewise.
> +     (pk_hserver_make_hyperlink): Likewise.
> +     * poke/poke.c (pk_set_var_int): Likewise.
> +     (set_script_args): Likewise.
> +     (initialize): Likewise.
> +     * poked/poked.c (poked_init): Likewise.
> +     * pokefmt/pokefmt.l (poke_init): Likewise.
> +     * testsuite/poke.libpoke/values.c (test_simple_values): Likewise.
> +     (test_simple_values_mapping): Likewise.
> +     (test_pk_typeof): Likewise.
> +     (main): Pass `pk_compiler' to `test_simple_values',
> +     `test_simple_values_mapping' and `test_pk_typeof'.
> +
>  2023-11-24  Jose E. Marchesi  <jemarch@gnu.org>
>  
>       * libpoke/pkl-typify.c (pkl_typify2_ps_type_array): Sanity check
> diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
> index acced2e3..9a75bd98 100644
> --- a/libpoke/libpoke.h
> +++ b/libpoke/libpoke.h
> @@ -741,7 +741,7 @@ void pk_set_pretty_print (pk_compiler pkc, int 
> pretty_print_p) LIBPOKE_API;
>     Return PK_NULL if SIZE exceeds the maximum number of bits supported
>     in Poke integers.  */
>  
> -pk_val pk_make_int (int64_t value, int size) LIBPOKE_API;
> +pk_val pk_make_int (pk_compiler pkc, int64_t value, int size) LIBPOKE_API;
>  
>  /* Return the numerical value stored in the given Poke integer.
>     VAL should be a Poke value of the right type.  */
> @@ -763,7 +763,7 @@ int pk_int_size (pk_val val) LIBPOKE_API;
>     Return NULL if SIZE exceeds the maximum number of bits supported in
>     Poke integers.  */
>  
> -pk_val pk_make_uint (uint64_t value, int size) LIBPOKE_API;
> +pk_val pk_make_uint (pk_compiler pkc, uint64_t value, int size) LIBPOKE_API;
>  
>  /* Return the numerical value stored in the given Poke unsigned
>     integer.
> @@ -784,7 +784,7 @@ int pk_uint_size (pk_val val) LIBPOKE_API;
>     STR is a NULL-terminated string, a copy of which will become the
>     value of the Poke string.  */
>  
> -pk_val pk_make_string (const char *str) LIBPOKE_API;
> +pk_val pk_make_string (pk_compiler pkc, const char *str) LIBPOKE_API;
>  
>  /* Return a NULL-terminated string with the value of the given Poke
>     string.  */
> @@ -804,7 +804,8 @@ const char *pk_string_str (pk_val val) LIBPOKE_API;
>     If any of the arguments is not of the right type return PK_NULL.
>     Otherwise return the created offset.  */
>  
> -pk_val pk_make_offset (pk_val magnitude, pk_val unit) LIBPOKE_API;
> +pk_val pk_make_offset (pk_compiler pkc, pk_val magnitude,
> +                       pk_val unit) LIBPOKE_API;
>  
>  /* Return the magnitude of the given Poke offset.  */
>  
> @@ -826,7 +827,8 @@ pk_val pk_offset_unit (pk_val val) LIBPOKE_API;
>     The fields and methods in the created struct are initialized to
>     PK_NULL.  */
>  
> -pk_val pk_make_struct (pk_val nfields, pk_val type) LIBPOKE_API;
> +pk_val pk_make_struct (pk_compiler pkc, pk_val nfields,
> +                       pk_val type) LIBPOKE_API;
>  
>  /* Get the number of fields of a struct. */
>  
> @@ -941,7 +943,8 @@ void pk_struct_set_field_value (pk_val sct, uint64_t idx,
>     ARRAY_TYPE is the type of the array.  Note, this is an array type,
>     not the type of the elements.  */
>  
> -pk_val pk_make_array (pk_val nelem, pk_val array_type) LIBPOKE_API;
> +pk_val pk_make_array (pk_compiler pkc, pk_val nelem,
> +                      pk_val array_type) LIBPOKE_API;
>  
>  /* Get the number of elements in the given array value, as an
>     uint<64>.  */
> @@ -1007,7 +1010,8 @@ uint64_t pk_sizeof (pk_val val) LIBPOKE_API;
>     SIGNED_P is an int<32> with a boolean specifying whether the type
>     is signed or not.  */
>  
> -pk_val pk_make_integral_type (pk_val size, pk_val signed_p) LIBPOKE_API;
> +pk_val pk_make_integral_type (pk_compiler pkc, pk_val size,
> +                              pk_val signed_p) LIBPOKE_API;
>  
>  /* Return an uint<64> containing the size, in bits, of the given
>     integral type.  */
> @@ -1023,13 +1027,13 @@ pk_val pk_integral_type_signed_p (pk_val type) 
> LIBPOKE_API;
>  
>  /* Build and return the string type.  */
>  
> -pk_val pk_make_string_type (void) LIBPOKE_API;
> +pk_val pk_make_string_type (pk_compiler pkc) LIBPOKE_API;
>  
>  /* The `any' type.  */
>  
>  /* Build and return the `any' type.  */
>  
> -pk_val pk_make_any_type (void) LIBPOKE_API;
> +pk_val pk_make_any_type (pk_compiler pkc) LIBPOKE_API;
>  
>  /* Offset types.  */
>  
> @@ -1044,7 +1048,8 @@ pk_val pk_make_any_type (void) LIBPOKE_API;
>     REF_TYPE is either PK_NULL or the type of the referenced type if the
>     offset is also a reference or pointer.  */
>  
> -pk_val pk_make_offset_type (pk_val base_type, pk_val unit, pk_val ref_type) 
> LIBPOKE_API;
> +pk_val pk_make_offset_type (pk_compiler pkc, pk_val base_type, pk_val unit,
> +                            pk_val ref_type) LIBPOKE_API;
>  
>  /* Get the base type of a given offset type.  */
>  
> @@ -1066,8 +1071,8 @@ pk_val pk_offset_type_unit (pk_val type) LIBPOKE_API;
>  
>     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) LIBPOKE_API;
> +pk_val pk_make_struct_type (pk_compiler pkc, pk_val nfields, pk_val name,
> +                            pk_val *fnames, pk_val *ftypes) LIBPOKE_API;
>  
>  /* Get the type of a struct.
>     This function is DEPRECATED; please use pk_typeof instead.  */
> @@ -1151,7 +1156,8 @@ void pk_struct_type_set_ftype (pk_val type, uint64_t 
> idx,
>     - A closure ()offset<uint<64>,1> to denote an array type bounded by
>       size.  */
>  
> -pk_val pk_make_array_type (pk_val etype, pk_val bound) LIBPOKE_API;
> +pk_val pk_make_array_type (pk_compiler pkc, pk_val etype,
> +                           pk_val bound) LIBPOKE_API;
>  
>  /* Get the type of the elements of the given array type.  */
>  
> diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c
> index 5bafce8f..dde9ea6a 100644
> --- a/libpoke/pk-val.c
> +++ b/libpoke/pk-val.c
> @@ -24,7 +24,7 @@
>  #include "libpoke.h"
>  
>  pk_val
> -pk_make_int (int64_t value, int size)
> +pk_make_int (pk_compiler pkc __attribute__ ((unused)), int64_t value, int 
> size)
>  {
>    return pvm_make_signed_integral (value, size);
>  }
> @@ -48,7 +48,8 @@ pk_int_size (pk_val val)
>  }
>  
>  pk_val
> -pk_make_uint (uint64_t value, int size)
> +pk_make_uint (pk_compiler pkc __attribute__ ((unused)), uint64_t value,
> +              int size)
>  {
>    return pvm_make_unsigned_integral (value, size);
>  }
> @@ -72,7 +73,7 @@ pk_uint_size (pk_val val)
>  }
>  
>  pk_val
> -pk_make_string (const char *str)
> +pk_make_string (pk_compiler pkc __attribute__ ((unused)), const char *str)
>  {
>    return pvm_make_string (str);
>  }
> @@ -84,7 +85,8 @@ pk_string_str (pk_val val)
>  }
>  
>  pk_val
> -pk_make_offset (pk_val magnitude, pk_val unit)
> +pk_make_offset (pk_compiler pkc __attribute__ ((unused)), pk_val magnitude,
> +                pk_val unit)
>  {
>    if (!PVM_IS_INTEGRAL (magnitude)
>        || !PVM_IS_ULONG (unit)
> @@ -174,10 +176,10 @@ pk_val_offset (pk_val val)
>    /* XXX "upunit" properly so we get a nice unit, not just bytes or
>       bits.  */
>    if (bit_offset % 8 == 0)
> -    return pk_make_offset (pvm_make_ulong (bit_offset / 8, 64),
> +    return pk_make_offset (/*pkc*/ NULL, pvm_make_ulong (bit_offset / 8, 64),
>                             pvm_make_ulong (8, 64));
>    else
> -    return pk_make_offset (val_offset, pvm_make_ulong (1, 64));
> +    return pk_make_offset (/*pkc*/ NULL, val_offset, pvm_make_ulong (1, 64));
>  }
>  
>  void
> @@ -282,7 +284,8 @@ pk_val_equal_p (pk_val val1, pk_val val2)
>  }
>  
>  pk_val
> -pk_make_struct (pk_val nfields, pk_val type)
> +pk_make_struct (pk_compiler pkc __attribute__ ((unused)), pk_val nfields,
> +                pk_val type)
>  {
>    return pvm_make_struct (nfields, pvm_make_ulong (0, 64), type);
>  }
> @@ -355,13 +358,15 @@ pk_struct_set_field_value (pk_val sct, uint64_t idx, 
> pk_val value)
>  }
>  
>  pk_val
> -pk_make_array (pk_val nelem, pk_val array_type)
> +pk_make_array (pk_compiler pkc __attribute__ ((unused)), pk_val nelem,
> +               pk_val array_type)
>  {
>    return pvm_make_array (nelem, array_type);
>  }
>  
>  pk_val
> -pk_make_integral_type (pk_val size, pk_val signed_p)
> +pk_make_integral_type (pk_compiler pkc __attribute__ ((unused)), pk_val size,
> +                       pk_val signed_p)
>  {
>    return pvm_make_integral_type (size, signed_p);
>  }
> @@ -379,13 +384,14 @@ pk_integral_type_signed_p (pk_val type)
>  }
>  
>  pk_val
> -pk_make_string_type (void)
> +pk_make_string_type (pk_compiler pkc __attribute__ ((unused)))
>  {
>    return pvm_make_string_type ();
>  }
>  
>  pk_val
> -pk_make_offset_type (pk_val base_type, pk_val unit, pk_val ref_type)
> +pk_make_offset_type (pk_compiler pkc __attribute__ ((unused)),
> +                     pk_val base_type, pk_val unit, pk_val ref_type)
>  {
>    return pvm_make_offset_type (base_type, unit, ref_type);
>  }
> @@ -403,7 +409,8 @@ pk_offset_type_unit (pk_val type)
>  }
>  
>  pk_val
> -pk_make_struct_type (pk_val nfields, pk_val name, pk_val *fnames, pk_val 
> *ftypes)
> +pk_make_struct_type (pk_compiler pkc __attribute__ ((unused)), pk_val 
> nfields,
> +                     pk_val name, pk_val *fnames, pk_val *ftypes)
>  {
>    return pvm_make_struct_type (nfields, name, fnames, ftypes);
>  }
> @@ -465,7 +472,8 @@ pk_struct_type_set_ftype (pk_val type, uint64_t idx, 
> pk_val field_type)
>  }
>  
>  pk_val
> -pk_make_array_type (pk_val etype, pk_val bound)
> +pk_make_array_type (pk_compiler pkc __attribute__ ((unused)), pk_val etype,
> +                    pk_val bound)
>  {
>    return pvm_make_array_type (etype, bound);
>  }
> diff --git a/poke/pk-cmd-help.c b/poke/pk-cmd-help.c
> index ebf4afd1..99732a87 100644
> --- a/poke/pk-cmd-help.c
> +++ b/poke/pk-cmd-help.c
> @@ -33,7 +33,7 @@ pk_cmd_help (int argc, struct pk_cmd_arg argv[], uint64_t 
> uflags)
>    assert (argc == 2);
>  
>    assert (PK_CMD_ARG_TYPE (argv[1]) == PK_CMD_ARG_STR);
> -  topic = pk_make_string (PK_CMD_ARG_STR (argv[1]));
> +  topic = pk_make_string (poke_compiler, PK_CMD_ARG_STR (argv[1]));
>  
>    pk_help = pk_decl_val (poke_compiler, "pk_help");
>    assert (pk_help != PK_NULL);
> diff --git a/poke/pk-cmd-set.c b/poke/pk-cmd-set.c
> index a2b7c76e..6044ceb3 100644
> --- a/poke/pk-cmd-set.c
> +++ b/poke/pk-cmd-set.c
> @@ -69,7 +69,7 @@ pk_cmd_set (int int_p,
>        assert (registry_get != PK_NULL);
>  
>        if (pk_call (poke_compiler, registry_get, &retval, &exit_exception,
> -                   2, pk_make_string (setting_name), registry)
> +                   2, pk_make_string (poke_compiler, setting_name), registry)
>            == PK_ERROR
>            || exit_exception != PK_NULL)
>          /* This shouldn't happen.  */
> @@ -87,16 +87,16 @@ pk_cmd_set (int int_p,
>        const char *retmsg;
>  
>        if (int_p)
> -        val = pk_make_int (PK_CMD_ARG_INT (argv[1]), 32);
> +        val = pk_make_int (poke_compiler, PK_CMD_ARG_INT (argv[1]), 32);
>        else
> -        val = pk_make_string (PK_CMD_ARG_STR (argv[1]));
> +        val = pk_make_string (poke_compiler, PK_CMD_ARG_STR (argv[1]));
>  
>        registry_set = pk_struct_ref_field_value (registry, "set");
>        assert (registry_set != PK_NULL);
>  
> -      if (pk_call (poke_compiler, registry_set, &retval, &exit_exception,
> -                   3, pk_make_string (setting_name), val, registry)
> -          == PK_ERROR
> +      if (pk_call (poke_compiler, registry_set, &retval, &exit_exception, 3,
> +                   pk_make_string (poke_compiler, setting_name), val, 
> registry)
> +              == PK_ERROR
>            || exit_exception != PK_NULL)
>          /* This shouldn't happen, since we know `newval' is of the
>             right type.  */
> diff --git a/poke/pk-hserver.c b/poke/pk-hserver.c
> index 8fe353e5..d2e2b5d9 100644
> --- a/poke/pk-hserver.c
> +++ b/poke/pk-hserver.c
> @@ -90,7 +90,7 @@ static int
>  pk_hserver_token_p (int token)
>  {
>    pk_val cls = pk_decl_val (poke_compiler, "hserver_token_p");
> -  pk_val token_val = pk_make_int (token, 32);
> +  pk_val token_val = pk_make_int (poke_compiler, token, 32);
>    pk_val token_p, exit_exception;
>    int ret;
>  
> @@ -106,7 +106,7 @@ static char
>  pk_hserver_token_kind (int token)
>  {
>    pk_val cls = pk_decl_val (poke_compiler, "hserver_token_kind");
> -  pk_val token_val = pk_make_int (token, 32);
> +  pk_val token_val = pk_make_int (poke_compiler, token, 32);
>    pk_val token_kind, exit_exception;
>    int ret;
>  
> @@ -122,7 +122,7 @@ static const char *
>  pk_hserver_cmd (int token)
>  {
>    pk_val cls = pk_decl_val (poke_compiler, "hserver_token_cmd");
> -  pk_val token_val = pk_make_int (token, 32);
> +  pk_val token_val = pk_make_int (poke_compiler, token, 32);
>    pk_val cmd, exit_exception;
>    int ret;
>  
> @@ -138,7 +138,7 @@ static pk_val
>  pk_hserver_function (int token)
>  {
>    pk_val cls = pk_decl_val (poke_compiler, "hserver_token_function");
> -  pk_val token_val = pk_make_int (token, 32);
> +  pk_val token_val = pk_make_int (poke_compiler, token, 32);
>    pk_val function, exit_exception;
>    int ret;
>  
> @@ -368,7 +368,7 @@ pk_hserver_init (void)
>        pk_fatal (NULL);
>      }
>    pk_decl_set_val (poke_compiler, "hserver_hostname",
> -                   pk_make_string (hostname));
> +                   pk_make_string (poke_compiler, hostname));
>  }
>  
>  void
> @@ -398,8 +398,9 @@ pk_hserver_start (void)
>        pk_fatal (NULL);
>      }
>  
> -  pk_decl_set_val (poke_compiler, "hserver_port",
> -                   pk_make_int (ntohs (clientname.sin_port), 32));
> +  pk_decl_set_val (
> +      poke_compiler, "hserver_port",
> +      pk_make_int (poke_compiler, ntohs (clientname.sin_port), 32));
>  
>    hserver_finish = 0;
>    ret = pthread_create (&hserver_thread,
> @@ -443,8 +444,8 @@ pk_hserver_make_hyperlink (char type,
>    pk_val hyperlink, kind_val, cmd_val, exit_exception;
>    int ret;
>  
> -  kind_val = pk_make_uint (type, 8);
> -  cmd_val = pk_make_string (cmd);
> +  kind_val = pk_make_uint (poke_compiler, type, 8);
> +  cmd_val = pk_make_string (poke_compiler, cmd);
>  
>    assert (cls != PK_NULL);
>    ret = pk_call (poke_compiler, cls, &hyperlink, &exit_exception,
> diff --git a/poke/poke.c b/poke/poke.c
> index 2e2e1c96..fba84a5f 100644
> --- a/poke/poke.c
> +++ b/poke/poke.c
> @@ -332,7 +332,7 @@ void
>  pk_set_var_int (const char *name, int value)
>  {
>    pk_decl_set_val (poke_compiler, name,
> -                   pk_make_int (value, 32));
> +                   pk_make_int (poke_compiler, value, 32));
>  }
>  
>  static void
> @@ -357,13 +357,14 @@ set_script_args (int argc, char *argv[])
>    /* Any argument after SCRIPT is an argument for the script.  */
>    i = i + 2;
>    nargs = argc - i;
> -  argv_array = pk_make_array (pk_make_uint (nargs, 64),
> -                              pk_make_array_type (pk_make_string_type (),
> -                                                  array_type_bounder));
> +  argv_array = pk_make_array (
> +      poke_compiler, pk_make_uint (poke_compiler, nargs, 64),
> +      pk_make_array_type (poke_compiler, pk_make_string_type (poke_compiler),
> +                          array_type_bounder));
>  
>    for (index = 0; i < argc; ++i, ++index)
>      pk_array_insert_elem (argv_array, index,
> -                          pk_make_string (argv[i]));
> +                          pk_make_string (poke_compiler, argv[i]));
>  
>    pk_defvar (poke_compiler, "argv", argv_array);
>  }
> @@ -619,7 +620,8 @@ initialize (int argc, char *argv[])
>  
>    /* Make poke_interactive_p available to poke programs.  */
>    if (pk_defvar (poke_compiler, "poke_interactive_p",
> -                 pk_make_int (poke_interactive_p, 32)) == PK_ERROR)
> +                 pk_make_int (poke_compiler, poke_interactive_p, 32))
> +      == PK_ERROR)
>      pk_fatal ("defining poke_interactive_p");
>  
>    /* Add the directories where poke installs .pk files to the
> @@ -647,7 +649,7 @@ initialize (int argc, char *argv[])
>      pk_assert_alloc (newpaths);
>  
>      pk_decl_set_val (poke_compiler,
> -                     "load_path", pk_make_string (newpaths));
> +                     "load_path", pk_make_string (poke_compiler, newpaths));
>      free (newpaths);
>    }
>  
> @@ -704,13 +706,13 @@ initialize (int argc, char *argv[])
>      pk_decl_set_val (poke_compiler, "pk_network_endian", network_endian);
>  
>      pk_decl_set_val (poke_compiler, "pk_auto_map_p",
> -                     pk_make_int (poke_default_auto_map_p, 32));
> +                     pk_make_int (poke_compiler, poke_default_auto_map_p, 
> 32));
>  
>      pk_decl_set_val (poke_compiler, "pk_have_libnbd_p",
>  #if defined HAVE_LIBNBD
> -                     pk_make_int (1, 32)
> +                     pk_make_int (poke_compiler, 1, 32)
>  #else
> -                     pk_make_int (0, 32)
> +                     pk_make_int (poke_compiler, 0, 32)
>  #endif
>                       );
>    }
> @@ -739,7 +741,7 @@ initialize (int argc, char *argv[])
>  
>    /* Set the value of the Poke variable pk_hserver_p.  */
>    pk_decl_set_val (poke_compiler, "pk_hserver_p",
> -                   pk_make_int (poke_hserver_p, 32));
> +                   pk_make_int (poke_compiler, poke_hserver_p, 32));
>  #endif
>  }
>  
> diff --git a/poked/poked.c b/poked/poked.c
> index 18de8c47..65ab602f 100644
> --- a/poked/poked.c
> +++ b/poked/poked.c
> @@ -969,7 +969,8 @@ poked_init (int pdap_version)
>      char *newpath = pk_str_concat (pk_string_str (load_path), ":",
>                                     poked_appdir, ":", poke_picklesdir, NULL);
>  
> -    pk_decl_set_val (pkc, "load_path", pk_make_string (newpath));
> +    pk_decl_set_val (pkc, "load_path",
> +                     pk_make_string (pkc, newpath));
>      free (newpath);
>    }
>  
> @@ -998,8 +999,9 @@ poked_init (int pdap_version)
>      }
>  
>    pk_decl_set_val (pkc, "__poked_pdap_version",
> -                   pk_make_int (pdap_version, 32));
> -  pk_decl_set_val (pkc, "__poked_libpoke_version", pk_make_string (VERSION));
> +                   pk_make_int (pkc, pdap_version, 32));
> +  pk_decl_set_val (pkc, "__poked_libpoke_version",
> +                   pk_make_string (pkc, VERSION));
>  
>    return OK;
>  }
> diff --git a/pokefmt/pokefmt.l b/pokefmt/pokefmt.l
> index 74505134..f95f54f5 100644
> --- a/pokefmt/pokefmt.l
> +++ b/pokefmt/pokefmt.l
> @@ -499,7 +499,8 @@ poke_init (struct poke *pk, const char *poke_src_file, 
> FILE *output)
>                                ":", poke_picklesdir, NULL);
>      if (new_path == NULL)
>        err (1, "pk_str_concat() failed");
> -    pk_decl_set_val (pk->compiler, "load_path", pk_make_string (new_path));
> +    pk_decl_set_val (pk->compiler, "load_path",
> +                     pk_make_string (pk->compiler, new_path));
>  
>      free (new_path);
>      free (user_load_path);
> diff --git a/testsuite/poke.libpoke/values.c b/testsuite/poke.libpoke/values.c
> index 99e84160..c22b4818 100644
> --- a/testsuite/poke.libpoke/values.c
> +++ b/testsuite/poke.libpoke/values.c
> @@ -39,7 +39,7 @@
>  /* Test simple type constructors, getters and setters.  */
>  
>  void
> -test_simple_values ()
> +test_simple_values (pk_compiler pkc)
>  {
>    static const char *awesome = "Poke is awesome!";
>    const size_t bigstr_len = 1u << 20; /* 1 MiB */
> @@ -60,40 +60,40 @@ test_simple_values ()
>    /* Signed integers */
>  
>    /* Exceeding maximum number of bits supported in poke integers.  */
> -  T ("pk_make_int_0", pk_make_int (0, 65) == PK_NULL);
> +  T ("pk_make_int_0", pk_make_int (pkc, 0, 65) == PK_NULL);
>  
> -  val = pk_make_int (666, 32);
> +  val = pk_make_int (pkc, 666, 32);
>    T ("pk_make_int_1", val != PK_NULL);
>    T ("pk_int_value_1", pk_int_value (val) == 666);
>    T ("pk_int_size_1", pk_int_size (val) == 32);
>    T ("pk_val_offset", pk_val_offset (val) == PK_NULL);
>  
> -  val = pk_make_int (-666, 32);
> +  val = pk_make_int (pkc, -666, 32);
>    T ("pk_make_int_2", val != PK_NULL);
>    T ("pk_int_value_2", pk_int_value (val) == -666);
>    T ("pk_int_size_2", pk_int_size (val) == 32);
>  
>    /* Unsigned integers */
>  
> -  val = pk_make_uint (UINT64_MAX, 63);
> +  val = pk_make_uint (pkc, UINT64_MAX, 63);
>    T ("pk_make_uint_0", val != PK_NULL);
>    T ("pk_uint_value_0", pk_uint_value (val) == (UINT64_MAX >> 1));
>    T ("pk_uint_size_0", pk_uint_size (val) == 63);
>    T ("pk_val_offset", pk_val_offset (val) == PK_NULL);
>  
> -  val = pk_make_uint (0, 64);
> +  val = pk_make_uint (pkc, 0, 64);
>    T ("pk_make_uint_1", val != PK_NULL);
>    T ("pk_uint_value_1", pk_uint_value (val) == 0);
>    T ("pk_uint_size_1", pk_uint_size (val) == 64);
>  
> -  val = pk_make_uint (0xabcdef, 24);
> +  val = pk_make_uint (pkc, 0xabcdef, 24);
>    T ("pk_make_uint_2", val != PK_NULL);
>    T ("pk_uint_value_2", pk_uint_value (val) == 0xabcdef);
>    T ("pk_uint_size_2", pk_uint_size (val) == 24);
>  
>    /* Strings */
>  
> -  val = pk_make_string (awesome);
> +  val = pk_make_string (pkc, awesome);
>    T ("pk_make_string_0", val != PK_NULL);
>    T ("pk_string_str_0", STREQ (pk_string_str (val), awesome));
>    T ("pk_val_offset", pk_val_offset (val) == PK_NULL);
> @@ -106,7 +106,7 @@ test_simple_values ()
>      memset (bigstr, 'P', bigstr_len);
>      bigstr[bigstr_len] = '\0';
>  
> -    val = pk_make_string (bigstr);
> +    val = pk_make_string (pkc, bigstr);
>  
>      memset (bigstr, 'p', bigstr_len);
>      free (bigstr);
> @@ -124,27 +124,27 @@ test_simple_values ()
>  
>    /* Offsets */
>  
> -  mag = pk_make_uint (0, 64);
> -  unit = pk_make_int (1, 64);
> +  mag = pk_make_uint (pkc, 0, 64);
> +  unit = pk_make_int (pkc, 1, 64);
>  
>    assert (mag != PK_NULL);
>    assert (unit != PK_NULL);
>  
> -  val = pk_make_offset (mag, unit);
> +  val = pk_make_offset (pkc, mag, unit);
>    T ("pk_make_offset_0", val == PK_NULL); /* Because of signed unit */
>  
> -  unit = pk_make_uint (0, 64);
> +  unit = pk_make_uint (pkc, 0, 64);
>    assert (unit != PK_NULL);
>  
> -  val = pk_make_offset (mag, unit);
> +  val = pk_make_offset (pkc, mag, unit);
>    T ("pk_make_offset_1", val == PK_NULL);
>  
> -  mag = pk_make_uint (UINT64_MAX, 64);
> -  unit = pk_make_uint (UINT64_MAX, 64);
> +  mag = pk_make_uint (pkc, UINT64_MAX, 64);
> +  unit = pk_make_uint (pkc, UINT64_MAX, 64);
>    assert (mag != PK_NULL);
>    assert (unit != PK_NULL);
>  
> -  val = pk_make_offset (mag, unit);
> +  val = pk_make_offset (pkc, mag, unit);
>    T ("pk_val_offset", pk_val_offset (val) == PK_NULL);
>    T ("pk_make_offset_2", val != PK_NULL);
>    T ("pk_offset_magnitude_2",
> @@ -155,19 +155,19 @@ test_simple_values ()
>  }
>  
>  void
> -test_simple_values_mapping ()
> +test_simple_values_mapping (pk_compiler pkc)
>  {
>    pk_val simple_values[] = {
> -    pk_make_int (1, 23),
> -    pk_make_int (2, 46),
> -    pk_make_uint (3, 23),
> -    pk_make_uint (4, 46),
> -    pk_make_string ("Poke"),
> -    pk_make_offset (pk_make_uint (5, 64), pk_make_uint (6, 64)),
> +    pk_make_int (pkc, 1, 23),
> +    pk_make_int (pkc, 2, 46),
> +    pk_make_uint (pkc, 3, 23),
> +    pk_make_uint (pkc, 4, 46),
> +    pk_make_string (pkc, "Poke"),
> +    pk_make_offset (pkc, pk_make_uint (pkc, 5, 64), pk_make_uint (pkc, 6, 
> 64)),
>    };
>    const int N = sizeof (simple_values) / sizeof (simple_values[0]);
> -  pk_val i32 = pk_make_int (7, 32);
> -  pk_val u64 = pk_make_uint (8, 64);
> +  pk_val i32 = pk_make_int (pkc, 7, 32);
> +  pk_val u64 = pk_make_uint (pkc, 8, 64);
>  
>  /* test case */
>  #define T0(cond, ...)                                                        
>  \
> @@ -277,10 +277,10 @@ error:
>  }
>  
>  void
> -test_pk_typeof ()
> +test_pk_typeof (pk_compiler pkc)
>  {
> -  pk_val uint32_type = pk_make_integral_type (pk_make_uint (32, 64),
> -                                              pk_make_int (1, 32));
> +  pk_val uint32_type = pk_make_integral_type (pkc, pk_make_uint (pkc, 32, 
> 64),
> +                                              pk_make_int (pkc, 1, 32));
>    pk_val res;
>  
>    /* If given a type, pk_typeof should return the type itself.  */
> @@ -324,7 +324,7 @@ test_pk_struct_ref_set_field_value ()
>        goto done;
>      }
>  
> -  pk_struct_ref_set_field_value (sct, "bar", pk_make_int (666, 32));
> +  pk_struct_ref_set_field_value (sct, "bar", pk_make_int (pkc, 666, 32));
>    val = pk_struct_ref_field_value (sct, "bar");
>    if (val == PK_NULL)
>      {
> @@ -395,10 +395,20 @@ test_pk_val_equal_p ()
>  int
>  main (int argc, char *argv[])
>  {
> -  test_simple_values ();
> -  test_simple_values_mapping ();
> +  pk_compiler pkc;
> +
> +  pkc = pk_compiler_new (&poke_term_if);
> +  if (pkc)
> +  {
> +    test_simple_values (pkc);
> +    test_simple_values_mapping (pkc);
> +    test_pk_typeof (pkc);
> +  }
> +  else
> +    fail ("pk_compiler_new failed");
> +  pk_compiler_free (pkc);
> +
>    test_pk_val_equal_p ();
> -  test_pk_typeof ();
>    test_pk_struct_ref_set_field_value ();
>  
>    totals ();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]