Landed sourcepawn-1.2. The big changes:
1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well.
2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense.
1 #include "KePageAllocator.h"
3 using namespace Knight;
11 class Knight::KePageAllocator
15 size_t page_granularity;
17 PageInfo *page_blocks;
20 static void *ke_LumpPageAlloc(KePageAllocator *alloc)
27 #if defined KE_PLATFORM_WINDOWS
30 alloc->page_granularity,
31 MEM_COMMIT|MEM_RESERVE,
33 #elif defined KE_PLATFORM_POSIX
34 base = valloc(alloc->page_granularity);
36 #error "Unsupported platform"
46 lump->next = alloc->page_blocks;
47 alloc->page_blocks = lump->next;
49 page = (char *)base + alloc->page_size;
50 pagesInBlock = alloc->page_granularity / alloc->page_size;
52 for (size_t i = 1; i < pagesInBlock; i++)
56 lump->next = alloc->free_pages;
57 alloc->free_pages = lump;
58 page += alloc->page_size;
64 KePageAllocator *Knight::KE_CreatePageAllocator()
66 KePageAllocator *alloc;
68 alloc = new KePageAllocator;
70 #if defined KE_PLATFORM_WINDOWS
74 alloc->page_size = info.dwPageSize;
75 alloc->page_granularity = info.dwAllocationGranularity;
76 #elif defined KE_PLATFORM_POSIX
77 alloc->page_size = sysconf(_SC_PAGESIZE);
78 alloc->page_granularity = alloc->page_size * 16;
80 #error "Unsupported platform"
83 alloc->free_pages = NULL;
84 alloc->page_blocks = NULL;
89 void Knight::KE_DestroyPageAllocator(KePageAllocator *alloc)
91 PageInfo *info, *next;
93 info = alloc->page_blocks;
97 #if defined KE_PLATFORM_WINDOWS
98 VirtualFree(info->base, 0, MEM_RELEASE);
99 #elif defined KE_PLATFORM_WINDOWS
102 #error "Unsupported platform"
108 info = alloc->free_pages;
117 void *Knight::KE_PageAlloc(KePageAllocator *alloc)
119 if (alloc->free_pages != NULL)
124 info = alloc->free_pages;
125 alloc->free_pages = info->next;
132 return ke_LumpPageAlloc(alloc);
135 void Knight::KE_PageFree(KePageAllocator *alloc, void *page)
141 info->next = alloc->free_pages;
142 alloc->free_pages = info->next;
145 size_t Knight::KE_PageSize(KePageAllocator *alloc)
147 return alloc->page_size;