Add Val_some,Val_none,Some_val, Is_none, Is_some, Tag_some (#9569)

Closes: #5154
master
Nicolás Ojeda Bär 2020-06-01 19:31:47 +02:00 committed by GitHub
parent 4bf7a79137
commit 973eeb1867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 0 deletions

View File

@ -30,6 +30,11 @@ Working version
(KC Sivaramakrishnan, review by Stephen Dolan, Gabriel Scherer,
and Xavier Leroy)
- #9569: Add `Val_none`, `Some_val`, `Is_none`, `Is_some`, `caml_alloc_some`,
and `Tag_some`.
(Nicolás Ojeda Bär, review by Stephen Dolan, Gabriel Scherer, Mark Shinwell,
and Xavier Leroy)
### Code generation and optimizations:
- #9441: Add RISC-V RV64G native-code backend.

View File

@ -654,6 +654,9 @@ containing \var{v} and \var{w} in fields 1 and 2.
false otherwise
\item "Is_block("\var{v}")" is true if value \var{v} is a pointer to a block,
and false if it is an immediate integer.
\item "Is_none("\var{v}")" is true if value \var{v} is "None".
\item "Is_some("\var{v}")" is true if value \var{v} (assumed to be of option
type) corresponds to the "Some" constructor.
\end{itemize}
\subsection{ss:c-int-ops}{Operations on integers}
@ -668,6 +671,7 @@ truth value of the C integer \var{x}.
\item "Bool_val("\var{v}")" returns 0 if \var{v} is the OCaml boolean
"false", 1 if \var{v} is "true".
\item "Val_true", "Val_false" represent the OCaml booleans "true" and "false".
\item "Val_none" represents the OCaml value "None".
\end{itemize}
\subsection{ss:c-block-access}{Accessing blocks}
@ -723,6 +727,8 @@ of a value \var{v} of any boxed type (record or concrete data type).
\item "caml_field_unboxable("\var{v}")" calls either
"caml_field_unboxed" or "caml_field_boxed" according to the default
representation of unboxable types in the current version of OCaml.
\item "Some_val("\var{v}")" returns the argument "\var{x}" of a value \var{v} of
the form "Some("\var{x}")".
\end{itemize}
The expressions "Field("\var{v}", "\var{n}")",
"Byte("\var{v}", "\var{n}")" and
@ -791,6 +797,8 @@ any boxed type) whose field is the value \var{v}.
\item "caml_alloc_unboxable("\var{v}")" calls either
"caml_alloc_unboxed" or "caml_alloc_boxed" according to the default
representation of unboxable types in the current version of OCaml.
\item "caml_alloc_some("\var{v}")" allocates a block representing
"Some("\var{v}")".
\end{itemize}
\subsubsection{sss:c-low-level-alloc}{Low-level interface}

View File

@ -272,3 +272,11 @@ CAMLprim value caml_update_dummy(value dummy, value newval)
}
return Val_unit;
}
CAMLexport value caml_alloc_some(value v)
{
CAMLparam1(v);
value some = caml_alloc_small(1, 0);
Store_field(some, 0, v);
CAMLreturn(some);
}

View File

@ -49,6 +49,7 @@ CAMLextern value caml_alloc_sprintf(const char * format, ...)
__attribute__ ((format (printf, 1, 2)))
#endif
;
CAMLextern value caml_alloc_some(value);
CAMLextern value caml_alloc_with_profinfo (mlsize_t, tag_t, intnat);
CAMLextern value caml_alloc_small_with_my_or_given_profinfo (

View File

@ -373,6 +373,14 @@ CAMLextern header_t *caml_atom_table;
#define Val_emptylist Val_int(0)
#define Tag_cons 0
/* Option constructors */
#define Val_none Val_int(0)
#define Some_val(v) Field(v, 0)
#define Tag_some 0
#define Is_none(v) ((v) == Val_None)
#define Is_some(v) Is_block(v)
/* The table of global identifiers */
extern value caml_global_data;