Skip to content

Commit

Permalink
Merge pull request #62 from thpatch/thecl-typed-variables
Browse files Browse the repository at this point in the history
Thecl typed variables
  • Loading branch information
ManDude authored Oct 27, 2019
2 parents 2994233 + 67c9cc9 commit bc9d292
Show file tree
Hide file tree
Showing 15 changed files with 3,081 additions and 834 deletions.
4 changes: 2 additions & 2 deletions thecl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ flex_target(EcsScan ecsscan.l ${CMAKE_CURRENT_BINARY_DIR}/ecsscan.c)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
add_executable(thecl
${BISON_EcsParse_OUTPUT_SOURCE} ${FLEX_EcsScan_OUTPUTS}
expr.c thecl.c eclmap.c thecl06.c thecl10.c
expr.h thecl.h eclmap.h)
expr.c thecl.c eclmap.c path.c thecl06.c thecl10.c
expr.h thecl.h eclmap.h path.h)
if(WIN32)
set(ADDITIONAL_LIBRARIES "")
else()
Expand Down
34 changes: 30 additions & 4 deletions thecl/eclmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "eclmap.h"
#include "program.h"
#include "util.h"
#include "thecl.h"

static void
eclmap_dump(
Expand Down Expand Up @@ -142,7 +143,9 @@ eclmap_find(

void
eclmap_load(
unsigned int version,
eclmap_t* opcodes,
eclmap_t* timeline_opcodes,
eclmap_t* globals,
FILE* f,
const char* fn)
Expand All @@ -163,7 +166,7 @@ eclmap_load(

int linecount = 1;
while(fgets(buffer, sizeof(buffer), f)) {
bool is_global = false;
int ent_type = ECLMAP_ENT_INVALID;

char *ptr, *ptrend;
eclmap_entry_t ent;
Expand Down Expand Up @@ -195,9 +198,13 @@ eclmap_load(
/* validate signature */
if(ptr[0] == '?') {
ent.signature = NULL;
ent_type = ECLMAP_ENT_OPCODE;
} else if (ptr[0] == '@') {
ent.signature = NULL;
ent_type = ECLMAP_ENT_TIMELINE_OPCODE;
} else if(ptr[0] == '$' || ptr[0] == '%') {
ent.signature = ptr;
is_global = true;
ent_type = ECLMAP_ENT_GLOBAL;
} else {
ent.signature = ptr;
if(ptr[0] == '_') ptr[0] = '\0'; /* allow empty strings to be specified with "_" */
Expand All @@ -213,7 +220,7 @@ eclmap_load(
}

/* validate mnemonic */
if(ptr[0] == '?') {
if(ptr[0] == '?' || ptr[0] == '@') {
ent.mnemonic = NULL;
}
else {
Expand All @@ -234,9 +241,28 @@ eclmap_load(
}
if(!util_strcmp_ref(ent.mnemonic, stringref("ins_"))) {
fprintf(stderr, "%s:%s:%u: mnemonic can't start with 'ins_'\n",argv0,fn,linecount);
continue;
}
else if(is_post_th10(version) && !strcmp(ent.mnemonic, "return")) {
fprintf(stderr, "%s:%s:%u: ignoring 'return' as it is not a usable mnemonic, use as keyword instead\n",argv0,fn,linecount);
continue;
}
}

eclmap_set(is_global ? globals : opcodes, &ent);
eclmap_t* dest;
switch(ent_type) {
case ECLMAP_ENT_INVALID:
continue;
case ECLMAP_ENT_OPCODE:
dest = opcodes;
break;
case ECLMAP_ENT_TIMELINE_OPCODE:
dest = timeline_opcodes;
break;
case ECLMAP_ENT_GLOBAL:
dest = globals;
}

eclmap_set(dest, &ent);
}
}
9 changes: 8 additions & 1 deletion thecl/eclmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ typedef struct eclmap_entry_t {

typedef list_t eclmap_t;

enum ECLMAP_ENT_TYPES {
ECLMAP_ENT_INVALID,
ECLMAP_ENT_OPCODE,
ECLMAP_ENT_TIMELINE_OPCODE,
ECLMAP_ENT_GLOBAL
};

/* Allocates and initalizes a new eclmap */
#define eclmap_new() ((eclmap_t*)list_new())
/* Frees an eclmap */
Expand All @@ -55,6 +62,6 @@ eclmap_entry_t* eclmap_get(eclmap_t* map, int opcode);
/* Finds an entry in a eclmap by mnemonic */
eclmap_entry_t* eclmap_find(eclmap_t* map, const char* mnemonic);
/* Loads entries from eclmap file (thread unsafe) */
void eclmap_load(eclmap_t* opcodes, eclmap_t* globals, FILE* f, const char* fn);
void eclmap_load(unsigned int version, eclmap_t* opcodes, eclmap_t* timeline_opcodes, eclmap_t* globals, FILE* f, const char* fn);

#endif
Loading

0 comments on commit bc9d292

Please sign in to comment.