diff --git a/array.h b/array.h index 498977e..5b30b94 100644 --- a/array.h +++ b/array.h @@ -53,6 +53,7 @@ void *array_set( variable *arr1, variable *key, variable *value ) { if( ! exists ) { arr->length++; } + } variable * array_get( variable *arr1, variable *key ) { @@ -136,7 +137,7 @@ int array_len1( array *arr1 ) { return arr->i++ < arr->length; }*/ -void * set_val( variable *a, variable *b ) { +void * array_set_val( variable *a, variable *b ) { *a = *b; } diff --git a/conf.h b/conf.h index 8ebc3d2..0900d9f 100644 --- a/conf.h +++ b/conf.h @@ -1 +1 @@ -#define Assembly 1 \ No newline at end of file +#define Assembly 0 \ No newline at end of file diff --git a/do-x86.h b/do-x86.h index 3da04b2..fabcf45 100644 --- a/do-x86.h +++ b/do-x86.h @@ -163,7 +163,8 @@ do_call_function_callback( l ) { int i = do_before_call_function(); - do_call_var( l ); + if( l ) + do_call_var( l ); #if Assembly printf("mov %d, %%ecx\n", ind); @@ -657,7 +658,7 @@ do_call_array(l) { expr(); function_set_arg(1); - function_call( &set_val, "set_val" ); + function_call( &array_set_val, "array_set_val" ); function_end(2); @@ -693,7 +694,7 @@ do_call_object( tokens *ctoks ) { expr(); function_set_arg(1); - function_call( &set_val, "set_val" ); + function_call( &array_set_val, "array_set_val" ); function_end(2); } } @@ -776,24 +777,58 @@ do_call_class( tokens *btoks, tokens *toks ) { btoks->type = 3; set_tokv( btoks, toks->id, 0 ); - next(); - -/* - vars_init(); + char *cls = toks->id; - ivar = ivar - 4; - *(int *)indvar = -ivar; - int l = ivar; -*/ + next(); + //create object for class function_init(0); function_call( &do_fn_create_array, "do_fn_create_array" ); function_end(0); - //do_equal(l); - //do_call_var(l); int l = array_get1( &var_stk, btoks->id ); do_equal(l); + + //set class name and all methods address in object + char *t; + t = mstrcat(cls, "%fn%"); + + function_init(3); + function_set_arg(0); + dovar(a,"class",1); + do_call_num(a); + function_set_arg(1); + dovar(b,cls,1); + do_call_num(b); + function_set_arg(2); + function_call( &array_set, "array_set" ); + function_end(3); + + for( int i = 0; i < sym_stk.length ; i++ ) { + int p = strstr(sym_stk.key[i], t ); + if( p ) { + int ll = sym_stk.value[i]; + + int len = strlen(cls); + char *v = safe_alloc_new(&alloc, sizeof( char *) ); + v = sym_stk.key[i]; + v += len+1; + + do_call_var(l); + + function_init(3); + function_set_arg(0); + dovar(a1,v,1); + do_call_num(a1); + function_set_arg(1); + dovar(b1,ll,2); + do_call_num(b1); + function_set_arg(2); + function_call( &array_set, "array_set" ); + function_end(3); + + } + } } do_create_class() { @@ -992,13 +1027,6 @@ do_for_loop() { } -do_class() { - -} - -do_new() { - -} do_shift_left() { diff --git a/dolang.c b/dolang.c index 318e1c1..7fc6edc 100644 --- a/dolang.c +++ b/dolang.c @@ -530,15 +530,10 @@ unary() { } else if( toks.c == '(' ) { - btoks.type = 3; - int cls = get_tokv( &btoks, 0 ); - char *t; - t = mstrcat(cls, "%fn%"); - t = mstrcat(t, ctoks.id); - - - int l = array_get1( &sym_stk, t); + char *t; + t = mstrcat("fn%", ctoks.id); + if( i > 0 ) { int l1 = array_get1( &var_stk, id); do_call_var( l1 ); @@ -546,7 +541,19 @@ unary() { i++; - do_call_function_class(l, ""); + + function_init(2); + function_set_arg(0); + dovar(a,t,1); + do_call_num(a); + function_set_arg(1); + function_call( &array_get, "array_get" ); + function_end(2); + + do_get_val(); + + do_call_function_callback(0); + } else { do_call_object(&ctoks); } @@ -628,7 +635,7 @@ sum(l) { } else if( btoks.t == 2018 ) { do_or(); } else if( btoks.t == 2019 ) { - do_or_or(); + //do_or_or(); } else if( btoks.t == 2020 ) { } else if( btoks.t == 2021 ) { do_div(); @@ -656,10 +663,10 @@ sum(l) { *ind++ = 0xb8; *ind = 1; ind += 4; - +/* printf("%d\n", ind - a + 4 ); exit(0); - +*/ *(int *)a = ind - a + 4; //00 00 00 00; } diff --git a/ext.h b/ext.h index fa6b384..0e54046 100644 --- a/ext.h +++ b/ext.h @@ -8,7 +8,7 @@ set_extensions() { array_set1( &ext, "array_len", &array_len); array_set1( &ext, "array_set", &array_set); array_set1( &ext, "array_get", &array_get); - array_set1( &ext, "set_val", &set_val); + array_set1( &ext, "array_set_val", &array_set_val); array_set1( &ext, "strcat", &mstrcat); array_set1( &ext, "microtime", &do_microtime); } \ No newline at end of file diff --git a/test/classAsParam.do b/test/classAsParam.do new file mode 100644 index 0000000..02aa468 --- /dev/null +++ b/test/classAsParam.do @@ -0,0 +1,27 @@ +class test { + a() { + print("in a\n"); + } + + b() { + print("in b\n"); + } +} + + +test(d) { + d.a(); +} + +main() { + + var a = new test; + a.b = "Test"; + print("Test"); + + print( a ); + + test( a ); + + a.b(); +} \ No newline at end of file diff --git a/test/import.do b/test/import.do new file mode 100644 index 0000000..b33c017 --- /dev/null +++ b/test/import.do @@ -0,0 +1,6 @@ +import testClass; + +main() { + var a = new test; + a.a(); +} \ No newline at end of file diff --git a/test/operator.do b/test/operator.do new file mode 100644 index 0000000..863d926 --- /dev/null +++ b/test/operator.do @@ -0,0 +1,9 @@ +main() { + + var a = "test"; + var b = 123; + + if( a || b ) { + print("here") + } +} \ No newline at end of file diff --git a/test/testClass.do b/test/testClass.do new file mode 100644 index 0000000..b75d739 --- /dev/null +++ b/test/testClass.do @@ -0,0 +1,5 @@ +class test { + test() { + + } +} \ No newline at end of file