Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
Embryo.h File Reference

Embryo virtual machine library. More...

Data Structures

struct  _Embryo_Version
 
union  Embryo_Float_Cell
 

Macros

#define EAPI
 
#define EMBRYO_VERSION_MAJOR   EFL_VERSION_MAJOR
 
#define EMBRYO_VERSION_MINOR   EFL_VERSION_MINOR
 
#define EMBRYO_CELL_NONE   0x7fffffff
 An invalid cell reference.
 
#define EMBRYO_FUNCTION_NONE   0x7fffffff /* An invalid/non existent function */
 An invalid/non-existent function.
 
#define EMBRYO_FUNCTION_MAIN   -1 /* Start at program entry point */
 Start at program entry point. More...
 
#define EMBRYO_FUNCTION_CONT   -2 /* Continue from last address */
 Continue from last address. More...
 
#define EMBRYO_FLOAT_TO_CELL(f)   ((Embryo_Float_Cell) f).c
 Float to Embryo_Cell.
 
#define EMBRYO_CELL_TO_FLOAT(c)   ((Embryo_Float_Cell) c).f
 Embryo_Cell to float.
 
#define EAPI
 

Typedefs

typedef struct _Embryo_Version Embryo_Version
 Represents the current version of Embryo.
 
typedef enum _Embryo_Error Embryo_Error
 
typedef enum _Embryo_Status Embryo_Status
 
typedef unsigned int Embryo_UCell
 
typedef int Embryo_Cell
 
typedef struct _Embryo_Program Embryo_Program
 
typedef int Embryo_Function
 

Enumerations

enum  _Embryo_Error {
  EMBRYO_ERROR_NONE,
  EMBRYO_ERROR_EXIT,
  EMBRYO_ERROR_ASSERT,
  EMBRYO_ERROR_STACKERR,
  EMBRYO_ERROR_BOUNDS,
  EMBRYO_ERROR_MEMACCESS,
  EMBRYO_ERROR_INVINSTR,
  EMBRYO_ERROR_STACKLOW,
  EMBRYO_ERROR_HEAPLOW,
  EMBRYO_ERROR_CALLBACK,
  EMBRYO_ERROR_NATIVE,
  EMBRYO_ERROR_DIVIDE,
  EMBRYO_ERROR_SLEEP,
  EMBRYO_ERROR_MEMORY = 16,
  EMBRYO_ERROR_FORMAT,
  EMBRYO_ERROR_VERSION,
  EMBRYO_ERROR_NOTFOUND,
  EMBRYO_ERROR_INDEX,
  EMBRYO_ERROR_DEBUG,
  EMBRYO_ERROR_INIT,
  EMBRYO_ERROR_USERDATA,
  EMBRYO_ERROR_INIT_JIT,
  EMBRYO_ERROR_PARAMS,
  EMBRYO_ERROR_DOMAIN
}
 
enum  _Embryo_Status {
  EMBRYO_PROGRAM_FAIL = 0,
  EMBRYO_PROGRAM_OK = 1,
  EMBRYO_PROGRAM_SLEEP = 2,
  EMBRYO_PROGRAM_BUSY = 3,
  EMBRYO_PROGRAM_TOOLONG = 4
}
 

Functions

EAPI int embryo_init (void)
 Initialises the Embryo library. More...
 
EAPI int embryo_shutdown (void)
 Shuts down the Embryo library. More...
 
EAPI Embryo_Program * embryo_program_new (void *data, int size)
 Creates a new Embryo program, with bytecode data that can be freed. More...
 
EAPI Embryo_Program * embryo_program_const_new (void *data, int size)
 Creates a new Embryo program, with bytecode data that cannot be freed. More...
 
EAPI Embryo_Program * embryo_program_load (const char *file)
 Creates a new Embryo program based on the bytecode data stored in the given file. More...
 
EAPI void embryo_program_free (Embryo_Program *ep)
 Frees the given Embryo program. More...
 
EAPI void embryo_program_native_call_add (Embryo_Program *ep, const char *name, Embryo_Cell(*func)(Embryo_Program *ep, Embryo_Cell *params))
 Adds a native program call to the given Embryo program. More...
 
EAPI void embryo_program_vm_reset (Embryo_Program *ep)
 Resets the current virtual machine session of the given program. More...
 
EAPI void embryo_program_vm_push (Embryo_Program *ep)
 Starts a new virtual machine session for the given program. More...
 
EAPI void embryo_program_vm_pop (Embryo_Program *ep)
 Frees the current virtual machine session associated with the given program. More...
 
EAPI void embryo_swap_16 (unsigned short *v)
 Ensures that the given unsigned short integer is in the small endian format. More...
 
EAPI void embryo_swap_32 (unsigned int *v)
 Ensures that the given unsigned integer is in the small endian format. More...
 
EAPI Embryo_Function embryo_program_function_find (Embryo_Program *ep, const char *name)
 Returns the function in the given program with the given name. More...
 
EAPI Embryo_Cell embryo_program_variable_find (Embryo_Program *ep, const char *name)
 Retrieves the location of the public variable in the given program with the given name. More...
 
EAPI int embryo_program_variable_count_get (Embryo_Program *ep)
 Retrieves the number of public variables in the given program. More...
 
EAPI Embryo_Cell embryo_program_variable_get (Embryo_Program *ep, int num)
 Retrieves the location of the public variable in the given program with the given identifier. More...
 
EAPI void embryo_program_error_set (Embryo_Program *ep, Embryo_Error error)
 Sets the error code for the given program to the given code. More...
 
EAPI Embryo_Error embryo_program_error_get (Embryo_Program *ep)
 Retrieves the current error code for the given program. More...
 
EAPI void embryo_program_data_set (Embryo_Program *ep, void *data)
 Sets the data associated to the given program. More...
 
EAPI void * embryo_program_data_get (Embryo_Program *ep)
 Retrieves the data associated to the given program. More...
 
EAPI const char * embryo_error_string_get (Embryo_Error error)
 Retrieves a string describing the given error code. More...
 
EAPI int embryo_data_string_length_get (Embryo_Program *ep, Embryo_Cell *str_cell)
 Retrieves the length of the string starting at the given cell. More...
 
EAPI void embryo_data_string_get (Embryo_Program *ep, Embryo_Cell *str_cell, char *dst)
 Copies the string starting at the given cell to the given buffer. More...
 
EAPI void embryo_data_string_set (Embryo_Program *ep, const char *src, Embryo_Cell *str_cell)
 Copies string in the given buffer into the virtual machine memory starting at the given cell. More...
 
EAPI Embryo_Cell * embryo_data_address_get (Embryo_Program *ep, Embryo_Cell addr)
 Retreives a pointer to the address in the virtual machine given by the given cell. More...
 
EAPI Embryo_Cell embryo_data_heap_push (Embryo_Program *ep, int cells)
 Increases the size of the heap of the given virtual machine by the given number of Embryo_Cells. More...
 
EAPI void embryo_data_heap_pop (Embryo_Program *ep, Embryo_Cell down_to)
 Decreases the size of the heap of the given virtual machine down to the given size. More...
 
EAPI int embryo_program_recursion_get (Embryo_Program *ep)
 Returns the number of virtual machines are running for the given program. More...
 
EAPI Embryo_Status embryo_program_run (Embryo_Program *ep, Embryo_Function func)
 Runs the given function of the given Embryo program in the current virtual machine. More...
 
EAPI Embryo_Cell embryo_program_return_value_get (Embryo_Program *ep)
 Retreives the return value of the last called function of the given program. More...
 
EAPI void embryo_program_max_cycle_run_set (Embryo_Program *ep, int max)
 Sets the maximum number of abstract machine cycles any given program run can execute before being put to sleep and returning. More...
 
EAPI int embryo_program_max_cycle_run_get (Embryo_Program *ep)
 Retreives the maximum number of abstract machine cycles a program is allowed to run. More...
 
EAPI int embryo_parameter_cell_push (Embryo_Program *ep, Embryo_Cell cell)
 Pushes an Embryo_Cell onto the function stack to use as a parameter for the next function that is called in the given program. More...
 
EAPI int embryo_parameter_string_push (Embryo_Program *ep, const char *str)
 Pushes a string onto the function stack to use as a parameter for the next function that is called in the given program. More...
 
EAPI int embryo_parameter_cell_array_push (Embryo_Program *ep, Embryo_Cell *cells, int num)
 Pushes an array of Embryo_Cells onto the function stack to be used as parameters for the next function that is called in the given program. More...
 

Variables

EAPI Embryo_Versionembryo_version
 

Detailed Description

Embryo virtual machine library.

This file includes the routines needed for Embryo library interaction. This is the only file you need to include.

Macro Definition Documentation

◆ EMBRYO_FUNCTION_MAIN

#define EMBRYO_FUNCTION_MAIN   -1 /* Start at program entry point */

Start at program entry point.

For use with embryo_program_run.

◆ EMBRYO_FUNCTION_CONT

#define EMBRYO_FUNCTION_CONT   -2 /* Continue from last address */

Continue from last address.

For use with embryo_program_run.

Enumeration Type Documentation

◆ _Embryo_Error

Enumerator
EMBRYO_ERROR_ASSERT 

Forced exit.

EMBRYO_ERROR_STACKERR 

Assertion failed.

EMBRYO_ERROR_BOUNDS 

Stack/heap collision.

EMBRYO_ERROR_MEMACCESS 

Index out of bounds.

EMBRYO_ERROR_INVINSTR 

Invalid memory access.

EMBRYO_ERROR_STACKLOW 

Invalid instruction.

EMBRYO_ERROR_HEAPLOW 

Stack underflow.

EMBRYO_ERROR_CALLBACK 

Heap underflow.

EMBRYO_ERROR_NATIVE 

No callback, or invalid callback.

EMBRYO_ERROR_DIVIDE 

Native function failed.

EMBRYO_ERROR_SLEEP 

Divide by zero.

EMBRYO_ERROR_MEMORY 

Go into sleepmode - code can be restarted.

EMBRYO_ERROR_FORMAT 

Out of memory.

EMBRYO_ERROR_VERSION 

Invalid file format.

EMBRYO_ERROR_NOTFOUND 

File is for a newer version of the Embryo_Program.

EMBRYO_ERROR_INDEX 

Function not found.

EMBRYO_ERROR_DEBUG 

Invalid index parameter (bad entry point)

EMBRYO_ERROR_INIT 

Debugger cannot run.

EMBRYO_ERROR_USERDATA 

Embryo_Program not initialized (or doubly initialized)

EMBRYO_ERROR_INIT_JIT 

Unable to set user data field (table full)

EMBRYO_ERROR_PARAMS 

Cannot initialize the JIT.

EMBRYO_ERROR_DOMAIN 

Parameter error.