Files
nunuhara_xsystem4/include/vm/heap.h
T
Nunuhara Cabbage 5d6f148e1b Reorganize project file structure
- Create separate directories for source and header files.
- Build code shared between xsystem4 and aindump as a static library.
- Create header dirs gfx/ system4/ and vm/
- Make CG.c/h usable without a running VM
2019-12-31 17:50:40 -08:00

72 lines
1.6 KiB
C

/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://gnu.org/licenses/>.
*/
#ifndef SYSTEM4_HEAP_H
#define SYSTEM4_HEAP_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct string;
struct page;
enum vm_pointer_type {
VM_PAGE,
VM_STRING
};
#define NR_VM_POINTER_TYPES (VM_STRING+1)
// Heap-backed objects. Reference counted.
struct vm_pointer {
int ref;
enum vm_pointer_type type;
union {
struct string *s;
struct page *page;
};
#ifdef DEBUG_HEAP
size_t alloc_addr;
size_t ref_addr;
size_t free_addr;
#endif
};
struct vm_pointer *heap;
size_t heap_size;
void heap_init(void);
void heap_delete(void);
int32_t heap_alloc_slot(enum vm_pointer_type type);
void heap_ref(int slot);
void heap_unref(int slot);
void exit_unref(int slot);
bool heap_index_valid(int index);
bool page_index_valid(int index);
struct page *heap_get_page(int index);
void heap_set_page(int slot, struct page *page);
#ifdef VM_PRIVATE
int32_t *heap_free_stack;
size_t heap_free_ptr;
#endif /* VM_PRIVATE */
#endif /* SYSTEM4_HEAP_H */