MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
shcore::polyglot::Polyglot_language Class Referenceabstract

The polyglot library may support several languages (guest languages), and provides out of the box C++ interfaces to handle common language elements, such as Objects, Maps, Arrays, Functions and primitive data types. More...

#include <polyglot_language.h>

Inheritance diagram for shcore::polyglot::Polyglot_language:
[legend]

Classes

class  Current_script
 
class  Script_scope
 

Public Member Functions

 Polyglot_language (Polyglot_common_context *common_context, const std::string &debug_port="")
 
 Polyglot_language (const Polyglot_language &)=delete
 
Polyglot_languageoperator= (const Polyglot_language &)=delete
 
 Polyglot_language (Polyglot_language &&)=delete
 
Polyglot_languageoperator= (Polyglot_language &&)=delete
 
virtual ~Polyglot_language ()=default
 
virtual const char * get_language_id () const =0
 
virtual void init_context_builder ()
 
virtual void initialize (const std::shared_ptr< IFile_system > &fs={})
 
virtual void finalize ()
 
Polyglot_languagelanguage ()
 The polyglot_utils file has the following functions that can be used to export C++ functions as polyglot global functions: More...
 
void throw_jit_executor_exception (const Jit_executor_exception &exception)
 Throws a specific exception type in the GraalVM environment, with a specific message. More...
 
virtual poly_value undefined () const =0
 Return the a guest language interpretation of the Undefined C++ value. More...
 
virtual bool is_undefined (poly_value value) const =0
 Returns true if the provided value is undefined in the guest language. More...
 
virtual poly_value array_buffer (const std::string &data) const =0
 Return the guest language interpretation of a binary string. More...
 
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. More...
 
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. More...
 
virtual shcore::Value to_native_object (poly_value object, const std::string &class_name)
 Converts a guest language object into its C++ representation. More...
 
void throw_exception_object (const shcore::Dictionary_t &data) const
 Translates a dictionary object into an exception in the guest language. More...
 
void throw_exception_object (const Polyglot_error &data) const
 Translates a Polyglot_error into an exception in the guest language. More...
 
virtual const std::vector< std::string > & keywords () const =0
 Retrieves the list of keywords in the guest language. More...
 
int64_t eval (const std::string &source, const std::string &code_str, poly_value *result) const
 Wraps a call to poly_context_eval. More...
 
poly_value create_source (const std::string &path) const
 
std::pair< Value, bool > debug (const std::string &path)
 Debugs the given script. More...
 
std::pair< Value, bool > execute (const std::string &code_str, const std::string &source)
 Executes the given script. More...
 
virtual bool load_plugin (const std::string &path)
 This function should be implemented to provide plugin load support. More...
 
poly_context copy_global_context () const
 Creates a copy of the global context. More...
 
poly_value poly_string (const std::string &data) const
 
std::string to_string (poly_value obj) const
 
poly_context context () const
 
poly_thread thread () const
 
const std::shared_ptr< Polyglot_object > & globals () const
 
poly_reference store (poly_value value)
 
void erase (poly_reference value)
 
void set_global (const std::string &name, const Value &value) const
 
void set_global (const std::string &name, poly_value value) const
 
void set_global_function (const std::string &name, poly_callback callback, void *data=nullptr)
 
Store get_global (const std::string &name) const
 
void terminate ()
 
bool is_terminating () const
 
Script_scope enter_script (const std::string &s)
 
Value convert (poly_value value) const
 
poly_value convert (const Value &value) const
 
Argument_list convert_args (const std::vector< poly_value > &args) const
 
poly_value type_info (poly_value value) const
 
bool get_member (poly_value object, const char *name, poly_value *member) const
 
std::string current_script_folder () const
 
Polyglot_common_contextcommon_context ()
 

Protected Member Functions

poly_value wrap_callback (poly_callback callback, void *data) const
 
void clear_is_terminating ()
 

Protected Attributes

Polyglot_common_contextm_common_context
 
poly_thread m_thread = nullptr
 
poly_context_builder m_context_builder = nullptr
 
Store m_context
 
std::unique_ptr< Polyglot_type_bridgerm_types
 
std::shared_ptr< Polyglot_objectm_globals
 
Current_script m_current_script
 
std::unique_ptr< Polyglot_storagem_storage
 
std::shared_ptr< IFile_systemm_file_system
 
std::string m_debug_port
 

Private Member Functions

void set_file_system ()
 
void throw_exception_object (poly_value exception) const
 
virtual poly_value create_exception_object (const std::string &error, poly_value exception_object) const =0
 
virtual void output_handler (const char *bytes, size_t length)=0
 
virtual void error_handler (const char *bytes, size_t length)=0
 
void enable_debug ()
 
virtual std::optional< std::string > get_debug_port () const
 

Static Private Member Functions

static void output_callback (const char *bytes, size_t length, void *data)
 
static void error_callback (const char *bytes, size_t length, void *data)
 

Private Attributes

std::unique_ptr< Polyglot_scopem_scope
 
bool m_terminating = false
 

Detailed Description

The polyglot library may support several languages (guest languages), and provides out of the box C++ interfaces to handle common language elements, such as Objects, Maps, Arrays, Functions and primitive data types.

However, it does not provide out of the box C++ interface for guest language non primitive data types or specific objects.

This class is to be used as the base class to handle the common language elements supported in the polyglot library, any guest language supported by the shell is meant to extend this class and add handling of the elements that are specific to it.

Constructor & Destructor Documentation

◆ Polyglot_language() [1/3]

shcore::polyglot::Polyglot_language::Polyglot_language ( Polyglot_common_context common_context,
const std::string &  debug_port = "" 
)
explicit

◆ Polyglot_language() [2/3]

shcore::polyglot::Polyglot_language::Polyglot_language ( const Polyglot_language )
delete

◆ Polyglot_language() [3/3]

shcore::polyglot::Polyglot_language::Polyglot_language ( Polyglot_language &&  )
delete

◆ ~Polyglot_language()

virtual shcore::polyglot::Polyglot_language::~Polyglot_language ( )
virtualdefault

Member Function Documentation

◆ array_buffer()

virtual poly_value shcore::polyglot::Polyglot_language::array_buffer ( const std::string &  data) const
pure virtual

Return the guest language interpretation of a binary string.

Implemented in shcore::polyglot::Java_script_interface.

◆ clear_is_terminating()

void shcore::polyglot::Polyglot_language::clear_is_terminating ( )
protected

◆ common_context()

Polyglot_common_context * shcore::polyglot::Polyglot_language::common_context ( )
inline

◆ context()

poly_context shcore::polyglot::Polyglot_language::context ( ) const

◆ convert() [1/2]

poly_value shcore::polyglot::Polyglot_language::convert ( const Value value) const

◆ convert() [2/2]

Value shcore::polyglot::Polyglot_language::convert ( poly_value  value) const

◆ convert_args()

Argument_list shcore::polyglot::Polyglot_language::convert_args ( const std::vector< poly_value > &  args) const

◆ copy_global_context()

poly_context shcore::polyglot::Polyglot_language::copy_global_context ( ) const

Creates a copy of the global context.

Context needs to be either deleted immediately (i.e.

in case of an error), or stored till JS context exists (in order to preserve execution environment).

◆ create_exception_object()

virtual poly_value shcore::polyglot::Polyglot_language::create_exception_object ( const std::string &  error,
poly_value  exception_object 
) const
privatepure virtual

◆ create_source()

poly_value shcore::polyglot::Polyglot_language::create_source ( const std::string &  path) const

◆ current_script_folder()

std::string shcore::polyglot::Polyglot_language::current_script_folder ( ) const

◆ debug()

std::pair< Value, bool > shcore::polyglot::Polyglot_language::debug ( const std::string &  path)

Debugs the given script.

◆ enable_debug()

void shcore::polyglot::Polyglot_language::enable_debug ( )
private

◆ enter_script()

Polyglot_language::Script_scope shcore::polyglot::Polyglot_language::enter_script ( const std::string &  s)

◆ erase()

void shcore::polyglot::Polyglot_language::erase ( poly_reference  value)

◆ error_callback()

void shcore::polyglot::Polyglot_language::error_callback ( const char *  bytes,
size_t  length,
void *  data 
)
staticprivate

◆ error_handler()

virtual void shcore::polyglot::Polyglot_language::error_handler ( const char *  bytes,
size_t  length 
)
privatepure virtual

Implemented in jit_executor::JavaScript.

◆ eval()

int64_t shcore::polyglot::Polyglot_language::eval ( const std::string &  source,
const std::string &  code_str,
poly_value *  result 
) const

Wraps a call to poly_context_eval.

◆ execute()

std::pair< Value, bool > shcore::polyglot::Polyglot_language::execute ( const std::string &  code_str,
const std::string &  source 
)

Executes the given script.

◆ finalize()

void shcore::polyglot::Polyglot_language::finalize ( )
virtual

◆ from_native_object()

virtual poly_value shcore::polyglot::Polyglot_language::from_native_object ( const Object_bridge_t object) const
pure virtual

Converts a C++ object into a representation of the object in the guest language.

◆ get_debug_port()

virtual std::optional< std::string > shcore::polyglot::Polyglot_language::get_debug_port ( ) const
inlineprivatevirtual

◆ get_global()

Store shcore::polyglot::Polyglot_language::get_global ( const std::string &  name) const

◆ get_language_id()

virtual const char * shcore::polyglot::Polyglot_language::get_language_id ( ) const
pure virtual

◆ get_member()

bool shcore::polyglot::Polyglot_language::get_member ( poly_value  object,
const char *  name,
poly_value *  member 
) const

◆ globals()

const std::shared_ptr< Polyglot_object > & shcore::polyglot::Polyglot_language::globals ( ) const

◆ init_context_builder()

void shcore::polyglot::Polyglot_language::init_context_builder ( )
virtual

◆ initialize()

void shcore::polyglot::Polyglot_language::initialize ( const std::shared_ptr< IFile_system > &  fs = {})
virtual

◆ is_object()

virtual bool shcore::polyglot::Polyglot_language::is_object ( poly_value  object,
std::string *  class_name = nullptr 
) const
pure virtual

Return true if the guest language identifies the value as an object.

Implemented in shcore::polyglot::Java_script_interface.

◆ is_terminating()

bool shcore::polyglot::Polyglot_language::is_terminating ( ) const

◆ is_undefined()

virtual bool shcore::polyglot::Polyglot_language::is_undefined ( poly_value  value) const
pure virtual

Returns true if the provided value is undefined in the guest language.

Implemented in shcore::polyglot::Java_script_interface.

◆ keywords()

virtual const std::vector< std::string > & shcore::polyglot::Polyglot_language::keywords ( ) const
pure virtual

Retrieves the list of keywords in the guest language.

Implemented in shcore::polyglot::Java_script_interface.

◆ language()

Polyglot_language * shcore::polyglot::Polyglot_language::language ( )
inline

The polyglot_utils file has the following functions that can be used to export C++ functions as polyglot global functions:

  • polyglot_handler*
  • native_handler*

These wrappers allow exposing class functions as long as the class containing them contains a language() function that returns a pointer to a Polyglot language.

This function, basically enables subclasses to expose functions as polyglot globals.

◆ load_plugin()

virtual bool shcore::polyglot::Polyglot_language::load_plugin ( const std::string &  path)
inlinevirtual

This function should be implemented to provide plugin load support.

◆ operator=() [1/2]

Polyglot_language & shcore::polyglot::Polyglot_language::operator= ( const Polyglot_language )
delete

◆ operator=() [2/2]

Polyglot_language & shcore::polyglot::Polyglot_language::operator= ( Polyglot_language &&  )
delete

◆ output_callback()

void shcore::polyglot::Polyglot_language::output_callback ( const char *  bytes,
size_t  length,
void *  data 
)
staticprivate

◆ output_handler()

virtual void shcore::polyglot::Polyglot_language::output_handler ( const char *  bytes,
size_t  length 
)
privatepure virtual

Implemented in jit_executor::JavaScript.

◆ poly_string()

poly_value shcore::polyglot::Polyglot_language::poly_string ( const std::string &  data) const

◆ set_file_system()

void shcore::polyglot::Polyglot_language::set_file_system ( )
private

◆ set_global() [1/2]

void shcore::polyglot::Polyglot_language::set_global ( const std::string &  name,
const Value value 
) const

◆ set_global() [2/2]

void shcore::polyglot::Polyglot_language::set_global ( const std::string &  name,
poly_value  value 
) const

◆ set_global_function()

void shcore::polyglot::Polyglot_language::set_global_function ( const std::string &  name,
poly_callback  callback,
void *  data = nullptr 
)

◆ store()

poly_reference shcore::polyglot::Polyglot_language::store ( poly_value  value)

◆ terminate()

void shcore::polyglot::Polyglot_language::terminate ( )

◆ thread()

poly_thread shcore::polyglot::Polyglot_language::thread ( ) const

◆ throw_exception_object() [1/3]

void shcore::polyglot::Polyglot_language::throw_exception_object ( const Polyglot_error data) const

Translates a Polyglot_error into an exception in the guest language.

◆ throw_exception_object() [2/3]

void shcore::polyglot::Polyglot_language::throw_exception_object ( const shcore::Dictionary_t data) const

Translates a dictionary object into an exception in the guest language.

◆ throw_exception_object() [3/3]

void shcore::polyglot::Polyglot_language::throw_exception_object ( poly_value  exception) const
private

◆ throw_jit_executor_exception()

void shcore::polyglot::Polyglot_language::throw_jit_executor_exception ( const Jit_executor_exception exception)

Throws a specific exception type in the GraalVM environment, with a specific message.

◆ to_native_object()

shcore::Value shcore::polyglot::Polyglot_language::to_native_object ( poly_value  object,
const std::string &  class_name 
)
virtual

Converts a guest language object into its C++ representation.

Reimplemented in jit_executor::JavaScript.

◆ to_string()

std::string shcore::polyglot::Polyglot_language::to_string ( poly_value  obj) const

◆ type_info()

poly_value shcore::polyglot::Polyglot_language::type_info ( poly_value  value) const

◆ undefined()

virtual poly_value shcore::polyglot::Polyglot_language::undefined ( ) const
pure virtual

Return the a guest language interpretation of the Undefined C++ value.

Implemented in shcore::polyglot::Java_script_interface.

◆ wrap_callback()

poly_value shcore::polyglot::Polyglot_language::wrap_callback ( poly_callback  callback,
void *  data 
) const
protected

Member Data Documentation

◆ m_common_context

Polyglot_common_context* shcore::polyglot::Polyglot_language::m_common_context
protected

◆ m_context

Store shcore::polyglot::Polyglot_language::m_context
protected

◆ m_context_builder

poly_context_builder shcore::polyglot::Polyglot_language::m_context_builder = nullptr
protected

◆ m_current_script

Current_script shcore::polyglot::Polyglot_language::m_current_script
protected

◆ m_debug_port

std::string shcore::polyglot::Polyglot_language::m_debug_port
protected

◆ m_file_system

std::shared_ptr<IFile_system> shcore::polyglot::Polyglot_language::m_file_system
protected

◆ m_globals

std::shared_ptr<Polyglot_object> shcore::polyglot::Polyglot_language::m_globals
protected

◆ m_scope

std::unique_ptr<Polyglot_scope> shcore::polyglot::Polyglot_language::m_scope
private

◆ m_storage

std::unique_ptr<Polyglot_storage> shcore::polyglot::Polyglot_language::m_storage
protected

◆ m_terminating

bool shcore::polyglot::Polyglot_language::m_terminating = false
private

◆ m_thread

poly_thread shcore::polyglot::Polyglot_language::m_thread = nullptr
protected

◆ m_types

std::unique_ptr<Polyglot_type_bridger> shcore::polyglot::Polyglot_language::m_types
protected

The documentation for this class was generated from the following files: