Skip to content

Commit

Permalink
Decode what he's doing in prime.wsa
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebath committed Aug 18, 2015
1 parent 6727751 commit 196efd6
Showing 1 changed file with 77 additions and 66 deletions.
143 changes: 77 additions & 66 deletions gen-prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,102 +9,113 @@ ws_pushs("prim numbers [2-100]");
ws_call(atom("printsln"));


{
// for(i=0; i<100; i++) memory[100+i] = 1;

ws_push(0);
//for loop
ws_label(atom("f_start_1"));
ws_dup(); ws_push(100); ws_sub();
ws_jz(atom("f_finished_1"));
ws_push(0);
//for loop
ws_label(atom("f_start_1"));
ws_dup(); ws_push(100); ws_sub();
ws_jz(atom("f_finished_1"));

ws_dup();
ws_push(100); ws_add();
ws_push(1);
ws_store();
ws_dup();
ws_push(100); ws_add();
ws_push(1);
ws_store();

ws_push(1); ws_add();
ws_jump(atom("f_start_1"));
ws_push(1); ws_add();
ws_jump(atom("f_start_1"));

ws_label(atom("f_finished_1"));
ws_drop();
ws_label(atom("f_finished_1"));
ws_drop();
}

//debug_printstack
//debug_printheap

ws_push(2);
//for loop
ws_label(atom("f_start_2"));
ws_dup(); ws_push(11); ws_sub();
ws_jz(atom("f_finished_2"));
{
/*
for(i=2; i<11; i++)
for(j=2; j<100; j++)
memory[100+i*j] = 0;
*/

ws_push(2);
//for loop
ws_label(atom("f_start_2"));
ws_dup(); ws_push(11); ws_sub();
ws_jz(atom("f_finished_2"));


ws_push(2);
//for loop
ws_label(atom("f_start_3"));
ws_dup(); ws_push(100); ws_sub();
ws_jz(atom("f_finished_3"));

ws_dup();
ws_push(1);
ws_swap();
ws_store();
ws_push(2);
//for loop
ws_label(atom("f_start_3"));
ws_dup(); ws_push(100); ws_sub();
ws_jz(atom("f_finished_3"));

ws_swap();
ws_dup();
ws_push(1);
ws_swap();
ws_store();

ws_dup();
ws_push(2);
ws_swap();
ws_store();
ws_swap();

ws_swap();
ws_dup();
ws_push(2);
ws_swap();
ws_store();

ws_push(1); ws_fetch();
ws_push(2); ws_fetch();
ws_mul();
ws_push(100); ws_add();
ws_swap();

ws_push(0);
ws_store();
ws_push(1); ws_fetch();
ws_push(2); ws_fetch();
ws_mul();
ws_push(100); ws_add();

ws_push(1); ws_add();
ws_push(0);
ws_store();

ws_jump(atom("f_start_3"));
ws_label(atom("f_finished_3"));
ws_drop();
ws_push(1); ws_add();

ws_jump(atom("f_start_3"));
ws_label(atom("f_finished_3"));
ws_drop();

ws_push(1); ws_add();

ws_jump(atom("f_start_2"));
ws_label(atom("f_finished_2"));
ws_drop();

ws_push(1); ws_add();

ws_jump(atom("f_start_2"));
ws_label(atom("f_finished_2"));
ws_drop();
}

ws_push(2);
//for loop
ws_label(atom("f_start_4"));
ws_dup(); ws_push(100); ws_sub();
ws_jz(atom("f_finished_4"));
{
ws_push(2);
//for loop
ws_label(atom("f_start_4"));
ws_dup(); ws_push(100); ws_sub();
ws_jz(atom("f_finished_4"));

ws_dup();
ws_push(100); ws_add();
ws_fetch();
ws_jz(atom("nodraw"));
ws_dup();
ws_push(100); ws_add();
ws_fetch();
ws_jz(atom("nodraw"));

ws_dup();
ws_outn();
ws_dup();
ws_outn();

ws_pushs(" ");
ws_call(atom("prints"));
ws_pushs(" ");
ws_call(atom("prints"));

ws_label(atom("nodraw"));
ws_label(atom("nodraw"));

ws_push(1); ws_add();
ws_jump(atom("f_start_4"));
ws_push(1); ws_add();
ws_jump(atom("f_start_4"));

ws_label(atom("f_finished_4"));
ws_drop();
ws_label(atom("f_finished_4"));
ws_drop();
}

ws_push(0);
ws_call(atom("printsln"));
Expand Down

0 comments on commit 196efd6

Please sign in to comment.