// header includes
#include "base/base_inc.h"
#include "os/os_inc.h"

// .c includes
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "os/os_entry_point.c"

#define LOG DebugPrintf
function void 
DebugPrintf(const char* format, ...)
{
    char buffer[4096];
    va_list args;
    va_start(args, format);
    vsprintf_s(buffer, sizeof(buffer), format, args);
    OutputDebugString(buffer);
    va_end(args);
}

typedef struct F64Node F64Node;
struct F64Node 
{
  F64Node *prev;
  F64Node *next;
  F64 value;
};

typedef struct F64List F64List;
struct F64List
{
  F64Node *first;
  F64Node *last;
  U32 length;
};

F64Node g_f64_nil_node = {0};

function void
F64_push_node(F64List *list, F64Node *n)
{
  if(list->first == 0)
  {
    list->first = n;
    list->last = n;
  } else {
    list->last->next = n;
    list->last = n;
  }
  list->length += 1;
}

function void
F64_push(Arena *arena, F64List *list, F64 value) 
{
  F64Node *node = PushArrayZero(arena, F64Node, 1);
  node->value = value;
  F64_push_node(list, node);
}

function void
print_F64_ll(F64List *list)
{
  for(F64Node *n = list->first; n != 0; n = n->next)
  {
    LOG(" %2.f \n", n->value);
  }
}

function void
reverse_linked_list_lol(void)
{
  Arena *ll_arena = m_make_arena();
  F64List list = {0};
  for (U32 i = 0; i < 10; i++) 
  {
    F64_push(ll_arena, &list, (F64)i);
  }

  print_F64_ll(&list);

  F64Node *prev = 0;
  F64Node *current = list.first;
  F64Node *next_temp = 0;
  while(current != 0) 
  {
    next_temp = current->next;
    current->next = prev;
    prev = current;
    current = next_temp;
  }
  list.first = prev;
   
  print_F64_ll(&list);
}



void
EntryPoint(void) 
{
  reverse_linked_list_lol();
}
