//online parser:
https://www.bccn.net/run/
程序代码:
#include <stdio.h>
#include <stdlib.h>
#pragma GCC diagnostic ignored "-Wint-conversion"
//#define PRINT_ON
#define STATE_POLL 0
#define Trans_real_Arg 0
typedef int ElmeType;
typedef struct node {
ElmeType data;
struct node *next;
}SLinkNode, *PSN;
#define stub
#define public typedef
#define class struct
//portable oo-style ??
public class v {
unsigned char state;
PSN addr;
int vtbl[2];
}vs, *pvs;
static pvs vm;
//bottom layer
void __post_local_address(PSN addr)
{
vm->addr = addr;
#ifdef PRINT_ON
printf("addr = %p\n", addr);
printf("vm->addr = %p\n", vm->addr);
#endif
}
PSN __recv_external_address(void)
{
return vm->addr;
}
//mid layer
void _register_state_func(int fa)
{
static int idx = 0;
vm->vtbl[idx++] = fa;
//boundary alert: state < 0xFF
vm->state++;
}
int _main(int argc, char **argv)
{
//BUG_ON
vm = (pvs)malloc(sizeof(vs));
//interface register mannually
_register_state_func(__post_local_address);
_register_state_func(__recv_external_address);
#ifdef PRINT_ON
printf("vm = %p\n", vm);
printf("end of %s\n", __func__);
#endif
return 0;
}
//For keeping prototype disusing **L
void InitList(SLinkNode *L)
{
PSN M;
M = (PSN)malloc(sizeof(SLinkNode));
#if Trans_real_Arg == 0
typedef int (*ra)(void);
#define RDY_STATE(_s) (_s >> 4) & 0x01
//Address trunc occurred!!!
//L = ((ra)(vm->vtbl[STATE_POLL + RDY_STATE(vm->state)]))();
//no trunc!
L = __recv_external_address();
#ifdef PRINT_ON
printf("revc L = %p\n", L);
#endif
#endif//Trans_real_Arg block
//#define SET_ADDR(_m) *(int *)(_m)
//SET_ADDR(L) = (PSN)malloc(sizeof(SLinkNode));
#define CAST2IDA(_m, _ida) ((PSN)(&(*_m)))->_ida
CAST2IDA(L, data) = M;
M->data = 125;
M->next = NULL;
#ifdef PRINT_ON
printf("M(*L) = %p\n", M);
printf("M->data = %d\n", M->data);
printf("M->next = %p\n", M->next);
printf("end of %s\n", __func__);
#endif
}
//main branch top layer
int main(int argc, char *argv[])
{
int i = 1;
SLinkNode *L = (PSN)InitList;
#ifdef PRINT_ON
printf("L(addr) = %p\n", &L);
#endif
#define T_PTR(_p) (void *)(_p)
_main(1, T_PTR("register callback function"));
#if Trans_real_Arg == 1
//Transfering real arguments
InitList((PSN)&L);
#else//Trans_real_Arg block
#define LOWBYTE(_b) (_b) & 0x0f
#define STATE_N(_s) LOWBYTE(_s)
while (i++ < STATE_N(vm->state)) {
#define RDY_POST(_s) ((_s) >> 4) & 0x01
if (!RDY_POST(vm->state)) {
typedef void (*pa)(int);
#ifdef PRINT_ON
//BUG_ON trunc address
printf("__int64 trunc: &L = %p\n", (PSN)&L);
#endif
//Address trunc occurred!!!
//((pa)(vm->vtbl[STATE_POLL + 0]))((PSN)&L);
//no trunc!
__post_local_address((PSN)&L);
#define SET_POST(_s) (_s) |= 0x10
SET_POST(vm->state);
//Transfering formal arguments ? 2333
InitList(L);
} else {
#define bus_stub
bus_stub;
#define switch_ctx()
switch_ctx();
}
}
#endif//Trans_real_Arg
#ifdef PRINT_ON
printf("L = %p\n", L);
printf("L->data = %d\n", L->data);
printf("L->next = %p\n", L->next);
printf("end of %s\n", __func__);
#endif
free(L);
return 0;
}
output sample:
L(addr) = 0x7ffd15da8860
vm = 0x1dde020
end of _main
__int64 trunc: &L = 0x7ffd15da8860
addr = 0x7ffd15da8860
vm->addr = 0x7ffd15da8860
revc L = 0x7ffd15da8860
M(*L) = 0x1dde040
M->data = 125
M->next = (nil)
end of InitList
L = 0x1dde040
L->data = 125
L->next = (nil)
end of main