| 1 |
#ifndef _NPL_H |
| 2 |
#define _NPL_H |
| 3 |
|
| 4 |
#include "nplc.h" |
| 5 |
#include <wchar.h> |
| 6 |
|
| 7 |
// 指定の構造体(T)からメンバ(m)までのオフセットを返す |
| 8 |
#define NPL_OFFSET(T, m) ((size_t)(&((T*)NULL)->m)) |
| 9 |
|
| 10 |
// キャストマクロを作るために内部的に使用するマクロ |
| 11 |
#define _NPL_CAST(ct, x, t) \ |
| 12 |
((ct*)_npl_cast( \ |
| 13 |
(void*)x, t, \ |
| 14 |
__FILE__, __func__, __LINE__)) |
| 15 |
|
| 16 |
#define NPL_HEAD(x) ((npl_head_t*)x) |
| 17 |
|
| 18 |
// 型情報付き構造体型キャストマクロ |
| 19 |
#define NPL_STRUCT(x) _NPL_CAST(npl_struct_t, x, npl_struct_type) |
| 20 |
#define NPL_ARGS(x) _NPL_CAST(npl_args_t, x, npl_args_type) |
| 21 |
#define NPL_STATE_EVENT(x) \ |
| 22 |
_NPL_CAST(npl_state_event_t, x, npl_state_event_type) |
| 23 |
#define NPL_CMD_EVENT(x) _NPL_CAST(npl_cmd_event_t, x, npl_cmd_event_type) |
| 24 |
|
| 25 |
// インターフェイス型キャストマクロ |
| 26 |
#define NPL_IFACE(x) _NPL_CAST(npl_iface_t, x, npl_iface_type) |
| 27 |
|
| 28 |
// uniface型キャストマクロ |
| 29 |
#define NPL_UNIFACE(x) _NPL_CAST(npl_uniface_t, x, npl_uniface_type) |
| 30 |
#define NPL_STREAM(x) _NPL_CAST(npl_stream_t, x, npl_stream_type) |
| 31 |
#define NPL_IPTR(x) _NPL_CAST(npl_iptr_t, x, npl_iptr_type) |
| 32 |
#define NPL_ISTATE(x) _NPL_CAST(npl_istate_t, x, npl_istate_type) |
| 33 |
|
| 34 |
// オブジェクト型キャストマクロ |
| 35 |
#define NPL_OBJECT(x) _NPL_CAST(npl_object_t, x, npl_object_type) |
| 36 |
#define NPL_TYPE(x) _NPL_CAST(npl_type_t, x, npl_type_type) |
| 37 |
#define NPL_CHUNK(x) _NPL_CAST(npl_chunk_t, x, npl_chunk_type) |
| 38 |
#define NPL_DEF(x) _NPL_CAST(npl_def_t, x, npl_def_type) |
| 39 |
#define NPL_VALUE(x) _NPL_CAST(npl_value_t, x, npl_value_type) |
| 40 |
#define NPL_STR(x) _NPL_CAST(npl_str_t, x, npl_str_type) |
| 41 |
#define NPL_MBSTR(x) _NPL_CAST(npl_mbstr_t, x, npl_mbstr_type) |
| 42 |
#define NPL_VAR(x) _NPL_CAST(npl_var_t, x, npl_var_type) |
| 43 |
#define NPL_PTR(x) _NPL_CAST(npl_ptr_t, x, npl_ptr_type) |
| 44 |
#define NPL_TUPLE(x) _NPL_CAST(npl_tuple_t, x, npl_tuple_type) |
| 45 |
#define NPL_BUFFER(x) _NPL_CAST(npl_buffer_t, x, npl_buffer_type) |
| 46 |
#define NPL_LIST(x) _NPL_CAST(npl_list_t, x, npl_list_type) |
| 47 |
#define NPL_DICT(x) _NPL_CAST(npl_dict_t, x, npl_dict_type) |
| 48 |
#define NPL_FUNC(x) _NPL_CAST(npl_func_t, x, npl_func_type) |
| 49 |
#define NPL_LISTENER(x) _NPL_CAST(npl_listener_t, x, npl_listener_type) |
| 50 |
#define NPL_VSTACK(x) _NPL_CAST(npl_vstack_t, x, npl_vstack_type) |
| 51 |
#define NPL_STATE(x) _NPL_CAST(npl_state_t, x, npl_state_type) |
| 52 |
#define NPL_FILE(x) _NPL_CAST(npl_file_t, x, npl_file_type) |
| 53 |
#define NPL_CMD(x) _NPL_CAST(npl_cmd_t, x, npl_cmd_type) |
| 54 |
|
| 55 |
// 基本データ型 |
| 56 |
typedef signed char npl_s8_t; |
| 57 |
typedef signed short npl_s16_t; |
| 58 |
typedef signed long npl_s32_t; |
| 59 |
typedef signed long long npl_s64_t; |
| 60 |
typedef unsigned char npl_u8_t; |
| 61 |
typedef unsigned short npl_u16_t; |
| 62 |
typedef unsigned long npl_u32_t; |
| 63 |
typedef unsigned long long npl_u64_t; |
| 64 |
typedef void* npl_addr_t; |
| 65 |
typedef double npl_float_t; |
| 66 |
|
| 67 |
// 構造体、列挙型 |
| 68 |
typedef enum npl_bool_t npl_bool_t; |
| 69 |
typedef unsigned char npl_byte_t; |
| 70 |
typedef union npl_reg_t npl_reg_t; |
| 71 |
typedef enum npl_token_type_t npl_token_type_t; |
| 72 |
typedef struct npl_vfunc_t npl_vfunc_t; |
| 73 |
typedef struct npl_head_t npl_head_t; |
| 74 |
typedef struct npl_member_t npl_member_t; |
| 75 |
typedef enum npl_class_type_t npl_class_type_t; |
| 76 |
typedef unsigned long npl_type_flag_t; |
| 77 |
typedef enum npl_state_event_type_t npl_state_event_type_t; |
| 78 |
typedef enum npl_cmd_event_type_t npl_cmd_event_type_t; |
| 79 |
typedef struct npl_uniface_list_t npl_uniface_list_t; |
| 80 |
typedef unsigned long npl_var_flag_t; |
| 81 |
typedef struct npl_token_t npl_token_t; |
| 82 |
typedef enum npl_func_type_t npl_func_type_t; |
| 83 |
typedef struct npl_command_list_t npl_command_list_t; |
| 84 |
|
| 85 |
// 組込み型構造体 |
| 86 |
typedef struct npl_mod_t npl_mod_t; |
| 87 |
typedef struct npl_type_t npl_type_t; |
| 88 |
typedef struct npl_val_t npl_val_t; |
| 89 |
typedef struct npl_buf_t npl_buf_t; |
| 90 |
typedef struct npl_cbuf_t npl_cbuf_t; |
| 91 |
typedef struct npl_sbuf_t npl_sbuf_t; |
| 92 |
typedef struct npl_stack_t npl_stack_t; |
| 93 |
typedef struct npl_vmi_t npl_vmi_t; |
| 94 |
typedef struct npl_vm_t npl_vm_t; |
| 95 |
typedef struct npl_vt_t npl_vt_t; |
| 96 |
typedef struct npl_source_t npl_source_t; |
| 97 |
typedef struct npl_cmdi_t npl_cmdi_t; |
| 98 |
|
| 99 |
// 型情報付き構造体 |
| 100 |
typedef struct npl_struct_t npl_struct_t; |
| 101 |
typedef struct npl_args_t npl_args_t; |
| 102 |
typedef struct npl_state_event_t npl_state_event_t; |
| 103 |
typedef struct npl_cmd_event_t npl_cmd_event_t; |
| 104 |
|
| 105 |
// インターフェイス |
| 106 |
typedef struct npl_iface_t npl_iface_t; |
| 107 |
|
| 108 |
// unifaces |
| 109 |
typedef struct npl_uniface_t npl_uniface_t; |
| 110 |
typedef struct npl_stream_t npl_stream_t; |
| 111 |
typedef struct npl_iptr_t npl_iptr_t; |
| 112 |
typedef struct npl_istate_t npl_istate_t; |
| 113 |
|
| 114 |
// オブジェクト型 |
| 115 |
typedef struct npl_object_t npl_object_t; |
| 116 |
typedef struct npl_chunk_t npl_chunk_t; |
| 117 |
typedef struct npl_def_t npl_def_t; |
| 118 |
typedef struct npl_value_t npl_value_t; |
| 119 |
typedef struct npl_str_t npl_str_t; |
| 120 |
typedef struct npl_mbstr_t npl_mbstr_t; |
| 121 |
typedef struct npl_var_t npl_var_t; |
| 122 |
typedef struct npl_ptr_t npl_ptr_t; |
| 123 |
typedef struct npl_tuple_t npl_tuple_t; |
| 124 |
typedef struct npl_buffer_t npl_buffer_t; |
| 125 |
typedef struct npl_list_t npl_list_t; |
| 126 |
typedef struct npl_dict_t npl_dict_t; |
| 127 |
typedef struct npl_func_t npl_func_t; |
| 128 |
typedef struct npl_listener_t npl_listener_t; |
| 129 |
typedef struct npl_vstack_t npl_vstack_t; |
| 130 |
typedef struct npl_state_t npl_state_t; |
| 131 |
typedef struct npl_file_t npl_file_t; |
| 132 |
typedef struct npl_cmd_t npl_cmd_t; |
| 133 |
|
| 134 |
// C関数型 |
| 135 |
typedef void (*npl_listener_func_t)( |
| 136 |
npl_object_t *object, |
| 137 |
npl_object_t *sender, |
| 138 |
npl_args_t *args); |
| 139 |
typedef int (*npl_cmd_func_t)(npl_cmd_t *cmd, size_t argc, wchar_t *argv[]); |
| 140 |
|
| 141 |
|
| 142 |
// グローバルな関数 |
| 143 |
int npl_init(void); |
| 144 |
int npl_final(void); |
| 145 |
char* npl_convert_to_mbs(const wchar_t *s); |
| 146 |
wchar_t* npl_convert_to_wcs(const char *s); |
| 147 |
int npl_add(size_t a, size_t b, size_t *r); |
| 148 |
int npl_sub(size_t a, size_t b, size_t *r); |
| 149 |
int npl_mul(size_t a, size_t b, size_t *r); |
| 150 |
|
| 151 |
void* _npl_cast( |
| 152 |
void *p, |
| 153 |
npl_type_t *type, |
| 154 |
const char *file_name, |
| 155 |
const char *func_name, |
| 156 |
unsigned int line_no); |
| 157 |
|
| 158 |
// NPLライブラリ・モジュール |
| 159 |
extern npl_mod_t _npl_module; |
| 160 |
|
| 161 |
extern npl_mod_t *npl_module; |
| 162 |
|
| 163 |
// 基本値の型情報 |
| 164 |
extern npl_type_t _npl_unset_type; |
| 165 |
extern npl_type_t _npl_bool_type; |
| 166 |
extern npl_type_t _npl_byte_type; |
| 167 |
extern npl_type_t _npl_size_type; |
| 168 |
extern npl_type_t _npl_int_type; |
| 169 |
extern npl_type_t _npl_uint_type; |
| 170 |
extern npl_type_t _npl_long_type; |
| 171 |
extern npl_type_t _npl_ulong_type; |
| 172 |
extern npl_type_t _npl_float_type; |
| 173 |
extern npl_type_t _npl_wchar_type; |
| 174 |
extern npl_type_t _npl_mbchar_type; |
| 175 |
extern npl_type_t _npl_ws_type; |
| 176 |
extern npl_type_t _npl_mbs_type; |
| 177 |
extern npl_type_t _npl_type_type; |
| 178 |
|
| 179 |
extern npl_type_t *npl_unset_type; |
| 180 |
extern npl_type_t *npl_bool_type; |
| 181 |
extern npl_type_t *npl_byte_type; |
| 182 |
extern npl_type_t *npl_size_type; |
| 183 |
extern npl_type_t *npl_int_type; |
| 184 |
extern npl_type_t *npl_uint_type; |
| 185 |
extern npl_type_t *npl_long_type; |
| 186 |
extern npl_type_t *npl_ulong_type; |
| 187 |
extern npl_type_t *npl_float_type; |
| 188 |
extern npl_type_t *npl_wchar_type; |
| 189 |
extern npl_type_t *npl_mbchar_type; |
| 190 |
extern npl_type_t *npl_ws_type; |
| 191 |
extern npl_type_t *npl_mbs_type; |
| 192 |
extern npl_type_t *npl_type_type; |
| 193 |
|
| 194 |
// 構造体の型情報 |
| 195 |
extern npl_type_t _npl_struct_type; |
| 196 |
extern npl_type_t _npl_args_type; |
| 197 |
extern npl_type_t _npl_state_event_type; |
| 198 |
extern npl_type_t _npl_cmd_event_type; |
| 199 |
|
| 200 |
extern npl_type_t *npl_struct_type; |
| 201 |
extern npl_type_t *npl_args_type; |
| 202 |
extern npl_type_t *npl_state_event_type; |
| 203 |
extern npl_type_t *npl_cmd_event_type; |
| 204 |
|
| 205 |
// インターフェースの型情報 |
| 206 |
extern npl_type_t _npl_iface_type; |
| 207 |
|
| 208 |
extern npl_type_t *npl_iface_type; |
| 209 |
|
| 210 |
// uniface型情報 |
| 211 |
extern npl_type_t _npl_uniface_type; |
| 212 |
extern npl_type_t _npl_stream_type; |
| 213 |
extern npl_type_t _npl_iptr_type; |
| 214 |
extern npl_type_t _npl_istate_type; |
| 215 |
|
| 216 |
extern npl_type_t *npl_uniface_type; |
| 217 |
extern npl_type_t *npl_stream_type; |
| 218 |
extern npl_type_t *npl_iptr_type; |
| 219 |
extern npl_type_t *npl_istate_type; |
| 220 |
|
| 221 |
// オブジェクトの型情報 |
| 222 |
extern npl_type_t _npl_object_type; |
| 223 |
extern npl_type_t _npl_chunk_type; |
| 224 |
extern npl_type_t _npl_def_type; |
| 225 |
extern npl_type_t _npl_value_type; |
| 226 |
extern npl_type_t _npl_str_type; |
| 227 |
extern npl_type_t _npl_mbstr_type; |
| 228 |
extern npl_type_t _npl_var_type; |
| 229 |
extern npl_type_t _npl_ptr_type; |
| 230 |
extern npl_type_t _npl_tuple_type; |
| 231 |
extern npl_type_t _npl_buffer_type; |
| 232 |
extern npl_type_t _npl_list_type; |
| 233 |
extern npl_type_t _npl_dict_type; |
| 234 |
extern npl_type_t _npl_func_type; |
| 235 |
extern npl_type_t _npl_listener_type; |
| 236 |
extern npl_type_t _npl_vstack_type; |
| 237 |
extern npl_type_t _npl_state_type; |
| 238 |
extern npl_type_t _npl_file_type; |
| 239 |
extern npl_type_t _npl_cmd_type; |
| 240 |
|
| 241 |
extern npl_type_t *npl_object_type; |
| 242 |
extern npl_type_t *npl_chunk_type; |
| 243 |
extern npl_type_t *npl_def_type; |
| 244 |
extern npl_type_t *npl_value_type; |
| 245 |
extern npl_type_t *npl_str_type; |
| 246 |
extern npl_type_t *npl_mbstr_type; |
| 247 |
extern npl_type_t *npl_var_type; |
| 248 |
extern npl_type_t *npl_ptr_type; |
| 249 |
extern npl_type_t *npl_tuple_type; |
| 250 |
extern npl_type_t *npl_buffer_type; |
| 251 |
extern npl_type_t *npl_list_type; |
| 252 |
extern npl_type_t *npl_dict_type; |
| 253 |
extern npl_type_t *npl_func_type; |
| 254 |
extern npl_type_t *npl_listener_type; |
| 255 |
extern npl_type_t *npl_vstack_type; |
| 256 |
extern npl_type_t *npl_state_type; |
| 257 |
extern npl_type_t *npl_file_type; |
| 258 |
extern npl_type_t *npl_cmd_type; |
| 259 |
|
| 260 |
// bool |
| 261 |
enum npl_bool_t { |
| 262 |
NPL_FALSE = 0, |
| 263 |
NPL_TRUE, |
| 264 |
}; |
| 265 |
|
| 266 |
// reg (register) |
| 267 |
union npl_reg_t { |
| 268 |
npl_s8_t s8; |
| 269 |
npl_s16_t s16; |
| 270 |
npl_s32_t s32; |
| 271 |
npl_s64_t s64; |
| 272 |
npl_u8_t u8; |
| 273 |
npl_u16_t u16; |
| 274 |
npl_u32_t u32; |
| 275 |
npl_u64_t u64; |
| 276 |
npl_addr_t addr; |
| 277 |
npl_float_t f; |
| 278 |
}; |
| 279 |
|
| 280 |
// token |
| 281 |
// 汎用的な予め定義されるトークン。 |
| 282 |
enum npl_token_type_t { |
| 283 |
NPL_TT_NULL = 0, |
| 284 |
|
| 285 |
NPL_TT_ID, |
| 286 |
NPL_TT_NUMBER, |
| 287 |
NPL_TT_CHARACTER, |
| 288 |
NPL_TT_STRING, |
| 289 |
NPL_TT_KEYWORD, |
| 290 |
|
| 291 |
NPL_TT_PLUS, // + |
| 292 |
NPL_TT_MINUS, // - |
| 293 |
NPL_TT_MUL, // * |
| 294 |
NPL_TT_DIV, // / |
| 295 |
NPL_TT_MOD, // % |
| 296 |
NPL_TT_HAT, // ^ |
| 297 |
NPL_TT_TILDE, // ~ |
| 298 |
|
| 299 |
NPL_TT_QUESTION, // ? |
| 300 |
NPL_TT_QUESTION2, // ?? |
| 301 |
NPL_TT_EXCLAMATION, // ! |
| 302 |
NPL_TT_EXCLAMATION2, // !! |
| 303 |
NPL_TT_SHARP, // # |
| 304 |
NPL_TT_SHARP2, // ## |
| 305 |
NPL_TT_DOLLAR, // $ |
| 306 |
NPL_TT_DOLLAR2, // $$ |
| 307 |
NPL_TT_AT, // @ |
| 308 |
NPL_TT_AT2, // @@ |
| 309 |
NPL_TT_AMP, // & |
| 310 |
NPL_TT_AMP2, // && |
| 311 |
NPL_TT_BAR, // | |
| 312 |
NPL_TT_BAR2, // || |
| 313 |
NPL_TT_DOT, // . |
| 314 |
NPL_TT_DOT2, // .. |
| 315 |
NPL_TT_COLON, // : |
| 316 |
NPL_TT_COLON2, // :: |
| 317 |
NPL_TT_COMMA, // , |
| 318 |
NPL_TT_SEMICOLON, // ; |
| 319 |
NPL_TT_UNDARBAR, // _ |
| 320 |
|
| 321 |
NPL_TT_PLUS_PLUS, // ++ |
| 322 |
NPL_TT_MINUS_MINUS, // -- |
| 323 |
NPL_TT_MUL_MUL, // ** |
| 324 |
NPL_TT_MOD_MOD, // %% |
| 325 |
NPL_TT_LSHIFT, // << |
| 326 |
NPL_TT_RSHIFT, // >> |
| 327 |
NPL_TT_ARROW, // -> |
| 328 |
|
| 329 |
NPL_TT_EQ, // = |
| 330 |
NPL_TT_EQEQ, // == |
| 331 |
NPL_TT_NEQ, // != |
| 332 |
NPL_TT_EQEQEQ, // === |
| 333 |
NPL_TT_NEQEQ, // !== |
| 334 |
NPL_TT_LT, // < |
| 335 |
NPL_TT_GT, // > |
| 336 |
NPL_TT_LE, // <= |
| 337 |
NPL_TT_GE, // >= |
| 338 |
NPL_TT_PLUS_EQ, // += |
| 339 |
NPL_TT_MINUS_EQ, // -= |
| 340 |
NPL_TT_MUL_EQ, // *= |
| 341 |
NPL_TT_DIV_EQ, // /= |
| 342 |
NPL_TT_MOD_EQ, // %= |
| 343 |
NPL_TT_COLON_EQ, // := |
| 344 |
NPL_TT_COLON_COLON_EQ, // ::= |
| 345 |
NPL_TT_AMP_EQ, // &= |
| 346 |
NPL_TT_BAR_EQ, // |= |
| 347 |
NPL_TT_QUESTION_EQ, // ?= |
| 348 |
NPL_TT_LSHIFT_EQ, // <<= |
| 349 |
NPL_TT_RSHIFT_EQ, // >>= |
| 350 |
|
| 351 |
NPL_TT_LPAR, // ( |
| 352 |
NPL_TT_RPAR, // ) |
| 353 |
NPL_TT_LBRACE, // { |
| 354 |
NPL_TT_RBRACE, // } |
| 355 |
NPL_TT_LBRACKET, // [ |
| 356 |
NPL_TT_RBRACKET, // ] |
| 357 |
}; |
| 358 |
|
| 359 |
// vfunc (仮想関数(オーバーライド可能な関数)) |
| 360 |
struct npl_vfunc_t { |
| 361 |
void *vfn; // 仮想関数のアドレス |
| 362 |
void *fn; // 呼び出す関数のアドレス |
| 363 |
}; |
| 364 |
|
| 365 |
// mod |
| 366 |
struct npl_mod_t { |
| 367 |
npl_type_t **types; |
| 368 |
}; |
| 369 |
|
| 370 |
// member (クラスメンバ情報) |
| 371 |
struct npl_member_t { |
| 372 |
npl_type_t *type; // メンバ型、メソッドの返り値型 |
| 373 |
npl_type_t **args; // メソッドの引数型リスト |
| 374 |
wchar_t *name; |
| 375 |
size_t offset; |
| 376 |
int (*setter)(npl_head_t *head, npl_val_t *val); |
| 377 |
int (*getter)(npl_head_t *head, npl_val_t *val_r); |
| 378 |
int (*method)(npl_head_t *head, npl_vm_t *vm); |
| 379 |
}; |
| 380 |
|
| 381 |
// type |
| 382 |
enum npl_class_type_t { |
| 383 |
NPL_CT_OBJECT, |
| 384 |
NPL_CT_STRUCT, |
| 385 |
NPL_CT_IFACE, |
| 386 |
NPL_CT_UNIFACE, |
| 387 |
NPL_CT_UNSET, |
| 388 |
NPL_CT_BOOL, |
| 389 |
NPL_CT_BYTE, |
| 390 |
NPL_CT_SIZE, |
| 391 |
NPL_CT_INT, |
| 392 |
NPL_CT_UINT, |
| 393 |
NPL_CT_LONG, |
| 394 |
NPL_CT_ULONG, |
| 395 |
NPL_CT_FLOAT, |
| 396 |
NPL_CT_WCHAR, |
| 397 |
NPL_CT_MBCHAR, |
| 398 |
NPL_CT_WS, |
| 399 |
NPL_CT_MBS, |
| 400 |
NPL_CT_TYPE, |
| 401 |
}; |
| 402 |
|
| 403 |
struct npl_type_t { |
| 404 |
void (*destructor)(void *p); |
| 405 |
npl_class_type_t ctype; |
| 406 |
wchar_t *name; |
| 407 |
npl_type_t *parent; |
| 408 |
size_t size; |
| 409 |
npl_member_t *members; |
| 410 |
npl_vfunc_t *vfuncs; // 配列 |
| 411 |
npl_type_t **ifaces; |
| 412 |
npl_uniface_list_t *unifaces; // 配列 |
| 413 |
}; |
| 414 |
|
| 415 |
int npl_type_check(npl_type_t *type, npl_type_t *base); |
| 416 |
wchar_t* npl_type_name(npl_type_t *type); |
| 417 |
void* npl_type_vfn(npl_type_t *type, void *vfn); |
| 418 |
size_t npl_type_uniface_list_size(npl_type_t *type); |
| 419 |
npl_uniface_list_t* npl_type_uniface_list(npl_type_t *type, size_t i); |
| 420 |
|
| 421 |
// val |
| 422 |
struct npl_val_t { |
| 423 |
npl_type_t *type; |
| 424 |
union { |
| 425 |
npl_object_t *object; |
| 426 |
npl_iface_t *iface; |
| 427 |
npl_uniface_t *uniface; |
| 428 |
npl_bool_t b; |
| 429 |
npl_byte_t byte; |
| 430 |
size_t size; |
| 431 |
int i; |
| 432 |
unsigned int u; |
| 433 |
long long l; |
| 434 |
unsigned long long ul; |
| 435 |
double f; |
| 436 |
wchar_t wc; |
| 437 |
char mbc; |
| 438 |
wchar_t *ws; |
| 439 |
char *mbs; |
| 440 |
npl_type_t *t; |
| 441 |
}; |
| 442 |
}; |
| 443 |
|
| 444 |
void npl_val_unset(npl_val_t *val); |
| 445 |
void npl_val_init(npl_val_t *val); |
| 446 |
void npl_val_copy(npl_val_t *dest, npl_val_t *src); |
| 447 |
void npl_val_move(npl_val_t *dest, npl_val_t *src); |
| 448 |
int npl_val_check(npl_val_t *val, npl_type_t *base); |
| 449 |
|
| 450 |
void npl_val_set_object(npl_val_t *val, npl_object_t *object); |
| 451 |
void npl_val_set_iface(npl_val_t *val, npl_iface_t *iface); |
| 452 |
void npl_val_set_uniface(npl_val_t *val, npl_uniface_t *uniface); |
| 453 |
void npl_val_set_null(npl_val_t *val); |
| 454 |
void npl_val_set_bool(npl_val_t *val, npl_bool_t b); |
| 455 |
void npl_val_set_byte(npl_val_t *val, npl_byte_t byte); |
| 456 |
void npl_val_set_size(npl_val_t *val, size_t size); |
| 457 |
void npl_val_set_int(npl_val_t *val, int i); |
| 458 |
void npl_val_set_uint(npl_val_t *val, unsigned int u); |
| 459 |
void npl_val_set_long(npl_val_t *val, long long l); |
| 460 |
void npl_val_set_ulong(npl_val_t *val, unsigned long long ul); |
| 461 |
void npl_val_set_float(npl_val_t *val, double f); |
| 462 |
void npl_val_set_wchar(npl_val_t *val, wchar_t wc); |
| 463 |
void npl_val_set_mbchar(npl_val_t *val, char mbc); |
| 464 |
void npl_val_set_ws(npl_val_t *val, wchar_t *ws); |
| 465 |
void npl_val_set_mbs(npl_val_t *val, char *mbs); |
| 466 |
void npl_val_set_type(npl_val_t *val, npl_type_t *t); |
| 467 |
|
| 468 |
// head |
| 469 |
struct npl_head_t { |
| 470 |
npl_type_t *type; |
| 471 |
}; |
| 472 |
|
| 473 |
npl_member_t* npl_member(npl_head_t *head, const wchar_t *name); |
| 474 |
void* npl_member_addr(npl_head_t *head, npl_member_t *m); |
| 475 |
int npl_set(npl_head_t *head, npl_member_t *m, npl_val_t *val); |
| 476 |
int npl_get(npl_head_t *head, npl_member_t *m, npl_val_t *val_r); |
| 477 |
int npl_call(npl_head_t *head, npl_member_t *m, npl_vm_t *vm); |
| 478 |
|
| 479 |
// struct |
| 480 |
struct npl_struct_t { |
| 481 |
npl_type_t *type; |
| 482 |
}; |
| 483 |
|
| 484 |
void npl_struct_init(void *ptr, npl_type_t *type); |
| 485 |
void npl_struct_final(npl_struct_t *s); |
| 486 |
int npl_struct_check(npl_struct_t *s, npl_type_t *base); |
| 487 |
|
| 488 |
// args |
| 489 |
struct npl_args_t { |
| 490 |
npl_struct_t s; |
| 491 |
}; |
| 492 |
|
| 493 |
int npl_args_init(npl_args_t *args); |
| 494 |
int npl_args_check(npl_args_t *args, npl_type_t *base); |
| 495 |
|
| 496 |
// state_event |
| 497 |
enum npl_state_event_type_t { |
| 498 |
NPL_SE_DEBUG, |
| 499 |
NPL_SE_WARNING, |
| 500 |
NPL_SE_ERROR, |
| 501 |
}; |
| 502 |
|
| 503 |
struct npl_state_event_t { |
| 504 |
npl_args_t args; |
| 505 |
npl_state_event_type_t type; |
| 506 |
const wchar_t *message; |
| 507 |
}; |
| 508 |
|
| 509 |
int npl_state_event_init(npl_state_event_t *args); |
| 510 |
|
| 511 |
// cmd_event |
| 512 |
enum npl_cmd_event_type_t { |
| 513 |
NPL_CE_DUMP_ARGV, |
| 514 |
NPL_CE_UNKNOWN_COMMAND, |
| 515 |
NPL_CE_FAILED, |
| 516 |
}; |
| 517 |
|
| 518 |
struct npl_cmd_event_t { |
| 519 |
npl_args_t args; |
| 520 |
npl_cmd_event_type_t type; |
| 521 |
npl_cmd_t *cmd; |
| 522 |
}; |
| 523 |
|
| 524 |
int npl_cmd_event_init(npl_cmd_event_t *args); |
| 525 |
|
| 526 |
// uniface_list |
| 527 |
struct npl_uniface_list_t { |
| 528 |
npl_type_t *type; |
| 529 |
size_t offset; |
| 530 |
}; |
| 531 |
|
| 532 |
// uniface |
| 533 |
struct npl_uniface_t { |
| 534 |
npl_type_t *type; |
| 535 |
npl_object_t *object; |
| 536 |
}; |
| 537 |
|
| 538 |
void npl_uniface_init( |
| 539 |
void *u, |
| 540 |
npl_type_t *type, |
| 541 |
npl_object_t *object); |
| 542 |
void npl_uniface_final(npl_uniface_t *u); |
| 543 |
void npl_uniface_ref(npl_uniface_t *u); |
| 544 |
void npl_uniface_unref(npl_uniface_t *u); |
| 545 |
void npl_uniface_destroy(npl_uniface_t *u); |
| 546 |
int npl_uniface_check(npl_uniface_t *u, npl_type_t *base); |
| 547 |
|
| 548 |
// stream |
| 549 |
struct npl_stream_t { |
| 550 |
npl_uniface_t uniface; |
| 551 |
void (*stream_print)(npl_stream_t *stream, wchar_t *str); |
| 552 |
void (*stream_read)(npl_stream_t *stream, wchar_t *buf, int n); |
| 553 |
void (*stream_readline)(npl_stream_t *stream, npl_sbuf_t *sbuf); |
| 554 |
int (*stream_error)(npl_stream_t *stream); |
| 555 |
int (*stream_eof)(npl_stream_t *stream); |
| 556 |
}; |
| 557 |
|
| 558 |
int npl_stream_init(npl_stream_t *stream); |
| 559 |
void npl_stream_print(npl_stream_t *stream, wchar_t *str); |
| 560 |
void npl_stream_read(npl_stream_t *stream, wchar_t *buf, int n); |
| 561 |
void npl_stream_readline(npl_stream_t *stream, npl_sbuf_t *sbuf); |
| 562 |
int npl_stream_error(npl_stream_t *stream); |
| 563 |
int npl_stream_eof(npl_stream_t *stream); |
| 564 |
|
| 565 |
// iptr |
| 566 |
struct npl_iptr_t { |
| 567 |
npl_uniface_t uniface; |
| 568 |
npl_buf_t *ptr_table; |
| 569 |
size_t size; |
| 570 |
size_t len; |
| 571 |
}; |
| 572 |
|
| 573 |
int npl_iptr_init(npl_iptr_t *iptr, size_t size, size_t len); |
| 574 |
|
| 575 |
void* npl_iptr_get(npl_iptr_t *iptr, size_t index); |
| 576 |
int npl_iptr_is_enable(npl_iptr_t *iptr, size_t index); |
| 577 |
|
| 578 |
// object class |
| 579 |
struct npl_object_t { |
| 580 |
npl_type_t *type; |
| 581 |
size_t ref_count; |
| 582 |
}; |
| 583 |
|
| 584 |
void npl_object_init(void *object, npl_type_t *type); |
| 585 |
npl_object_t* npl_object_alloc(npl_type_t *type); |
| 586 |
npl_object_t* npl_object_new(void); |
| 587 |
void npl_object_ref(npl_object_t *object); |
| 588 |
void npl_object_unref(npl_object_t *object); |
| 589 |
int npl_object_check(npl_object_t *object, npl_type_t *base); |
| 590 |
void* npl_object_vfn(npl_object_t *object, void *vfn); |
| 591 |
void npl_object_destroy(npl_object_t *object); |
| 592 |
|
| 593 |
npl_str_t* npl_object_to_str(npl_object_t *object); |
| 594 |
wchar_t* npl_object_name(npl_object_t *object); |
| 595 |
npl_uniface_t* npl_object_get_uniface( |
| 596 |
npl_object_t *object, |
| 597 |
npl_type_t *utype); |
| 598 |
|
| 599 |
// iface interface |
| 600 |
struct npl_iface_t { |
| 601 |
npl_object_t object; |
| 602 |
}; |
| 603 |
|
| 604 |
void npl_iface_ref(npl_iface_t *iface); |
| 605 |
void npl_iface_unref(npl_iface_t *iface); |
| 606 |
void npl_iface_destroy(npl_iface_t *iface); |
| 607 |
void* npl_iface_vfn(npl_iface_t *iface, void *vfn); |
| 608 |
|
| 609 |
// buf |
| 610 |
struct npl_buf_t { |
| 611 |
void *buf; |
| 612 |
size_t bytes; |
| 613 |
}; |
| 614 |
|
| 615 |
int npl_buf_init(npl_buf_t *buf, size_t bytes); |
| 616 |
void npl_buf_final(npl_buf_t *buf); |
| 617 |
size_t npl_buf_size(npl_buf_t *buf); |
| 618 |
void* npl_buf_get_buffer(npl_buf_t *buf, size_t offset); |
| 619 |
void npl_buf_clear(npl_buf_t *buf); |
| 620 |
int npl_buf_expand(npl_buf_t *buf, size_t bytes); |
| 621 |
int npl_buf_reduce(npl_buf_t *buf, size_t bytes); |
| 622 |
|
| 623 |
// cbuf |
| 624 |
struct npl_cbuf_t { |
| 625 |
void *cbuf; |
| 626 |
size_t size; |
| 627 |
size_t len; |
| 628 |
}; |
| 629 |
|
| 630 |
int npl_cbuf_init(npl_cbuf_t *cbuf, size_t size, size_t len); |
| 631 |
void npl_cbuf_final(npl_cbuf_t *cbuf); |
| 632 |
size_t npl_cbuf_size(npl_cbuf_t *cbuf); |
| 633 |
size_t npl_cbuf_len(npl_cbuf_t *cbuf); |
| 634 |
void* npl_cbuf_get_buffer(npl_cbuf_t *cbuf); |
| 635 |
void* npl_cbuf_get(npl_cbuf_t *cbuf, size_t i); |
| 636 |
void npl_cbuf_clear(npl_cbuf_t *cbuf); |
| 637 |
int npl_cbuf_expand(npl_cbuf_t *cbuf, size_t n); |
| 638 |
int npl_cbuf_reduce(npl_cbuf_t *cbuf, size_t len); |
| 639 |
|
| 640 |
// sbuf |
| 641 |
struct npl_sbuf_t { |
| 642 |
npl_cbuf_t cbuf; |
| 643 |
size_t pos; |
| 644 |
}; |
| 645 |
|
| 646 |
int npl_sbuf_init(npl_sbuf_t *sb); |
| 647 |
void npl_sbuf_final(npl_sbuf_t *sb); |
| 648 |
void npl_sbuf_rewind(npl_sbuf_t *sb); |
| 649 |
int npl_sbuf_add(npl_sbuf_t *sb, const wchar_t *s); |
| 650 |
int npl_sbuf_put(npl_sbuf_t *sb, wchar_t ch); |
| 651 |
size_t npl_sbuf_size(npl_sbuf_t *sb); |
| 652 |
wchar_t* npl_sbuf_get_buffer(npl_sbuf_t *sb); |
| 653 |
size_t npl_sbuf_len(npl_sbuf_t *sb); |
| 654 |
void npl_sbuf_clear(npl_sbuf_t *sb); |
| 655 |
int npl_sbuf_expand(npl_sbuf_t *sb, size_t n); |
| 656 |
int npl_sbuf_reduce(npl_sbuf_t *sb, size_t len); |
| 657 |
int npl_sbuf_copy(npl_sbuf_t *dest, npl_sbuf_t *src); |
| 658 |
|
| 659 |
// buffer class |
| 660 |
// (バイト列データ) |
| 661 |
struct npl_buffer_t { |
| 662 |
npl_object_t object; |
| 663 |
npl_buf_t buf; |
| 664 |
size_t bytes; |
| 665 |
}; |
| 666 |
|
| 667 |
int npl_buffer_init(npl_buffer_t *buffer); |
| 668 |
npl_buffer_t* npl_buffer_new(void); |
| 669 |
void npl_buffer_clear(npl_buffer_t *buffer); |
| 670 |
int npl_buffer_add(npl_buffer_t *buffer, size_t n, void *p); |
| 671 |
void* npl_buffer_get(npl_buffer_t *buffer, size_t offset); |
| 672 |
size_t npl_buffer_size(npl_buffer_t *buffer); |
| 673 |
|
| 674 |
// list class |
| 675 |
npl_list_t* npl_list_new(void); |
| 676 |
void npl_list_clear(npl_list_t *list); |
| 677 |
int npl_list_prepend(npl_list_t *list, npl_object_t *object); |
| 678 |
int npl_list_append(npl_list_t *list, npl_object_t *object); |
| 679 |
int npl_list_insert(npl_list_t *list, size_t i, npl_object_t *object); |
| 680 |
size_t npl_list_len(npl_list_t *list); |
| 681 |
npl_object_t* npl_list_get(npl_list_t *list, size_t i); |
| 682 |
void npl_list_delete(npl_list_t *list, size_t i); |
| 683 |
|
| 684 |
// dict class |
| 685 |
struct npl_dict_t { |
| 686 |
npl_object_t object; |
| 687 |
npl_cbuf_t dict; |
| 688 |
size_t pos; |
| 689 |
}; |
| 690 |
|
| 691 |
int npl_dict_init(npl_dict_t *d); |
| 692 |
npl_dict_t* npl_dict_new(void); |
| 693 |
int npl_dict_set(npl_dict_t *d, wchar_t *name, npl_object_t *object); |
| 694 |
npl_object_t* npl_dict_get(npl_dict_t *d, wchar_t *name); |
| 695 |
|
| 696 |
// chunk class |
| 697 |
struct npl_chunk_t { |
| 698 |
npl_object_t object; |
| 699 |
size_t bytes; |
| 700 |
void *chunk; |
| 701 |
}; |
| 702 |
|
| 703 |
npl_chunk_t* npl_chunk_alloc(npl_type_t *type, size_t bytes); |
| 704 |
|
| 705 |
// def class |
| 706 |
struct npl_def_t { |
| 707 |
npl_chunk_t chunk; |
| 708 |
npl_object_t *p; |
| 709 |
}; |
| 710 |
|
| 711 |
npl_def_t* npl_def_new(wchar_t *name); |
| 712 |
wchar_t* npl_def_name(npl_def_t *def); |
| 713 |
void npl_def_set(npl_def_t *def, npl_object_t *object); |
| 714 |
npl_object_t* npl_def_get(npl_def_t *def); |
| 715 |
|
| 716 |
// value class |
| 717 |
struct npl_value_t { |
| 718 |
npl_object_t object; |
| 719 |
npl_val_t val; |
| 720 |
}; |
| 721 |
|
| 722 |
int npl_value_init(npl_value_t *value); |
| 723 |
npl_value_t* npl_value_new(void); |
| 724 |
npl_val_t* npl_value_get(npl_value_t *value); |
| 725 |
|
| 726 |
// str class |
| 727 |
// str はワイド文字の文字列。 |
| 728 |
struct npl_str_t { |
| 729 |
npl_chunk_t chunk; |
| 730 |
}; |
| 731 |
|
| 732 |
npl_str_t* npl_str_new(const wchar_t *s); |
| 733 |
npl_str_t* npl_str_new_from_mbs(const char *s); |
| 734 |
wchar_t* npl_str_get(npl_str_t *s); |
| 735 |
|
| 736 |
// mbstr class |
| 737 |
// mbstr はマルチバイト文字の文字列。 |
| 738 |
struct npl_mbstr_t { |
| 739 |
npl_chunk_t chunk; |
| 740 |
}; |
| 741 |
|
| 742 |
npl_mbstr_t* npl_mbstr_new(const char *s); |
| 743 |
npl_mbstr_t* npl_mbstr_new_from_wcs(const wchar_t *s); |
| 744 |
char* npl_mbstr_get(npl_mbstr_t *str); |
| 745 |
|
| 746 |
// var class |
| 747 |
|
| 748 |
#define NPL_VF_IMMUTABLE (1<<0) |
| 749 |
// 値変更不可 |
| 750 |
|
| 751 |
struct npl_var_t { |
| 752 |
npl_chunk_t chunk; // チャンクを名前に充てる |
| 753 |
npl_type_t *type; |
| 754 |
npl_var_flag_t flag; |
| 755 |
npl_val_t val; // 変数の値 |
| 756 |
}; |
| 757 |
|
| 758 |
npl_var_t* npl_var_new(const wchar_t *name); |
| 759 |
wchar_t* npl_var_name(npl_var_t *var); |
| 760 |
int npl_var_set_type(npl_var_t *var, npl_type_t *type); |
| 761 |
void npl_var_set_immutable(npl_var_t *var); |
| 762 |
void npl_var_unset(npl_var_t *var); |
| 763 |
|
| 764 |
int npl_var_check(npl_var_t *var, npl_type_t *base); |
| 765 |
int npl_var_set_object(npl_var_t *var, npl_object_t *object); |
| 766 |
int npl_var_set_iface(npl_var_t *var, npl_iface_t *iface); |
| 767 |
int npl_var_set_uniface(npl_var_t *var, npl_uniface_t *uniface); |
| 768 |
int npl_var_set_null(npl_var_t *var); |
| 769 |
int npl_var_set_bool(npl_var_t *var, npl_bool_t b); |
| 770 |
int npl_var_set_byte(npl_var_t *var, npl_byte_t byte); |
| 771 |
int npl_var_set_size(npl_var_t *var, size_t size); |
| 772 |
int npl_var_set_int(npl_var_t *var, int i); |
| 773 |
int npl_var_set_uint(npl_var_t *var, unsigned int u); |
| 774 |
int npl_var_set_long(npl_var_t *var, long long l); |
| 775 |
int npl_var_set_ulong(npl_var_t *var, unsigned long long ul); |
| 776 |
int npl_var_set_float(npl_var_t *var, double f); |
| 777 |
int npl_var_set_wchar(npl_var_t *var, wchar_t wc); |
| 778 |
int npl_var_set_mbchar(npl_var_t *var, char mbc); |
| 779 |
|
| 780 |
// ptr class (ポインタ) |
| 781 |
struct npl_ptr_t { |
| 782 |
npl_object_t object; |
| 783 |
npl_iptr_t *iptr; |
| 784 |
size_t index; |
| 785 |
}; |
| 786 |
|
| 787 |
// tuple class |
| 788 |
struct npl_tuple_t { |
| 789 |
npl_chunk_t chunk; |
| 790 |
size_t len; |
| 791 |
npl_val_t *val; |
| 792 |
}; |
| 793 |
|
| 794 |
npl_tuple_t* npl_tuple_new(size_t len); |
| 795 |
size_t npl_tuple_len(npl_tuple_t *tuple); |
| 796 |
|
| 797 |
// vm opcode |
| 798 |
#define NPL_OP_NOP 0 |
| 799 |
#define NPL_OP_BREAK 1 |
| 800 |
#define NPL_OP_END 2 |
| 801 |
#define NPL_OP_SETP 3 |
| 802 |
#define NPL_OP_ADDP 4 |
| 803 |
#define NPL_OP_STORE 5 |
| 804 |
#define NPL_OP_LOAD 6 |
| 805 |
#define NPL_OP_SET 7 |
| 806 |
#define NPL_OP_PUSH 8 |
| 807 |
#define NPL_OP_POP 9 |
| 808 |
|
| 809 |
// vmi (virtual machine interpreter) |
| 810 |
struct npl_vmi_t { |
| 811 |
void *code; |
| 812 |
size_t pc; // program counter |
| 813 |
}; |
| 814 |
|
| 815 |
npl_u8_t npl_vmi_u8(npl_vmi_t *vmi); |
| 816 |
npl_u16_t npl_vmi_u16(npl_vmi_t *vmi); |
| 817 |
npl_u32_t npl_vmi_u32(npl_vmi_t *vmi); |
| 818 |
npl_u64_t npl_vmi_u64(npl_vmi_t *vmi); |
| 819 |
npl_s8_t npl_vmi_s8(npl_vmi_t *vmi); |
| 820 |
npl_s16_t npl_vmi_s16(npl_vmi_t *vmi); |
| 821 |
npl_s32_t npl_vmi_s32(npl_vmi_t *vmi); |
| 822 |
npl_s64_t npl_vmi_s64(npl_vmi_t *vmi); |
| 823 |
npl_addr_t npl_vmi_addr(npl_vmi_t *vmi); |
| 824 |
npl_float_t npl_vmi_float(npl_vmi_t *vmi); |
| 825 |
|
| 826 |
// vm (virtual machine) |
| 827 |
struct npl_vm_t { |
| 828 |
void *ptr[2]; |
| 829 |
void *obj; |
| 830 |
void *var; |
| 831 |
npl_buf_t stack; |
| 832 |
size_t sp; // stack pointer |
| 833 |
npl_vmi_t vmi; |
| 834 |
}; |
| 835 |
|
| 836 |
int npl_vm_init(npl_vm_t *vm); |
| 837 |
void npl_vm_final(npl_vm_t *vm); |
| 838 |
void npl_vm_clear(npl_vm_t *vm); |
| 839 |
npl_u8_t npl_vm_exec(npl_vm_t *vm); |
| 840 |
|
| 841 |
// func class |
| 842 |
enum npl_func_type_t { |
| 843 |
NPL_FNT_LISTENER, |
| 844 |
}; |
| 845 |
|
| 846 |
struct npl_func_t { |
| 847 |
npl_chunk_t chunk; |
| 848 |
npl_func_type_t type; |
| 849 |
npl_object_t *this_ptr; |
| 850 |
union { |
| 851 |
npl_listener_func_t fn_lst; |
| 852 |
}; |
| 853 |
}; |
| 854 |
|
| 855 |
npl_func_t* npl_func_new_listener( |
| 856 |
npl_object_t *this_ptr, |
| 857 |
npl_listener_func_t fn_lst); |
| 858 |
void npl_func_call_listener( |
| 859 |
npl_func_t *fn, |
| 860 |
npl_object_t *sender, |
| 861 |
npl_args_t *args); |
| 862 |
|
| 863 |
// listener class |
| 864 |
struct npl_listener_t { |
| 865 |
npl_object_t object; |
| 866 |
npl_cbuf_t _cbuf; |
| 867 |
size_t n; |
| 868 |
}; |
| 869 |
|
| 870 |
int npl_listener_init(npl_listener_t *lst); |
| 871 |
npl_listener_t* npl_listener_new(void); |
| 872 |
int npl_listener_add( |
| 873 |
npl_listener_t *lst, |
| 874 |
npl_object_t *object, |
| 875 |
npl_listener_func_t func); |
| 876 |
int npl_listener_add_func(npl_listener_t *lst, npl_func_t *fn); |
| 877 |
void npl_listener_call( |
| 878 |
npl_listener_t *lst, |
| 879 |
npl_object_t *sender, |
| 880 |
npl_args_t *args); |
| 881 |
void npl_listener_remove(npl_listener_t *lst, npl_object_t *object); |
| 882 |
void npl_listener_remove_func(npl_listener_t *lst, npl_func_t *fn); |
| 883 |
void npl_listener_clear(npl_listener_t *lst); |
| 884 |
|
| 885 |
// stack |
| 886 |
struct npl_stack_t { |
| 887 |
npl_cbuf_t stack; |
| 888 |
size_t count; |
| 889 |
}; |
| 890 |
|
| 891 |
int npl_stack_init(npl_stack_t *s); |
| 892 |
void npl_stack_final(npl_stack_t *s); |
| 893 |
int npl_stack_push(npl_stack_t *s, npl_object_t *object); |
| 894 |
npl_object_t* npl_stack_pop(npl_stack_t *s); |
| 895 |
npl_object_t* npl_stack_get(npl_stack_t *s, size_t i); |
| 896 |
void npl_stack_remove(npl_stack_t *s, size_t n); |
| 897 |
|
| 898 |
// vstack class |
| 899 |
struct npl_vstack_t { |
| 900 |
npl_object_t object; |
| 901 |
npl_stack_t stack; |
| 902 |
npl_vstack_t *prev; |
| 903 |
npl_vstack_t *parent; |
| 904 |
}; |
| 905 |
|
| 906 |
int npl_vstack_init(npl_vstack_t *vs); |
| 907 |
npl_vstack_t* npl_vstack_new(void); |
| 908 |
|
| 909 |
// vt |
| 910 |
struct npl_vt_t { |
| 911 |
npl_vstack_t *current; |
| 912 |
}; |
| 913 |
|
| 914 |
int npl_vt_init(npl_vt_t *vt); |
| 915 |
void npl_vt_final(npl_vt_t *vt); |
| 916 |
int npl_vt_enter(npl_vt_t *vt); |
| 917 |
int npl_vt_enter_func(npl_vt_t *vt, const wchar_t *name); |
| 918 |
int npl_vt_leave(npl_vt_t *vt); |
| 919 |
npl_var_t* npl_vt_add(npl_vt_t *vt, const wchar_t *name); |
| 920 |
npl_var_t* npl_vt_find(npl_vt_t *vt, const wchar_t *name); |
| 921 |
|
| 922 |
// source |
| 923 |
#define NPL_SOURCE_BUFFER_SIZE 256 |
| 924 |
|
| 925 |
struct npl_source_t { |
| 926 |
wchar_t buf1[NPL_SOURCE_BUFFER_SIZE]; |
| 927 |
wchar_t buf2[NPL_SOURCE_BUFFER_SIZE]; |
| 928 |
wchar_t *_p_read, *_p_write; |
| 929 |
wchar_t *buf; // 内容の読み出しには、こちらを使用する |
| 930 |
int done; |
| 931 |
}; |
| 932 |
|
| 933 |
int npl_source_init(npl_source_t *src); |
| 934 |
void npl_source_final(npl_source_t *src); |
| 935 |
void npl_source_get_read_buffer(npl_source_t *src, wchar_t **r); |
| 936 |
wchar_t* npl_source_get_write_buffer(npl_source_t *src); |
| 937 |
void npl_source_swap(npl_source_t *src); |
| 938 |
void npl_source_done(npl_source_t *src); |
| 939 |
int npl_source_is_buffered(npl_source_t *src); |
| 940 |
|
| 941 |
// istate |
| 942 |
struct npl_istate_t { |
| 943 |
npl_uniface_t uniface; |
| 944 |
npl_vt_t _vt; |
| 945 |
int running; |
| 946 |
int break_flag; |
| 947 |
int (*istate_do)(npl_istate_t *ist); |
| 948 |
}; |
| 949 |
|
| 950 |
int npl_istate_init(npl_istate_t *ist); |
| 951 |
int npl_istate_do(npl_istate_t *ist); |
| 952 |
void npl_istate_quit(npl_istate_t *ist); |
| 953 |
void npl_istate_break(npl_istate_t *ist); |
| 954 |
npl_var_t* npl_istate_add_var(npl_istate_t *ist, const wchar_t *name); |
| 955 |
npl_var_t* npl_istate_find_var(npl_istate_t *ist, const wchar_t *name); |
| 956 |
|
| 957 |
// state class |
| 958 |
struct npl_state_t { |
| 959 |
npl_object_t object; |
| 960 |
npl_istate_t istate; |
| 961 |
npl_listener_t *_state_event; |
| 962 |
}; |
| 963 |
|
| 964 |
int npl_state_init(npl_state_t *state); |
| 965 |
npl_state_t* npl_state_new(void); |
| 966 |
int npl_state_add_listener( |
| 967 |
npl_state_t *state, |
| 968 |
npl_object_t *object, |
| 969 |
npl_listener_func_t func); |
| 970 |
|
| 971 |
// state events |
| 972 |
void npl_state_debug(npl_state_t *state, const wchar_t *ws); |
| 973 |
void npl_state_warning(npl_state_t *state, const wchar_t *ws); |
| 974 |
void npl_state_error(npl_state_t *state, const wchar_t *ws); |
| 975 |
|
| 976 |
// file class |
| 977 |
struct npl_file_t { |
| 978 |
npl_object_t object; |
| 979 |
npl_stream_t stream; |
| 980 |
void *fp; |
| 981 |
}; |
| 982 |
|
| 983 |
int npl_file_init(npl_file_t *file, void *fp); |
| 984 |
npl_file_t* npl_file_new(void *fp); |
| 985 |
npl_file_t* npl_file_open(wchar_t *filename, wchar_t *mode); |
| 986 |
npl_file_t* npl_file_stdout(void); |
| 987 |
npl_file_t* npl_file_stdin(void); |
| 988 |
npl_file_t* npl_file_stderr(void); |
| 989 |
void npl_file_close(npl_file_t *file); |
| 990 |
|
| 991 |
// cmd |
| 992 |
struct npl_command_list_t { |
| 993 |
const wchar_t *name; |
| 994 |
npl_cmd_func_t func; |
| 995 |
}; |
| 996 |
|
| 997 |
struct npl_cmd_t { |
| 998 |
npl_state_t state; |
| 999 |
npl_command_list_t *commands[8]; // 静的配列のみ |
| 1000 |
size_t _commands_len; |
| 1001 |
npl_cmdi_t *ci; |
| 1002 |
|
| 1003 |
// flags |
| 1004 |
int f_dump_argv; |
| 1005 |
}; |
| 1006 |
|
| 1007 |
int npl_cmd_init(npl_cmd_t *cmd); |
| 1008 |
npl_cmd_t* npl_cmd_new(void); |
| 1009 |
int npl_cmd_add_listener( |
| 1010 |
npl_cmd_t *cmd, |
| 1011 |
npl_object_t *object, |
| 1012 |
npl_listener_func_t func); |
| 1013 |
void npl_cmd_quit(npl_cmd_t *cmd); |
| 1014 |
int npl_cmd_is_done(npl_cmd_t *cmd); |
| 1015 |
int npl_cmd_add_command_list(npl_cmd_t *cmd, npl_command_list_t *list); |
| 1016 |
int npl_cmd_push_cmdi(npl_cmd_t *cmd, npl_cmdi_t *ci); |
| 1017 |
void npl_cmd_pop_cmdi(npl_cmd_t *cmd); |
| 1018 |
int npl_cmd_do(npl_cmd_t *cmd); |
| 1019 |
|
| 1020 |
npl_var_t* npl_cmd_get_var(npl_cmd_t *cmd, wchar_t *name); |
| 1021 |
wchar_t* npl_cmd_get_str(npl_cmd_t *cmd, wchar_t *name); |
| 1022 |
npl_file_t* npl_cmd_get_file(npl_cmd_t *cmd, wchar_t *name); |
| 1023 |
|
| 1024 |
int npl_cmd_set_object(npl_cmd_t *cmd, wchar_t *name, npl_object_t *object); |
| 1025 |
int npl_cmd_set_iface(npl_cmd_t *cmd, wchar_t *name, npl_iface_t *iface); |
| 1026 |
int npl_cmd_set_uniface( |
| 1027 |
npl_cmd_t *cmd, |
| 1028 |
wchar_t *name, |
| 1029 |
npl_uniface_t *uniface); |
| 1030 |
int npl_cmd_set_null(npl_cmd_t *cmd, wchar_t *name); |
| 1031 |
int npl_cmd_set_bool(npl_cmd_t *cmd, wchar_t *name, npl_bool_t b); |
| 1032 |
int npl_cmd_set_byte(npl_cmd_t *cmd, wchar_t *name, npl_byte_t byte); |
| 1033 |
int npl_cmd_set_size(npl_cmd_t *cmd, wchar_t *name, size_t size); |
| 1034 |
int npl_cmd_set_int(npl_cmd_t *cmd, wchar_t *name, int i); |
| 1035 |
int npl_cmd_set_uint(npl_cmd_t *cmd, wchar_t *name, unsigned int u); |
| 1036 |
int npl_cmd_set_long(npl_cmd_t *cmd, wchar_t *name, long long l); |
| 1037 |
int npl_cmd_set_ulong(npl_cmd_t *cmd, wchar_t *name, unsigned long long ul); |
| 1038 |
int npl_cmd_set_float(npl_cmd_t *cmd, wchar_t *name, double f); |
| 1039 |
int npl_cmd_set_wchar(npl_cmd_t *cmd, wchar_t *name, wchar_t wc); |
| 1040 |
int npl_cmd_set_mbchar(npl_cmd_t *cmd, wchar_t *name, char mbc); |
| 1041 |
int npl_cmd_set_str(npl_cmd_t *cmd, wchar_t *name, wchar_t *ws); |
| 1042 |
int npl_cmd_set_file(npl_cmd_t *cmd, wchar_t *name, npl_file_t *file); |
| 1043 |
|
| 1044 |
// cmd events |
| 1045 |
void npl_cmd_dump_argv(npl_cmd_t *cmd); |
| 1046 |
void npl_cmd_unknown_command(npl_cmd_t *cmd); |
| 1047 |
void npl_cmd_failed(npl_cmd_t *cmd); |
| 1048 |
|
| 1049 |
// cmdi (cmd interpreter data) |
| 1050 |
struct npl_cmdi_t { |
| 1051 |
npl_cmdi_t *prev; |
| 1052 |
npl_cbuf_t _argv; |
| 1053 |
npl_sbuf_t _cmd_buf; |
| 1054 |
npl_source_t src; |
| 1055 |
int lf; // 改行 |
| 1056 |
int sq, dq; // シングル・ダブルクォート |
| 1057 |
int es; // エスケープ・シーケンス |
| 1058 |
int comment; // コメント |
| 1059 |
|
| 1060 |
size_t argc; |
| 1061 |
wchar_t **argv; |
| 1062 |
npl_var_t *result; |
| 1063 |
}; |
| 1064 |
|
| 1065 |
int npl_cmdi_init(npl_cmdi_t *ci); |
| 1066 |
void npl_cmdi_final(npl_cmdi_t *ci); |
| 1067 |
|
| 1068 |
#endif /* _NPL_H */ |
| 1069 |
|