/* Copyright (C) 2024 Aryadev Chavali
 * 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 Version 2 for
 * details.
 * You may distribute and modify this code under the terms of the GNU General
 * Public License Version 2, which you should have received a copy of along with
 * this program.  If not, please go to .
 * Created: 2024-10-25
 * Author: Aryadev Chavali
 * Description: Entrypoint
 */
#include 
#include 
#include 
#include 
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef struct
{
  u8 *buffer;
  u64 size_memory, size_stack, size_registers;
} vm_t;
#define VM_DEFAULT_MEM_SIZE       (1024)
#define VM_DEFAULT_STACK_SIZE     (128 * sizeof(u64))
#define VM_DEFAULT_REGISTERS_SIZE (8 * sizeof(u64))
#define VM_STACK(VM)     ((VM)->buffer + (VM)->size_memory + (VM)->size_registers)
#define VM_REGISTERS(VM) ((u64 *)((VM)->buffer + (VM)->size_memory))
#define VM_IP(VM)        (VM_REGISTERS(VM)[0])
#define VM_SP(VM)        (VM_REGISTERS(VM)[1])
void vm_init_malloc(vm_t *vm)
{
  if (vm->size_stack == 0)
    vm->size_stack = VM_DEFAULT_STACK_SIZE;
  if (vm->size_registers == 0)
    vm->size_registers = VM_DEFAULT_REGISTERS_SIZE;
  if (vm->size_memory == 0)
    vm->size_memory = VM_DEFAULT_MEM_SIZE;
  vm->buffer = calloc(1, vm->size_memory + vm->size_stack + vm->size_registers);
}
void vm_stop(vm_t *vm)
{
  free(vm->buffer);
  memset(vm, 0, sizeof(*vm));
}
int main(void)
{
  vm_t vm = {0};
  vm_init_malloc(&vm);
  vm_stop(&vm);
  return 0;
}