svn update: 49540 (latest:49550)
[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 0
35 #define EMBRYO_VERSION_MINOR 9
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    /* potentioal error values */
48    enum
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      };
77
78    /* possible function type values that are enumerated */
79 #define EMBRYO_FUNCTION_NONE 0x7fffffff /* An invalid/non existant function */
80 #define EMBRYO_FUNCTION_MAIN -1         /* Start at program entry point */
81 #define EMBRYO_FUNCTION_CONT -2         /* Continue from last address */
82   /** An invalid cell reference */
83 #define EMBRYO_CELL_NONE     0x7fffffff
84    /* program run return values */
85 #define EMBRYO_PROGRAM_OK      1
86 #define EMBRYO_PROGRAM_SLEEP   2
87 #define EMBRYO_PROGRAM_BUSY    3
88 #define EMBRYO_PROGRAM_TOOLONG 4
89 #define EMBRYO_PROGRAM_FAIL    0
90
91    typedef unsigned int                Embryo_UCell;
92    typedef int                         Embryo_Cell;
93    typedef struct _Embryo_Program      Embryo_Program;
94    typedef int                         Embryo_Function;
95
96    typedef union
97      {
98         float       f;
99         Embryo_Cell c;
100      } Embryo_Float_Cell;
101
102 #if defined _MSC_VER || defined __SUNPRO_C
103 /** Float to Embryo_Cell */
104 # define EMBRYO_FLOAT_TO_CELL(f) (((Embryo_Float_Cell *)&(f))->c)
105 /** Embryo_Cell to float */
106 # define EMBRYO_CELL_TO_FLOAT(c) (((Embryo_Float_Cell *)&(c))->f)
107 #else
108 /** Float to Embryo_Cell */
109 # define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c
110 /** Embryo_Cell to float */
111 # define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f
112 #endif
113
114    EAPI int              embryo_init(void);
115    EAPI int              embryo_shutdown(void);
116
117    EAPI Embryo_Program  *embryo_program_new(void *data, int size);
118    EAPI Embryo_Program  *embryo_program_const_new(void *data, int size);
119    EAPI Embryo_Program  *embryo_program_load(char *file);
120    EAPI void             embryo_program_free(Embryo_Program *ep);
121    EAPI void             embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params));
122    EAPI void             embryo_program_vm_reset(Embryo_Program *ep);
123    EAPI void             embryo_program_vm_push(Embryo_Program *ep);
124    EAPI void             embryo_program_vm_pop(Embryo_Program *ep);
125    EAPI void             embryo_swap_16(unsigned short *v);
126    EAPI void             embryo_swap_32(unsigned int *v);
127    EAPI Embryo_Function  embryo_program_function_find(Embryo_Program *ep, const char *name);
128    EAPI Embryo_Cell      embryo_program_variable_find(Embryo_Program *ep, const char *name);
129    EAPI int              embryo_program_variable_count_get(Embryo_Program *ep);
130    EAPI Embryo_Cell      embryo_program_variable_get(Embryo_Program *ep, int num);
131    EAPI void             embryo_program_error_set(Embryo_Program *ep, int error);
132    EAPI int              embryo_program_error_get(Embryo_Program *ep);
133    EAPI void             embryo_program_data_set(Embryo_Program *ep, void *data);
134    EAPI void            *embryo_program_data_get(Embryo_Program *ep);
135    EAPI const char      *embryo_error_string_get(int error);
136    EAPI int              embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell);
137    EAPI void             embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst);
138    EAPI void             embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cell);
139    EAPI Embryo_Cell     *embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr);
140    EAPI Embryo_Cell      embryo_data_heap_push(Embryo_Program *ep, int cells);
141    EAPI void             embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to);
142    EAPI int              embryo_program_recursion_get(Embryo_Program *ep);
143    EAPI int              embryo_program_run(Embryo_Program *ep, Embryo_Function func);
144    EAPI Embryo_Cell      embryo_program_return_value_get(Embryo_Program *ep);
145    EAPI void             embryo_program_max_cycle_run_set(Embryo_Program *ep, int max);
146    EAPI int              embryo_program_max_cycle_run_get(Embryo_Program *ep);
147    EAPI int              embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell);
148    EAPI int              embryo_parameter_string_push(Embryo_Program *ep, const char *str);
149    EAPI int              embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num);
150
151 #ifdef  __cplusplus
152 }
153 #endif
154
155 #endif