Skip to content

Commit

Permalink
Merge pull request #59 from Priw8/master
Browse files Browse the repository at this point in the history
Some new features and bug fixes in thecl
  • Loading branch information
32th-System authored Aug 27, 2019
2 parents 24826bf + 06758a0 commit 5e0318c
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 58 deletions.
422 changes: 382 additions & 40 deletions thecl/ecsparse.y

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"else" return ELSE;
"do" return DO;
"while" return WHILE;
"times" return TIMES;
"switch" return SWITCH;
"case" return CASE;
"break" return BREAK;
Expand Down Expand Up @@ -126,6 +127,10 @@ _fS return CAST_FI;
yylval.floating = strtof(yytext, NULL);
return FLOATING;
}
rad\(-?[0-9]+(\.[0-9]*)?f\) {
yylval.floating = strtof(yytext+4, NULL) / 180.0f * 3.14159265359f;
return FLOATING;
}
ins_[0-9]+ {
yylval.integer = strtol(yytext + 4, NULL, 10);
return INSTRUCTION;
Expand All @@ -138,6 +143,12 @@ ins_[0-9]+ {
yylval.integer = strtol(yytext, NULL, 16);
return INTEGER;
}
-?0b[0-1]+ {
bool isNegative = yytext[0] == '-';
yylval.integer = strtol(yytext + (isNegative ? 3 : 2), NULL, 2);
if (isNegative) yylval.integer = -yylval.integer;
return INTEGER;
}
![-*ENHLWXYZO4567]+ {
yylval.string = strdup(yytext + 1);
return RANK;
Expand Down
14 changes: 1 addition & 13 deletions thecl/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,7 @@ th10_expressions[] = {
static const expr_t*
expr_get_table(unsigned int version)
{
if ( version == 10
|| version == 103
|| version == 11
|| version == 12
|| version == 125
|| version == 128
|| version == 13
|| version == 14
|| version == 143
|| version == 15
|| version == 16
|| version == 165
|| version == 17)
if (not_pre_th10(version))
return th10_expressions;
return th10_no_expressions;
}
Expand Down
32 changes: 31 additions & 1 deletion thecl/thecl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern const thecl_module_t th10_ecl;
eclmap_t* g_eclmap_opcode = NULL;
eclmap_t* g_eclmap_global = NULL;
bool g_ecl_rawoutput = false;
bool g_ecl_simplecreate = false;
bool g_was_error = false;

thecl_t*
Expand Down Expand Up @@ -173,6 +174,25 @@ free_eclmaps(void)
eclmap_free(g_eclmap_global);
}

int
not_pre_th10(
unsigned int version)
{
return version == 10
|| version == 103
|| version == 11
|| version == 12
|| version == 125
|| version == 128
|| version == 13
|| version == 14
|| version == 143
|| version == 15
|| version == 16
|| version == 165
|| version == 17;
}

static void
print_usage(void)
{
Expand All @@ -183,6 +203,7 @@ print_usage(void)
" -V display version information and exit\n"
" -m use map file for translating mnemonics\n"
" -r output raw ECL opcodes, applying minimal transformations\n"
" -s use simple creation, which doesn't add any instructions automatically\n"
"VERSION can be:\n"
" 6, 7, 8, 9, 95, 10, 103 (for Uwabami Breakers), 11, 12, 125, 128, 13, 14, 143, 15, 16, 165 or 17\n"
"Report bugs to <" PACKAGE_BUGREPORT ">.\n", argv0);
Expand All @@ -208,7 +229,7 @@ main(int argc, char* argv[])
int opt;
int ind=0;
while(argv[util_optind]) {
switch(opt = util_getopt(argc, argv, ":c:d:Vm:r")) {
switch(opt = util_getopt(argc, argv, ":c:d:Vm:r:s")) {
case 'c':
case 'd':
if(mode != -1) {
Expand All @@ -234,6 +255,9 @@ main(int argc, char* argv[])
case 'r':
g_ecl_rawoutput = true;
break;
case 's':
g_ecl_simplecreate = true;
break;
default:
util_getopt_default(&ind,argv,opt,print_usage);
}
Expand Down Expand Up @@ -284,6 +308,12 @@ main(int argc, char* argv[])
exit(1);
}
}
if (g_ecl_simplecreate) {
if (mode != 'c') {
fprintf(stderr, "%s: 's' option cannot be used while dumping\n", argv0);
exit(1);
}
}

if (0 < argc) {
current_input = argv[0];
Expand Down
11 changes: 11 additions & 0 deletions thecl/thecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ typedef enum {
#define RANK_ID_6 (1 << 6)
#define RANK_ID_7 (1 << 7)

// Numbers of important ECL instructions
#define TH10_INS_RET_BIG 1
#define TH10_INS_RET_NORMAL 10
#define TH10_INS_CALL 11
#define TH10_INS_CALL_ASYNC 15
#define TH10_INS_STACK_ALLOC 40

typedef struct thecl_param_t {
int type;
value_t value;
Expand All @@ -69,6 +76,9 @@ thecl_param_t* param_new(
void param_free(
thecl_param_t* param);

int not_pre_th10(
unsigned int version);

typedef struct thecl_instr_t {
thecl_instr_type type;
char* string;
Expand Down Expand Up @@ -188,6 +198,7 @@ extern int yyparse(parser_state_t*);
extern eclmap_t* g_eclmap_opcode;
extern eclmap_t* g_eclmap_global;
extern bool g_ecl_rawoutput;
extern bool g_ecl_simplecreate;
extern bool g_was_error;

#endif
8 changes: 4 additions & 4 deletions thecl/thecl06.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,10 @@ th06_dump(
(instr->rank) & RANK_NORMAL ? "N" : "",
(instr->rank) & RANK_HARD ? "H" : "",
(instr->rank) & RANK_LUNATIC ? "L" : "",
!((instr->rank) & RANK_ID_4) ? "W" : "",
!((instr->rank) & RANK_ID_5) ? "X" : "",
!((instr->rank) & RANK_ID_6) ? "Y" : "",
!((instr->rank) & RANK_ID_7) ? "Z" : "");
!((instr->rank) & RANK_ID_4) ? "4" : "",
!((instr->rank) & RANK_ID_5) ? "5" : "",
!((instr->rank) & RANK_ID_6) ? "6" : "",
!((instr->rank) & RANK_ID_7) ? "7" : "");
}
break;
case THECL_INSTR_INSTR: {
Expand Down
10 changes: 10 additions & 0 deletions util/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ list_head(
return NULL;
}

void*
list_tail(
list_t* list)
{
if (list->tail)
return list->tail->data;
else
return NULL;
}

int
list_empty(
list_t* list)
Expand Down
2 changes: 2 additions & 0 deletions util/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ list_t* list_new(void);
list_node_t* list_node_new(void);
/* Returns the data of head in the list. */
void* list_head(list_t* list);
/* Returns the data of tail in the list. */
void* list_tail(list_t* list);
/* Returns 1 if the list is empty. */
int list_empty(list_t* list);
/* Sets a node as the tail of the list. */
Expand Down

0 comments on commit 5e0318c

Please sign in to comment.