Skip to content

Commit

Permalink
e
Browse files Browse the repository at this point in the history
  • Loading branch information
pejman-hkh committed Aug 3, 2022
1 parent 66ff7e5 commit 6a9fea4
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 35 deletions.
3 changes: 2 additions & 1 deletion array.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void *array_set( variable *arr1, variable *key, variable *value ) {
if( ! exists ) {
arr->length++;
}

}

variable * array_get( variable *arr1, variable *key ) {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion conf.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define Assembly 1
#define Assembly 0
68 changes: 48 additions & 20 deletions do-x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -992,13 +1027,6 @@ do_for_loop() {
}


do_class() {

}

do_new() {

}

do_shift_left() {

Expand Down
31 changes: 19 additions & 12 deletions dolang.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,30 @@ 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 );
}

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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
27 changes: 27 additions & 0 deletions test/classAsParam.do
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 6 additions & 0 deletions test/import.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import testClass;

main() {
var a = new test;
a.a();
}
9 changes: 9 additions & 0 deletions test/operator.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
main() {

var a = "test";
var b = 123;

if( a || b ) {
print("here")
}
}
5 changes: 5 additions & 0 deletions test/testClass.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class test {
test() {

}
}

0 comments on commit 6a9fea4

Please sign in to comment.