📄 finsh.h.svn-base
字号:
#ifndef __FINSH_H__#define __FINSH_H__#include <rtthread.h>/* -- the beginning of option -- */#define FINSH_NAME_MAX 16 /* max length of identifier */#define FINSH_NODE_MAX 16 /* max number of node */#define FINSH_HEAP_MAX 128 /* max length of heap */#define FINSH_STRING_MAX 128 /* max length of string */#define FINSH_VARIABLE_MAX 8 /* max number of variable */#define FINSH_STACK_MAX 128 /* max stack size */#define FINSH_TEXT_MAX 128 /* max text segment size */#define HEAP_ALIGNMENT 4 /* heap alignment */typedef unsigned char u_char;typedef unsigned short u_short;typedef unsigned long u_long;typedef u_long size_t;#define FINSH_GET16(x) (*(x)) | (*((x)+1) << 8)#define FINSH_GET32(x) (*(x)) | (*((x)+1) << 8) | (*((x)+2) << 16) | (*((x)+3) << 24)#define FINSH_SET16(x, v) \ do \ { \ *(x) = (v) & 0x00ff; \ (*((x)+1)) = (v) >> 8; \ } while ( 0 )#define FINSH_SET32(x, v) \ do \ { \ *(x) = (v) & 0x000000ff; \ (*((x)+1)) = ((v) >> 8) & 0x000000ff; \ (*((x)+2)) = ((v) >> 16) & 0x000000ff; \ (*((x)+3)) = ((v) >> 24); \ } while ( 0 )#define NULL RT_NULLvoid* memset(void * dst, int s, size_t count);size_t strlen(const char *s);char *strncpy(char *dest, const char *src, size_t n);int strcmp (const char *s1, const char *s2);int strncmp(const char *s1, const char *s2, size_t n);int isalpha( int ch );int atoi(const char* s);/* -- end of option -- */#define FINSH_VERSION_MAJOR 0#define FINSH_VERSION_MINOR 4/* error code */#define FINSH_ERROR_OK 0 /* No error */#define FINSH_ERROR_INVALID_TOKEN 1 /* Invalid token */#define FINSH_ERROR_EXPECT_TYPE 2 /* Expect a type */#define FINSH_ERROR_UNKNOWN_TYPE 3 /* Unknown type */#define FINSH_ERROR_VARIABLE_EXIST 4 /* Variable exist */#define FINSH_ERROR_EXPECT_OPERATOR 5 /* Expect a operater */#define FINSH_ERROR_MEMORY_FULL 6 /* Memory full */#define FINSH_ERROR_UNKNOWN_OP 7 /* Unknown operator */#define FINSH_ERROR_UNKNOWN_NODE 8 /* Unknown node */#define FINSH_ERROR_EXPECT_CHAR 9 /* Expect a character */#define FINSH_ERROR_UNEXPECT_END 10 /* Unexpect end */#define FINSH_ERROR_UNKNOWN_TOKEN 11 /* Unknown token */#define FINSH_ERROR_NO_FLOAT 12 /* Float not supported */#define FINSH_ERROR_UNKNOWN_SYMBOL 13 /* Unknown symbol */#define FINSH_ERROR_NULL_NODE 14 /* Null node */typedef long (*syscall_func)();/* system call table */struct finsh_syscall{ char* name; /* the name of system call */ syscall_func func; /* the function address of system call */};extern struct finsh_syscall global_syscall_table[];/* find out system call, which should be implemented in user program */struct finsh_syscall* finsh_syscall_lookup(const char* name);/* system variable table */struct finsh_sysvar{ char* name; /* the name of system call */ u_char type; /* the type of variable */ void* var ; /* the address of variable */};extern struct finsh_sysvar global_sysvar_table[];/* find out system variable, which should be implemented in user program */struct finsh_sysvar* finsh_sysvar_lookup(const char* name);struct finsh_token{ char eof; char replay; int position; u_char current_token; union { char char_value; int int_value; long long_value; } value; u_char string[128]; u_char* line;};#define FINSH_IDTYPE_VAR 0x01#define FINSH_IDTYPE_SYSVAR 0x02#define FINSH_IDTYPE_SYSCALL 0x04#define FINSH_IDTYPE_ADDRESS 0x08struct finsh_node{ u_char node_type; /* node node_type */ u_char data_type; /* node data node_type */ u_char idtype; /* id node information */ union { /* value node */ char char_value; short short_value; int int_value; long long_value; void* ptr; } value; union { /* point to variable identifier or function identifier */ struct finsh_var *var; struct finsh_sysvar *sysvar; struct finsh_syscall*syscall; }id; /* sibling and child node */ struct finsh_node *sibling, *child;};struct finsh_parser{ u_char* parser_string; struct finsh_token token; struct finsh_node* root;};/* finsh data type */enum finsh_type { finsh_type_unknown = 0, finsh_type_void, /* 1 */ finsh_type_voidp, /* 2 */ finsh_type_char, /* 3 */ finsh_type_uchar, /* 4 */ finsh_type_charp, /* 5 */ finsh_type_short, /* 6 */ finsh_type_ushort, /* 7 */ finsh_type_shortp, /* 8 */ finsh_type_int, /* 9 */ finsh_type_uint, /* 10 */ finsh_type_intp, /* 11 */ finsh_type_long, /* 12 */ finsh_type_ulong, /* 13 */ finsh_type_longp /* 14 */};/* init finsh environment */int finsh_init(struct finsh_parser* parser);/* flush finsh node, text segment */int finsh_flush(struct finsh_parser* parser);/* reset all of finsh */int finsh_reset(struct finsh_parser* parser);/* run finsh parser to generate abstract synatx tree */void finsh_parser_run (struct finsh_parser* parser, const unsigned char* string);/* run compiler to compile abstract syntax tree */int finsh_compiler_run(struct finsh_node* node);/* run finsh virtual machine */void finsh_vm_run(void);/* get variable value */struct finsh_var* finsh_var_lookup(const char* name);/* get bottom value of stack */long finsh_stack_bottom(void);/* get error number of finsh */u_char finsh_errno(void);/* get error string */const char* finsh_error_string(u_char type);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -