update

This commit is contained in:
ValKmjolnir 2023-07-01 00:55:00 +08:00
parent 8e4e4bfe89
commit 90ad1a53d7
6 changed files with 288 additions and 173 deletions

View File

@ -150,7 +150,7 @@ bool ast_dumper::visit_ternary_operator(ternary_operator* node) {
bool ast_dumper::visit_binary_operator(binary_operator* node) {
dump_indent();
std::cout << "binary_operator ";
switch(node->get_type()) {
switch(node->get_operator_type()) {
case binary_operator::binary_type::add: std::cout << "+"; break;
case binary_operator::binary_type::sub: std::cout << "-"; break;
case binary_operator::binary_type::mult: std::cout << "*"; break;
@ -180,7 +180,7 @@ bool ast_dumper::visit_binary_operator(binary_operator* node) {
bool ast_dumper::visit_unary_operator(unary_operator* node) {
dump_indent();
std::cout << "unary_operator ";
switch(node->get_type()) {
switch(node->get_operator_type()) {
case unary_operator::unary_type::negative: std::cout << "-"; break;
case unary_operator::unary_type::logical_not: std::cout << "!"; break;
case unary_operator::unary_type::bitwise_not: std::cout << "~"; break;

View File

@ -304,10 +304,10 @@ public:
expr(location, expr_type::ast_binary),
left(nullptr), right(nullptr) {}
~binary_operator();
void set_type(binary_type operator_type) {type = operator_type;}
void set_operator_type(binary_type operator_type) {type = operator_type;}
void set_left(expr* node) {left = node;}
void set_right(expr* node) {right = node;}
binary_type get_type() const {return type;}
binary_type get_operator_type() const {return type;}
expr* get_left() {return left;}
expr* get_right() {return right;}
void accept(ast_visitor*) override;
@ -330,9 +330,9 @@ public:
expr(location, expr_type::ast_unary),
value(nullptr) {}
~unary_operator();
void set_type(unary_type operator_type) {type = operator_type;}
void set_operator_type(unary_type operator_type) {type = operator_type;}
void set_value(expr* node) {value = node;}
unary_type get_type() const {return type;}
unary_type get_operator_type() const {return type;}
expr* get_value() {return value;}
void accept(ast_visitor*) override;
};
@ -454,10 +454,10 @@ public:
expr(location, expr_type::ast_assign),
left(nullptr), right(nullptr) {}
~assignment_expr();
void set_type(assign_type operator_type) {type = operator_type;}
void set_assignment_type(assign_type operator_type) {type = operator_type;}
void set_left(expr* node) {left = node;}
void set_right(expr* node) {right = node;}
assign_type get_type() const {return type;}
assign_type get_assignment_type() const {return type;}
expr* get_left() {return left;}
expr* get_right() {return right;}
void accept(ast_visitor*) override;

View File

@ -433,19 +433,68 @@ void codegen::def_gen(definition_expr* node) {
node->get_variable_name()? single_def(node):multi_def(node);
}
void codegen::multi_assign_gen(multi_assign* node) {
if (node[1]->get_type()==expr_type::ast_tuple && node[0].size()<node[1].size()) {
die("lack values in multi-assignment", node[1]->get_location());
} else if (node[1]->get_type()==expr_type::ast_tuple && node[0].size()>node[1].size()) {
die("too many values in multi-assignment", node[1]->get_location());
void codegen::assignment_gen(assignment_expr* node) {
switch(node->get_assignment_type()) {
case assignment_expr::assign_type::equal:
calc_gen(node->get_right());
mcall((call_expr*)node->get_left());
gen(op_meq, 0, node->get_location().begin_line);
break;
case assignment_expr::assign_type::add_equal:
case assignment_expr::assign_type::sub_equal:
case assignment_expr::assign_type::mult_equal:
case assignment_expr::assign_type::div_equal:
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
}
mcall((call_expr*)node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
gen(node->get_type()-ast_addeq+op_addeq, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(node->get_type()-ast_addeq+op_addeqc, num_table[num], node->get_location().begin_line);
}
break;
case assignment_expr::assign_type::concat_equal:
if (node[1]->get_type()!=ast_str) {
calc_gen(node[1]);
} else {
regist_str(node[1].str());
}
mcall(node[0]);
if (node[1]->get_type()!=ast_str) {
gen(op_lnkeq, 0, node->get_location().begin_line);
} else {
gen(op_lnkeqc, str_table[node[1].str()], node->get_location().begin_line);
}
break;
case assignment_expr::assign_type::bitwise_and_equal:
case assignment_expr::assign_type::bitwise_or_equal:
case assignment_expr::assign_type::bitwise_xor_equal:
calc_gen(node->get_right());
mcall((call_expr*)node->get_left());
gen(node->get_type()-ast_btandeq+op_btandeq, 0, node->get_location().begin_line);
break;
}
i32 size=node[0].size();
if (node[1]->get_type()==expr_type::ast_tuple) {
}
void codegen::multi_assign_gen(multi_assign* node) {
if (node->get_value()->get_type()==expr_type::ast_tuple &&
node->get_tuple()->get_elements().size()<((tuple_expr*)node->get_value())->get_elements().size()) {
die("lack values in multi-assignment", node->get_value()->get_location());
} else if (node->get_value()->get_type()==expr_type::ast_tuple &&
node->get_tuple()->get_elements().size()>((tuple_expr*)node->get_value())->get_elements().size()) {
die("too many values in multi-assignment", node->get_value()->get_location());
}
i32 size = node->get_tuple()->get_elements().size();
if (node->get_value()->get_type()==expr_type::ast_tuple) {
for(i32 i=size-1;i>=0;--i) {
calc_gen(node[1][i]);
calc_gen(((tuple_expr*)node->get_value())->get_elements()[i]);
}
auto& tuple = node->get_tuple()->get_elements();
for(i32 i=0;i<size;++i) {
mcall(node[0][i]);
mcall((call_expr*)tuple[i]);
// multi assign user loadl and loadg to avoid meq's stack--
// and this operation changes local and global value directly
if (code.back().op==op_mcalll) {
@ -455,16 +504,17 @@ void codegen::multi_assign_gen(multi_assign* node) {
} else if (code.back().op==op_mcallg) {
code.back().op=op_loadg;
} else {
gen(op_meq, 1, node[0][i]->get_location().begin_line);
gen(op_meq, 1, tuple[i]->get_location().begin_line);
}
}
} else {
calc_gen(node[1]);
calc_gen(node->get_value());
auto& tuple = node->get_tuple()->get_elements();
for(i32 i=0;i<size;++i) {
gen(op_callvi, i, node[1]->get_location().begin_line);
gen(op_callvi, i, node->get_value()->get_location().begin_line);
// multi assign user loadl and loadg to avoid meq's stack--
// and this operation changes local and global value directly
mcall(node[0][i]);
mcall((call_expr*)tuple[i]);
if (code.back().op==op_mcalll) {
code.back().op=op_loadl;
} else if (code.back().op==op_mupval) {
@ -472,7 +522,7 @@ void codegen::multi_assign_gen(multi_assign* node) {
} else if (code.back().op==op_mcallg) {
code.back().op=op_loadg;
} else {
gen(op_meq, 1, node[0][i]->get_location().begin_line);
gen(op_meq, 1, tuple[i]->get_location().begin_line);
}
}
gen(op_pop, 0, node->get_location().begin_line);
@ -481,25 +531,31 @@ void codegen::multi_assign_gen(multi_assign* node) {
void codegen::cond_gen(condition_expr* node) {
std::vector<usize> jmp_label;
for(auto& tmp:node.child()) {
if (tmp->get_type()==expr_type::ast_if || tmp->get_type()==expr_type::ast_elsif) {
calc_gen(tmp[0]);
usize ptr=code.size();
gen(op_jf, 0, tmp->get_location().begin_line);
block_gen(tmp[1]);
// without 'else' the last condition doesn't need to jmp
if (&tmp!=&node.child().back()) {
jmp_label.push_back(code.size());
gen(op_jmp, 0, tmp->get_location().begin_line);
}
code[ptr].num=code.size();
} else {
block_gen(tmp[0]);
break;
calc_gen(node->get_if_statement()->get_condition());
auto ptr = code.size();
gen(op_jf, 0, node->get_if_statement()->get_location().begin_line);
block_gen(node->get_if_statement()->get_code_block());
code[ptr].num = code.size();
for(auto tmp : node->get_elsif_stataments()) {
calc_gen(tmp->get_condition());
ptr = code.size();
gen(op_jf, 0, tmp->get_location().begin_line);
block_gen(tmp->get_code_block());
// the last condition doesn't need to jmp
if (tmp!=node->get_elsif_stataments().back() ||
node->get_else_statement()) {
jmp_label.push_back(code.size());
gen(op_jmp, 0, tmp->get_location().begin_line);
}
code[ptr].num=code.size();
}
if (node->get_else_statement()) {
block_gen(node->get_else_statement()->get_code_block());
}
for(auto i:jmp_label) {
code[i].num=code.size();
code[i].num = code.size();
}
}
@ -712,6 +768,156 @@ void codegen::and_gen(binary_operator* node) {
// jt jumps here
}
void codegen::unary_gen(unary_operator* node) {
calc_gen(node->get_value());
switch(node->get_operator_type()) {
case unary_operator::unary_type::negative:
gen(op_usub, 0, node->get_location().begin_line); break;
case unary_operator::unary_type::logical_not:
gen(op_lnot, 0, node->get_location().begin_line); break;
case unary_operator::unary_type::bitwise_not:
gen(op_bnot, 0, node->get_location().begin_line); break;
}
}
void codegen::binary_gen(binary_operator* node) {
switch(node->get_operator_type()) {
case binary_operator::binary_type::condition_or: or_gen(node); return;
case binary_operator::binary_type::condition_and: and_gen(node); return;
default: break;
}
switch(node->get_operator_type()) {
case binary_operator::binary_type::cmpeq:
calc_gen(node->get_left());
calc_gen(node->get_right());
gen(op_eq, 0, node->get_location().begin_line);
return;
case binary_operator::binary_type::cmpneq:
calc_gen(node->get_left());
calc_gen(node->get_right());
gen(op_neq, 0, node->get_location().begin_line);
return;
case binary_operator::binary_type::bitwise_or:
calc_gen(node->get_left());
calc_gen(node->get_right());
gen(op_btor, 0, node->get_location().begin_line);
return;
case binary_operator::binary_type::bitwise_xor:
calc_gen(node->get_left());
calc_gen(node->get_right());
gen(op_btxor, 0, node->get_location().begin_line);
return;
case binary_operator::binary_type::bitwise_and:
calc_gen(node->get_left());
calc_gen(node->get_right());
gen(op_btand, 0, node->get_location().begin_line);
return;
default: break;
}
switch(node->get_operator_type()) {
case binary_operator::binary_type::add:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_add, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_addc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::sub:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_sub, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_subc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::mult:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_mul, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_mulc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::div:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_div, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_divc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::concat:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_str) {
calc_gen(node->get_right());
gen(op_lnk, 0, node->get_location().begin_line);
} else {
const auto& str = ((string_literal*)node->get_right())->get_content();
regist_str(str);
gen(op_lnkc, str_table[str], node->get_location().begin_line);
}
break;
// ast_cmpeq(27)~ast_geq(32) op_eq(29)~op_geq(34)
case binary_operator::binary_type::less:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_less, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_lessc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::leq:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_leq, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_leqc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::grt:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_grt, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_grtc, num_table[num], node->get_location().begin_line);
}
return;
case binary_operator::binary_type::geq:
calc_gen(node->get_left());
if (node->get_right()->get_type()!=expr_type::ast_num) {
calc_gen(node->get_right());
gen(op_geq, 0, node->get_location().begin_line);
} else {
auto num = ((number_literal*)node->get_right())->get_number();
regist_num(num);
gen(op_geqc, num_table[num], node->get_location().begin_line);
}
return;
}
}
void codegen::trino_gen(ternary_operator* node) {
calc_gen(node->get_condition());
usize lfalse=code.size();
@ -727,7 +933,7 @@ void codegen::trino_gen(ternary_operator* node) {
void codegen::calc_gen(expr* node) {
switch(node->get_type()) {
case expr_type::ast_nil:
gen(op_pnil,0,node->get_location().begin_line); break;
gen(op_pnil, 0, node->get_location().begin_line); break;
case expr_type::ast_num:
num_gen((number_literal*)node); break;
case expr_type::ast_str:
@ -744,110 +950,14 @@ void codegen::calc_gen(expr* node) {
func_gen((function*)node); break;
case expr_type::ast_call:
call_gen((call_expr*)node); break;
case expr_type::ast_equal:
calc_gen(node[1]);
mcall(node[0]);
gen(op_meq, 0, node->get_location().begin_line);
break;
// ast_addeq(22)~ast_lnkeq(26) op_addeq(23)~op_lnkeq(27)
case expr_type::ast_addeq:case expr_type::ast_subeq:case expr_type::ast_multeq:case expr_type::ast_diveq:
if (node[1]->get_type()!=ast_num) {
calc_gen(node[1]);
}
mcall(node[0]);
if (node[1]->get_type()!=ast_num) {
gen(node->get_type()-ast_addeq+op_addeq, 0, node->get_location().begin_line);
} else {
regist_num(node[1].num());
gen(node->get_type()-ast_addeq+op_addeqc, num_table[node[1].num()], node->get_location().begin_line);
}
break;
case expr_type::ast_lnkeq:
if (node[1]->get_type()!=ast_str) {
calc_gen(node[1]);
} else {
regist_str(node[1].str());
}
mcall(node[0]);
if (node[1]->get_type()!=ast_str) {
gen(op_lnkeq, 0, node->get_location().begin_line);
} else {
gen(op_lnkeqc, str_table[node[1].str()], node->get_location().begin_line);
}
break;
case expr_type::ast_btandeq:case expr_type::ast_btoreq:case expr_type::ast_btxoreq:
calc_gen(node[1]);
mcall(node[0]);
gen(node->get_type()-ast_btandeq+op_btandeq, 0, node->get_location().begin_line);
break;
case expr_type::ast_or:or_gen(node);break;
case expr_type::ast_and:and_gen(node);break;
// ast_add(33)~ast_link(37) op_add(18)~op_lnk(22)
case expr_type::ast_add:case expr_type::ast_sub:case expr_type::ast_mult:case expr_type::ast_div:
calc_gen(node[0]);
if (node[1]->get_type()!=ast_num) {
calc_gen(node[1]);
gen(node->get_type()-ast_add+op_add, 0, node->get_location().begin_line);
} else {
regist_num(node[1].num());
gen(node->get_type()-ast_add+op_addc, num_table[node[1].num()], node->get_location().begin_line);
}
break;
case expr_type::ast_link:
calc_gen(node[0]);
if (node[1]->get_type()!=ast_str) {
calc_gen(node[1]);
gen(op_lnk, 0, node->get_location().begin_line);
} else {
regist_str(node[1].str());
gen(op_lnkc, str_table[node[1].str()], node->get_location().begin_line);
}
break;
// ast_cmpeq(27)~ast_geq(32) op_eq(29)~op_geq(34)
case expr_type::ast_cmpeq:case expr_type::ast_neq:
calc_gen(node[0]);
calc_gen(node[1]);
gen(node->get_type()-ast_cmpeq+op_eq, 0, node->get_location().begin_line);
break;
case expr_type::ast_less:case expr_type::ast_leq:case expr_type::ast_grt:case expr_type::ast_geq:
calc_gen(node[0]);
if (node[1]->get_type()!=ast_num) {
calc_gen(node[1]);
gen(node->get_type()-ast_less+op_less, 0, node->get_location().begin_line);
} else {
regist_num(node[1].num());
gen(node->get_type()-ast_less+op_lessc, num_table[node[1].num()], node->get_location().begin_line);
}
break;
case expr_type::ast_assign:
assignment_gen((assignment_expr*)node); break;
case expr_type::ast_ternary:
trino_gen((ternary_operator*)node);break;
case expr_type::ast_neg:
calc_gen(node[0]);
gen(op_usub, 0, node->get_location().begin_line);
break;
case expr_type::ast_lnot:
calc_gen(node[0]);
gen(op_lnot, 0, node->get_location().begin_line);
break;
case expr_type::ast_bnot:
calc_gen(node[0]);
gen(op_bnot, 0, node->get_location().begin_line);
break;
case expr_type::ast_bitor:
calc_gen(node[0]);
calc_gen(node[1]);
gen(op_btor, 0, node->get_location().begin_line);
break;
case expr_type::ast_bitxor:
calc_gen(node[0]);
calc_gen(node[1]);
gen(op_btxor, 0, node->get_location().begin_line);
break;
case expr_type::ast_bitand:
calc_gen(node[0]);
calc_gen(node[1]);
gen(op_btand, 0, node->get_location().begin_line);
break;
trino_gen((ternary_operator*)node); break;
case expr_type::ast_unary:
unary_gen((unary_operator*)node); break;
case expr_type::ast_binary:
binary_gen((binary_operator*)node); break;
case expr_type::ast_def:
single_def((definition_expr*)node);
call_id(((definition_expr*)node)->get_variable_name());

View File

@ -75,6 +75,8 @@ private:
void multi_def(definition_expr*);
void single_def(definition_expr*);
void def_gen(definition_expr*);
void assignment_gen(assignment_expr*);
void assign_statement(assignment_expr*);
void multi_assign_gen(multi_assign*);
void cond_gen(condition_expr*);
void loop_gen(expr*);
@ -86,6 +88,8 @@ private:
void foreach_gen(forei_expr*);
void or_gen(binary_operator*);
void and_gen(binary_operator*);
void unary_gen(unary_operator*);
void binary_gen(binary_operator*);
void trino_gen(ternary_operator*);
void calc_gen(expr*);
void block_gen(code_block*);

View File

@ -401,12 +401,12 @@ expr* parse::calc() {
} else if (tok::eq<=toks[ptr].type && toks[ptr].type<=tok::lnkeq) {
auto tmp = new assignment_expr(toks[ptr].loc);
switch(toks[ptr].type) {
case tok::eq: tmp->set_type(assignment_expr::assign_type::equal); break;
case tok::addeq: tmp->set_type(assignment_expr::assign_type::add_equal); break;
case tok::subeq: tmp->set_type(assignment_expr::assign_type::sub_equal); break;
case tok::multeq: tmp->set_type(assignment_expr::assign_type::mult_equal); break;
case tok::diveq: tmp->set_type(assignment_expr::assign_type::div_equal); break;
case tok::lnkeq: tmp->set_type(assignment_expr::assign_type::concat_equal); break;
case tok::eq: tmp->set_assignment_type(assignment_expr::assign_type::equal); break;
case tok::addeq: tmp->set_assignment_type(assignment_expr::assign_type::add_equal); break;
case tok::subeq: tmp->set_assignment_type(assignment_expr::assign_type::sub_equal); break;
case tok::multeq: tmp->set_assignment_type(assignment_expr::assign_type::mult_equal); break;
case tok::diveq: tmp->set_assignment_type(assignment_expr::assign_type::div_equal); break;
case tok::lnkeq: tmp->set_assignment_type(assignment_expr::assign_type::concat_equal); break;
default: break;
}
tmp->set_left(node);
@ -416,9 +416,9 @@ expr* parse::calc() {
} else if (toks[ptr].type==tok::btandeq || toks[ptr].type==tok::btoreq || toks[ptr].type==tok::btxoreq) {
auto tmp = new assignment_expr(toks[ptr].loc);
switch(toks[ptr].type) {
case tok::btandeq: tmp->set_type(assignment_expr::assign_type::bitwise_and_equal); break;
case tok::btoreq: tmp->set_type(assignment_expr::assign_type::bitwise_or_equal); break;
case tok::btxoreq: tmp->set_type(assignment_expr::assign_type::bitwise_xor_equal); break;
case tok::btandeq: tmp->set_assignment_type(assignment_expr::assign_type::bitwise_and_equal); break;
case tok::btoreq: tmp->set_assignment_type(assignment_expr::assign_type::bitwise_or_equal); break;
case tok::btxoreq: tmp->set_assignment_type(assignment_expr::assign_type::bitwise_xor_equal); break;
default: break;
}
tmp->set_left(node);
@ -434,7 +434,7 @@ expr* parse::bitwise_or() {
auto node = bitwise_xor();
while(lookahead(tok::btor)) {
auto tmp = new binary_operator(toks[ptr].loc);
tmp->set_type(binary_operator::binary_type::bitwise_or);
tmp->set_operator_type(binary_operator::binary_type::bitwise_or);
tmp->set_left(node);
match(tok::btor);
tmp->set_right(bitwise_xor());
@ -449,7 +449,7 @@ expr* parse::bitwise_xor() {
auto node = bitwise_and();
while(lookahead(tok::btxor)) {
auto tmp = new binary_operator(toks[ptr].loc);
tmp->set_type(binary_operator::binary_type::bitwise_xor);
tmp->set_operator_type(binary_operator::binary_type::bitwise_xor);
tmp->set_left(node);
match(tok::btxor);
tmp->set_right(bitwise_and());
@ -464,7 +464,7 @@ expr* parse::bitwise_and() {
auto node = or_expr();
while(lookahead(tok::btand)) {
auto tmp = new binary_operator(toks[ptr].loc);
tmp->set_type(binary_operator::binary_type::bitwise_and);
tmp->set_operator_type(binary_operator::binary_type::bitwise_and);
tmp->set_left(node);
match(tok::btand);
tmp->set_right(or_expr());
@ -479,7 +479,7 @@ expr* parse::or_expr() {
auto node = and_expr();
while(lookahead(tok::opor)) {
auto tmp = new binary_operator(toks[ptr].loc);
tmp->set_type(binary_operator::binary_type::condition_or);
tmp->set_operator_type(binary_operator::binary_type::condition_or);
tmp->set_left(node);
match(tok::opor);
tmp->set_right(and_expr());
@ -494,7 +494,7 @@ expr* parse::and_expr() {
auto node = cmp_expr();
while(lookahead(tok::opand)) {
auto tmp = new binary_operator(toks[ptr].loc);
tmp->set_type(binary_operator::binary_type::condition_and);
tmp->set_operator_type(binary_operator::binary_type::condition_and);
tmp->set_left(node);
match(tok::opand);
tmp->set_right(cmp_expr());
@ -510,12 +510,12 @@ expr* parse::cmp_expr() {
while(tok::cmpeq<=toks[ptr].type && toks[ptr].type<=tok::geq) {
auto tmp = new binary_operator(toks[ptr].loc);
switch(toks[ptr].type) {
case tok::cmpeq: tmp->set_type(binary_operator::binary_type::cmpeq); break;
case tok::neq: tmp->set_type(binary_operator::binary_type::cmpneq); break;
case tok::less: tmp->set_type(binary_operator::binary_type::less); break;
case tok::leq: tmp->set_type(binary_operator::binary_type::leq); break;
case tok::grt: tmp->set_type(binary_operator::binary_type::grt); break;
case tok::geq: tmp->set_type(binary_operator::binary_type::geq); break;
case tok::cmpeq: tmp->set_operator_type(binary_operator::binary_type::cmpeq); break;
case tok::neq: tmp->set_operator_type(binary_operator::binary_type::cmpneq); break;
case tok::less: tmp->set_operator_type(binary_operator::binary_type::less); break;
case tok::leq: tmp->set_operator_type(binary_operator::binary_type::leq); break;
case tok::grt: tmp->set_operator_type(binary_operator::binary_type::grt); break;
case tok::geq: tmp->set_operator_type(binary_operator::binary_type::geq); break;
default: break;
}
tmp->set_left(node);
@ -533,9 +533,9 @@ expr* parse::additive_expr() {
while(lookahead(tok::add) || lookahead(tok::sub) || lookahead(tok::floater)) {
auto tmp = new binary_operator(toks[ptr].loc);
switch(toks[ptr].type) {
case tok::add: tmp->set_type(binary_operator::binary_type::add); break;
case tok::sub: tmp->set_type(binary_operator::binary_type::sub); break;
case tok::floater: tmp->set_type(binary_operator::binary_type::concat); break;
case tok::add: tmp->set_operator_type(binary_operator::binary_type::add); break;
case tok::sub: tmp->set_operator_type(binary_operator::binary_type::sub); break;
case tok::floater: tmp->set_operator_type(binary_operator::binary_type::concat); break;
default: break;
}
tmp->set_left(node);
@ -553,9 +553,9 @@ expr* parse::multive_expr() {
while(lookahead(tok::mult) || lookahead(tok::div)) {
auto tmp = new binary_operator(toks[ptr].loc);
if (lookahead(tok::mult)) {
tmp->set_type(binary_operator::binary_type::mult);
tmp->set_operator_type(binary_operator::binary_type::mult);
} else {
tmp->set_type(binary_operator::binary_type::div);
tmp->set_operator_type(binary_operator::binary_type::div);
}
tmp->set_left(node);
match(toks[ptr].type);
@ -571,15 +571,15 @@ unary_operator* parse::unary() {
auto node = new unary_operator(toks[ptr].loc);
switch(toks[ptr].type) {
case tok::sub:
node->set_type(unary_operator::unary_type::negative);
node->set_operator_type(unary_operator::unary_type::negative);
match(tok::sub);
break;
case tok::opnot:
node->set_type(unary_operator::unary_type::logical_not);
node->set_operator_type(unary_operator::unary_type::logical_not);
match(tok::opnot);
break;
case tok::floater:
node->set_type(unary_operator::unary_type::bitwise_not);
node->set_operator_type(unary_operator::unary_type::bitwise_not);
match(tok::floater);
break;
default: break;

View File

@ -5,9 +5,10 @@ var http=func(){
return {
establish:func(ip,port){
sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP);
if(socket.bind(sd,ip,port)<0){
println("failed to bind socket "~sd~" at IP: "~ip~" port: "~port~".");
return;
while(socket.bind(sd,ip,port)<0){
println("[",os.time(),"] failed to bind socket "~sd~" at IP: "~ip~" port: "~port~".");
unix.sleep(5);
println("[",os.time(),"] retrying...");
}
socket.listen(sd,1);
println("[",os.time(),"] start server at [",ip,":",port,"]");