Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class d_list_int
- {
- private:
- int *content;
- int c_count;
- int c_lenght;
- static const int max_count = 1024;
- void increase_size()
- {
- int *t = new int[c_lenght + 1];
- for(int i = 0; i < c_lenght; i++)
- {
- t[i] = content[i];
- }
- content = t;
- c_lenght++;
- }
- public:
- d_list_int()
- {
- content = new int {0};
- c_count = 1;
- c_lenght = 1;
- }
- void push_at_back(int val)
- {
- if(c_count + 1 >= max_count)
- {
- cerr << "PEREPOLNRNIE STEKA!!!!!" << endl;
- cerr << "ELEMENT NE DOBAVLEN!!!!" << endl;
- return;
- }
- if(c_count + 1 >= c_lenght) increase_size();
- content[c_count] = val;
- c_count++;
- }
- int get_last_val()
- {
- if(c_count < 2) return content[0];
- c_count--;
- return content[c_count];
- }
- int get_lenght()
- {
- return c_count;
- }
- int get_first_val()
- {
- return content[0];
- }
- void set_first_val(int val)
- {
- content[0] = val;
- }
- };
- class d_list_pointer
- {
- private:
- void* *content;
- int c_count;
- int c_lenght;
- static const int max_count = 1024;
- void increase_size()
- {
- void* *t = new void*[c_lenght + 1];
- for(int i = 0; i < c_lenght; i++)
- {
- t[i] = content[i];
- }
- content = t;
- c_lenght++;
- }
- public:
- d_list_pointer(void *nlptr)
- {
- content = new void* {nlptr};
- c_count = 1;
- c_lenght = 1;
- }
- void push_at_back(void *val)
- {
- if(c_count + 1 >= max_count)
- {
- cerr << "PEREPOLNRNIE STEKA!!!!!" << endl;
- cerr << "ELEMENT NE DOBAVLEN!!!!" << endl;
- return;
- }
- if(c_count + 1 >= c_lenght) increase_size();
- content[c_count] = val;
- c_count++;
- }
- void* get_last_val()
- {
- if(c_count < 2) return content[0];
- c_count--;
- return content[c_count];
- }
- int get_lenght()
- {
- return c_count;
- }
- void* get_first_val()
- {
- return content[0];
- }
- };
- int main()
- {
- cout << "Hello world! Just do magick!" << endl;
- int values[1024];
- d_list_int prg_stack;
- d_list_pointer prg_pointers(&&END_PROGRAM);
- void *portal = &&START_PROGRAM;
- goto *portal;
- // FUNCTIONS --------------------------------------------------------------------
- // Add(x, y) = x + y --
- func_add_2:
- {
- int a = prg_stack.get_last_val();
- int b = prg_stack.get_last_val();
- prg_stack.push_at_back(a + b);
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // --------------------
- // Inc(x) = x + 1 -----
- func_inc_1:
- {
- int x = prg_stack.get_last_val();
- x++;
- prg_stack.push_at_back(x);
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // --------------------
- // Negative(x) = -x ---
- func_negative_1:
- {
- int x = prg_stack.get_last_val();
- prg_stack.push_at_back(-x);
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // --------------------
- // Subtract(x, y) = x - y
- func_subtract_2:
- {
- prg_pointers.push_at_back(&&func_subtract_2_return_point_1);
- goto func_negative_1;
- func_subtract_2_return_point_1:
- prg_pointers.push_at_back(&&func_subtract_2_return_point_2);
- goto func_add_2;
- func_subtract_2_return_point_2:
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // --------------------
- // dec(x) = x - 1
- func_dec_1:
- {
- prg_stack.push_at_back(1);
- prg_pointers.push_at_back(&&func_subtract_2_return_point_1);
- goto func_subtract_2;
- func_dec_1_return_point_1:
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // --------------------
- // Min(x, y) ---------
- func_min_2:
- {
- int a = prg_stack.get_last_val();
- int b = prg_stack.get_last_val();
- if(a < b) prg_stack.push_at_back(a);
- else prg_stack.push_at_back(b);
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // -------------------
- // Max(x, y) ---------
- func_max_2:
- {
- int a = prg_stack.get_last_val();
- int b = prg_stack.get_last_val();
- if(a > b) prg_stack.push_at_back(a);
- else prg_stack.push_at_back(b);
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- // -------------------
- // Mult(x, y) = x * y -
- func_mult_2:
- {
- int a = prg_stack.get_last_val();
- int b = prg_stack.get_last_val();
- if(b == 0)
- {
- prg_stack.push_at_back(0);
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- if(a < b)
- {
- prg_stack.push_at_back(a);
- a = b;
- b = prg_stack.get_last_val();
- }
- prg_stack.push_at_back(0);
- prg_stack.push_at_back(a);
- prg_stack.push_at_back(b);
- func_mult_2_loop_1:
- {
- int b = prg_stack.get_last_val();
- int a = prg_stack.get_last_val();
- prg_stack.push_at_back(a);
- prg_pointers.push_at_back(&&func_mult_2_return_point_1); //
- goto func_add_2; // res += a;
- func_mult_2_return_point_1: //
- prg_stack.push_at_back(b);
- prg_pointers.push_at_back(&&func_mult_2_return_point_2); //
- goto func_dec_1; // b--;
- func_mult_2_return_point_2: //
- b = prg_stack.get_last_val();
- if(b == 0)
- {
- portal = prg_pointers.get_last_val();
- goto *portal;
- }
- prg_stack.push_at_back(a);
- prg_stack.push_at_back(b);
- goto func_mult_2_loop_1;
- }
- }
- // --------------------
- // START --------------------------------------------------------------------
- START_PROGRAM:
- int x, y, z;
- cin >> x >> y;
- prg_stack.push_at_back(x);
- prg_stack.push_at_back(y);
- prg_pointers.push_at_back(&&return_point_1);
- goto func_mult_2;
- return_point_1:
- z = prg_stack.get_last_val();
- cout << z << endl;
- END_PROGRAM:
- // END ----------------------------------------------------------------------
- //getch();
- return prg_stack.get_first_val();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement