Created
March 24, 2012 21:20
-
-
Save m4rw3r/2188184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context *ctx = malloc(sizeof(Context)); | |
Context_init(ctx); | |
uint64_t varsum = Context_allocVariable(ctx); | |
uint64_t varn = Context_allocVariable(ctx); | |
uint64_t vara = Context_allocVariable(ctx); | |
uint64_t varb = Context_allocVariable(ctx); | |
uint64_t vari = Context_allocVariable(ctx); | |
Instruction instructions[] = { | |
{INS(SETTO), varsum, Value_fromInt32(0).asBits, NULL}, | |
{INS(SETTO), varn, Value_fromInt32(20).asBits, NULL}, | |
{INS(SETTO), vara, Value_fromInt32(0).asBits, NULL}, | |
{INS(SETTO), varb, Value_fromInt32(1).asBits, NULL}, | |
{INS(SETTO), vari, Value_fromInt32(0).asBits, NULL}, | |
{INS(IS_LT), vari, varn, NULL}, | |
{INS(JMPZ), 0, 0, NULL}, | |
{INS(VARADD), vari, 1, NULL}, | |
{INS(ADD), vara, varb, NULL}, | |
{INS(SETLV), varsum, 0, NULL}, | |
{INS(COPY), varb, vara, NULL}, | |
{INS(COPY), varsum, varb, NULL}, | |
{INS(FETCH), varsum, 0, NULL}, | |
{INS(PRINT), 0, 0, NULL}, | |
{INS(JMP), 0, 0, NULL}, | |
{INS(FETCH), varsum, 0, NULL}, | |
{INS(PRINT), 0, 0, NULL}, | |
}; | |
int number = sizeof(instructions) / sizeof(Instruction); | |
/* Create the linked list */ | |
for(i = 1; i < number; i++) | |
{ | |
instructions[i - 1].next = &instructions[i]; | |
} | |
/* Manually assign jump addresses */ | |
instructions[6].data1 = (uint64_t) &instructions[15]; | |
instructions[14].data1 = (uint64_t) &instructions[5]; | |
/* Run */ | |
Instruction *next = instructions; | |
while(next != 0) | |
{ | |
next = Eval_instruction(next, ctx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment