Skip to content

Instantly share code, notes, and snippets.

@cosinusoidally
Created July 31, 2022 13:36
Show Gist options
  • Save cosinusoidally/c6443f6ccfcdc347383a1a3c2e3f9faf to your computer and use it in GitHub Desktop.
Save cosinusoidally/c6443f6ccfcdc347383a1a3c2e3f9faf to your computer and use it in GitHub Desktop.
unsigned char my_clamp(const int x) {
return (x < 0) ? 0 : ((x > 0xFF) ? 0xFF : (unsigned char) x);
}
int f0(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 0
// 0,4,29,DUK_OP_ADD_RC
regs[29]=regs[4]+15;
// branch: undefined
// ip: 1
// 1,29,29,DUK_OP_BASR_RC
regs[29]=regs[29]>>4;
// branch: undefined
// ip: 2
// 1,29,6,DUK_OP_BASL_RC
regs[6]=regs[29]<<4;
// branch: undefined
// ip: 3
// 2,6,7,DUK_OP_BASR_RC
regs[7]=regs[6]>>1;
// branch: undefined
// ip: 4
// 128,0,8,DUK_OP_LDINT
regs[8]=0;
// branch: undefined
// ip: 5
// 0,6,9,DUK_OP_LDREG
regs[9]=regs[6];
// branch: undefined
// ip: 6
// 4,6,29,DUK_OP_SUB_RR
regs[29]=regs[6]-regs[4];
// branch: undefined
// ip: 7
// 29,6,10,DUK_OP_ADD_RR
regs[10]=regs[6]+regs[29];
// branch: undefined
// ip: 8
// 128,0,11,DUK_OP_LDINT
regs[11]=0;
// branch: undefined
// ip: 9
// 2,4,29,DUK_OP_BASR_RC
regs[29]=regs[4]>>1;
// branch: undefined
// ip: 10
// 29,7,12,DUK_OP_SUB_RR
regs[12]=regs[7]-regs[29];
// branch: undefined
// ip: 11
// 128,0,13,DUK_OP_LDINT
regs[13]=0;
// branch: undefined
// ip: 12
// 1,4,14,DUK_OP_MUL_RC
regs[14]=regs[4]*4;
// branch: undefined
// ip: 13
// 1,4,15,DUK_OP_MUL_RC
regs[15]=regs[4]*4;
// branch: undefined
// ip: 14
// 2,4,16,DUK_OP_BASR_RC
regs[16]=regs[4]>>1;
// branch: undefined
// ip: 15
// 2,5,17,DUK_OP_BASR_RC
regs[17]=regs[5]>>1;
// branch: undefined
return 1;
}
int f16(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 16
// 0,0,0,DUK_OP_LABEL
// label: 0
return 1;
// branch: [19]
}
int f17(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 17
// 128,0,108,DUK_OP_JUMP
return 1;
// branch: [126]
}
int f18(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 18
// 128,0,5,DUK_OP_JUMP
return 1;
// branch: [24]
}
int f19(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 19
// 128,0,23,DUK_OP_LDINT
regs[23]=0;
// branch: undefined
return 1;
}
int f20(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 20
// 17,23,29,DUK_OP_LT_RR
regs[29]=regs[23]<regs[17];
// branch: undefined
return 1;
}
int f21(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 21
// 0,29,0,DUK_OP_IFFALSE_R
r=0;
cv=regs[29];
if(!cv){
r++;
};
r++;
return r;
// branch: [22,23]
}
int f22(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 22
// 128,0,3,DUK_OP_JUMP
return 1;
// branch: [26]
}
int f23(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 23
// 128,0,102,DUK_OP_JUMP
return 1;
// branch: [126]
}
int f24(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 24
// 0,23,29,DUK_OP_POSTINCR
r=regs[23];ro=r++;regs[23]=r;regs[29]=ro;
// branch: undefined
return 1;
}
int f25(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 25
// 127,255,250,DUK_OP_JUMP
return 1;
// branch: [20]
}
int f26(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 26
// 0,1,0,DUK_OP_LABEL
// label: 1
return 1;
// branch: [29]
}
int f27(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 27
// 128,0,91,DUK_OP_JUMP
return 1;
// branch: [119]
}
int f28(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 28
// 128,0,5,DUK_OP_JUMP
return 1;
// branch: [34]
}
int f29(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 29
// 128,0,24,DUK_OP_LDINT
regs[24]=0;
// branch: undefined
return 1;
}
int f30(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 30
// 16,24,29,DUK_OP_LT_RR
regs[29]=regs[24]<regs[16];
// branch: undefined
return 1;
}
int f31(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 31
// 0,29,0,DUK_OP_IFFALSE_R
r=0;
cv=regs[29];
if(!cv){
r++;
};
r++;
return r;
// branch: [32,33]
}
int f32(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 32
// 128,0,3,DUK_OP_JUMP
return 1;
// branch: [36]
}
int f33(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 33
// 128,0,85,DUK_OP_JUMP
return 1;
// branch: [119]
}
int f34(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 34
// 0,24,29,DUK_OP_POSTINCR
r=regs[24];ro=r++;regs[24]=r;regs[29]=ro;
// branch: undefined
return 1;
}
int f35(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 35
// 127,255,250,DUK_OP_JUMP
return 1;
// branch: [30]
}
int f36(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 36
// 0,1,29,DUK_OP_LDREG
regs[29]=regs[1];
// branch: undefined
// ip: 37
// 11,29,18,DUK_OP_GETPROP_RR
regs[18]=((unsigned char *)regs[29])[regs[11]];
// branch: undefined
// ip: 38
// 0,2,29,DUK_OP_LDREG
regs[29]=regs[2];
// branch: undefined
// ip: 39
// 11,29,19,DUK_OP_GETPROP_RR
regs[19]=((unsigned char *)regs[29])[regs[11]];
// branch: undefined
// ip: 40
// 0,11,29,DUK_OP_POSTINCR
r=regs[11];ro=r++;regs[11]=r;regs[29]=ro;
// branch: undefined
// ip: 41
// 3,18,29,DUK_OP_MUL_RC
regs[29]=regs[18]*103;
// branch: undefined
// ip: 42
// 4,29,29,DUK_OP_BASR_RC
regs[29]=regs[29]>>8;
// branch: undefined
// ip: 43
// 29,18,29,DUK_OP_ADD_RR
regs[29]=regs[18]+regs[29];
// branch: undefined
// ip: 44
// 5,29,20,DUK_OP_SUB_RC
regs[20]=regs[29]-179;
// branch: undefined
// ip: 45
// 6,19,29,DUK_OP_MUL_RC
regs[29]=regs[19]*88;
// branch: undefined
// ip: 46
// 4,29,29,DUK_OP_BASR_RC
regs[29]=regs[29]>>8;
// branch: undefined
// ip: 47
// 7,29,29,DUK_OP_SUB_RC
regs[29]=regs[29]-44;
// branch: undefined
// ip: 48
// 8,18,30,DUK_OP_MUL_RC
regs[30]=regs[18]*183;
// branch: undefined
// ip: 49
// 4,30,30,DUK_OP_BASR_RC
regs[30]=regs[30]>>8;
// branch: undefined
// ip: 50
// 30,29,29,DUK_OP_ADD_RR
regs[29]=regs[29]+regs[30];
// branch: undefined
// ip: 51
// 9,29,21,DUK_OP_SUB_RC
regs[21]=regs[29]-91;
// branch: undefined
// ip: 52
// 10,19,29,DUK_OP_MUL_RC
regs[29]=regs[19]*198;
// branch: undefined
// ip: 53
// 4,29,29,DUK_OP_BASR_RC
regs[29]=regs[29]>>8;
// branch: undefined
// ip: 54
// 29,19,29,DUK_OP_ADD_RR
regs[29]=regs[19]+regs[29];
// branch: undefined
// ip: 55
// 11,29,22,DUK_OP_SUB_RC
regs[22]=regs[29]-227;
// branch: undefined
// ip: 56
// 0,0,29,DUK_OP_LDREG
regs[29]=regs[0];
// branch: undefined
// ip: 57
// 0,8,30,DUK_OP_POSTINCR
r=regs[8];ro=r++;regs[8]=r;regs[30]=ro;
// branch: undefined
// ip: 58
// 30,29,25,DUK_OP_GETPROP_RR
regs[25]=((unsigned char *)regs[29])[regs[30]];
// branch: undefined
// ip: 59
// 0,0,29,DUK_OP_LDREG
regs[29]=regs[0];
// branch: undefined
// ip: 60
// 0,8,30,DUK_OP_POSTINCR
r=regs[8];ro=r++;regs[8]=r;regs[30]=ro;
// branch: undefined
// ip: 61
// 30,29,26,DUK_OP_GETPROP_RR
regs[26]=((unsigned char *)regs[29])[regs[30]];
// branch: undefined
// ip: 62
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 63
// 0,13,30,DUK_OP_LDREG
regs[30]=regs[13];
// branch: undefined
// ip: 64
// 20,25,31,DUK_OP_ADD_RR
regs[31]=regs[25]+regs[20];
// branch: undefined
// ip: 65
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 66
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 67
// 2,13,30,DUK_OP_ADD_RC
regs[30]=regs[13]+1;
// branch: undefined
// ip: 68
// 21,25,31,DUK_OP_SUB_RR
regs[31]=regs[25]-regs[21];
// branch: undefined
// ip: 69
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 70
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 71
// 12,13,30,DUK_OP_ADD_RC
regs[30]=regs[13]+2;
// branch: undefined
// ip: 72
// 22,25,31,DUK_OP_ADD_RR
regs[31]=regs[25]+regs[22];
// branch: undefined
// ip: 73
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 74
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 75
// 1,13,30,DUK_OP_ADD_RC
regs[30]=regs[13]+4;
// branch: undefined
// ip: 76
// 20,26,31,DUK_OP_ADD_RR
regs[31]=regs[26]+regs[20];
// branch: undefined
// ip: 77
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 78
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 79
// 13,13,30,DUK_OP_ADD_RC
regs[30]=regs[13]+5;
// branch: undefined
// ip: 80
// 21,26,31,DUK_OP_SUB_RR
regs[31]=regs[26]-regs[21];
// branch: undefined
// ip: 81
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 82
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 83
// 14,13,30,DUK_OP_ADD_RC
regs[30]=regs[13]+6;
// branch: undefined
// ip: 84
// 22,26,31,DUK_OP_ADD_RR
regs[31]=regs[26]+regs[22];
// branch: undefined
// ip: 85
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 86
// 4,13,13,DUK_OP_ADD_RC
regs[13]=regs[13]+8;
// branch: undefined
// ip: 87
// 0,0,29,DUK_OP_LDREG
regs[29]=regs[0];
// branch: undefined
// ip: 88
// 0,9,30,DUK_OP_POSTINCR
r=regs[9];ro=r++;regs[9]=r;regs[30]=ro;
// branch: undefined
// ip: 89
// 30,29,27,DUK_OP_GETPROP_RR
regs[27]=((unsigned char *)regs[29])[regs[30]];
// branch: undefined
// ip: 90
// 0,0,29,DUK_OP_LDREG
regs[29]=regs[0];
// branch: undefined
// ip: 91
// 0,9,30,DUK_OP_POSTINCR
r=regs[9];ro=r++;regs[9]=r;regs[30]=ro;
// branch: undefined
// ip: 92
// 30,29,28,DUK_OP_GETPROP_RR
regs[28]=((unsigned char *)regs[29])[regs[30]];
// branch: undefined
// ip: 93
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 94
// 0,14,30,DUK_OP_LDREG
regs[30]=regs[14];
// branch: undefined
// ip: 95
// 20,27,31,DUK_OP_ADD_RR
regs[31]=regs[27]+regs[20];
// branch: undefined
// ip: 96
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 97
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 98
// 2,14,30,DUK_OP_ADD_RC
regs[30]=regs[14]+1;
// branch: undefined
// ip: 99
// 21,27,31,DUK_OP_SUB_RR
regs[31]=regs[27]-regs[21];
// branch: undefined
// ip: 100
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 101
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 102
// 12,14,30,DUK_OP_ADD_RC
regs[30]=regs[14]+2;
// branch: undefined
// ip: 103
// 22,27,31,DUK_OP_ADD_RR
regs[31]=regs[27]+regs[22];
// branch: undefined
// ip: 104
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 105
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 106
// 1,14,30,DUK_OP_ADD_RC
regs[30]=regs[14]+4;
// branch: undefined
// ip: 107
// 20,28,31,DUK_OP_ADD_RR
regs[31]=regs[28]+regs[20];
// branch: undefined
// ip: 108
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 109
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 110
// 13,14,30,DUK_OP_ADD_RC
regs[30]=regs[14]+5;
// branch: undefined
// ip: 111
// 21,28,31,DUK_OP_SUB_RR
regs[31]=regs[28]-regs[21];
// branch: undefined
// ip: 112
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 113
// 0,3,29,DUK_OP_LDREG
regs[29]=regs[3];
// branch: undefined
// ip: 114
// 14,14,30,DUK_OP_ADD_RC
regs[30]=regs[14]+6;
// branch: undefined
// ip: 115
// 22,28,31,DUK_OP_ADD_RR
regs[31]=regs[28]+regs[22];
// branch: undefined
// ip: 116
// 31,30,29,DUK_OP_PUTPROP_RR
((unsigned char *)regs[29])[regs[30]]=my_clamp(regs[31]);
// branch: undefined
// ip: 117
// 4,14,14,DUK_OP_ADD_RC
regs[14]=regs[14]+8;
// branch: undefined
return 1;
}
int f118(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 118
// 127,255,171,DUK_OP_JUMP
return 1;
// branch: [34]
}
int f119(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 119
// 0,1,0,DUK_OP_ENDLABEL
// endlabel: 1
// branch: undefined
// ip: 120
// 10,8,8,DUK_OP_ADD_RR
regs[8]=regs[8]+regs[10];
// branch: undefined
// ip: 121
// 10,9,9,DUK_OP_ADD_RR
regs[9]=regs[9]+regs[10];
// branch: undefined
// ip: 122
// 15,13,13,DUK_OP_ADD_RR
regs[13]=regs[13]+regs[15];
// branch: undefined
// ip: 123
// 15,14,14,DUK_OP_ADD_RR
regs[14]=regs[14]+regs[15];
// branch: undefined
// ip: 124
// 12,11,11,DUK_OP_ADD_RR
regs[11]=regs[11]+regs[12];
// branch: undefined
return 1;
}
int f125(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 125
// 127,255,154,DUK_OP_JUMP
return 1;
// branch: [24]
}
int f126(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 126
// 0,0,0,DUK_OP_ENDLABEL
// endlabel: 0
// branch: undefined
// ip: 127
// 0,0,0,DUK_OP_RETUNDEF
return 0;
// branch: undefined
return 1;
}
unsigned int foo[128][3];
int init(){
foo[0][0]=&f0;
foo[0][1]=16;
foo[16][0]=&f16;
foo[16][1]=19;
foo[17][0]=&f17;
foo[17][1]=126;
foo[18][0]=&f18;
foo[18][1]=24;
foo[19][0]=&f19;
foo[19][1]=20;
foo[20][0]=&f20;
foo[20][1]=21;
foo[21][0]=&f21;
foo[21][1]=22;
foo[21][2]=23;
foo[22][0]=&f22;
foo[22][1]=26;
foo[23][0]=&f23;
foo[23][1]=126;
foo[24][0]=&f24;
foo[24][1]=25;
foo[25][0]=&f25;
foo[25][1]=20;
foo[26][0]=&f26;
foo[26][1]=29;
foo[27][0]=&f27;
foo[27][1]=119;
foo[28][0]=&f28;
foo[28][1]=34;
foo[29][0]=&f29;
foo[29][1]=30;
foo[30][0]=&f30;
foo[30][1]=31;
foo[31][0]=&f31;
foo[31][1]=32;
foo[31][2]=33;
foo[32][0]=&f32;
foo[32][1]=36;
foo[33][0]=&f33;
foo[33][1]=119;
foo[34][0]=&f34;
foo[34][1]=35;
foo[35][0]=&f35;
foo[35][1]=30;
foo[36][0]=&f36;
foo[36][1]=118;
foo[118][0]=&f118;
foo[118][1]=34;
foo[119][0]=&f119;
foo[119][1]=125;
foo[125][0]=&f125;
foo[125][1]=24;
foo[126][0]=&f126;
foo[126][1]=128;
}
typedef int (* fn)(unsigned int *regs);
int loop(unsigned int *regs){
int r;
int *cb=foo[0];
while(r=((fn)(cb[0]))(regs)){
cb=foo[cb[r]];
};
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment