|
@@ -29,7 +29,7 @@ V d(){L p=m[0]-K;L o=p>=0&&p<MZ?m[p]:0;fprintf(stderr,"[wm] stopped at address:
|
|
|
V e(S s,...){fflush(stderr);fprintf(stderr,"[wm] error: ");va_list a;va_start(a,s);vfprintf(stderr,s,a);va_end(a);putchar('\n');d();exit(K);}
|
|
|
P a(Z z){P r=malloc(z);if(!r)e("out of memory.");R r;}
|
|
|
P ra(P p,Z z){P r=realloc(p,z);if(!r)e("out of memory.");R r;}
|
|
|
-V l(S s,FILE*f){m[0]=K;if(!f)e("can't open file '%s'.",s);Z i=K;U b[8];LP(){Z z=fread(b,K,8,f);if(!z)break;if(z!=8){I pz=ftell(f);if(pz<0)e("decoding of the image '%s' failed.",s);else e("decoding of the image '%s' failed near byte at #%ld.",s,pz-z);}if(i>=LLONG_MAX)e("image '%s' is too large (max. = %lld).",s,LLONG_MAX);if(i>=EZ)e("image '%s' doesn't fit into the memory (size = %ld).",s,EZ);m[i++]=(((L)b[0])&0xff)|((((L)b[K])&0xff)<<8)|((((L)b[2])&0xff)<<16)|((((L)b[3])&0xff)<<24)|((((L)b[4])&0xff)<<32)|((((L)b[5])&0xff)<<40)|((((L)b[6])&0xff)<<48)|((((L)b[7])&0xff)<<56);if(Du){if(m[i-1]<1)fprintf(stderr,"%04lu:%08lld ",i-2,m[i-1]);else fprintf(stderr,"%04lu:%08llx ",i-2,m[i-1]);if((i-1)%4==0)fputs("\n",stderr);}}if(Du){fprintf(stderr,"\n(%lu)\n",i-1);if(!DD)fputs("\n",stderr);}}
|
|
|
+V l(S s,FILE*f){m[0]=K;if(!f)e("can't open file '%s'.",s);Z i=K;U b[8];LP(){Z z=fread(b,K,8,f);if(!z)break;if(z!=8){I pz=ftell(f);if(pz<0)e("decoding of the image '%s' failed.",s);else e("decoding of the image '%s' failed near byte at #%ld.",s,pz-z);}if(i>=LLONG_MAX)e("image '%s' is too large (max. = %lld).",s,LLONG_MAX);if(i>=EZ)e("image '%s' doesn't fit into the memory (size = %ld).",s,EZ);m[i++]=(((L)b[0])&0xff)|((((L)b[K])&0xff)<<8)|((((L)b[2])&0xff)<<16)|((((L)b[3])&0xff)<<24)|((((L)b[4])&0xff)<<32)|((((L)b[5])&0xff)<<40)|((((L)b[6])&0xff)<<48)|((((L)b[7])&0xff)<<56);if(Du){if(m[i-1]<1)fprintf(stderr,"%04lu:%08lld ",i-2,m[i-1]);else fprintf(stderr,"%04lu:%08llx ",i-2,m[i-1]);if((i-1)%4==0)fputs("\n",stderr);}}if(Du){fprintf(stderr,"(%lu)\n",i-1);if(!DD)fputs("\n",stderr);}}
|
|
|
V pj(L a){if(jp>=0&&jp>=JZ)e("jump frame overflow.");m[++jp+JA]=a;}
|
|
|
L tj(){if(jp<0)e("jump frame underflow.");R m[JA+jp--];}
|
|
|
L lj(){if(jp<0)e("jump frame underflow.");R m[JA+jp];}
|
|
@@ -72,7 +72,7 @@ SW(d)DR1(0,~a);DR2(1,b&a);DR2(2,b|a);
|
|
|
DR1(80,eX(a));DR1(81,ouD(a));
|
|
|
DR0(40,a=po();pu(a);pu(a););DR0(41,a=po();b=po();pu(b);pu(a););DR0(42,po(););DF(e("illegal special directive: 0x%llx.",d);)}
|
|
|
L r(L a){if(a==-K)R getchar();ELIF(a==-2)R 0;ELIF(a==-3)Rk;ELIF(a==-4)R-K;ELIF(a==-5)R lj();ELIF(a==-6)R time(0);ELIF(a==-7)R MZ+sp;ELIF(a==-8)R EZ;ELIF(a==-9)R SZ;ELIF(a==-10)R MZ;ELIF(a==-11)R JZ;ELIF(a==-12)R iL();ELIF(a==-13){R aM(64);}if(a<0||a>=MZ)e("attempt to read from an illegal address: 0x%x.",a);R m[a];}
|
|
|
-V w(L a,L v){if(a==-K){putchar(v);R;}ELIF(a==-2){printf("%lld",v);R;}ELIF(a==-5){pj(v);R;}ELIF(a==-6){usleep(v);R;}ELIF(a==-7){sp=v-MZ;R;}ELIF(a==-8){fo(v);R;}ELIF(a==-9){if(v>=0)close(v);R;}ELIF(a==-10){fr(v);R;}ELIF(a==-11){fw(v);R;}ELIF(a==-12){fs(v);R;}ELIF(a==-13){SW(r(v))CS(0,w(v,aM(64));)CS(K,mF(v);)CS(2,mW(v);)CS(3,w(v,mR(v));)DF(w(v,-1);)R;}ELIF(a==-14){cP(v);R;}else if(-15){R;}if(a<0||a>=MZ)e("attempt to write (value = 0x%x) to an illegal address: 0x%x.",v,a);m[a]=v;}
|
|
|
+V w(L a,L v){if(a==-K){putchar(v);R;}ELIF(a==-2){printf("%lld",v);R;}ELIF(a==-5){pj(v);R;}ELIF(a==-6){usleep(v);R;}ELIF(a==-7){sp=v-MZ;R;}ELIF(a==-8){fo(v);R;}ELIF(a==-9){if(v>=0)close(v);R;}ELIF(a==-10){fr(v);R;}ELIF(a==-11){fw(v);R;}ELIF(a==-12){fs(v);R;}ELIF(a==-13){SW(r(v))CS(0,w(v,aM(64));)CS(K,mF(v);)CS(2,mW(v);)CS(3,w(v,mR(v));)DF(w(v,-1);)R;}ELIF(a==-14){cP(v);R;}else if(a==-15){R;}if(a<0||a>=MZ)e("attempt to write (value = 0x%x) to an illegal address: 0x%x.",v,a);m[a]=v;}
|
|
|
#define OP1(x,p)case x:a=g();if(s)break;{p}break
|
|
|
#define OP2(x,p)case x:a=g();b=g();if(s)break;{p}break
|
|
|
#define OP3(x,p)case x:a=g();b=g();c=g();if(s)break;{p}break
|