mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-22 07:03:36 +08:00
Add enum-to-string functions for syntax tree and opcodes.
This commit is contained in:
+1
-1
@@ -113,7 +113,7 @@ struct js_Function
|
||||
};
|
||||
|
||||
js_Function *jsC_compile(js_State *J, js_Ast *prog);
|
||||
|
||||
const char *jsC_opcodestring(int opcode);
|
||||
void jsC_dumpfunction(js_State *J, js_Function *fun);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define nelem(a) (sizeof (a) / sizeof (a)[0])
|
||||
|
||||
static const char *astname[] = {
|
||||
"list", "fundec", "ident", "number", "string", "regexp", "undef",
|
||||
"null", "true", "false", "this", "fun", "array", "object", "prop_val",
|
||||
@@ -25,6 +27,20 @@ static const char *opname[] = {
|
||||
#include "opnames.h"
|
||||
};
|
||||
|
||||
const char *jsP_aststring(js_AstType type)
|
||||
{
|
||||
if (type < 0 || type > nelem(astname))
|
||||
return "<unknown>";
|
||||
return astname[type];
|
||||
}
|
||||
|
||||
const char *jsC_opcodestring(int type)
|
||||
{
|
||||
if (type < 0 || type > nelem(opname))
|
||||
return "<unknown>";
|
||||
return opname[type];
|
||||
}
|
||||
|
||||
static inline void pc(int c)
|
||||
{
|
||||
putchar(c);
|
||||
|
||||
@@ -128,6 +128,7 @@ js_Ast *jsP_parse(js_State *J, const char *filename, const char *source);
|
||||
void jsP_optimize(js_State *J, js_Ast *prog);
|
||||
void jsP_freeparse(js_State *J);
|
||||
|
||||
const char *jsP_aststring(js_AstType type);
|
||||
void jsP_dumpsyntax(js_State *J, js_Ast *prog);
|
||||
void jsP_dumplist(js_State *J, js_Ast *prog);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user