api cleanups too.
[framework/uifw/embryo.git] / src / lib / Embryo.h
1 #ifndef _EMBRYO_H
2 #define _EMBRYO_H
3
4 #ifdef EAPI
5 # undef EAPI
6 #endif
7
8 #ifdef _WIN32
9 # ifdef EFL_EMBRYO_BUILD
10 #  ifdef DLL_EXPORT
11 #   define EAPI __declspec(dllexport)
12 #  else
13 #   define EAPI
14 #  endif /* ! DLL_EXPORT */
15 # else
16 #  define EAPI __declspec(dllimport)
17 # endif /* ! EFL_EMBRYO_BUILD */
18 #else
19 # ifdef __GNUC__
20 #  if __GNUC__ >= 4
21 #   define EAPI __attribute__ ((visibility("default")))
22 #  else
23 #   define EAPI
24 #  endif
25 # else
26 #  define EAPI
27 # endif
28 #endif /* ! _WIN32 */
29
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
33
34 #define EMBRYO_VERSION_MAJOR 1
35 #define EMBRYO_VERSION_MINOR 0
36    
37    typedef struct _Embryo_Version
38      {
39         int major;
40         int minor;
41         int micro;
42         int revision;
43      } Embryo_Version;
44    
45    EAPI extern Embryo_Version *embryo_version;
46    
47    /* potential error values */
48    typedef enum _Embryo_Error
49      {
50         EMBRYO_ERROR_NONE,
51           /* reserve the first 15 error codes for exit codes of the abstract machine */
52           EMBRYO_ERROR_EXIT,         /** Forced exit */
53           EMBRYO_ERROR_ASSERT,       /** Assertion failed */
54           EMBRYO_ERROR_STACKERR,     /** Stack/heap collision */
55           EMBRYO_ERROR_BOUNDS,       /** Index out of bounds */
56           EMBRYO_ERROR_MEMACCESS,    /** Invalid memory access */
57           EMBRYO_ERROR_INVINSTR,     /** Invalid instruction */
58           EMBRYO_ERROR_STACKLOW,     /** Stack underflow */
59           EMBRYO_ERROR_HEAPLOW,      /** Heap underflow */
60           EMBRYO_ERROR_CALLBACK,     /** No callback, or invalid callback */
61           EMBRYO_ERROR_NATIVE,       /** Native function failed */
62           EMBRYO_ERROR_DIVIDE,       /** Divide by zero */
63           EMBRYO_ERROR_SLEEP,        /** Go into sleepmode - code can be restarted */
64
65           EMBRYO_ERROR_MEMORY = 16,  /** Out of memory */
66           EMBRYO_ERROR_FORMAT,       /** Invalid file format */
67           EMBRYO_ERROR_VERSION,      /** File is for a newer version of the Embryo_Program */
68           EMBRYO_ERROR_NOTFOUND,     /** Function not found */
69           EMBRYO_ERROR_INDEX,        /** Invalid index parameter (bad entry point) */
70           EMBRYO_ERROR_DEBUG,        /** Debugger cannot run */
71           EMBRYO_ERROR_INIT,         /** Embryo_Program not initialized (or doubly initialized) */
72           EMBRYO_ERROR_USERDATA,     /** Unable to set user data field (table full) */
73           EMBRYO_ERROR_INIT_JIT,     /** Cannot initialize the JIT */
74           EMBRYO_ERROR_PARAMS,       /** Parameter error */
75           EMBRYO_ERROR_DOMAIN,       /** Domain error, expression result does not fit in range */
76      } Embryo_Error;
77
78    /* program run return values */
79    typedef enum _Embryo_Status
80      {
81         EMBRYO_PROGRAM_FAIL = 0,
82         EMBRYO_PROGRAM_OK = 1,
83         EMBRYO_PROGRAM_SLEEP = 2,
84         EMBRYO_PROGRAM_BUSY = 3,
85         EMBRYO_PROGRAM_TOOLONG = 4
86      } Embryo_Status;
87    
88    typedef unsigned int                Embryo_UCell;
89    typedef int                         Embryo_Cell;
90   /** An invalid cell reference */
91 #define EMBRYO_CELL_NONE     0x7fffffff
92    
93    typedef struct _Embryo_Program      Embryo_Program;
94    typedef int                         Embryo_Function;
95    /* possible function type values that are enumerated */
96 #define EMBRYO_FUNCTION_NONE 0x7fffffff /* An invalid/non existent function */
97 #define EMBRYO_FUNCTION_MAIN -1         /* Start at program entry point */
98 #define EMBRYO_FUNCTION_CONT -2         /* Continue from last address */
99
100    typedef union
101      {
102         float       f;
103         Embryo_Cell c;
104      } Embryo_Float_Cell;
105
106 #if defined _MSC_VER || defined __SUNPRO_C
107 /** Float to Embryo_Cell */
108 # define EMBRYO_FLOAT_TO_CELL(f) (((Embryo_Float_Cell *)&(f))->c)
109 /** Embryo_Cell to float */
110 # define EMBRYO_CELL_TO_FLOAT(c) (((Embryo_Float_Cell *)&(c))->f)
111 #else
112 /** Float to Embryo_Cell */
113 # define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c
114 /** Embryo_Cell to float */
115 # define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f
116 #endif
117
118    EAPI int              embryo_init(void);
119    EAPI int              embryo_shutdown(void);
120
121    EAPI Embryo_Program  *embryo_program_new(void *data, int size);
122    EAPI Embryo_Program  *embryo_program_const_new(void *data, int size);
123    EAPI Embryo_Program  *embryo_program_load(char *file);
124    EAPI void             embryo_program_free(Embryo_Program *ep);
125    EAPI void             embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params));
126    EAPI void             embryo_program_vm_reset(Embryo_Program *ep);
127    EAPI void             embryo_program_vm_push(Embryo_Program *ep);
128    EAPI void             embryo_program_vm_pop(Embryo_Program *ep);
129    EAPI void             embryo_swap_16(unsigned short *v);
130    EAPI void             embryo_swap_32(unsigned int *v);
131    EAPI Embryo_Function  embryo_program_function_find(Embryo_Program *ep, const char *name);
132    EAPI Embryo_Cell      embryo_program_variable_find(Embryo_Program *ep, const char *name);
133    EAPI int              embryo_program_variable_count_get(Embryo_Program *ep);
134    EAPI Embryo_Cell      embryo_program_variable_get(Embryo_Program *ep, int num);
135    EAPI void             embryo_program_error_set(Embryo_Program *ep, Embryo_Error error);
136    EAPI Embryo_Error     embryo_program_error_get(Embryo_Program *ep);
137    EAPI void             embryo_program_data_set(Embryo_Program *ep, void *data);
138    EAPI void            *embryo_program_data_get(Embryo_Program *ep);
139    EAPI const char      *embryo_error_string_get(Embryo_Error error);
140    EAPI int              embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell);
141    EAPI void             embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst);
142    EAPI void             embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cell);
143    EAPI Embryo_Cell     *embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr);
144    EAPI Embryo_Cell      embryo_data_heap_push(Embryo_Program *ep, int cells);
145    EAPI void             embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to);
146    EAPI int              embryo_program_recursion_get(Embryo_Program *ep);
147    EAPI Embryo_Status    embryo_program_run(Embryo_Program *ep, Embryo_Function func);
148    EAPI Embryo_Cell      embryo_program_return_value_get(Embryo_Program *ep);
149    EAPI void             embryo_program_max_cycle_run_set(Embryo_Program *ep, int max);
150    EAPI int              embryo_program_max_cycle_run_get(Embryo_Program *ep);
151    EAPI int              embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell);
152    EAPI int              embryo_parameter_string_push(Embryo_Program *ep, const char *str);
153    EAPI int              embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num);
154
155 #ifdef  __cplusplus
156 }
157 #endif
158
159 #endif