mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-06 13:58:14 +03:00
Distinguish between global/local pages
Fix bug when calling variable_type on global variable (e.g. in A_ALLOC on global).
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#define CACHE_SIZE 64
|
||||
|
||||
static const char *pagetype_strtab[] = {
|
||||
[GLOBAL_PAGE] = "GLOBAL_PAGE",
|
||||
[LOCAL_PAGE] = "LOCAL_PAGE",
|
||||
[STRUCT_PAGE] = "STRUCT_PAGE",
|
||||
[ARRAY_PAGE] = "ARRAY_PAGE"
|
||||
@@ -123,6 +124,10 @@ enum ain_data_type array_type(enum ain_data_type type)
|
||||
enum ain_data_type variable_type(struct page *page, int varno, enum ain_data_type *struct_type)
|
||||
{
|
||||
switch (page->type) {
|
||||
case GLOBAL_PAGE:
|
||||
if (struct_type)
|
||||
*struct_type = ain->globals[varno].struct_type;
|
||||
return ain->globals[varno].data_type;
|
||||
case LOCAL_PAGE:
|
||||
if (struct_type)
|
||||
*struct_type = ain->functions[page->index].vars[varno].struct_type;
|
||||
|
||||
@@ -25,6 +25,7 @@ struct ain_variable;
|
||||
enum ain_data_type;
|
||||
|
||||
enum page_type {
|
||||
GLOBAL_PAGE,
|
||||
LOCAL_PAGE,
|
||||
STRUCT_PAGE,
|
||||
ARRAY_PAGE
|
||||
|
||||
@@ -1127,9 +1127,7 @@ void vm_execute_ain(struct ain *program)
|
||||
link_libraries();
|
||||
|
||||
// Initialize globals
|
||||
heap[0].page = xmalloc(sizeof(struct page) + sizeof(union vm_value) * ain->nr_globals);
|
||||
heap[0].page->nr_vars = ain->nr_globals;
|
||||
//heap[0].page->vars = ain->globals; // FIXME: wrong type
|
||||
heap[0].page = alloc_page(GLOBAL_PAGE, 0, ain->nr_globals);
|
||||
for (int i = 0; i < ain->nr_globals; i++) {
|
||||
switch (ain->globals[i].data_type) {
|
||||
case AIN_STRING:
|
||||
|
||||
Reference in New Issue
Block a user