26#ifndef MYSQLSHDK_SCRIPTING_POLYGLOT_LANGUAGES_POLYGLOT_LANGUAGE_H_ 
   27#define MYSQLSHDK_SCRIPTING_POLYGLOT_LANGUAGES_POLYGLOT_LANGUAGE_H_ 
   51class Polyglot_language;
 
   93  poly_value 
execute(
const std::string &code);
 
  116    : 
public std::enable_shared_from_this<Polyglot_language> {
 
  150    void push(
const std::string &script);
 
  164                             const std::string &debug_port = 
"");
 
  178  virtual void initialize(
const std::shared_ptr<IFile_system> &fs = {});
 
  227                         std::string *class_name = 
nullptr) 
const = 0;
 
  240                                         const std::string &class_name);
 
  255  virtual const std::vector<std::string> &
keywords() 
const = 0;
 
  260  int64_t 
eval(
const std::string &
source, 
const std::string &code_str,
 
  261               poly_value *
result) 
const;
 
  268  std::pair<Value, bool> 
debug(
const std::string &
path);
 
  273  std::pair<Value, bool> 
execute(
const std::string &code_str,
 
  274                                 const std::string &
source);
 
  280    throw std::runtime_error(
"Plugin support is not available.");
 
  288  poly_value 
poly_string(
const std::string &data) 
const;
 
  289  std::string 
to_string(poly_value obj) 
const;
 
  292  poly_thread 
thread() 
const;
 
  293  const std::shared_ptr<Polyglot_object> &
globals() 
const;
 
  301                           void *data = 
nullptr);
 
  315  bool get_member(poly_value 
object, 
const char *name,
 
  316                  poly_value *member) 
const;
 
  323  poly_value 
wrap_callback(poly_callback callback, 
void *data) 
const;
 
  331  std::unique_ptr<Polyglot_type_bridger> 
m_types;
 
  349      const std::string &error, poly_value exception_object) 
const = 0;
 
Definition: jit_executor_exceptions.h:34
 
Common context for GraalVM Languages.
Definition: polyglot_common_context.h:65
 
Represents polyglot errors that will be created from information available in the polyglot library st...
Definition: polyglot_error.h:77
 
Definition: polyglot_language.h:140
 
void push(const std::string &script)
Definition: polyglot_language.cc:64
 
std::stack< std::string > m_scripts
Definition: polyglot_language.h:160
 
std::string m_root
Definition: polyglot_language.h:159
 
Current_script()
Definition: polyglot_language.cc:54
 
std::string current_folder() const
Definition: polyglot_language.cc:60
 
Current_script & operator=(const Current_script &)=delete
 
Current_script & operator=(Current_script &&)=delete
 
std::string current_script() const
Definition: polyglot_language.h:154
 
Current_script(const Current_script &)=delete
 
Current_script(Current_script &&)=delete
 
void pop()
Definition: polyglot_language.h:152
 
Definition: polyglot_language.h:118
 
Script_scope(const Script_scope &)=delete
 
Polyglot_language * m_owner
Definition: polyglot_language.h:137
 
~Script_scope()
Definition: polyglot_language.h:134
 
Script_scope(Script_scope &&)=default
 
Script_scope & operator=(Script_scope &&)=default
 
Script_scope & operator=(const Script_scope &)=delete
 
Script_scope(Polyglot_language *owner, const std::string &s)
Definition: polyglot_language.h:122
 
The polyglot library may support several languages (guest languages), and provides out of the box C++...
Definition: polyglot_language.h:116
 
bool get_member(poly_value object, const char *name, poly_value *member) const
Definition: polyglot_language.cc:440
 
virtual bool is_object(poly_value object, std::string *class_name=nullptr) const =0
Return true if the guest language identifies the value as an object.
 
Script_scope enter_script(const std::string &s)
Definition: polyglot_language.cc:452
 
const std::shared_ptr< Polyglot_object > & globals() const
Definition: polyglot_language.cc:413
 
static void error_callback(const char *bytes, size_t length, void *data)
Definition: polyglot_language.cc:286
 
std::pair< Value, bool > execute(const std::string &code_str, const std::string &source)
Executes the given script.
Definition: polyglot_language.cc:265
 
poly_value poly_string(const std::string &data) const
Definition: polyglot_language.cc:342
 
Polyglot_language(Polyglot_language &&)=delete
 
void erase(poly_reference value)
Definition: polyglot_language.cc:438
 
Current_script m_current_script
Definition: polyglot_language.h:333
 
void terminate()
Definition: polyglot_language.cc:350
 
Argument_list convert_args(const std::vector< poly_value > &args) const
Definition: polyglot_language.cc:425
 
poly_reference store(poly_value value)
Definition: polyglot_language.cc:434
 
int64_t eval(const std::string &source, const std::string &code_str, poly_value *result) const
Wraps a call to poly_context_eval.
Definition: polyglot_language.cc:233
 
virtual poly_value undefined() const =0
Return the a guest language interpretation of the Undefined C++ value.
 
Store m_context
Definition: polyglot_language.h:330
 
Polyglot_language(const Polyglot_language &)=delete
 
virtual poly_value array_buffer(const std::string &data) const =0
Return the guest language interpretation of a binary string.
 
Polyglot_language * language()
The polyglot_utils file has the following functions that can be used to export C++ functions as polyg...
Definition: polyglot_language.h:196
 
std::string to_string(poly_value obj) const
Definition: polyglot_language.cc:346
 
Polyglot_common_context * m_common_context
Definition: polyglot_language.h:326
 
Polyglot_language & operator=(Polyglot_language &&)=delete
 
virtual void output_handler(const char *bytes, size_t length)=0
 
std::string current_script_folder() const
Definition: polyglot_language.cc:292
 
virtual const char * get_language_id() const =0
 
std::shared_ptr< IFile_system > m_file_system
Definition: polyglot_language.h:335
 
void clear_is_terminating()
Definition: polyglot_language.cc:367
 
virtual const std::vector< std::string > & keywords() const =0
Retrieves the list of keywords in the guest language.
 
poly_context context() const
Definition: polyglot_language.cc:409
 
bool is_terminating() const
Definition: polyglot_language.cc:365
 
virtual poly_value from_native_object(const Object_bridge_t &object) const =0
Converts a C++ object into a representation of the object in the guest language.
 
virtual void finalize()
Definition: polyglot_language.cc:203
 
virtual shcore::Value to_native_object(poly_value object, const std::string &class_name)
Converts a guest language object into its C++ representation.
Definition: polyglot_language.cc:227
 
virtual void error_handler(const char *bytes, size_t length)=0
 
poly_context copy_global_context() const
Creates a copy of the global context.
Definition: polyglot_language.cc:384
 
Store get_global(const std::string &name) const
Definition: polyglot_language.cc:338
 
poly_thread thread() const
Definition: polyglot_language.cc:411
 
std::string m_debug_port
Definition: polyglot_language.h:338
 
void throw_exception_object(const shcore::Dictionary_t &data) const
Translates a dictionary object into an exception in the guest language.
Definition: polyglot_language.cc:304
 
Polyglot_common_context * common_context()
Definition: polyglot_language.h:320
 
virtual bool is_undefined(poly_value value) const =0
Returns true if the provided value is undefined in the guest language.
 
virtual poly_value create_exception_object(const std::string &error, poly_value exception_object) const =0
 
void set_file_system()
Definition: polyglot_language.cc:457
 
Value convert(poly_value value) const
Definition: polyglot_language.cc:417
 
virtual void initialize(const std::shared_ptr< IFile_system > &fs={})
Definition: polyglot_language.cc:143
 
poly_value wrap_callback(poly_callback callback, void *data) const
Definition: polyglot_language.cc:369
 
Polyglot_language & operator=(const Polyglot_language &)=delete
 
void set_global(const std::string &name, const Value &value) const
Definition: polyglot_language.cc:321
 
poly_value type_info(poly_value value) const
Definition: polyglot_language.cc:430
 
std::unique_ptr< Polyglot_type_bridger > m_types
Definition: polyglot_language.h:331
 
poly_value create_source(const std::string &path) const
Definition: polyglot_language.cc:244
 
virtual std::optional< std::string > get_debug_port() const
Definition: polyglot_language.h:353
 
std::unique_ptr< Polyglot_scope > m_scope
Definition: polyglot_language.h:341
 
static void output_callback(const char *bytes, size_t length, void *data)
Definition: polyglot_language.cc:280
 
virtual void init_context_builder()
Definition: polyglot_language.cc:120
 
void enable_debug()
Definition: polyglot_language.cc:109
 
Polyglot_language(Polyglot_common_context *common_context, const std::string &debug_port="")
Definition: polyglot_language.cc:105
 
void throw_jit_executor_exception(const Jit_executor_exception &exception)
Throws a specific exception type in the GraalVM environment, with a specific message.
Definition: polyglot_language.cc:221
 
std::pair< Value, bool > debug(const std::string &path)
Debugs the given script.
Definition: polyglot_language.cc:252
 
virtual bool load_plugin(const std::string &path)
This function should be implemented to provide plugin load support.
Definition: polyglot_language.h:279
 
bool m_terminating
Definition: polyglot_language.h:342
 
poly_thread m_thread
Definition: polyglot_language.h:328
 
poly_context_builder m_context_builder
Definition: polyglot_language.h:329
 
std::shared_ptr< Polyglot_object > m_globals
Definition: polyglot_language.h:332
 
std::unique_ptr< Polyglot_storage > m_storage
Definition: polyglot_language.h:334
 
virtual ~Polyglot_language()=default
 
void set_global_function(const std::string &name, poly_callback callback, void *data=nullptr)
Definition: polyglot_language.cc:331
 
Allows creating a temporary global variable with a random name which will only live until the executi...
Definition: polyglot_language.h:74
 
Scoped_global(const Scoped_global &)=delete
 
std::string m_name
Definition: polyglot_language.h:99
 
const Polyglot_language * m_language
Definition: polyglot_language.h:98
 
Scoped_global(Scoped_global &&)=delete
 
Scoped_global & operator=(const Scoped_global &)=delete
 
poly_value execute(const std::string &code)
Definition: polyglot_language.cc:83
 
~Scoped_global()
Definition: polyglot_language.cc:96
 
Scoped_global & operator=(Scoped_global &&)=delete
 
Helper class to handle polyglot values made permanent.
Definition: polyglot_store.h:47
 
static char * path
Definition: mysqldump.cc:150
 
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
 
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
 
std::shared_ptr< Object_bridge > Object_bridge_t
Definition: polyglot_object_bridge.h:89
 
Definition: file_system_exceptions.h:34
 
std::vector< Value > Argument_list
Definition: jit_executor_value.h:429
 
Value::Map_type_ref Dictionary_t
Definition: jit_executor_value.h:430
 
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
 
Pointer to a function that may be implemented in any language.
Definition: jit_executor_value.h:130