Files
ivy/frontend/debug.c

131 lines
2.4 KiB
C
Raw Normal View History

#include <blue/term.h>
#include <ivy/lang/lex.h>
#include <ivy/asm/lex.h>
#include <stdio.h>
extern void print_lex_token(struct ivy_token *tok)
{
switch (tok->t_type) {
case IVY_TOK_KEYWORD:
b_puts("[magenta]");
break;
case IVY_TOK_SYMBOL:
b_puts("[blue]");
break;
case IVY_TOK_ATOM:
b_puts("[yellow]");
break;
case IVY_TOK_INT:
case IVY_TOK_DOUBLE:
b_puts("[yellow]");
break;
case IVY_TOK_LABEL:
b_puts("[red]");
break;
case IVY_TOK_IDENT:
b_puts("[cyan]");
break;
case IVY_TOK_STRING:
b_puts("[green]");
break;
case IVY_TOK_STR_START:
b_puts("[green]");
break;
case IVY_TOK_STR_END:
b_puts("[green]");
break;
case IVY_TOK_LINEFEED:
b_puts("[dark_grey]");
break;
default:
break;
}
b_puts(ivy_lex_token_type_to_string(tok->t_type));
switch (tok->t_type) {
case IVY_TOK_IDENT:
case IVY_TOK_LABEL:
case IVY_TOK_STRING:
case IVY_TOK_ATOM:
printf("(%s)", tok->t_str);
break;
case IVY_TOK_SYMBOL:
printf("(%s)", ivy_symbol_to_string(tok->t_symbol));
break;
case IVY_TOK_KEYWORD:
printf("(%s)", ivy_keyword_to_string(tok->t_keyword));
break;
case IVY_TOK_INT:
printf("(%llu)", tok->t_int);
break;
case IVY_TOK_DOUBLE:
printf("(%lf)", tok->t_double);
break;
default:
break;
}
b_puts("[reset]\n");
}
extern void print_asm_lex_token(struct ivy_asm_token *tok)
{
switch (tok->t_type) {
case IVY_ASM_TOK_KEYWORD:
b_puts("[magenta]");
break;
case IVY_ASM_TOK_SYMBOL:
b_puts("[blue]");
break;
case IVY_ASM_TOK_INT:
case IVY_ASM_TOK_DOUBLE:
b_puts("[yellow]");
break;
case IVY_ASM_TOK_LABEL:
b_puts("[red]");
break;
case IVY_ASM_TOK_IDENT:
b_puts("[cyan]");
break;
case IVY_ASM_TOK_STRING:
b_puts("[green]");
break;
case IVY_ASM_TOK_LINEFEED:
b_puts("[dark_grey]");
break;
default:
break;
}
b_puts(ivy_asm_token_type_to_string(tok->t_type));
switch (tok->t_type) {
case IVY_ASM_TOK_IDENT:
case IVY_ASM_TOK_LABEL:
case IVY_ASM_TOK_STRING:
printf("(%s)", tok->t_str);
break;
case IVY_ASM_TOK_SYMBOL:
printf("(%s)", ivy_asm_symbol_to_string(tok->t_symbol));
break;
case IVY_ASM_TOK_KEYWORD:
printf("(%s)", ivy_asm_keyword_to_string(tok->t_keyword));
break;
case IVY_ASM_TOK_INT:
if (tok->t_int.sign) {
printf("(%lld)", tok->t_int.v);
} else {
printf("(%llu)", tok->t_int.uv);
}
break;
case IVY_ASM_TOK_DOUBLE:
printf("(%lf)", tok->t_double);
break;
default:
break;
}
b_puts("[reset]\n");
}