| 45 |
#define NPL_BUFFER(x) _NPL_CAST(npl_buffer_t, x, npl_buffer_type) |
#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) |
#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) |
#define NPL_DICT(x) _NPL_CAST(npl_dict_t, x, npl_dict_type) |
|
#define NPL_SM(x) _NPL_CAST(npl_sm_t, x, npl_sm_type) |
|
| 48 |
#define NPL_FUNC(x) _NPL_CAST(npl_func_t, x, npl_func_type) |
#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) |
#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) |
#define NPL_VSTACK(x) _NPL_CAST(npl_vstack_t, x, npl_vstack_type) |
| 52 |
#define NPL_FILE(x) _NPL_CAST(npl_file_t, x, npl_file_type) |
#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) |
#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; |
typedef enum npl_bool_t npl_bool_t; |
| 69 |
typedef unsigned char npl_byte_t; |
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; |
typedef enum npl_token_type_t npl_token_type_t; |
| 72 |
typedef struct npl_vfunc_t npl_vfunc_t; |
typedef struct npl_vfunc_t npl_vfunc_t; |
|
typedef enum npl_opcode_t npl_opcode_t; |
|
| 73 |
typedef struct npl_head_t npl_head_t; |
typedef struct npl_head_t npl_head_t; |
| 74 |
typedef struct npl_member_t npl_member_t; |
typedef struct npl_member_t npl_member_t; |
| 75 |
typedef enum npl_class_type_t npl_class_type_t; |
typedef enum npl_class_type_t npl_class_type_t; |
| 83 |
typedef struct npl_command_list_t npl_command_list_t; |
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; |
typedef struct npl_type_t npl_type_t; |
| 88 |
typedef struct npl_val_t npl_val_t; |
typedef struct npl_val_t npl_val_t; |
| 89 |
typedef struct npl_buf_t npl_buf_t; |
typedef struct npl_buf_t npl_buf_t; |
| 90 |
typedef struct npl_cbuf_t npl_cbuf_t; |
typedef struct npl_cbuf_t npl_cbuf_t; |
| 91 |
typedef struct npl_sbuf_t npl_sbuf_t; |
typedef struct npl_sbuf_t npl_sbuf_t; |
| 92 |
typedef struct npl_stack_t npl_stack_t; |
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; |
typedef struct npl_vt_t npl_vt_t; |
| 96 |
typedef struct npl_source_t npl_source_t; |
typedef struct npl_source_t npl_source_t; |
| 97 |
typedef struct npl_cmdi_t npl_cmdi_t; |
typedef struct npl_cmdi_t npl_cmdi_t; |
| 124 |
typedef struct npl_buffer_t npl_buffer_t; |
typedef struct npl_buffer_t npl_buffer_t; |
| 125 |
typedef struct npl_list_t npl_list_t; |
typedef struct npl_list_t npl_list_t; |
| 126 |
typedef struct npl_dict_t npl_dict_t; |
typedef struct npl_dict_t npl_dict_t; |
|
typedef struct npl_sm_t npl_sm_t; |
|
| 127 |
typedef struct npl_func_t npl_func_t; |
typedef struct npl_func_t npl_func_t; |
| 128 |
typedef struct npl_listener_t npl_listener_t; |
typedef struct npl_listener_t npl_listener_t; |
| 129 |
typedef struct npl_vstack_t npl_vstack_t; |
typedef struct npl_vstack_t npl_vstack_t; |
| 155 |
const char *func_name, |
const char *func_name, |
| 156 |
unsigned int line_no); |
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; |
extern npl_type_t _npl_unset_type; |
| 165 |
extern npl_type_t _npl_bool_type; |
extern npl_type_t _npl_bool_type; |
| 231 |
extern npl_type_t _npl_buffer_type; |
extern npl_type_t _npl_buffer_type; |
| 232 |
extern npl_type_t _npl_list_type; |
extern npl_type_t _npl_list_type; |
| 233 |
extern npl_type_t _npl_dict_type; |
extern npl_type_t _npl_dict_type; |
|
extern npl_type_t _npl_sm_type; |
|
| 234 |
extern npl_type_t _npl_func_type; |
extern npl_type_t _npl_func_type; |
| 235 |
extern npl_type_t _npl_listener_type; |
extern npl_type_t _npl_listener_type; |
| 236 |
extern npl_type_t _npl_vstack_type; |
extern npl_type_t _npl_vstack_type; |
| 250 |
extern npl_type_t *npl_buffer_type; |
extern npl_type_t *npl_buffer_type; |
| 251 |
extern npl_type_t *npl_list_type; |
extern npl_type_t *npl_list_type; |
| 252 |
extern npl_type_t *npl_dict_type; |
extern npl_type_t *npl_dict_type; |
|
extern npl_type_t *npl_sm_type; |
|
| 253 |
extern npl_type_t *npl_func_type; |
extern npl_type_t *npl_func_type; |
| 254 |
extern npl_type_t *npl_listener_type; |
extern npl_type_t *npl_listener_type; |
| 255 |
extern npl_type_t *npl_vstack_type; |
extern npl_type_t *npl_vstack_type; |
| 263 |
NPL_TRUE, |
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 |
// token |
| 281 |
// 汎用的な予め定義されるトークン。 |
// 汎用的な予め定義されるトークン。 |
| 282 |
enum npl_token_type_t { |
enum npl_token_type_t { |
| 362 |
void *fn; // 呼び出す関数のアドレス |
void *fn; // 呼び出す関数のアドレス |
| 363 |
}; |
}; |
| 364 |
|
|
| 365 |
// opcode |
// mod |
| 366 |
enum npl_opcode_t { |
struct npl_mod_t { |
| 367 |
NPL_OPC_NULL = 0, |
npl_type_t **types; |
|
NPL_OPC_END, |
|
| 368 |
}; |
}; |
| 369 |
|
|
| 370 |
// member (クラスメンバ情報) |
// member (クラスメンバ情報) |
| 371 |
struct npl_member_t { |
struct npl_member_t { |
| 372 |
npl_type_t *type; // メンバ型、メソッドの返り値型 |
npl_type_t *type; // メンバ型、メソッドの返り値型 |
| 373 |
|
npl_type_t **args; // メソッドの引数型リスト |
| 374 |
wchar_t *name; |
wchar_t *name; |
| 375 |
size_t offset; |
size_t offset; |
| 376 |
int (*setter)(npl_head_t *head, npl_val_t *val); |
int (*setter)(npl_head_t *head, npl_val_t *val); |
| 377 |
int (*getter)(npl_head_t *head, npl_val_t *val_r); |
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 |
// type |
| 474 |
void* npl_member_addr(npl_head_t *head, npl_member_t *m); |
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); |
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); |
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 |
// struct |
| 480 |
struct npl_struct_t { |
struct npl_struct_t { |
| 794 |
npl_tuple_t* npl_tuple_new(size_t len); |
npl_tuple_t* npl_tuple_new(size_t len); |
| 795 |
size_t npl_tuple_len(npl_tuple_t *tuple); |
size_t npl_tuple_len(npl_tuple_t *tuple); |
| 796 |
|
|
| 797 |
// sm class (stack machine) |
// vm opcode |
| 798 |
struct npl_sm_t { |
#define NPL_OP_NOP 0 |
| 799 |
npl_object_t object; |
#define NPL_OP_BREAK 1 |
| 800 |
}; |
#define NPL_OP_END 2 |
| 801 |
|
#define NPL_OP_SETP 3 |
| 802 |
int npl_sm_init(npl_sm_t *sm); |
#define NPL_OP_ADDP 4 |
| 803 |
npl_sm_t* npl_sm_new(void); |
#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 |
// func class |
| 842 |
enum npl_func_type_t { |
enum npl_func_type_t { |