forked from digego/extempore
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
911a62d
commit 0ea47ed
Showing
3 changed files
with
103 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
#pragma once | ||
|
||
#include <UNIV.h> | ||
|
||
#include <cinttypes> | ||
|
||
namespace extemp { | ||
namespace ClosureAddressTable { | ||
/////////////////////////////////////////////////////////////////////// | ||
// This here for Extempore Compiler Runtime. | ||
// This is temporary and needs to replaced with something sensible! | ||
struct closure_address_table | ||
{ | ||
uint64_t id; | ||
char *name; | ||
uint32_t offset; | ||
char *type; | ||
struct closure_address_table *next; | ||
}; | ||
|
||
EXPORT closure_address_table* get_address_table(const char *name, extemp::ClosureAddressTable::closure_address_table *table); | ||
|
||
EXPORT uint32_t get_address_offset(uint64_t id, closure_address_table* table); | ||
EXPORT bool check_address_exists(uint64_t id, closure_address_table* table); | ||
EXPORT bool check_address_type(uint64_t id, closure_address_table* table, const char* type); | ||
} // namespace ClosureAddressTable | ||
} // namespace extemp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
#include <EXTClosureAddressTable.h> | ||
|
||
#include <cstring> | ||
|
||
namespace extemp { | ||
namespace ClosureAddressTable { | ||
EXPORT closure_address_table * get_address_table(const char *name, closure_address_table *table) { | ||
while (table) { | ||
if (strcmp(table->name, name)) | ||
return table; | ||
table = table->next; | ||
} | ||
printf("Unable to locate %s in closure environment a\n", name); | ||
return 0; | ||
} | ||
|
||
EXPORT uint32_t get_address_offset(uint64_t id, closure_address_table* table) | ||
{ | ||
while(table) | ||
{ | ||
// printf("%p name: %s\ntablename: %s\n\n", name, name, table->name); | ||
if(table->id == id) { | ||
// printf("in %s returning offset %d from %s\n", table->name, table->offset, name); | ||
return table->offset; | ||
} | ||
table = table->next; | ||
} | ||
printf("Unable to locate %" PRIu64 " in closure environment b\n", id); | ||
return 0; | ||
} | ||
|
||
EXPORT bool check_address_exists(uint64_t id, closure_address_table* table) | ||
{ | ||
do { | ||
if (table->id == id) { | ||
return true; | ||
} | ||
table = table->next; | ||
} while (table); | ||
return false; | ||
} | ||
|
||
EXPORT bool check_address_type(uint64_t id, closure_address_table* table, const char* type) | ||
{ | ||
while(table) | ||
{ | ||
if(table->id == id) { | ||
if((strcmp(table->type, type)!=0) && (strcmp("{i8*, i8*, void (i8*, i8*)*}**", type) != 0)) { | ||
printf("Runtime Type Error: bad type %s for %s. Should be %s\n", type, table->name, table->type); | ||
return 0; | ||
} | ||
else { | ||
return 1; | ||
} | ||
} | ||
table = table->next; | ||
} | ||
printf("Unable to locate id in closure environment type: %s d\n",type); | ||
return 0; | ||
} | ||
|
||
|
||
} // namespace ClosureAddressTable | ||
} // namespace extemp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters