Add assembler
This commit is contained in:
26
misc/io.c
26
misc/io.c
@@ -75,9 +75,9 @@ bool isdotjack(char* f, int len) {
|
||||
return strcmp(strtail(f, len, strlen(ext)), ext) == 0;
|
||||
}
|
||||
|
||||
bool isdir(char* f, int len) {
|
||||
bool isdir(char* f) {
|
||||
bool readsmt = false;
|
||||
for(int i = len-1; i >= 0; i--) {
|
||||
for(int i = strlen(f)-1; i >= 0; i--) {
|
||||
if(f[i] == '.') {
|
||||
if(readsmt)
|
||||
return false;
|
||||
@@ -160,10 +160,7 @@ FILELIST* getsinglefile(char* file) {
|
||||
}
|
||||
|
||||
FILELIST* getfiles(char* input) {
|
||||
int inplen = strlen(input);
|
||||
bool isitdir = isdir(input, inplen);
|
||||
|
||||
if(isitdir)
|
||||
if(isdir(input))
|
||||
return getfilesfromdir(input);
|
||||
else
|
||||
return getsinglefile(input);
|
||||
@@ -178,3 +175,20 @@ void freefilelist(FILELIST* fs) {
|
||||
if(next != NULL)
|
||||
freefilelist(next);
|
||||
}
|
||||
|
||||
char* getouthack(char* input) {
|
||||
char* out;
|
||||
int inplen = strlen(input);
|
||||
if(isdir(input)) {
|
||||
char* name = getname(input, inplen);
|
||||
int sz = (inplen + strlen(name) + 7) * sizeof(char);
|
||||
out = (char*)malloc(sz);
|
||||
sprintf(out, "%s/%s.hack", input, name);
|
||||
free(name);
|
||||
}
|
||||
else {
|
||||
out = heapstr(input, inplen);
|
||||
out[inplen-4] = 'h';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@@ -11,4 +11,5 @@ typedef struct flist {
|
||||
|
||||
FILELIST* getfiles(char* input);
|
||||
void freefilelist(FILELIST* fs);
|
||||
char* getouthack(char* input);
|
||||
#endif
|
||||
|
@@ -93,7 +93,6 @@ void actonunits(COMPILEUNIT* units, void*(*fun)(void*)) {
|
||||
void freeunit(COMPILEUNIT* u) {
|
||||
freeparser(u->parser);
|
||||
freelnblk(u->compiled);
|
||||
freestrlist(u->asmlns);
|
||||
freevmtranslator(u->vmtranslator);
|
||||
free(u);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ typedef struct unit {
|
||||
PARSER* parser;
|
||||
CLASS* parsed;
|
||||
COMPILER* compiler;
|
||||
STRINGLIST* asmlns;
|
||||
ASMBLK* asmlns;
|
||||
LINEBLOCK* compiled;
|
||||
VMTRANSLATOR* vmtranslator;
|
||||
struct unit* next;
|
||||
|
Reference in New Issue
Block a user