poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 4/5] pkl: improve PVM type introspection 2022-10-23 Mohammad-


From: Jose E. Marchesi
Subject: Re: [PATCH 4/5] pkl: improve PVM type introspection 2022-10-23 Mohammad-Reza Nabipoor <address@hidden>
Date: Mon, 24 Oct 2022 00:06:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

OK for master.
Thanks!

>       * libpoke/pkl-gen-attrs.pks (attr_size): Add `typof' and `nip'
>       instructions around `tyis*` instructions.
>       (attr_eoffset): Likewise.
>       (attr_esize): Likewise.
>       (attr_ename): Likewise.
>       (attr_elem): Likewise.
>       * libpoke/pkl-insn.def (isn): New instruction.
>       (isty): Likewise.
>       (tyigetsz): Likewise.
>       (tyigetsg): Likewise.
>       (tyisv): Likewise.
>       (tyogetm): Likewise.
>       (tyogetu): Likewise.
>       (tyagetn): Likewise.
>       (tyagett): Likewise.
>       (tyagetb): Likewise.
>       (tysctgetnf): Likewise.
>       (tysctgetfn): Likewise.
>       (tysctgetft): Likewise.
>       * libpoke/pkl-rt.pk (_pkl_print_format_any): Adapt.
>       * libpoke/pvm-val.c (pvm_typeof): Handle closure case (return
>       `PVM_NULL' as the type of closure).
>       * libpoke/pvm.jitter (isn): New instruction.
>       (isty): Likewise.
>       (tyigetsz): Likewise.
>       (tyigetsg): Likewise.
>       (tyisv): Likewise.
>       (tyogetm): Likewise.
>       (tyogetu): Likewise.
>       (tyagetn): Likewise.
>       (tyagett): Likewise.
>       (tyagetb): Likewise.
>       (tysctgetnf): Likewise.
>       (tysctgetfn): Likewise.
>       (tysctgetft): Likewise.
>       (tyisi): Adapt to expect type (not value).
>       (tyisiu): Likewise.
>       (tyisl): Likewise.
>       (tyislu): Likewise.
>       (tyiso): Likewise.
>       (tyiss): Likewise.
>       (tyisa): Likewise.
>       (tyisc): Likewise.
>       (tyissct): Likewise.
> ---
>  ChangeLog                 |  47 ++++++++
>  libpoke/pkl-gen-attrs.pks |  34 ++++--
>  libpoke/pkl-insn.def      |  49 +++++---
>  libpoke/pkl-rt.pk         |  32 ++---
>  libpoke/pvm-val.c         |   2 +
>  libpoke/pvm.jitter        | 240 +++++++++++++++++++++++++++++++++-----
>  6 files changed, 339 insertions(+), 65 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 6976f2cf..4801c643 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,50 @@
> +2022-10-23  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * libpoke/pkl-gen-attrs.pks (attr_size): Add `typof' and `nip'
> +     instructions around `tyis*` instructions.
> +     (attr_eoffset): Likewise.
> +     (attr_esize): Likewise.
> +     (attr_ename): Likewise.
> +     (attr_elem): Likewise.
> +     * libpoke/pkl-insn.def (isn): New instruction.
> +     (isty): Likewise.
> +     (tyigetsz): Likewise.
> +     (tyigetsg): Likewise.
> +     (tyisv): Likewise.
> +     (tyogetm): Likewise.
> +     (tyogetu): Likewise.
> +     (tyagetn): Likewise.
> +     (tyagett): Likewise.
> +     (tyagetb): Likewise.
> +     (tysctgetnf): Likewise.
> +     (tysctgetfn): Likewise.
> +     (tysctgetft): Likewise.
> +     * libpoke/pkl-rt.pk (_pkl_print_format_any): Adapt.
> +     * libpoke/pvm-val.c (pvm_typeof): Handle closure case (return
> +     `PVM_NULL' as the type of closure).
> +     * libpoke/pvm.jitter (isn): New instruction.
> +     (isty): Likewise.
> +     (tyigetsz): Likewise.
> +     (tyigetsg): Likewise.
> +     (tyisv): Likewise.
> +     (tyogetm): Likewise.
> +     (tyogetu): Likewise.
> +     (tyagetn): Likewise.
> +     (tyagett): Likewise.
> +     (tyagetb): Likewise.
> +     (tysctgetnf): Likewise.
> +     (tysctgetfn): Likewise.
> +     (tysctgetft): Likewise.
> +     (tyisi): Adapt to expect type (not value).
> +     (tyisiu): Likewise.
> +     (tyisl): Likewise.
> +     (tyislu): Likewise.
> +     (tyiso): Likewise.
> +     (tyiss): Likewise.
> +     (tyisa): Likewise.
> +     (tyisc): Likewise.
> +     (tyissct): Likewise.
> +
>  2022-10-23  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>  
>       * libpoke/pvm.jitter (iolist): Create an array with right type.
> diff --git a/libpoke/pkl-gen-attrs.pks b/libpoke/pkl-gen-attrs.pks
> index 64d50590..7d351559 100644
> --- a/libpoke/pkl-gen-attrs.pks
> +++ b/libpoke/pkl-gen-attrs.pks
> @@ -36,7 +36,9 @@
>          ;; value.
>     .c if (PKL_AST_TYPE_CODE (@type) == PKL_TYPE_ANY)
>     .c {
> +        typof
>          tyisc
> +        nip
>          bzi .not_a_function
>          push PVM_E_CONV
>          push "msg"
> @@ -161,10 +163,14 @@
>          .macro attr_eoffset
>          ;; If the value is not composite, raise E_inval.
>          swap                    ; IDX VAL
> -        tyissct                 ; IDX VAL ISSCT
> +        typof                   ; IDX VAL TYP
> +        tyissct                 ; IDX VAL TYP ISSCT
> +        nip                     ; IDX VAL ISSCT
>          bnzi .struct
>          drop                    ; IDX VAL
> -        tyisa                   ; IDX VAL ISARR
> +        typof                   ; IDX VAL TYP
> +        tyisa                   ; IDX VAL TYP ISARR
> +        nip                     ; IDX VAL ISARR
>          bnzi .array
>          push PVM_E_INVAL
>          push "msg"
> @@ -200,10 +206,14 @@
>          .macro attr_esize
>          ;; If the value is not composite, raise E_inval.
>          swap                    ; IDX VAL
> -        tyissct                 ; IDX VAL ISSCT
> +        typof                   ; IDX VAL TYP
> +        tyissct                 ; IDX VAL TYP ISSCT
> +        nip                     ; IDX VAL ISSCT
>          bnzi .struct
>          drop                    ; IDX VAL
> -        tyisa                   ; IDX VAL ISARR
> +        typof                   ; IDX VAL TYP
> +        tyisa                   ; IDX VAL TYP ISARR
> +        nip                     ; IDX VAL ISARR
>          bnzi .array
>          push PVM_E_INVAL
>          push "msg"
> @@ -257,10 +267,14 @@
>          .macro attr_ename
>          ;; If the value is not composite, raise E_inval.
>          swap                    ; IDX VAL
> -        tyissct                 ; IDX VAL ISSCT
> +        typof                   ; IDX VAL TYP
> +        tyissct                 ; IDX VAL TYP ISSCT
> +        nip                     ; IDX VAL ISSCT
>          bnzi .struct
>          drop                    ; IDX VAL
> -        tyisa                   ; IDX VAL ISARR
> +        typof                   ; IDX VAL TYP
> +        tyisa                   ; IDX VAL TYP ISARR
> +        nip                     ; IDX VAL ISARR
>          bnzi .array
>          push PVM_E_INVAL
>          push "msg"
> @@ -313,10 +327,14 @@
>          .macro attr_elem
>          ;; If the value is not composite, raise E_inval.
>          swap                    ; IDX VAL
> -        tyissct                 ; IDX VAL ISSCT
> +        typof                   ; IDX VAL TYP
> +        tyissct                 ; IDX VAL TYP ISSCT
> +        nip                     ; IDX VAL ISSCT
>          bnzi .struct
>          drop                    ; IDX VAL
> -        tyisa                   ; IDX VAL ISARR
> +        typof                   ; IDX VAL TYP
> +        tyisa                   ; IDX VAL TYP ISARR
> +        nip                     ; IDX VAL ISARR
>          bnzi .array
>          push PVM_E_INVAL
>          push "msg"
> diff --git a/libpoke/pkl-insn.def b/libpoke/pkl-insn.def
> index a0bd73a0..d3114876 100644
> --- a/libpoke/pkl-insn.def
> +++ b/libpoke/pkl-insn.def
> @@ -289,6 +289,10 @@ PKL_DEF_INSN(PKL_INSN_SSET,"","sset")
>  PKL_DEF_INSN(PKL_INSN_SSETI,"","sseti")
>  PKL_DEF_INSN(PKL_INSN_SMODI,"","smodi")
>  
> +/* Instructions to handle values.  */
> +
> +PKL_DEF_INSN(PKL_INSN_ISN,"","isn")
> +
>  /* Instructions to handle mapped values.  */
>  
>  PKL_DEF_INSN(PKL_INSN_MM,"","mm")
> @@ -324,33 +328,46 @@ PKL_DEF_INSN(PKL_INSN_MSETSIZ,"","msetsiz")
>  
>  PKL_DEF_INSN(PKL_INSN_ISA,"","isa")
>  
> -PKL_DEF_INSN(PKL_INSN_MKTYV,"","mktyv")
> -PKL_DEF_INSN(PKL_INSN_MKTYI,"","mktyi")
> -PKL_DEF_INSN(PKL_INSN_MKTYS,"","mktys")
> -PKL_DEF_INSN(PKL_INSN_MKTYO,"","mktyo")
> -PKL_DEF_INSN(PKL_INSN_MKTYSCT,"","mktysct")
> -PKL_DEF_INSN(PKL_INSN_MKTYC,"","mktyc")
> -
> -PKL_DEF_INSN(PKL_INSN_MKTYA,"","mktya")
> -PKL_DEF_INSN(PKL_INSN_TYAGETN,"","tyagetn")
> -PKL_DEF_INSN(PKL_INSN_TYAGETT,"","tyagett")
> -PKL_DEF_INSN(PKL_INSN_TYAGETB,"","tyagetb")
> -
>  PKL_DEF_INSN(PKL_INSN_TYPOF,"","typof")
> +PKL_DEF_INSN(PKL_INSN_ISTY,"","isty")
>  
> +PKL_DEF_INSN(PKL_INSN_MKTYI,"","mktyi")
> +PKL_DEF_INSN(PKL_INSN_TYIGETSZ,"","tyigetsz")
> +PKL_DEF_INSN(PKL_INSN_TYIGETSG,"","tyigetsg")
>  PKL_DEF_INSN(PKL_INSN_TYISI,"","tyisi")
>  PKL_DEF_INSN(PKL_INSN_TYISIU,"","tyisiu")
>  PKL_DEF_INSN(PKL_INSN_TYISL,"","tyisl")
>  PKL_DEF_INSN(PKL_INSN_TYISLU,"","tyislu")
> +
> +PKL_DEF_INSN(PKL_INSN_MKTYV,"","mktyv")
> +PKL_DEF_INSN(PKL_INSN_TYISV,"","tyisv")
> +
> +PKL_DEF_INSN(PKL_INSN_MKTYS,"","mktys")
>  PKL_DEF_INSN(PKL_INSN_TYISS,"","tyiss")
> +
> +PKL_DEF_INSN(PKL_INSN_MKTYO,"","mktyo")
> +PKL_DEF_INSN(PKL_INSN_TYOGETM,"","tyogetm")
> +PKL_DEF_INSN(PKL_INSN_TYOGETU,"","tyogetu")
>  PKL_DEF_INSN(PKL_INSN_TYISO,"","tyiso")
> -PKL_DEF_INSN(PKL_INSN_TYISA,"","tyisa")
> -PKL_DEF_INSN(PKL_INSN_TYISC,"","tyisc")
> -PKL_DEF_INSN(PKL_INSN_TYISSCT,"","tyissct")
>  
> -/** Struct types. */
> +PKL_DEF_INSN(PKL_INSN_MKTYC,"","mktyc")
> +PKL_DEF_INSN(PKL_INSN_TYISC,"","tyisc")
> +/* PKL_DEF_INSN(PKL_INSN_TYCNA,"","tycna") */
> +/* PKL_DEF_INSN(PKL_INSN_TYCAT,"","tycat") */
> +/* PKL_DEF_INSN(PKL_INSN_TYCRT,"","tycrt") */
>  
> +PKL_DEF_INSN(PKL_INSN_MKTYSCT,"","mktysct")
>  PKL_DEF_INSN(PKL_INSN_TYSCTGETN,"","tysctgetn")
> +PKL_DEF_INSN(PKL_INSN_TYSCTGETNF,"","tysctgetnf")
> +PKL_DEF_INSN(PKL_INSN_TYSCTGETFN,"","tysctgetfn")
> +PKL_DEF_INSN(PKL_INSN_TYSCTGETFT,"","tysctgetft")
> +PKL_DEF_INSN(PKL_INSN_TYISSCT,"","tyissct")
> +
> +PKL_DEF_INSN(PKL_INSN_MKTYA,"","mktya")
> +PKL_DEF_INSN(PKL_INSN_TYAGETN,"","tyagetn")
> +PKL_DEF_INSN(PKL_INSN_TYAGETT,"","tyagett")
> +PKL_DEF_INSN(PKL_INSN_TYAGETB,"","tyagetb")
> +PKL_DEF_INSN(PKL_INSN_TYISA,"","tyisa")
>  
>  /* Branch instructions.  */
>  
> diff --git a/libpoke/pkl-rt.pk b/libpoke/pkl-rt.pk
> index 38ff29aa..c2560a78 100644
> --- a/libpoke/pkl-rt.pk
> +++ b/libpoke/pkl-rt.pk
> @@ -1051,28 +1051,32 @@ immutable fun _pkl_print_format_any = (any val,
>      ctx.end_class ("struct");
>    }
>  
> -  if (asm int<32>: ("tyisi; nip" : val))
> +  if (asm int<32>: ("isn; nip" : val))
> +    ctx.emit ("null");
> +  else if (asm int<32>: ("isty; nip" : val))
> +    /* handle_type */;
> +  else if (asm int<32>: ("typof; nip; isn; nip" : val))
> +    {
> +      ctx.begin_class ("special");
> +      ctx.emit ("#<closure>");
> +      ctx.end_class ("special");
> +    }
> +  else if (asm int<32>: ("typof; nip; tyisi; nip" : val))
>      handle_integral :long_p 0 :signed_p 1;
> -  else if (asm int<32>: ("tyiso; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyiso; nip" : val))
>      handle_offset;
> -  else if (asm int<32>: ("tyisl; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyisl; nip" : val))
>      handle_integral :long_p 1 :signed_p 1;
> -  else if (asm int<32>: ("tyisiu; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyisiu; nip" : val))
>      handle_integral :long_p 0 :signed_p 0;
> -  else if (asm int<32>: ("tyislu; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyislu; nip" : val))
>      handle_integral :long_p 1 :signed_p 0;
> -  else if (asm int<32>: ("tyiss; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyiss; nip" : val))
>      handle_string;
> -  else if (asm int<32>: ("tyisa; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyisa; nip" : val))
>      handle_array;
> -  else if (asm int<32>: ("tyissct; nip" : val))
> +  else if (asm int<32>: ("typof; nip; tyissct; nip" : val))
>      handle_struct;
> -  else if (asm int<32>: ("tyisc; nip" : val))
> -    {
> -      ctx.begin_class ("special");
> -      ctx.emit ("#<closure>");
> -      ctx.end_class ("special");
> -    }
>    else
>      {
>        ctx.begin_class ("special");
> diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
> index 85d1453a..641fbd8b 100644
> --- a/libpoke/pvm-val.c
> +++ b/libpoke/pvm-val.c
> @@ -1643,6 +1643,8 @@ pvm_typeof (pvm_val val)
>      type = PVM_VAL_SCT_TYPE (val);
>    else if (PVM_IS_TYP (val))
>      type = val;
> +  else if (PVM_IS_CLS (val))
> +    type = PVM_NULL;
>    else
>      assert (0);
>  
> diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
> index 05a89c19..bdb85351 100644
> --- a/libpoke/pvm.jitter
> +++ b/libpoke/pvm.jitter
> @@ -5311,6 +5311,22 @@ instruction ogetbt ()
>    end
>  end
>  
> +
> +## Instructions to handle values
> +
> +# Instruction: isn
> +#
> +# Given a value, push 1 on the stack if the value is null.
> +# Push 0 otherwise.
> +#
> +# Stack: ( VAL -- VAL INT )
> +
> +instruction isn ()
> +  code
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (JITTER_TOP_STACK () == PVM_NULL, 32));
> +  end
> +end
> +
>  
>  ## Instructions to handle mapped values
>  
> @@ -5659,120 +5675,191 @@ instruction typof ()
>    end
>  end
>  
> +# Instruction: isty
> +#
> +# Given a value, push 1 on the stack if it is a PVM type.
> +# Push 0 otherwise.
> +#
> +# Stack: ( TYPE -- TYPE INT )
> +
> +instruction isty ()
> +  code
> +    int is_type_p = PVM_IS_TYP (JITTER_TOP_STACK ());
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (is_type_p, 32));
> +  end
> +end
> +
>  # Instruction: tyisi
>  #
> -# Given a value, push 1 on the stack if it is an integer.
> +# Given a type, push 1 on the stack if it is an int.
>  # Push 0 otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyisi ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_INT (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isi_p
> +      = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_INTEGRAL
> +        && PVM_VAL_INT (PVM_VAL_TYP_I_SIGNED_P (typ))
> +        && PVM_VAL_ULONG (PVM_VAL_TYP_I_SIZE (typ)) <= 32;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isi_p, 32));
>    end
>  end
>  
>  # Instruction: tyisiu
>  #
> -# Given a value, push 1 on the stack if it is an unsigned integer.
> +# Given a type, push 1 on the stack if it is an uint.
>  # Push 0 otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyisiu ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_UINT (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isiu_p
> +      = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_INTEGRAL
> +        && !PVM_VAL_INT (PVM_VAL_TYP_I_SIGNED_P (typ))
> +        && PVM_VAL_ULONG (PVM_VAL_TYP_I_SIZE (typ)) <= 32;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isiu_p, 32));
>    end
>  end
>  
>  # Instruction: tyisl
>  #
> -# Given a value, push 1 on the stack if it is a long.
> +# Given a type, push 1 on the stack if it is a long.
>  # Push 0 otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyisl ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_LONG (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isl_p
> +      = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_INTEGRAL
> +        && PVM_VAL_INT (PVM_VAL_TYP_I_SIGNED_P (typ))
> +        && PVM_VAL_ULONG (PVM_VAL_TYP_I_SIZE (typ)) > 32;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isl_p, 32));
>    end
>  end
>  
>  # Instruction: tyislu
>  #
> -# Given a value, push 1 on the stack if it is an unsigned integer.
> +# Given a type, push 1 on the stack if it is an ulong.
>  # Push 0 otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyislu ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_ULONG (JITTER_TOP_STACK ()), 
> 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int islu_p
> +      = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_INTEGRAL
> +        && !PVM_VAL_INT (PVM_VAL_TYP_I_SIGNED_P (typ))
> +        && PVM_VAL_ULONG (PVM_VAL_TYP_I_SIZE (typ)) > 32;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (islu_p, 32));
>    end
>  end
>  
>  # Instruction: tyiso
>  #
> -# Given a value, push 1 on the stack if it is an offset.  Push 0
> +# Given a type, push 1 on the stack if it is an offset.  Push 0
>  # otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyiso ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_OFF (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isoff_p = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_OFFSET;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isoff_p, 32));
>    end
>  end
>  
>  # Instruction: tyiss
>  #
> -# Given a value, push 1 on the stack if it is a string.  Push 0
> +# Given a type, push 1 on the stack if it is a string.  Push 0
>  # otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyiss ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_STR (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isstr_p = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_STRING;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isstr_p, 32));
>    end
>  end
>  
>  # Instruction: tyisa
>  #
> -# Given a value, push 1 on the stack if it is an array.  Push 0
> +# Given a type, push 1 on the stack if it is an array.  Push 0
>  # otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyisa ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_ARR (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isarr_p = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_ARRAY;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isarr_p, 32));
>    end
>  end
>  
>  # Instruction: tyisc
>  #
> -# Given a value, push 1 on the stack if it is a closure.  Push 0
> +# Given a type, push 1 on the stack if it is a closure.  Push 0
>  # otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyisc ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_CLS (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int iscls_p = typ == PVM_NULL ? 1
> +                                  : PVM_VAL_TYP_CODE (typ) == 
> PVM_TYPE_CLOSURE;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (iscls_p, 32));
>    end
>  end
>  
>  # Instruction: tyissct
>  #
> -# Given a value, push 1 on the stack if it is a struct.  Push 0
> +# Given a type, push 1 on the stack if it is a struct.  Push 0
>  # otherwise.
>  #
> -# Stack: ( VAL -- VAL INT )
> +# Stack: ( TYPE -- TYPE INT )
>  
>  instruction tyissct ()
>    code
> -    JITTER_PUSH_STACK (PVM_MAKE_INT (PVM_IS_SCT (JITTER_TOP_STACK ()), 32));
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int issct_p = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_STRUCT;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (issct_p, 32));
> +  end
> +end
> +
> +# Instruction: tyisv ()
> +#
> +# Given a type, push 1 on the stack if it is a void.  Push 0
> +# otherwise.
> +#
> +# Stack: ( TYPE -- TYPE INT)
> +
> +instruction tyisv ()
> +  code
> +    pvm_val typ = JITTER_TOP_STACK ();
> +    int isv_p = PVM_VAL_TYP_CODE (typ) == PVM_TYPE_VOID;
> +
> +    JITTER_PUSH_STACK (PVM_MAKE_INT (isv_p, 32));
>    end
>  end
>  
> @@ -5806,6 +5893,33 @@ instruction mktyi ()
>    end
>  end
>  
> +# Instruction: tyigetsz
> +#
> +# Given an integral type, push its size (in bits) to the stack.
> +#
> +# Stack: ( ITYPE -- ITYPE ULONG )
> +instruction tyigetsz ()
> +  code
> +    pvm_val size = PVM_VAL_TYP_I_SIZE (JITTER_TOP_STACK ());
> +
> +    JITTER_PUSH_STACK (size);
> +  end
> +end
> +
> +# Instruction: tyigetsg
> +#
> +# Given an integral type, push its sign to the stack.  0 means
> +# unsigned and 1 means signed.
> +#
> +# Stack: ( ITYPE -- ITYPE INT )
> +instruction tyigetsg ()
> +  code
> +    pvm_val sign = PVM_VAL_TYP_I_SIGNED_P (JITTER_TOP_STACK ());
> +
> +    JITTER_PUSH_STACK (sign);
> +  end
> +end
> +
>  # Instruction: mktys
>  #
>  # Push a string type on the stack.
> @@ -5835,6 +5949,30 @@ instruction mktyo ()
>    end
>  end
>  
> +# Instruction: tyogetm
> +#
> +# Given an offset type, push type of magnitude to the stack.
> +#
> +# Stack : ( OTYPE -- OTYPE ITYPE)
> +
> +instruction tyogetm ()
> +  code
> +    JITTER_PUSH_STACK (PVM_VAL_TYP_O_BASE_TYPE (JITTER_TOP_STACK ()));
> +  end
> +end
> +
> +# Instruction: tyogetu
> +#
> +# Given an offset type, push unit value to the stack.
> +#
> +# Stack : ( OTYPE -- OTYPE ULONG)
> +
> +instruction tyogetu ()
> +  code
> +    JITTER_PUSH_STACK (PVM_VAL_TYP_O_UNIT (JITTER_TOP_STACK ()));
> +  end
> +end
> +
>  # Instruction: mktya
>  #
>  # Given an elements type and an unsigned long denoting a length, build
> @@ -5961,6 +6099,54 @@ instruction tysctgetn ()
>    end
>  end
>  
> +# Instruction: tysctgetnf
> +#
> +# Given a struct type, push its number of fields to the stack.
> +#
> +# Stack: ( SCT -- SCT ULONG )
> +
> +instruction tysctgetnf ()
> +  code
> +    pvm_val type = JITTER_TOP_STACK ();
> +    pvm_val type_nfields = PVM_VAL_TYP_S_NFIELDS (type);
> +
> +    JITTER_PUSH_STACK (type_nfields);
> +  end
> +end
> +
> +# Instruction: tysctgetfn
> +#
> +# Given a struct type and an index, push the field name to the stack.
> +# If the field is not named push PVM_NULL.
> +#
> +# Stack: ( SCT ULONG -- SCT ULONG STR )
> +
> +instruction tysctgetfn ()
> +  code
> +    pvm_val type = JITTER_UNDER_TOP_STACK ();
> +    pvm_val index = JITTER_TOP_STACK ();
> +    pvm_val *field_names = PVM_VAL_TYP_S_FNAMES (type);
> +
> +    JITTER_PUSH_STACK (field_names[PVM_VAL_ULONG (index)]);
> +  end
> +end
> +
> +# Instruction: tysctgetft
> +#
> +# Given a struct type and an index, push the field type to the stack.
> +#
> +# Stack: ( SCT ULONG -- SCT ULONG TYP )
> +
> +instruction tysctgetft ()
> +  code
> +    pvm_val type = JITTER_UNDER_TOP_STACK ();
> +    pvm_val index = JITTER_TOP_STACK ();
> +    pvm_val *field_types = PVM_VAL_TYP_S_FTYPES (type);
> +
> +    JITTER_PUSH_STACK (field_types[PVM_VAL_ULONG (index)]);
> +  end
> +end
> +
>  
>  ## IO instructions



reply via email to

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