Defines | Functions

objs/kite_obj_create.c File Reference

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <dlfcn.h>
#include "kite_object.h"
#include "kite_gc.h"

Defines

#define NULL_OBJECT   "System.null"
#define INTEGER_OBJECT   "System.integer"
#define FLOAT_OBJECT   "System.float"
#define STRING_OBJECT   "System.string"
#define LIST_OBJECT   "System.list"
#define METHOD_OBJECT   "System.method"
#define BOOLEAN_OBJECT   "System.boolean"

Functions

kite_object_tkite_new_null (kite_thread_t *thd)
kite_object_tkite_new_integer (kite_thread_t *thd, long val)
kite_object_tkite_new_float (kite_thread_t *thd, double val)
kite_object_tkite_new_string (kite_thread_t *thd, char *str)
kite_object_tkite_new_string_with_length (kite_thread_t *thd, char *str, int len)
kite_object_tkite_new_ident (kite_thread_t *thd, char *str)
kite_object_tkite_new_list (kite_thread_t *thd)
kite_object_tkite_new_boolean (kite_thread_t *thd, int val)
kite_object_tkite_new_method_compiled (kite_thread_t *thd, kite_compiled_func_t ptr, int numargs)
kite_object_tkite_new_method_compiled_with_docs (kite_thread_t *thd, kite_compiled_func_t ptr, char *doc, int numargs,...)
kite_object_tkite_new_method_bytecode (kite_thread_t *thd, struct kite_opcode_t *ptr, int numargs)
kite_object_tkite_new_method_bytecode_with_docs (kite_thread_t *thd, struct kite_opcode_t *ptr, char *doc, int numargs,...)
kite_object_tkite_new_class (kite_thread_t *thd, kite_object_t *inherits, char *name)
kite_object_tkite_new_instance (kite_thread_t *thd, kite_object_t *class)
kite_object_tkite_new_instance_with_constructor (kite_thread_t *thd, kite_object_t *class, kite_object_t *args)
kite_object_tkite_new_exception (kite_thread_t *thd, char *name, char *msg)
void kite_free_instruction_list (kite_thread_t *thd, struct kite_opcode_t *opc)
void kite_destruct_object_nofree (kite_thread_t *thd, kite_object_t **obj, int r)
void kite_finalize_object (void *obj, void *cd)
void kite_destruct_object (kite_thread_t *thd, kite_object_t **obj, int r)

Define Documentation

#define BOOLEAN_OBJECT   "System.boolean"

Referenced by kite_new_boolean().

#define FLOAT_OBJECT   "System.float"

Referenced by kite_new_float().

#define INTEGER_OBJECT   "System.integer"

Referenced by kite_new_integer().

#define LIST_OBJECT   "System.list"

Referenced by kite_new_list().

#define METHOD_OBJECT   "System.method"
#define NULL_OBJECT   "System.null"

Referenced by kite_new_null().

#define STRING_OBJECT   "System.string"

Function Documentation

void kite_destruct_object ( kite_thread_t *  ,
kite_object_t **  ,
int   
)

Destroy object.

References kite_destruct_object_nofree().

Referenced by kite_finalize_object(), and kite_gc_destroy_all().

void kite_destruct_object_nofree ( kite_thread_t *  ,
kite_object_t **  ,
int   
)
void kite_finalize_object ( void *  ,
void *   
)

Destroy object.

References kite_destruct_object().

Referenced by kite_new_class(), and kite_new_instance().

void kite_free_instruction_list ( kite_thread_t *  thd,
struct kite_opcode_t *  opc 
)
kite_object_t* kite_new_boolean ( kite_thread_t *  thd,
int  val 
)

Create a new boolean object.

Parameters:
thd The associated thread for the object.
val The value to associate with the object.
Returns:
The new object.

References BOOLEAN_OBJECT, FALSE, kite_dereference_and_load(), kite_reference_object(), and TRUE.

Referenced by kite_boolean_object().

kite_object_t* kite_new_class ( kite_thread_t *  thd,
kite_object_t parent,
char *  name 
)

Create a new Kite class.

Parameters:
thd The associated thread for this object.
parent The class that this inherits from.
name The new class' name.
Returns:
The new object.

References kite_object_t::builtin_data, FALSE, kite_function_t::funcptr, kite_object_t::funcvalue, kite_object_t::inherit_from, kite_finalize_object(), kite_gc_incremental(), kite_list_add_end(), kite_reference_object(), kite_object_t::name, kite_object_t::object_data, and kite_object_t::type.

Referenced by kite_dereference_and_load(), and kite_new_ident().

kite_object_t* kite_new_exception ( kite_thread_t *  thd,
char *  name,
char *  message 
)

Create a new exception object.

Parameters:
thd The thread to associate the exception with.
name The fully-qualified name of the exception (e.g. System.exceptions.FileError)
message The message to associate with the given exception.
Returns:
The new object.

References kite_dereference_and_load(), kite_dereference_object(), kite_list_object(), kite_new_instance_with_constructor(), and kite_new_string().

Referenced by kite_dereference_and_load(), kite_vm_call_method(), and kite_vm_call_operator().

kite_object_t* kite_new_float ( kite_thread_t *  thd,
double  val 
)

Create a new floating-point object.

Parameters:
thd The associated thread for the object.
val The value to associate with the object.
Returns:
The new object.

References FLOAT_OBJECT, and kite_dereference_and_load().

Referenced by kite_float_object().

kite_object_t* kite_new_ident ( kite_thread_t *  thd,
char *  val 
)

Create a new identifier object.

Parameters:
thd The associated thread for the object.
val The value to associate with the object.
Returns:
The new object.

References kite_object_t::builtin_data, kite_symtab_t::global, KITE_FIND_ANY_IN_SYMTAB, kite_new_class(), kite_new_symtab(), kite_symtab_insert(), kite_symtab_t::name, kite_object_t::stringvalue, kite_object_t::type, and kite_symtab_t::value.

Referenced by kite_new_method_bytecode_with_docs(), and kite_new_method_compiled_with_docs().

kite_object_t* kite_new_instance ( kite_thread_t *  thd,
kite_object_t parent 
)

Create a new Kite instance (without initialization)

Parameters:
thd The associated thread for this object.
parent The class that this instance is associated with.
Returns:
The new object.

References kite_object_t::inherit_from, kite_finalize_object(), kite_gc_incremental(), kite_list_add_end(), kite_reference_object(), kite_object_t::name, kite_object_t::object_data, and kite_object_t::type.

Referenced by kite_new_instance_with_constructor(), kite_new_list(), kite_new_method_bytecode(), kite_new_method_compiled(), kite_new_null(), kite_new_string(), and kite_new_string_with_length().

kite_object_t* kite_new_instance_with_constructor ( kite_thread_t *  thd,
kite_object_t parent,
kite_object_t args 
)

Create a new Kite instance (with initialization)

Parameters:
thd The associated thread for this object.
parent The class that this instance is associated with.
args A list specifying arguments to pass to the constructor.
Returns:
The new object.
Note:
thd->exception will contain an exception object if the constructor fails.
See also:
struct kite_thread_t

References kite_new_instance(), and kite_vm_call_constructor().

Referenced by kite_new_exception().

kite_object_t* kite_new_integer ( kite_thread_t *  thd,
long  val 
)

Create a new integer object.

Parameters:
thd The associated thread for the object.
val The value to associate with the object.
Returns:
The new object.

References INTEGER_OBJECT, and kite_dereference_and_load().

Referenced by kite_handle_signal(), and kite_int_object().

kite_object_t* kite_new_list ( kite_thread_t *  thd  ) 
kite_object_t* kite_new_method_bytecode ( kite_thread_t *  thd,
struct kite_opcode_t *  func,
int  numargs 
)

Create a new method object (based on Kite bytecode).

Parameters:
thd The associated thread for the object.
func The C function that this method refers to.
numargs The number of arguments this method should take in Kite code.
Returns:
The new object.

References kite_object_t::builtin_data, kite_function_t::funcptr, kite_function_t::functype, kite_object_t::funcvalue, kite_dereference_and_load(), kite_new_instance(), METHOD_OBJECT, kite_function_t::numargs, and kite_object_t::type.

Referenced by kite_new_method_bytecode_with_docs().

kite_object_t* kite_new_method_bytecode_with_docs ( kite_thread_t *  thd,
struct kite_opcode_t *  func,
char *  desc,
int  numargs,
  ... 
)

Create a new method object with documentation strings (based on Kite bytecode).

Parameters:
thd The associated thread for the object.
func The bytecode that this method refers to.
desc The method's description.
numargs The number of arguments this method should take in Kite code.
argname (for each argument) The name of the argument.
argdesc (for each argument) The description of the argument.
Returns:
The new object.

References kite_append_list(), kite_new_ident(), kite_new_list(), kite_new_method_bytecode(), kite_set_arginfo(), and kite_set_docstring().

kite_object_t* kite_new_method_compiled ( kite_thread_t *  thd,
kite_compiled_func_t  func,
int  numargs 
)

Create a new method object (based on C-compiled code).

Parameters:
thd The associated thread for the object.
func The C function that this method refers to.
numargs The number of arguments this method should take in Kite code.
Returns:
The new object.

References kite_object_t::builtin_data, kite_function_t::funcptr, kite_function_t::functype, kite_object_t::funcvalue, kite_dereference_and_load(), kite_new_instance(), METHOD_OBJECT, kite_function_t::numargs, and kite_object_t::type.

Referenced by kite_new_method_compiled_with_docs().

kite_object_t* kite_new_method_compiled_with_docs ( kite_thread_t *  thd,
kite_compiled_func_t  func,
char *  desc,
int  numargs,
  ... 
)

Create a new method object with documentation strings (based on C-compiled code).

Parameters:
thd The associated thread for the object.
func The C function that this method refers to.
desc The method's description.
numargs The number of arguments this method should take in Kite code.
argname (for each argument) The name of the argument.
argdesc (for each argument) The description of the argument.
Returns:
The new object.

References kite_append_list(), kite_new_ident(), kite_new_list(), kite_new_method_compiled(), kite_set_arginfo(), and kite_set_docstring().

kite_object_t* kite_new_null ( kite_thread_t *  thd  ) 

Create a new null object.

Parameters:
thd The associated thread for the object.
Returns:
The new object.

References kite_dereference_and_load(), kite_new_instance(), kite_reference_object(), NULL_OBJECT, and kite_object_t::type.

Referenced by kite_handle_signal().

kite_object_t* kite_new_string ( kite_thread_t *  thd,
char *  val 
)

Create a new string object.

Parameters:
thd The associated thread for the object.
val The value to associate with the object.
Returns:
The new object.

References kite_object_t::builtin_data, kite_dereference_and_load(), kite_new_instance(), STRING_OBJECT, kite_object_t::stringvalue, and kite_object_t::type.

Referenced by kite_new_exception(), kite_object_name(), kite_string_object(), and kite_vm_call_method().

kite_object_t* kite_new_string_with_length ( kite_thread_t *  thd,
char *  val,
int  length 
)

Create a new string object (with given length).

Parameters:
thd The associated thread for the object.
val The value to associate with the object.
length The length of the string.
Returns:
The new object.

References kite_object_t::builtin_data, kite_dereference_and_load(), KITE_GET_STRING_VALUE, kite_new_instance(), STRING_OBJECT, kite_object_t::stringvalue, and kite_object_t::type.