/*

JavaScript to C++ translator generated C++ code.

Version: 1.0.0
Date: Wed Apr 24 19:37:35 2019


*/

#include "js.h"

//
// START PROGRAM DECLARATION
//

using namespace std;

using namespace eval_function;

void * js::java_script_pointer = 0;

eval_engine * eval_function::p_eval_engine = 0;

class ARRAY ;
class TEST ;
class START ;
class ARRAY : public Function {
public :
Var operator ( ) ( ArgArray * _args = 0 ) ; 
Function * new_instence() const { return new ARRAY(); }
} ;

class TEST : public Function {
public :
Var operator ( ) ( ArgArray * _args = 0 ) ; 
Function * new_instence() const { return new TEST(); }
} ;

class START : public Function {
public :
Var operator ( ) ( ArgArray * _args = 0 ) ; 
Function * new_instence() const { return new START(); }
} ;

ARRAY Array ;
TEST test ;
START start ;
Var __Array ( ArgArray * _args = 0 ) ;
Var __test ( ArgArray * _args = 0 ) ;

Var * __Array_new ( ArgArray * _args = 0 ) ;
Var * __test_new ( ArgArray * _args = 0 ) ;

Var __Array ( ArgArray * _args ) {
return Array ( _args ) ;
}

Var __test ( ArgArray * _args ) {
return test ( _args ) ;
}

Var * __Array_new ( ArgArray * _args ) {
Var temp = __Array ( _args ) ;
temp.type_code = Var::OBJECT_VALUE ;
temp.type_string = "Array" ;
Var * ret = new Var ( temp ) ;
ret->type_code = Var::OBJECT_VALUE ;
ret->type_string = "Array" ;
ret -> set_this ( ) ;
return ret ;
}

Var * __test_new ( ArgArray * _args ) {
Var temp = __test ( _args ) ;
temp.type_code = Var::OBJECT_VALUE ;
temp.type_string = "test" ;
Var * ret = new Var ( temp ) ;
ret->type_code = Var::OBJECT_VALUE ;
ret->type_string = "test" ;
ret -> set_this ( ) ;
return ret ;
}


Var the_array ;
Var i ;
Var matrix ;
Var j ;

Var ARRAY :: operator ( ) ( ArgArray * _args ) 
{
if(the_this == 0) the_this = new Var();
parent = the_this;


return *the_this;
}

Var TEST :: operator ( ) ( ArgArray * _args ) 
{
if(the_this == 0) the_this = new Var();
parent = the_this;

Var a =  __Array_new  ( ) ;

p_eval_engine->register_var("a", INT_VAR, a.get_pointer_value());
a [ a  . pointer -> get_member() [ "length" ]  ] = Var ( "HELLO" )  ;
a [ a  . pointer -> get_member() [ "length" ]  ] = Var ( "WORLD" )  ;
for ( Var i = Var ( 0 )  ;
i < a  . pointer -> get_member() [ "length" ]  ;
i ++ ) { 
p_eval_engine->register_var("i", INT_VAR, i.get_pointer_value());
 print (  auto_ptr < ArgArray > ( new ArgArray (  new Var ( a [ i ] )  ) ) . get ( )    ) ;
}
for ( Var i = Var ( 0 )  ;
i < a  . pointer -> get_member() [ "length" ]  ;
i ++ ) { 
p_eval_engine->register_var("i", INT_VAR, i.get_pointer_value());
 print (  auto_ptr < ArgArray > ( new ArgArray (  new Var ( a [ i ] )  ) ) . get ( )    ) ;
}

return *the_this;
}

Var START :: operator ( ) ( ArgArray * _args ) 
{

 the_array =  __Array_new  ( ) ;
the_array [ the_array . pointer -> get_member() [  "length" ]  ] = Var ( 100 )  ;
the_array [ the_array . pointer -> get_member() [  "length" ]  ] = Var ( 200 )  ;
for (  i = Var ( 0 )  ;
i < the_array . pointer -> get_member() [  "length" ]  ;
i ++ ) print (  auto_ptr < ArgArray > ( new ArgArray (  new Var ( the_array [ i ] )  ) ) . get ( )    ) ;
for (  i = Var ( 0 )  ;
i < the_array . pointer -> get_member() [  "length" ]  ;
i ++ ) {
print (  auto_ptr < ArgArray > ( new ArgArray (  new Var ( the_array [ i ] )  ) ) . get ( )    ) ;
}
test ( ) ;
 matrix =  __Array_new  ( ) ;
matrix [ Var ( 0 )  ] =  __Array_new  ( ) ;
matrix [ Var ( 1 )  ] =  __Array_new  ( ) ;
matrix [ Var ( 2 )  ] =  __Array_new  ( ) ;
for (  i = Var ( 0 )  ;
i < Var ( 3 )  ;
i ++ ) {
for (  j = Var ( 0 )  ;
j < Var ( 3 )  ;
j ++ ) {
matrix [ i ][ j ] = i * j ;
}
}
for (  i = Var ( 0 )  ;
i < Var ( 3 )  ;
i ++ ) {
for (  j = Var ( 0 )  ;
j < Var ( 3 )  ;
j ++ ) {
print (  auto_ptr < ArgArray > ( new ArgArray (  new Var ( matrix [ i ][ j ] )  ) ) . get ( )      ) ;
}
}
return Var();
}

void hello() { cout << "Hello...\n" << endl; }
extern "C" {
extern int main (int argc, char ** argv);
extern void script_init (void * rt, void * cx, void * obj);
}

int main (int argc, char ** argv)
{
{
ref_count_map_type temp_ref;
ref_count = &temp_ref;
int ret = 0 ;
ArgArray args ;
StringArrayVar * argv2  = new StringArrayVar ( "argv" ) ;
eval_engine e_engine;
p_eval_engine = &e_engine;
p_eval_engine->register_fun("Array", (void*)__Array, 0);
p_eval_engine->register_fun("test", (void*)__test, 0);
p_eval_engine->register_fun("read_file", (void*)read_file, 1);
p_eval_engine->register_fun("write_file", (void*)write_file, 2);
p_eval_engine->register_fun("split", (void*)split, 2);
p_eval_engine->register_fun("parseInt", (void*)parseInt, 1);
p_eval_engine->register_fun("print", (void*)print, 1);
p_eval_engine->register_fun("print2", (void*)print2, 1);
p_eval_engine->register_fun("exit", (void*)my_exit, 1);
p_eval_engine->register_fun("input", (void*)my_input, 1);
p_eval_engine->register_fun("eval", (void*)in_eval, 1);
for ( int i = 0 ; i < argc ; i ++ ) {
argv2  -> add_string ( new Var ( argv [ i ] ) ) ;
}
args . add ( argv2 ) ;
try {
start ( auto_ptr < ArgArray > ( to_param ( args.arg_count() , argv2 ) ) . get ( ) ) ;
ret = 0;
}
catch( js_exception se ) {
cout << "message: " << se.get_message() << endl << flush;
cout << "file: " << se.get_file() << endl << flush;
cout << "line: " << se.get_line() << endl << flush;
ret = 1;
}
catch( ... ) {
cout << "unknown exception..." << endl;
ret = 1;
}
cout << "ret0=" << ret << endl;
clean_ref();
cout << "ret1=" << ret << endl;
}

cout << "done0..." << endl;
return 0;
}

