mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-03 07:29:37 +00:00
e371d304f6
- Create the possibility of forward declaration of structs as part of the language. - Generation of forward declarations in the .asm header files. - Treat global variables as part of global memory, even in libraries. Ensure that globals are not overwritten when importing. - Ensure that the various compilation models (stack, var, phi) in combination with the memory models (zp, mem) result in proper execution of code and proper memory allocation etc, etc. - Added the lru-cache logic to properly test the compilation and memory model combinations. (A lot of bugfixes as a result!)
91 lines
1.8 KiB
C
91 lines
1.8 KiB
C
#pragma var_model(mem)
|
|
#pragma calling(__phicall)
|
|
|
|
#include <lru-cache-mem-stackcall_asm.h>
|
|
#include <conio-mem-stackcall_asm.h>
|
|
|
|
#include <conio.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "lru-cache-mem-stackcall.h"
|
|
#include <division.h>
|
|
|
|
void wait_key()
|
|
{
|
|
// while (!kbhit())
|
|
// ;
|
|
}
|
|
|
|
void display()
|
|
{
|
|
lru_cache_display(0, 2);
|
|
wait_key();
|
|
}
|
|
|
|
lru_cache_data_t get(lru_cache_key_t key)
|
|
{
|
|
gotoxy(0, 0);
|
|
printf("get: %04x ", key);
|
|
lru_cache_data_t data = lru_cache_get(lru_cache_index(key));
|
|
printf(":%04x", data);
|
|
display();
|
|
return data;
|
|
}
|
|
|
|
void set(lru_cache_key_t key, lru_cache_data_t data)
|
|
{
|
|
gotoxy(0, 0);
|
|
printf("set: %04x:%04x", key, data);
|
|
lru_cache_set(lru_cache_index(key), data);
|
|
display();
|
|
}
|
|
|
|
void insert(lru_cache_key_t key, lru_cache_data_t data)
|
|
{
|
|
gotoxy(0, 0);
|
|
printf("add: %04x:%04x ", key, data);
|
|
lru_cache_insert(key, data);
|
|
display();
|
|
}
|
|
|
|
void delete (lru_cache_key_t key)
|
|
{
|
|
gotoxy(0, 0);
|
|
printf("del: %04x ", key);
|
|
lru_cache_delete(key);
|
|
display();
|
|
}
|
|
|
|
void main()
|
|
{
|
|
lru_cache_init();
|
|
|
|
clrscr();
|
|
scroll(0);
|
|
|
|
int cache[128];
|
|
|
|
// char ch = kbhit();
|
|
char ch = 0;
|
|
do {
|
|
if (lru_cache_is_max()) {
|
|
lru_cache_key_t last = lru_cache_find_last();
|
|
delete(last);
|
|
} else {
|
|
lru_cache_key_t key = rand() % 0x20;
|
|
lru_cache_data_t data = get(key);
|
|
if (data != LRU_CACHE_NOTHING) {
|
|
data += 1;
|
|
if (data < 20) {
|
|
set(key, data);
|
|
} else {
|
|
delete(key);
|
|
}
|
|
} else {
|
|
insert(key, 0);
|
|
}
|
|
}
|
|
// ch = kbhit();
|
|
} while (ch != 'x');
|
|
}
|