...
 
Commits (2)
malbolg20: malbolge20.c malbolge20: malbolge20.c
CC -o malbolge20 malbolge20.c -lm ${CC} -o malbolge20 malbolge20.c -lm
clean: clean:
rm -rf malbolge20 malbolge20.o rm -rf malbolge20 malbolge20.o
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
#ifdef __GNUC__ #ifdef __GNUC__
static inline static inline
#endif #endif
void exec(int flag[59049], unsigned long **mem, unsigned long init[59049][2] ); void exec(int flag[59049], unsigned int **mem, unsigned int init[59049][2] );
#ifdef __GNUC__ #ifdef __GNUC__
static inline static inline
#endif #endif
unsigned long op( unsigned long x, unsigned long y ); unsigned int op( unsigned int x, unsigned int y );
void make_init_mem(int id, unsigned long **mem, unsigned long init[59049][2]); void make_init_mem(int id, unsigned int **mem, unsigned int init[59049][2]);
const char xlat1[] = const char xlat1[] =
"+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA\"lI" "+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA\"lI"
...@@ -30,10 +30,10 @@ const char xlat2[] = ...@@ -30,10 +30,10 @@ const char xlat2[] =
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
unsigned long **mem; unsigned int **mem;
int flag[59049];// ブロックが使用済みか否か int flag[59049];// ブロックが使用済みか否か
unsigned long init[59050][2]; // 各ブロックの最初2つ分の初期値を記憶 unsigned int init[59050][2]; // 各ブロックの最初2つ分の初期値を記憶
unsigned long i,ii = 0; unsigned int i,ii = 0;
int x; int x;
for(i=0;i<59049;i++){// フラグ初期化 for(i=0;i<59049;i++){// フラグ初期化
...@@ -51,7 +51,7 @@ int main( int argc, char **argv ) ...@@ -51,7 +51,7 @@ int main( int argc, char **argv )
return ( 1 ); return ( 1 );
} }
mem = (unsigned long **)malloc( sizeof(unsigned long) * 59049 ); mem = (unsigned int **)malloc( sizeof(unsigned int) * 59049 );
if ( mem == NULL ) if ( mem == NULL )
{ {
fclose( f ); fclose( f );
...@@ -61,7 +61,7 @@ int main( int argc, char **argv ) ...@@ -61,7 +61,7 @@ int main( int argc, char **argv )
int id=0; int id=0;
//第0ブロックのメモリ領域確保 //第0ブロックのメモリ領域確保
mem[id] = (unsigned long *)malloc( sizeof(unsigned long) * 59049 ); mem[id] = (unsigned int *)malloc( sizeof(unsigned int) * 59049 );
if ( mem[id] == NULL ) if ( mem[id] == NULL )
{ {
fclose( f ); fclose( f );
...@@ -102,7 +102,7 @@ int main( int argc, char **argv ) ...@@ -102,7 +102,7 @@ int main( int argc, char **argv )
return ( 1 ); return ( 1 );
} }
//次ブロックのメモリ領域を確保 //次ブロックのメモリ領域を確保
mem[id] = (unsigned long *)malloc( sizeof(unsigned long) * 59049 ); mem[id] = (unsigned int *)malloc( sizeof(unsigned int) * 59049 );
if ( mem[id] == NULL ) if ( mem[id] == NULL )
{ {
fclose( f ); fclose( f );
...@@ -138,7 +138,7 @@ int main( int argc, char **argv ) ...@@ -138,7 +138,7 @@ int main( int argc, char **argv )
/* 各ブロックの遅延初期化を行うための準備をする関数 */ /* 各ブロックの遅延初期化を行うための準備をする関数 */
/* 各ブロックの最初の2ワードを計算し, initに格納 */ /* 各ブロックの最初の2ワードを計算し, initに格納 */
void make_init_mem(int id, unsigned long **mem, unsigned long init[59049][2]){ void make_init_mem(int id, unsigned int **mem, unsigned int init[59049][2]){
int i,j; int i,j;
int x, y, temp0, temp1; int x, y, temp0, temp1;
int num0[3][3] = {{0, 1, 2}, {0, 1, 1}, {0, 2, 2}, }; int num0[3][3] = {{0, 1, 2}, {0, 1, 1}, {0, 2, 2}, };
...@@ -169,7 +169,7 @@ static inline ...@@ -169,7 +169,7 @@ static inline
#endif #endif
/* JMPとMOV_Dの時に呼ばれ, その処理を実行する. */ /* JMPとMOV_Dの時に呼ばれ, その処理を実行する. */
void mem_manage(unsigned long *reg_addr, unsigned long num, int *id, unsigned long **mem, unsigned long init[59049][2], int flag[59049]){ void mem_manage(unsigned int *reg_addr, unsigned int num, int *id, unsigned int **mem, unsigned int init[59049][2], int flag[59049]){
int new_reg_addr=0; int new_reg_addr=0;
int new_id; int new_id;
int i; int i;
...@@ -182,7 +182,7 @@ void mem_manage(unsigned long *reg_addr, unsigned long num, int *id, unsigned lo ...@@ -182,7 +182,7 @@ void mem_manage(unsigned long *reg_addr, unsigned long num, int *id, unsigned lo
/* 初期化されていないブロックだった場合、初期化する*/ /* 初期化されていないブロックだった場合、初期化する*/
if(flag[new_id]==UNALLOCATED){ //すでに初期化済みかチェック if(flag[new_id]==UNALLOCATED){ //すでに初期化済みかチェック
mem[new_id] = (unsigned long *)malloc( sizeof(unsigned long) * 59049 ); mem[new_id] = (unsigned int *)malloc( sizeof(unsigned int) * 59049 );
if ( mem[new_id] == NULL ){ if ( mem[new_id] == NULL ){
fclose( f ); fclose( f );
free(mem); free(mem);
...@@ -202,7 +202,7 @@ void mem_manage(unsigned long *reg_addr, unsigned long num, int *id, unsigned lo ...@@ -202,7 +202,7 @@ void mem_manage(unsigned long *reg_addr, unsigned long num, int *id, unsigned lo
} }
/* 命令実行後のインクリメント. increment(c, c_id)*/ /* 命令実行後のインクリメント. increment(c, c_id)*/
void increment(unsigned long *reg_addr, int *id, int flag[59049], unsigned long **mem, unsigned long init[59049][2]){ void increment(unsigned int *reg_addr, int *id, int flag[59049], unsigned int **mem, unsigned int init[59049][2]){
int i; int i;
if ( *reg_addr == 59048 ){ if ( *reg_addr == 59048 ){
if(*id == 59048){ if(*id == 59048){
...@@ -210,7 +210,7 @@ void increment(unsigned long *reg_addr, int *id, int flag[59049], unsigned long ...@@ -210,7 +210,7 @@ void increment(unsigned long *reg_addr, int *id, int flag[59049], unsigned long
}else{ }else{
*id+=1; *reg_addr=0; *id+=1; *reg_addr=0;
if(flag[*id]==UNALLOCATED){ //すでに初期化済みかチェック if(flag[*id]==UNALLOCATED){ //すでに初期化済みかチェック
mem[*id] = (unsigned long *)malloc( sizeof(unsigned long) * 59049 ); mem[*id] = (unsigned int *)malloc( sizeof(unsigned int) * 59049 );
if ( mem[*id] == NULL ){ if ( mem[*id] == NULL ){
fclose( f ); fclose( f );
fputs( "can't allocate memory\n", stderr ); fputs( "can't allocate memory\n", stderr );
...@@ -230,9 +230,9 @@ void increment(unsigned long *reg_addr, int *id, int flag[59049], unsigned long ...@@ -230,9 +230,9 @@ void increment(unsigned long *reg_addr, int *id, int flag[59049], unsigned long
} }
void exec( int flag[59049], unsigned long **mem, unsigned long init[59049][2] ) void exec( int flag[59049], unsigned int **mem, unsigned int init[59049][2] )
{ {
unsigned long a = 0, c = 0, d = 0; unsigned int a = 0, c = 0, d = 0;
int x; int x;
int c_id=0, d_id=0; int c_id=0, d_id=0;
for (;;) for (;;)
...@@ -281,12 +281,12 @@ void exec( int flag[59049], unsigned long **mem, unsigned long init[59049][2] ) ...@@ -281,12 +281,12 @@ void exec( int flag[59049], unsigned long **mem, unsigned long init[59049][2] )
static inline static inline
#endif #endif
unsigned long op( unsigned long x, unsigned long y ) unsigned int op( unsigned int x, unsigned int y )
{ {
unsigned long i = 0, j; unsigned int i = 0, j;
static const unsigned long p9[10] = static const unsigned int p9[10] =
{ 1, 9, 81, 729, 6561 ,59049, 531441, 4782969, 43046721, 387420489}; { 1, 9, 81, 729, 6561 ,59049, 531441, 4782969, 43046721, 387420489};
static const unsigned long o[9][9] = static const unsigned int o[9][9] =
{ {
{ 4, 3, 3, 1, 0, 0, 1, 0, 0 }, { 4, 3, 3, 1, 0, 0, 1, 0, 0 },
{ 4, 3, 5, 1, 0, 2, 1, 0, 2 }, { 4, 3, 5, 1, 0, 2, 1, 0, 2 },
......