cleanup + compiler tuple syntax

This commit is contained in:
xensik 2022-07-22 20:30:42 +02:00
parent 0fc0834a83
commit 3236e6e079
109 changed files with 17543 additions and 16069 deletions

View File

@ -201,6 +201,9 @@ xsk::gsc::h1::parser::symbol_type H1lex(xsk::gsc::h1::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -528,7 +531,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -732,6 +737,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -201,6 +201,9 @@ xsk::gsc::h2::parser::symbol_type H2lex(xsk::gsc::h2::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -528,7 +531,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -732,6 +737,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -199,6 +199,9 @@ xsk::gsc::iw5::parser::symbol_type IW5lex(xsk::gsc::iw5::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -518,7 +521,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -722,6 +727,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -199,6 +199,9 @@ xsk::gsc::iw6::parser::symbol_type IW6lex(xsk::gsc::iw6::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -518,7 +521,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -722,6 +727,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -199,6 +199,9 @@ xsk::gsc::iw7::parser::symbol_type IW7lex(xsk::gsc::iw7::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -518,7 +521,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -722,6 +727,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -205,6 +205,9 @@ xsk::gsc::iw8::parser::symbol_type IW8lex(xsk::gsc::iw8::lexer& lexer);
%type <ast::expr_isdefined::ptr> expr_isdefined %type <ast::expr_isdefined::ptr> expr_isdefined
%type <ast::expr_istrue::ptr> expr_istrue %type <ast::expr_istrue::ptr> expr_istrue
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -532,7 +535,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -748,6 +753,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -201,6 +201,9 @@ xsk::gsc::s1::parser::symbol_type S1lex(xsk::gsc::s1::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -528,7 +531,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -732,6 +737,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -201,6 +201,9 @@ xsk::gsc::s2::parser::symbol_type S2lex(xsk::gsc::s2::lexer& lexer);
%type <ast::expr_arguments::ptr> expr_arguments %type <ast::expr_arguments::ptr> expr_arguments
%type <ast::expr_arguments::ptr> expr_arguments_no_empty %type <ast::expr_arguments::ptr> expr_arguments_no_empty
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -528,7 +531,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -732,6 +737,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -205,6 +205,9 @@ xsk::gsc::s4::parser::symbol_type S4lex(xsk::gsc::s4::lexer& lexer);
%type <ast::expr_isdefined::ptr> expr_isdefined %type <ast::expr_isdefined::ptr> expr_isdefined
%type <ast::expr_istrue::ptr> expr_istrue %type <ast::expr_istrue::ptr> expr_istrue
%type <ast::expr_reference::ptr> expr_reference %type <ast::expr_reference::ptr> expr_reference
%type <ast::expr> expr_tuple
%type <ast::expr_tuple::ptr> expr_tuple_arguments
%type <ast::expr> expr_tuple_types
%type <ast::expr_array::ptr> expr_array %type <ast::expr_array::ptr> expr_array
%type <ast::expr_field::ptr> expr_field %type <ast::expr_field::ptr> expr_field
%type <ast::expr_size::ptr> expr_size %type <ast::expr_size::ptr> expr_size
@ -532,7 +535,9 @@ expr_or_empty
; ;
expr_assign expr_assign
: expr_object ASSIGN expr : expr_tuple ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN expr
{ $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_equal>(@$, std::move($1), std::move($3)); }
| expr_object ASSIGN_BW_OR expr | expr_object ASSIGN_BW_OR expr
{ $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); } { $$.as_node = std::make_unique<ast::expr_assign_bitwise_or>(@$, std::move($1), std::move($3)); }
@ -748,6 +753,24 @@ expr_reference
{ $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_reference>(@$, std::move($1), std::move($3)); }
; ;
expr_tuple
: LBRACKET expr_tuple_arguments RBRACKET
{ $$.as_node = std::move($2); }
;
expr_tuple_arguments
: expr_tuple_arguments COMMA expr_tuple_types
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr_tuple_types
{ $$ = std::make_unique<ast::expr_tuple>(@$); $$->list.push_back(std::move($1)); }
;
expr_tuple_types
: expr_array { $$.as_node = std::move($1); }
| expr_field { $$.as_node = std::move($1); }
| expr_identifier { $$.as_node = std::move($1); }
;
expr_array expr_array
: expr_object LBRACKET expr RBRACKET : expr_object LBRACKET expr RBRACKET
{ $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); } { $$ = std::make_unique<ast::expr_array>(@$, std::move($1), std::move($3)); }

View File

@ -385,7 +385,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -492,6 +492,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -555,7 +559,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -568,7 +572,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::h1 } // namespace xsk::gsc::h1

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -395,7 +400,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1038,11 +1043,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1548,7 +1560,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1593,6 +1605,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1632,7 +1667,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1718,7 +1753,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2248,7 +2283,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2315,11 +2350,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2342,11 +2377,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2374,7 +2409,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2383,7 +2418,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2391,8 +2426,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2424,13 +2459,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2590,23 +2625,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if(blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if(blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2633,7 +2685,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2647,7 +2699,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2660,7 +2711,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2838,8 +2889,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2854,7 +2904,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2887,7 +2937,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -96,6 +96,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -137,10 +138,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -300,7 +300,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -494,7 +494,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -517,7 +517,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -175,7 +175,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -683,7 +683,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -717,7 +717,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -751,7 +751,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace h1 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,104 +540,107 @@ namespace xsk { namespace gsc { namespace h1 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waitframe // stmt_waitframe
char dummy63[sizeof (ast::stmt_waitframe::ptr)]; char dummy64[sizeof (ast::stmt_waitframe::ptr)];
// stmt_waittill // stmt_waittill
char dummy64[sizeof (ast::stmt_waittill::ptr)]; char dummy65[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy65[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy66[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy66[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy67[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy67[sizeof (ast::stmt_while::ptr)]; char dummy68[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -643,7 +648,7 @@ namespace xsk { namespace gsc { namespace h1 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy68[sizeof (std::string)]; char dummy69[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -997,30 +1002,33 @@ namespace xsk { namespace gsc { namespace h1 {
S_expr_arguments = 170, // expr_arguments S_expr_arguments = 170, // expr_arguments
S_expr_arguments_no_empty = 171, // expr_arguments_no_empty S_expr_arguments_no_empty = 171, // expr_arguments_no_empty
S_expr_reference = 172, // expr_reference S_expr_reference = 172, // expr_reference
S_expr_array = 173, // expr_array S_expr_tuple = 173, // expr_tuple
S_expr_field = 174, // expr_field S_expr_tuple_arguments = 174, // expr_tuple_arguments
S_expr_size = 175, // expr_size S_expr_tuple_types = 175, // expr_tuple_types
S_expr_paren = 176, // expr_paren S_expr_array = 176, // expr_array
S_expr_object = 177, // expr_object S_expr_field = 177, // expr_field
S_expr_thisthread = 178, // expr_thisthread S_expr_size = 178, // expr_size
S_expr_empty_array = 179, // expr_empty_array S_expr_paren = 179, // expr_paren
S_expr_undefined = 180, // expr_undefined S_expr_object = 180, // expr_object
S_expr_game = 181, // expr_game S_expr_thisthread = 181, // expr_thisthread
S_expr_self = 182, // expr_self S_expr_empty_array = 182, // expr_empty_array
S_expr_anim = 183, // expr_anim S_expr_undefined = 183, // expr_undefined
S_expr_level = 184, // expr_level S_expr_game = 184, // expr_game
S_expr_animation = 185, // expr_animation S_expr_self = 185, // expr_self
S_expr_animtree = 186, // expr_animtree S_expr_anim = 186, // expr_anim
S_expr_identifier_nosize = 187, // expr_identifier_nosize S_expr_level = 187, // expr_level
S_expr_identifier = 188, // expr_identifier S_expr_animation = 188, // expr_animation
S_expr_path = 189, // expr_path S_expr_animtree = 189, // expr_animtree
S_expr_istring = 190, // expr_istring S_expr_identifier_nosize = 190, // expr_identifier_nosize
S_expr_string = 191, // expr_string S_expr_identifier = 191, // expr_identifier
S_expr_vector = 192, // expr_vector S_expr_path = 192, // expr_path
S_expr_float = 193, // expr_float S_expr_istring = 193, // expr_istring
S_expr_integer = 194, // expr_integer S_expr_string = 194, // expr_string
S_expr_false = 195, // expr_false S_expr_vector = 195, // expr_vector
S_expr_true = 196 // expr_true S_expr_float = 196, // expr_float
S_expr_integer = 197, // expr_integer
S_expr_false = 198, // expr_false
S_expr_true = 199 // expr_true
}; };
}; };
@ -1086,6 +1094,8 @@ namespace xsk { namespace gsc { namespace h1 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1208,6 +1218,10 @@ namespace xsk { namespace gsc { namespace h1 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1861,6 +1875,20 @@ namespace xsk { namespace gsc { namespace h1 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2376,6 +2404,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2498,6 +2528,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4839,8 +4873,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2419, ///< Last index in yytable_. yylast_ = 2479, ///< Last index in yytable_.
yynnts_ = 84, ///< Number of nonterminal symbols. yynnts_ = 87, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4896,6 +4930,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -5018,6 +5054,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5218,6 +5258,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5340,6 +5382,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5547,7 +5593,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::h1 } } } // xsk::gsc::h1
#line 5551 "parser.hpp" #line 5597 "parser.hpp"

View File

@ -45,7 +45,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -57,7 +57,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -74,7 +74,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -103,7 +103,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string
@ -3516,8 +3516,8 @@ const std::array<std::pair<std::uint16_t, const char*>, 804> token_list
{ 0xA795, "maps/mp/gametypes/_gamescores" }, { 0xA795, "maps/mp/gametypes/_gamescores" },
{ 0xA796, "maps/mp/gametypes/_globalentities" }, { 0xA796, "maps/mp/gametypes/_globalentities" },
{ 0xA797, "maps/mp/gametypes/_globallogic" }, { 0xA797, "maps/mp/gametypes/_globallogic" },
{ 0xA798, "maps/mp/gametypes/_hardpoints" }, { 0xA798, "maps/mp/gametypes/_hardpoints" },
{ 0xA799, "maps/mp/gametypes/_healthoverlay" }, { 0xA799, "maps/mp/gametypes/_healthoverlay" },
{ 0xA79A, "maps/mp/gametypes/_high_jump_mp" }, { 0xA79A, "maps/mp/gametypes/_high_jump_mp" },
{ 0xA79B, "maps/mp/gametypes/_horde_armory" }, { 0xA79B, "maps/mp/gametypes/_horde_armory" },
{ 0xA79C, "maps/mp/gametypes/_horde_crates" }, { 0xA79C, "maps/mp/gametypes/_horde_crates" },

View File

@ -385,7 +385,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -492,6 +492,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -555,7 +559,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -568,7 +572,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::h2 } // namespace xsk::gsc::h2

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -395,7 +400,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1038,11 +1043,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1548,7 +1560,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1593,6 +1605,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1632,7 +1667,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1718,7 +1753,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2247,7 +2282,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2314,11 +2349,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2341,11 +2376,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2373,7 +2408,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2382,7 +2417,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get()} );
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2390,8 +2425,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2423,13 +2458,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2589,23 +2624,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2632,7 +2684,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2646,7 +2698,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2659,7 +2710,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2837,8 +2888,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2853,7 +2903,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2886,7 +2936,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -96,6 +96,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -137,10 +138,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -300,7 +300,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -494,7 +494,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -517,7 +517,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -175,7 +175,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -683,7 +683,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -717,7 +717,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -751,7 +751,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace h2 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,104 +540,107 @@ namespace xsk { namespace gsc { namespace h2 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waitframe // stmt_waitframe
char dummy63[sizeof (ast::stmt_waitframe::ptr)]; char dummy64[sizeof (ast::stmt_waitframe::ptr)];
// stmt_waittill // stmt_waittill
char dummy64[sizeof (ast::stmt_waittill::ptr)]; char dummy65[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy65[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy66[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy66[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy67[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy67[sizeof (ast::stmt_while::ptr)]; char dummy68[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -643,7 +648,7 @@ namespace xsk { namespace gsc { namespace h2 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy68[sizeof (std::string)]; char dummy69[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -997,30 +1002,33 @@ namespace xsk { namespace gsc { namespace h2 {
S_expr_arguments = 170, // expr_arguments S_expr_arguments = 170, // expr_arguments
S_expr_arguments_no_empty = 171, // expr_arguments_no_empty S_expr_arguments_no_empty = 171, // expr_arguments_no_empty
S_expr_reference = 172, // expr_reference S_expr_reference = 172, // expr_reference
S_expr_array = 173, // expr_array S_expr_tuple = 173, // expr_tuple
S_expr_field = 174, // expr_field S_expr_tuple_arguments = 174, // expr_tuple_arguments
S_expr_size = 175, // expr_size S_expr_tuple_types = 175, // expr_tuple_types
S_expr_paren = 176, // expr_paren S_expr_array = 176, // expr_array
S_expr_object = 177, // expr_object S_expr_field = 177, // expr_field
S_expr_thisthread = 178, // expr_thisthread S_expr_size = 178, // expr_size
S_expr_empty_array = 179, // expr_empty_array S_expr_paren = 179, // expr_paren
S_expr_undefined = 180, // expr_undefined S_expr_object = 180, // expr_object
S_expr_game = 181, // expr_game S_expr_thisthread = 181, // expr_thisthread
S_expr_self = 182, // expr_self S_expr_empty_array = 182, // expr_empty_array
S_expr_anim = 183, // expr_anim S_expr_undefined = 183, // expr_undefined
S_expr_level = 184, // expr_level S_expr_game = 184, // expr_game
S_expr_animation = 185, // expr_animation S_expr_self = 185, // expr_self
S_expr_animtree = 186, // expr_animtree S_expr_anim = 186, // expr_anim
S_expr_identifier_nosize = 187, // expr_identifier_nosize S_expr_level = 187, // expr_level
S_expr_identifier = 188, // expr_identifier S_expr_animation = 188, // expr_animation
S_expr_path = 189, // expr_path S_expr_animtree = 189, // expr_animtree
S_expr_istring = 190, // expr_istring S_expr_identifier_nosize = 190, // expr_identifier_nosize
S_expr_string = 191, // expr_string S_expr_identifier = 191, // expr_identifier
S_expr_vector = 192, // expr_vector S_expr_path = 192, // expr_path
S_expr_float = 193, // expr_float S_expr_istring = 193, // expr_istring
S_expr_integer = 194, // expr_integer S_expr_string = 194, // expr_string
S_expr_false = 195, // expr_false S_expr_vector = 195, // expr_vector
S_expr_true = 196 // expr_true S_expr_float = 196, // expr_float
S_expr_integer = 197, // expr_integer
S_expr_false = 198, // expr_false
S_expr_true = 199 // expr_true
}; };
}; };
@ -1086,6 +1094,8 @@ namespace xsk { namespace gsc { namespace h2 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1208,6 +1218,10 @@ namespace xsk { namespace gsc { namespace h2 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1861,6 +1875,20 @@ namespace xsk { namespace gsc { namespace h2 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2376,6 +2404,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2498,6 +2528,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4839,8 +4873,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2419, ///< Last index in yytable_. yylast_ = 2479, ///< Last index in yytable_.
yynnts_ = 84, ///< Number of nonterminal symbols. yynnts_ = 87, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4896,6 +4930,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -5018,6 +5054,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5218,6 +5258,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5340,6 +5382,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5547,7 +5593,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::h2 } } } // xsk::gsc::h2
#line 5551 "parser.hpp" #line 5597 "parser.hpp"

View File

@ -45,7 +45,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -57,7 +57,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -74,7 +74,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -103,7 +103,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -383,7 +383,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -490,6 +490,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -553,7 +557,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -566,7 +570,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::iw5 } // namespace xsk::gsc::iw5

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -392,7 +397,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1030,11 +1035,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1540,7 +1552,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1585,6 +1597,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1624,7 +1659,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1710,7 +1745,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2238,7 +2273,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2305,11 +2340,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2332,11 +2367,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2364,7 +2399,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2373,7 +2408,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2381,8 +2416,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2414,13 +2449,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2580,23 +2615,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2623,7 +2675,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2637,7 +2689,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2650,7 +2701,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2828,8 +2879,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2844,7 +2894,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2877,7 +2927,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -95,6 +95,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -136,10 +137,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -299,7 +299,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -493,7 +493,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));

View File

@ -172,7 +172,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -682,7 +682,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -716,7 +716,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -750,7 +750,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace iw5 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,101 +540,104 @@ namespace xsk { namespace gsc { namespace iw5 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waittill // stmt_waittill
char dummy63[sizeof (ast::stmt_waittill::ptr)]; char dummy64[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy64[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy65[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy65[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy66[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy66[sizeof (ast::stmt_while::ptr)]; char dummy67[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -640,7 +645,7 @@ namespace xsk { namespace gsc { namespace iw5 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy67[sizeof (std::string)]; char dummy68[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -991,30 +996,33 @@ namespace xsk { namespace gsc { namespace iw5 {
S_expr_arguments = 168, // expr_arguments S_expr_arguments = 168, // expr_arguments
S_expr_arguments_no_empty = 169, // expr_arguments_no_empty S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_reference = 170, // expr_reference S_expr_reference = 170, // expr_reference
S_expr_array = 171, // expr_array S_expr_tuple = 171, // expr_tuple
S_expr_field = 172, // expr_field S_expr_tuple_arguments = 172, // expr_tuple_arguments
S_expr_size = 173, // expr_size S_expr_tuple_types = 173, // expr_tuple_types
S_expr_paren = 174, // expr_paren S_expr_array = 174, // expr_array
S_expr_object = 175, // expr_object S_expr_field = 175, // expr_field
S_expr_thisthread = 176, // expr_thisthread S_expr_size = 176, // expr_size
S_expr_empty_array = 177, // expr_empty_array S_expr_paren = 177, // expr_paren
S_expr_undefined = 178, // expr_undefined S_expr_object = 178, // expr_object
S_expr_game = 179, // expr_game S_expr_thisthread = 179, // expr_thisthread
S_expr_self = 180, // expr_self S_expr_empty_array = 180, // expr_empty_array
S_expr_anim = 181, // expr_anim S_expr_undefined = 181, // expr_undefined
S_expr_level = 182, // expr_level S_expr_game = 182, // expr_game
S_expr_animation = 183, // expr_animation S_expr_self = 183, // expr_self
S_expr_animtree = 184, // expr_animtree S_expr_anim = 184, // expr_anim
S_expr_identifier_nosize = 185, // expr_identifier_nosize S_expr_level = 185, // expr_level
S_expr_identifier = 186, // expr_identifier S_expr_animation = 186, // expr_animation
S_expr_path = 187, // expr_path S_expr_animtree = 187, // expr_animtree
S_expr_istring = 188, // expr_istring S_expr_identifier_nosize = 188, // expr_identifier_nosize
S_expr_string = 189, // expr_string S_expr_identifier = 189, // expr_identifier
S_expr_vector = 190, // expr_vector S_expr_path = 190, // expr_path
S_expr_float = 191, // expr_float S_expr_istring = 191, // expr_istring
S_expr_integer = 192, // expr_integer S_expr_string = 192, // expr_string
S_expr_false = 193, // expr_false S_expr_vector = 193, // expr_vector
S_expr_true = 194 // expr_true S_expr_float = 194, // expr_float
S_expr_integer = 195, // expr_integer
S_expr_false = 196, // expr_false
S_expr_true = 197 // expr_true
}; };
}; };
@ -1080,6 +1088,8 @@ namespace xsk { namespace gsc { namespace iw5 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1202,6 +1212,10 @@ namespace xsk { namespace gsc { namespace iw5 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1851,6 +1865,20 @@ namespace xsk { namespace gsc { namespace iw5 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2352,6 +2380,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2474,6 +2504,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4796,8 +4830,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2363, ///< Last index in yytable_. yylast_ = 2371, ///< Last index in yytable_.
yynnts_ = 83, ///< Number of nonterminal symbols. yynnts_ = 86, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4853,6 +4887,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -4975,6 +5011,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5171,6 +5211,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5293,6 +5335,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5496,7 +5542,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw5 } } } // xsk::gsc::iw5
#line 5500 "parser.hpp" #line 5546 "parser.hpp"

View File

@ -45,7 +45,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -57,7 +57,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -74,7 +74,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -103,7 +103,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -384,7 +384,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -491,6 +491,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -554,7 +558,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -567,7 +571,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::iw6 } // namespace xsk::gsc::iw6

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -392,7 +397,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1030,11 +1035,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1540,7 +1552,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1585,6 +1597,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1624,7 +1659,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1710,7 +1745,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2238,7 +2273,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2305,11 +2340,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2332,11 +2367,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2364,7 +2399,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2373,7 +2408,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2381,8 +2416,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2414,13 +2449,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2580,23 +2615,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2623,7 +2675,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2637,7 +2689,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2650,7 +2701,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2828,8 +2879,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2844,7 +2894,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2877,7 +2927,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -95,6 +95,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -136,10 +137,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -299,7 +299,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -493,7 +493,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -516,7 +516,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -174,7 +174,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -682,7 +682,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -716,7 +716,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -750,7 +750,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace iw6 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,101 +540,104 @@ namespace xsk { namespace gsc { namespace iw6 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waittill // stmt_waittill
char dummy63[sizeof (ast::stmt_waittill::ptr)]; char dummy64[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy64[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy65[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy65[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy66[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy66[sizeof (ast::stmt_while::ptr)]; char dummy67[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -640,7 +645,7 @@ namespace xsk { namespace gsc { namespace iw6 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy67[sizeof (std::string)]; char dummy68[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -991,30 +996,33 @@ namespace xsk { namespace gsc { namespace iw6 {
S_expr_arguments = 168, // expr_arguments S_expr_arguments = 168, // expr_arguments
S_expr_arguments_no_empty = 169, // expr_arguments_no_empty S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_reference = 170, // expr_reference S_expr_reference = 170, // expr_reference
S_expr_array = 171, // expr_array S_expr_tuple = 171, // expr_tuple
S_expr_field = 172, // expr_field S_expr_tuple_arguments = 172, // expr_tuple_arguments
S_expr_size = 173, // expr_size S_expr_tuple_types = 173, // expr_tuple_types
S_expr_paren = 174, // expr_paren S_expr_array = 174, // expr_array
S_expr_object = 175, // expr_object S_expr_field = 175, // expr_field
S_expr_thisthread = 176, // expr_thisthread S_expr_size = 176, // expr_size
S_expr_empty_array = 177, // expr_empty_array S_expr_paren = 177, // expr_paren
S_expr_undefined = 178, // expr_undefined S_expr_object = 178, // expr_object
S_expr_game = 179, // expr_game S_expr_thisthread = 179, // expr_thisthread
S_expr_self = 180, // expr_self S_expr_empty_array = 180, // expr_empty_array
S_expr_anim = 181, // expr_anim S_expr_undefined = 181, // expr_undefined
S_expr_level = 182, // expr_level S_expr_game = 182, // expr_game
S_expr_animation = 183, // expr_animation S_expr_self = 183, // expr_self
S_expr_animtree = 184, // expr_animtree S_expr_anim = 184, // expr_anim
S_expr_identifier_nosize = 185, // expr_identifier_nosize S_expr_level = 185, // expr_level
S_expr_identifier = 186, // expr_identifier S_expr_animation = 186, // expr_animation
S_expr_path = 187, // expr_path S_expr_animtree = 187, // expr_animtree
S_expr_istring = 188, // expr_istring S_expr_identifier_nosize = 188, // expr_identifier_nosize
S_expr_string = 189, // expr_string S_expr_identifier = 189, // expr_identifier
S_expr_vector = 190, // expr_vector S_expr_path = 190, // expr_path
S_expr_float = 191, // expr_float S_expr_istring = 191, // expr_istring
S_expr_integer = 192, // expr_integer S_expr_string = 192, // expr_string
S_expr_false = 193, // expr_false S_expr_vector = 193, // expr_vector
S_expr_true = 194 // expr_true S_expr_float = 194, // expr_float
S_expr_integer = 195, // expr_integer
S_expr_false = 196, // expr_false
S_expr_true = 197 // expr_true
}; };
}; };
@ -1080,6 +1088,8 @@ namespace xsk { namespace gsc { namespace iw6 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1202,6 +1212,10 @@ namespace xsk { namespace gsc { namespace iw6 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1851,6 +1865,20 @@ namespace xsk { namespace gsc { namespace iw6 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2352,6 +2380,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2474,6 +2504,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4796,8 +4830,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2363, ///< Last index in yytable_. yylast_ = 2371, ///< Last index in yytable_.
yynnts_ = 83, ///< Number of nonterminal symbols. yynnts_ = 86, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4853,6 +4887,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -4975,6 +5011,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5171,6 +5211,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5293,6 +5335,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5496,7 +5542,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw6 } } } // xsk::gsc::iw6
#line 5500 "parser.hpp" #line 5546 "parser.hpp"

View File

@ -47,7 +47,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -59,7 +59,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -76,7 +76,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -105,7 +105,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -384,7 +384,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -491,6 +491,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -554,7 +558,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -567,7 +571,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::iw7 } // namespace xsk::gsc::iw7

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -392,7 +397,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1030,11 +1035,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1540,7 +1552,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1585,6 +1597,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1624,7 +1659,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1710,7 +1745,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2238,7 +2273,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2305,11 +2340,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2332,11 +2367,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2364,7 +2399,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2373,7 +2408,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2381,8 +2416,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2414,13 +2449,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2580,23 +2615,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2623,7 +2675,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2637,7 +2689,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2650,7 +2701,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2828,8 +2879,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2844,7 +2894,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2877,7 +2927,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -95,6 +95,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -136,10 +137,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -299,7 +299,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -493,7 +493,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -516,7 +516,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -174,7 +174,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -682,7 +682,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -716,7 +716,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -750,7 +750,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace iw7 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,101 +540,104 @@ namespace xsk { namespace gsc { namespace iw7 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waittill // stmt_waittill
char dummy63[sizeof (ast::stmt_waittill::ptr)]; char dummy64[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy64[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy65[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy65[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy66[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy66[sizeof (ast::stmt_while::ptr)]; char dummy67[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -640,7 +645,7 @@ namespace xsk { namespace gsc { namespace iw7 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy67[sizeof (std::string)]; char dummy68[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -991,30 +996,33 @@ namespace xsk { namespace gsc { namespace iw7 {
S_expr_arguments = 168, // expr_arguments S_expr_arguments = 168, // expr_arguments
S_expr_arguments_no_empty = 169, // expr_arguments_no_empty S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_reference = 170, // expr_reference S_expr_reference = 170, // expr_reference
S_expr_array = 171, // expr_array S_expr_tuple = 171, // expr_tuple
S_expr_field = 172, // expr_field S_expr_tuple_arguments = 172, // expr_tuple_arguments
S_expr_size = 173, // expr_size S_expr_tuple_types = 173, // expr_tuple_types
S_expr_paren = 174, // expr_paren S_expr_array = 174, // expr_array
S_expr_object = 175, // expr_object S_expr_field = 175, // expr_field
S_expr_thisthread = 176, // expr_thisthread S_expr_size = 176, // expr_size
S_expr_empty_array = 177, // expr_empty_array S_expr_paren = 177, // expr_paren
S_expr_undefined = 178, // expr_undefined S_expr_object = 178, // expr_object
S_expr_game = 179, // expr_game S_expr_thisthread = 179, // expr_thisthread
S_expr_self = 180, // expr_self S_expr_empty_array = 180, // expr_empty_array
S_expr_anim = 181, // expr_anim S_expr_undefined = 181, // expr_undefined
S_expr_level = 182, // expr_level S_expr_game = 182, // expr_game
S_expr_animation = 183, // expr_animation S_expr_self = 183, // expr_self
S_expr_animtree = 184, // expr_animtree S_expr_anim = 184, // expr_anim
S_expr_identifier_nosize = 185, // expr_identifier_nosize S_expr_level = 185, // expr_level
S_expr_identifier = 186, // expr_identifier S_expr_animation = 186, // expr_animation
S_expr_path = 187, // expr_path S_expr_animtree = 187, // expr_animtree
S_expr_istring = 188, // expr_istring S_expr_identifier_nosize = 188, // expr_identifier_nosize
S_expr_string = 189, // expr_string S_expr_identifier = 189, // expr_identifier
S_expr_vector = 190, // expr_vector S_expr_path = 190, // expr_path
S_expr_float = 191, // expr_float S_expr_istring = 191, // expr_istring
S_expr_integer = 192, // expr_integer S_expr_string = 192, // expr_string
S_expr_false = 193, // expr_false S_expr_vector = 193, // expr_vector
S_expr_true = 194 // expr_true S_expr_float = 194, // expr_float
S_expr_integer = 195, // expr_integer
S_expr_false = 196, // expr_false
S_expr_true = 197 // expr_true
}; };
}; };
@ -1080,6 +1088,8 @@ namespace xsk { namespace gsc { namespace iw7 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1202,6 +1212,10 @@ namespace xsk { namespace gsc { namespace iw7 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1851,6 +1865,20 @@ namespace xsk { namespace gsc { namespace iw7 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2352,6 +2380,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2474,6 +2504,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4796,8 +4830,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2363, ///< Last index in yytable_. yylast_ = 2371, ///< Last index in yytable_.
yynnts_ = 83, ///< Number of nonterminal symbols. yynnts_ = 86, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4853,6 +4887,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -4975,6 +5011,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5171,6 +5211,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5293,6 +5335,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5496,7 +5542,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw7 } } } // xsk::gsc::iw7
#line 5500 "parser.hpp" #line 5546 "parser.hpp"

View File

@ -47,7 +47,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -59,7 +59,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -76,7 +76,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -105,7 +105,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -439,7 +439,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_far_call(inst, true); assemble_far_call(inst, true);
break;*/ break;*/
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -546,6 +546,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -623,7 +627,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -636,7 +640,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::iw8 } // namespace xsk::gsc::iw8

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -395,7 +400,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1044,11 +1049,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1580,7 +1592,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
data.push_back(variable_create_index(entry, blk)); data.push_back(variable_create_index(entry, blk));
} }
@ -1644,6 +1656,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1683,7 +1718,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1769,7 +1804,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2298,7 +2333,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2365,11 +2400,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2392,11 +2427,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2424,7 +2459,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2433,7 +2468,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2441,8 +2476,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2474,13 +2509,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2640,23 +2675,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2683,7 +2735,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2697,7 +2749,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2710,7 +2761,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2888,8 +2939,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2904,7 +2954,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2937,7 +2987,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -98,6 +98,7 @@ private:
void emit_expr_istrue(const ast::expr_istrue::ptr& expr, const block::ptr& blk); void emit_expr_istrue(const ast::expr_istrue::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -139,10 +140,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -352,7 +352,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_far_call(inst, true); disassemble_far_call(inst, true);
break;*/ break;*/
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -559,7 +559,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -582,7 +582,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -212,7 +212,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -696,7 +696,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -730,7 +730,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -764,7 +764,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace iw8 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -544,104 +546,107 @@ namespace xsk { namespace gsc { namespace iw8 {
// expr_true // expr_true
char dummy37[sizeof (ast::expr_true::ptr)]; char dummy37[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy38[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy38[sizeof (ast::expr_undefined::ptr)]; char dummy39[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy39[sizeof (ast::expr_vector::ptr)]; char dummy40[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy40[sizeof (ast::include::ptr)]; char dummy41[sizeof (ast::include::ptr)];
// program // program
char dummy41[sizeof (ast::program::ptr)]; char dummy42[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy42[sizeof (ast::stmt)]; char dummy43[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy43[sizeof (ast::stmt_assign::ptr)]; char dummy44[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy44[sizeof (ast::stmt_break::ptr)]; char dummy45[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy45[sizeof (ast::stmt_breakpoint::ptr)]; char dummy46[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy46[sizeof (ast::stmt_call::ptr)]; char dummy47[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy47[sizeof (ast::stmt_case::ptr)]; char dummy48[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy48[sizeof (ast::stmt_continue::ptr)]; char dummy49[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy49[sizeof (ast::stmt_default::ptr)]; char dummy50[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy50[sizeof (ast::stmt_dev::ptr)]; char dummy51[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy51[sizeof (ast::stmt_dowhile::ptr)]; char dummy52[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy52[sizeof (ast::stmt_endon::ptr)]; char dummy53[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy53[sizeof (ast::stmt_expr::ptr)]; char dummy54[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy54[sizeof (ast::stmt_for::ptr)]; char dummy55[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy55[sizeof (ast::stmt_foreach::ptr)]; char dummy56[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy56[sizeof (ast::stmt_if::ptr)]; char dummy57[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy57[sizeof (ast::stmt_ifelse::ptr)]; char dummy58[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy58[sizeof (ast::stmt_list::ptr)]; char dummy59[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy59[sizeof (ast::stmt_notify::ptr)]; char dummy60[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy60[sizeof (ast::stmt_prof_begin::ptr)]; char dummy61[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy61[sizeof (ast::stmt_prof_end::ptr)]; char dummy62[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy62[sizeof (ast::stmt_return::ptr)]; char dummy63[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy63[sizeof (ast::stmt_switch::ptr)]; char dummy64[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy64[sizeof (ast::stmt_wait::ptr)]; char dummy65[sizeof (ast::stmt_wait::ptr)];
// stmt_waitframe // stmt_waitframe
char dummy65[sizeof (ast::stmt_waitframe::ptr)]; char dummy66[sizeof (ast::stmt_waitframe::ptr)];
// stmt_waittill // stmt_waittill
char dummy66[sizeof (ast::stmt_waittill::ptr)]; char dummy67[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy67[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy68[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy68[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy69[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy69[sizeof (ast::stmt_while::ptr)]; char dummy70[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -649,7 +654,7 @@ namespace xsk { namespace gsc { namespace iw8 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy70[sizeof (std::string)]; char dummy71[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -1009,30 +1014,33 @@ namespace xsk { namespace gsc { namespace iw8 {
S_expr_isdefined = 174, // expr_isdefined S_expr_isdefined = 174, // expr_isdefined
S_expr_istrue = 175, // expr_istrue S_expr_istrue = 175, // expr_istrue
S_expr_reference = 176, // expr_reference S_expr_reference = 176, // expr_reference
S_expr_array = 177, // expr_array S_expr_tuple = 177, // expr_tuple
S_expr_field = 178, // expr_field S_expr_tuple_arguments = 178, // expr_tuple_arguments
S_expr_size = 179, // expr_size S_expr_tuple_types = 179, // expr_tuple_types
S_expr_paren = 180, // expr_paren S_expr_array = 180, // expr_array
S_expr_object = 181, // expr_object S_expr_field = 181, // expr_field
S_expr_thisthread = 182, // expr_thisthread S_expr_size = 182, // expr_size
S_expr_empty_array = 183, // expr_empty_array S_expr_paren = 183, // expr_paren
S_expr_undefined = 184, // expr_undefined S_expr_object = 184, // expr_object
S_expr_game = 185, // expr_game S_expr_thisthread = 185, // expr_thisthread
S_expr_self = 186, // expr_self S_expr_empty_array = 186, // expr_empty_array
S_expr_anim = 187, // expr_anim S_expr_undefined = 187, // expr_undefined
S_expr_level = 188, // expr_level S_expr_game = 188, // expr_game
S_expr_animation = 189, // expr_animation S_expr_self = 189, // expr_self
S_expr_animtree = 190, // expr_animtree S_expr_anim = 190, // expr_anim
S_expr_identifier_nosize = 191, // expr_identifier_nosize S_expr_level = 191, // expr_level
S_expr_identifier = 192, // expr_identifier S_expr_animation = 192, // expr_animation
S_expr_path = 193, // expr_path S_expr_animtree = 193, // expr_animtree
S_expr_istring = 194, // expr_istring S_expr_identifier_nosize = 194, // expr_identifier_nosize
S_expr_string = 195, // expr_string S_expr_identifier = 195, // expr_identifier
S_expr_vector = 196, // expr_vector S_expr_path = 196, // expr_path
S_expr_float = 197, // expr_float S_expr_istring = 197, // expr_istring
S_expr_integer = 198, // expr_integer S_expr_string = 198, // expr_string
S_expr_false = 199, // expr_false S_expr_vector = 199, // expr_vector
S_expr_true = 200 // expr_true S_expr_float = 200, // expr_float
S_expr_integer = 201, // expr_integer
S_expr_false = 202, // expr_false
S_expr_true = 203 // expr_true
}; };
}; };
@ -1098,6 +1106,8 @@ namespace xsk { namespace gsc { namespace iw8 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1228,6 +1238,10 @@ namespace xsk { namespace gsc { namespace iw8 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1909,6 +1923,20 @@ namespace xsk { namespace gsc { namespace iw8 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2424,6 +2452,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2554,6 +2584,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4925,8 +4959,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2481, ///< Last index in yytable_. yylast_ = 2542, ///< Last index in yytable_.
yynnts_ = 86, ///< Number of nonterminal symbols. yynnts_ = 89, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4982,6 +5016,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -5112,6 +5148,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5312,6 +5352,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5442,6 +5484,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5649,7 +5695,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw8 } } } // xsk::gsc::iw8
#line 5653 "parser.hpp" #line 5699 "parser.hpp"

View File

@ -47,7 +47,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -59,7 +59,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -76,7 +76,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -105,7 +105,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -385,7 +385,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -492,6 +492,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -555,7 +559,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -568,7 +572,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::s1 } // namespace xsk::gsc::s1

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -395,7 +400,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1038,11 +1043,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1548,7 +1560,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1593,6 +1605,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1632,7 +1667,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1718,7 +1753,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2247,7 +2282,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2314,11 +2349,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2341,11 +2376,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2373,7 +2408,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2382,7 +2417,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2390,8 +2425,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2423,13 +2458,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2589,23 +2624,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2632,7 +2684,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2646,7 +2698,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2659,7 +2710,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2837,8 +2888,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2853,7 +2903,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2886,7 +2936,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -96,6 +96,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -137,10 +138,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -300,7 +300,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -494,7 +494,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -517,7 +517,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -683,7 +683,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -717,7 +717,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -751,7 +751,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace s1 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,104 +540,107 @@ namespace xsk { namespace gsc { namespace s1 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waitframe // stmt_waitframe
char dummy63[sizeof (ast::stmt_waitframe::ptr)]; char dummy64[sizeof (ast::stmt_waitframe::ptr)];
// stmt_waittill // stmt_waittill
char dummy64[sizeof (ast::stmt_waittill::ptr)]; char dummy65[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy65[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy66[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy66[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy67[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy67[sizeof (ast::stmt_while::ptr)]; char dummy68[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -643,7 +648,7 @@ namespace xsk { namespace gsc { namespace s1 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy68[sizeof (std::string)]; char dummy69[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -997,30 +1002,33 @@ namespace xsk { namespace gsc { namespace s1 {
S_expr_arguments = 170, // expr_arguments S_expr_arguments = 170, // expr_arguments
S_expr_arguments_no_empty = 171, // expr_arguments_no_empty S_expr_arguments_no_empty = 171, // expr_arguments_no_empty
S_expr_reference = 172, // expr_reference S_expr_reference = 172, // expr_reference
S_expr_array = 173, // expr_array S_expr_tuple = 173, // expr_tuple
S_expr_field = 174, // expr_field S_expr_tuple_arguments = 174, // expr_tuple_arguments
S_expr_size = 175, // expr_size S_expr_tuple_types = 175, // expr_tuple_types
S_expr_paren = 176, // expr_paren S_expr_array = 176, // expr_array
S_expr_object = 177, // expr_object S_expr_field = 177, // expr_field
S_expr_thisthread = 178, // expr_thisthread S_expr_size = 178, // expr_size
S_expr_empty_array = 179, // expr_empty_array S_expr_paren = 179, // expr_paren
S_expr_undefined = 180, // expr_undefined S_expr_object = 180, // expr_object
S_expr_game = 181, // expr_game S_expr_thisthread = 181, // expr_thisthread
S_expr_self = 182, // expr_self S_expr_empty_array = 182, // expr_empty_array
S_expr_anim = 183, // expr_anim S_expr_undefined = 183, // expr_undefined
S_expr_level = 184, // expr_level S_expr_game = 184, // expr_game
S_expr_animation = 185, // expr_animation S_expr_self = 185, // expr_self
S_expr_animtree = 186, // expr_animtree S_expr_anim = 186, // expr_anim
S_expr_identifier_nosize = 187, // expr_identifier_nosize S_expr_level = 187, // expr_level
S_expr_identifier = 188, // expr_identifier S_expr_animation = 188, // expr_animation
S_expr_path = 189, // expr_path S_expr_animtree = 189, // expr_animtree
S_expr_istring = 190, // expr_istring S_expr_identifier_nosize = 190, // expr_identifier_nosize
S_expr_string = 191, // expr_string S_expr_identifier = 191, // expr_identifier
S_expr_vector = 192, // expr_vector S_expr_path = 192, // expr_path
S_expr_float = 193, // expr_float S_expr_istring = 193, // expr_istring
S_expr_integer = 194, // expr_integer S_expr_string = 194, // expr_string
S_expr_false = 195, // expr_false S_expr_vector = 195, // expr_vector
S_expr_true = 196 // expr_true S_expr_float = 196, // expr_float
S_expr_integer = 197, // expr_integer
S_expr_false = 198, // expr_false
S_expr_true = 199 // expr_true
}; };
}; };
@ -1086,6 +1094,8 @@ namespace xsk { namespace gsc { namespace s1 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1208,6 +1218,10 @@ namespace xsk { namespace gsc { namespace s1 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1861,6 +1875,20 @@ namespace xsk { namespace gsc { namespace s1 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2376,6 +2404,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2498,6 +2528,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4839,8 +4873,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2419, ///< Last index in yytable_. yylast_ = 2479, ///< Last index in yytable_.
yynnts_ = 84, ///< Number of nonterminal symbols. yynnts_ = 87, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4896,6 +4930,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -5018,6 +5054,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5218,6 +5258,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5340,6 +5382,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5547,7 +5593,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::s1 } } } // xsk::gsc::s1
#line 5551 "parser.hpp" #line 5597 "parser.hpp"

View File

@ -47,7 +47,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -59,7 +59,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -76,7 +76,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -105,7 +105,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -175,7 +175,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -386,7 +386,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_end_switch(inst); assemble_end_switch(inst);
break; break;
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -493,6 +493,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -556,7 +560,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -569,7 +573,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::s2 } // namespace xsk::gsc::s2

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -395,7 +400,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1038,11 +1043,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1548,7 +1560,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
{ {
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk)); emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
} }
@ -1593,6 +1605,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1632,7 +1667,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1718,7 +1753,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2247,7 +2282,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2314,11 +2349,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2341,11 +2376,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2373,7 +2408,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2382,7 +2417,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2390,8 +2425,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2423,13 +2458,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2589,23 +2624,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2632,7 +2684,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2646,7 +2698,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2659,7 +2710,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2837,8 +2888,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2853,7 +2903,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2886,7 +2936,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -96,6 +96,7 @@ private:
void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -137,10 +138,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ private:
void decompile_instruction(const instruction::ptr& inst); void decompile_instruction(const instruction::ptr& inst);
void decompile_expressions(const instruction::ptr& inst); void decompile_expressions(const instruction::ptr& inst);
void decompile_statements(const ast::stmt_list::ptr& stmt); void decompile_statements(const ast::stmt_list::ptr& stmt);
void decompile_infinites(const ast::stmt_list::ptr& stmt);
void decompile_loops(const ast::stmt_list::ptr& stmt); void decompile_loops(const ast::stmt_list::ptr& stmt);
void decompile_switches(const ast::stmt_list::ptr& stmt); void decompile_switches(const ast::stmt_list::ptr& stmt);
void decompile_ifelses(const ast::stmt_list::ptr& stmt); void decompile_ifelses(const ast::stmt_list::ptr& stmt);
@ -37,8 +36,8 @@ private:
void decompile_tuples(const ast::stmt_list::ptr& stmt); void decompile_tuples(const ast::stmt_list::ptr& stmt);
void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_if(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_ifelse_end(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_infinite(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_inf(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_loop(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_while(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end); void decompile_dowhile(const ast::stmt_list::ptr& stmt, std::size_t begin, std::size_t end);
@ -93,7 +92,6 @@ private:
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk); void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk); void process_expr_array(const ast::expr_array::ptr& expr, const block::ptr& blk);
void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk); void process_expr_field(const ast::expr_field::ptr& expr, const block::ptr& blk);
void process_expr_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk);
void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk); void process_expr_vector(const ast::expr_vector::ptr& vec, const block::ptr& blk);
void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false); void process_var_create(ast::expr& expr, const block::ptr& blk, bool fromstmt = false);
void process_var_access(ast::expr& expr, const block::ptr& blk); void process_var_access(ast::expr& expr, const block::ptr& blk);

View File

@ -301,7 +301,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
disassemble_end_switch(inst); disassemble_end_switch(inst);
break; break;
default: default:
throw disasm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw disasm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -495,7 +495,7 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
} }
} }
throw disasm_error(utils::string::va("Couldn't resolve function name at index '0x%04X'!", idx)); throw disasm_error(utils::string::va("couldn't resolve function name at index '0x%04X'!", idx));
} }
throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data())); throw disasm_error(utils::string::va("\"%s\" is not valid function address!", index.data()));
@ -518,7 +518,6 @@ void disassembler::print_function(const function::ptr& func)
print_instruction(inst); print_instruction(inst);
} }
output_->write_string("\n");
output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data())); output_->write_string(utils::string::va("end_%s\n", func->name.substr(4).data()));
} }

View File

@ -683,7 +683,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -717,7 +717,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -751,7 +751,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(utils::string::hex_to_dec(buffer_.data), loc_);
} }
throw error("UNEXPECTED LEXER INTERNAL ERROR!"); throw error("UNEXPECTED LEXER INTERNAL ERROR!");

File diff suppressed because it is too large Load Diff

View File

@ -446,6 +446,8 @@ namespace xsk { namespace gsc { namespace s2 {
// expr_ternary // expr_ternary
// expr_binary // expr_binary
// expr_primitive // expr_primitive
// expr_tuple
// expr_tuple_types
// expr_object // expr_object
char dummy6[sizeof (ast::expr)]; char dummy6[sizeof (ast::expr)];
@ -538,104 +540,107 @@ namespace xsk { namespace gsc { namespace s2 {
// expr_true // expr_true
char dummy35[sizeof (ast::expr_true::ptr)]; char dummy35[sizeof (ast::expr_true::ptr)];
// expr_tuple_arguments
char dummy36[sizeof (ast::expr_tuple::ptr)];
// expr_undefined // expr_undefined
char dummy36[sizeof (ast::expr_undefined::ptr)]; char dummy37[sizeof (ast::expr_undefined::ptr)];
// expr_vector // expr_vector
char dummy37[sizeof (ast::expr_vector::ptr)]; char dummy38[sizeof (ast::expr_vector::ptr)];
// include // include
char dummy38[sizeof (ast::include::ptr)]; char dummy39[sizeof (ast::include::ptr)];
// program // program
char dummy39[sizeof (ast::program::ptr)]; char dummy40[sizeof (ast::program::ptr)];
// stmt // stmt
// stmt_or_dev // stmt_or_dev
char dummy40[sizeof (ast::stmt)]; char dummy41[sizeof (ast::stmt)];
// stmt_assign // stmt_assign
char dummy41[sizeof (ast::stmt_assign::ptr)]; char dummy42[sizeof (ast::stmt_assign::ptr)];
// stmt_break // stmt_break
char dummy42[sizeof (ast::stmt_break::ptr)]; char dummy43[sizeof (ast::stmt_break::ptr)];
// stmt_breakpoint // stmt_breakpoint
char dummy43[sizeof (ast::stmt_breakpoint::ptr)]; char dummy44[sizeof (ast::stmt_breakpoint::ptr)];
// stmt_call // stmt_call
char dummy44[sizeof (ast::stmt_call::ptr)]; char dummy45[sizeof (ast::stmt_call::ptr)];
// stmt_case // stmt_case
char dummy45[sizeof (ast::stmt_case::ptr)]; char dummy46[sizeof (ast::stmt_case::ptr)];
// stmt_continue // stmt_continue
char dummy46[sizeof (ast::stmt_continue::ptr)]; char dummy47[sizeof (ast::stmt_continue::ptr)];
// stmt_default // stmt_default
char dummy47[sizeof (ast::stmt_default::ptr)]; char dummy48[sizeof (ast::stmt_default::ptr)];
// stmt_dev // stmt_dev
char dummy48[sizeof (ast::stmt_dev::ptr)]; char dummy49[sizeof (ast::stmt_dev::ptr)];
// stmt_dowhile // stmt_dowhile
char dummy49[sizeof (ast::stmt_dowhile::ptr)]; char dummy50[sizeof (ast::stmt_dowhile::ptr)];
// stmt_endon // stmt_endon
char dummy50[sizeof (ast::stmt_endon::ptr)]; char dummy51[sizeof (ast::stmt_endon::ptr)];
// stmt_expr // stmt_expr
char dummy51[sizeof (ast::stmt_expr::ptr)]; char dummy52[sizeof (ast::stmt_expr::ptr)];
// stmt_for // stmt_for
char dummy52[sizeof (ast::stmt_for::ptr)]; char dummy53[sizeof (ast::stmt_for::ptr)];
// stmt_foreach // stmt_foreach
char dummy53[sizeof (ast::stmt_foreach::ptr)]; char dummy54[sizeof (ast::stmt_foreach::ptr)];
// stmt_if // stmt_if
char dummy54[sizeof (ast::stmt_if::ptr)]; char dummy55[sizeof (ast::stmt_if::ptr)];
// stmt_ifelse // stmt_ifelse
char dummy55[sizeof (ast::stmt_ifelse::ptr)]; char dummy56[sizeof (ast::stmt_ifelse::ptr)];
// stmt_list // stmt_list
// stmt_or_dev_list // stmt_or_dev_list
// stmt_block // stmt_block
char dummy56[sizeof (ast::stmt_list::ptr)]; char dummy57[sizeof (ast::stmt_list::ptr)];
// stmt_notify // stmt_notify
char dummy57[sizeof (ast::stmt_notify::ptr)]; char dummy58[sizeof (ast::stmt_notify::ptr)];
// stmt_prof_begin // stmt_prof_begin
char dummy58[sizeof (ast::stmt_prof_begin::ptr)]; char dummy59[sizeof (ast::stmt_prof_begin::ptr)];
// stmt_prof_end // stmt_prof_end
char dummy59[sizeof (ast::stmt_prof_end::ptr)]; char dummy60[sizeof (ast::stmt_prof_end::ptr)];
// stmt_return // stmt_return
char dummy60[sizeof (ast::stmt_return::ptr)]; char dummy61[sizeof (ast::stmt_return::ptr)];
// stmt_switch // stmt_switch
char dummy61[sizeof (ast::stmt_switch::ptr)]; char dummy62[sizeof (ast::stmt_switch::ptr)];
// stmt_wait // stmt_wait
char dummy62[sizeof (ast::stmt_wait::ptr)]; char dummy63[sizeof (ast::stmt_wait::ptr)];
// stmt_waitframe // stmt_waitframe
char dummy63[sizeof (ast::stmt_waitframe::ptr)]; char dummy64[sizeof (ast::stmt_waitframe::ptr)];
// stmt_waittill // stmt_waittill
char dummy64[sizeof (ast::stmt_waittill::ptr)]; char dummy65[sizeof (ast::stmt_waittill::ptr)];
// stmt_waittillframeend // stmt_waittillframeend
char dummy65[sizeof (ast::stmt_waittillframeend::ptr)]; char dummy66[sizeof (ast::stmt_waittillframeend::ptr)];
// stmt_waittillmatch // stmt_waittillmatch
char dummy66[sizeof (ast::stmt_waittillmatch::ptr)]; char dummy67[sizeof (ast::stmt_waittillmatch::ptr)];
// stmt_while // stmt_while
char dummy67[sizeof (ast::stmt_while::ptr)]; char dummy68[sizeof (ast::stmt_while::ptr)];
// "path" // "path"
// "identifier" // "identifier"
@ -643,7 +648,7 @@ namespace xsk { namespace gsc { namespace s2 {
// "localized string" // "localized string"
// "float" // "float"
// "integer" // "integer"
char dummy68[sizeof (std::string)]; char dummy69[sizeof (std::string)];
}; };
/// The size of the largest semantic type. /// The size of the largest semantic type.
@ -997,30 +1002,33 @@ namespace xsk { namespace gsc { namespace s2 {
S_expr_arguments = 170, // expr_arguments S_expr_arguments = 170, // expr_arguments
S_expr_arguments_no_empty = 171, // expr_arguments_no_empty S_expr_arguments_no_empty = 171, // expr_arguments_no_empty
S_expr_reference = 172, // expr_reference S_expr_reference = 172, // expr_reference
S_expr_array = 173, // expr_array S_expr_tuple = 173, // expr_tuple
S_expr_field = 174, // expr_field S_expr_tuple_arguments = 174, // expr_tuple_arguments
S_expr_size = 175, // expr_size S_expr_tuple_types = 175, // expr_tuple_types
S_expr_paren = 176, // expr_paren S_expr_array = 176, // expr_array
S_expr_object = 177, // expr_object S_expr_field = 177, // expr_field
S_expr_thisthread = 178, // expr_thisthread S_expr_size = 178, // expr_size
S_expr_empty_array = 179, // expr_empty_array S_expr_paren = 179, // expr_paren
S_expr_undefined = 180, // expr_undefined S_expr_object = 180, // expr_object
S_expr_game = 181, // expr_game S_expr_thisthread = 181, // expr_thisthread
S_expr_self = 182, // expr_self S_expr_empty_array = 182, // expr_empty_array
S_expr_anim = 183, // expr_anim S_expr_undefined = 183, // expr_undefined
S_expr_level = 184, // expr_level S_expr_game = 184, // expr_game
S_expr_animation = 185, // expr_animation S_expr_self = 185, // expr_self
S_expr_animtree = 186, // expr_animtree S_expr_anim = 186, // expr_anim
S_expr_identifier_nosize = 187, // expr_identifier_nosize S_expr_level = 187, // expr_level
S_expr_identifier = 188, // expr_identifier S_expr_animation = 188, // expr_animation
S_expr_path = 189, // expr_path S_expr_animtree = 189, // expr_animtree
S_expr_istring = 190, // expr_istring S_expr_identifier_nosize = 190, // expr_identifier_nosize
S_expr_string = 191, // expr_string S_expr_identifier = 191, // expr_identifier
S_expr_vector = 192, // expr_vector S_expr_path = 192, // expr_path
S_expr_float = 193, // expr_float S_expr_istring = 193, // expr_istring
S_expr_integer = 194, // expr_integer S_expr_string = 194, // expr_string
S_expr_false = 195, // expr_false S_expr_vector = 195, // expr_vector
S_expr_true = 196 // expr_true S_expr_float = 196, // expr_float
S_expr_integer = 197, // expr_integer
S_expr_false = 198, // expr_false
S_expr_true = 199 // expr_true
}; };
}; };
@ -1086,6 +1094,8 @@ namespace xsk { namespace gsc { namespace s2 {
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (std::move (that.value)); value.move< ast::expr > (std::move (that.value));
break; break;
@ -1208,6 +1218,10 @@ namespace xsk { namespace gsc { namespace s2 {
value.move< ast::expr_true::ptr > (std::move (that.value)); value.move< ast::expr_true::ptr > (std::move (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (std::move (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (std::move (that.value)); value.move< ast::expr_undefined::ptr > (std::move (that.value));
break; break;
@ -1861,6 +1875,20 @@ namespace xsk { namespace gsc { namespace s2 {
{} {}
#endif #endif
#if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_tuple::ptr&& v, location_type&& l)
: Base (t)
, value (std::move (v))
, location (std::move (l))
{}
#else
basic_symbol (typename Base::kind_type t, const ast::expr_tuple::ptr& v, const location_type& l)
: Base (t)
, value (v)
, location (l)
{}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l) basic_symbol (typename Base::kind_type t, ast::expr_undefined::ptr&& v, location_type&& l)
: Base (t) : Base (t)
@ -2376,6 +2404,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.template destroy< ast::expr > (); value.template destroy< ast::expr > ();
break; break;
@ -2498,6 +2528,10 @@ switch (yykind)
value.template destroy< ast::expr_true::ptr > (); value.template destroy< ast::expr_true::ptr > ();
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.template destroy< ast::expr_tuple::ptr > ();
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.template destroy< ast::expr_undefined::ptr > (); value.template destroy< ast::expr_undefined::ptr > ();
break; break;
@ -4839,8 +4873,8 @@ switch (yykind)
/// Constants. /// Constants.
enum enum
{ {
yylast_ = 2419, ///< Last index in yytable_. yylast_ = 2479, ///< Last index in yytable_.
yynnts_ = 84, ///< Number of nonterminal symbols. yynnts_ = 87, ///< Number of nonterminal symbols.
yyfinal_ = 22 ///< Termination state number. yyfinal_ = 22 ///< Termination state number.
}; };
@ -4896,6 +4930,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.copy< ast::expr > (YY_MOVE (that.value)); value.copy< ast::expr > (YY_MOVE (that.value));
break; break;
@ -5018,6 +5054,10 @@ switch (yykind)
value.copy< ast::expr_true::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_true::ptr > (YY_MOVE (that.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.copy< ast::expr_tuple::ptr > (YY_MOVE (that.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value)); value.copy< ast::expr_undefined::ptr > (YY_MOVE (that.value));
break; break;
@ -5218,6 +5258,8 @@ switch (yykind)
case symbol_kind::S_expr_ternary: // expr_ternary case symbol_kind::S_expr_ternary: // expr_ternary
case symbol_kind::S_expr_binary: // expr_binary case symbol_kind::S_expr_binary: // expr_binary
case symbol_kind::S_expr_primitive: // expr_primitive case symbol_kind::S_expr_primitive: // expr_primitive
case symbol_kind::S_expr_tuple: // expr_tuple
case symbol_kind::S_expr_tuple_types: // expr_tuple_types
case symbol_kind::S_expr_object: // expr_object case symbol_kind::S_expr_object: // expr_object
value.move< ast::expr > (YY_MOVE (s.value)); value.move< ast::expr > (YY_MOVE (s.value));
break; break;
@ -5340,6 +5382,10 @@ switch (yykind)
value.move< ast::expr_true::ptr > (YY_MOVE (s.value)); value.move< ast::expr_true::ptr > (YY_MOVE (s.value));
break; break;
case symbol_kind::S_expr_tuple_arguments: // expr_tuple_arguments
value.move< ast::expr_tuple::ptr > (YY_MOVE (s.value));
break;
case symbol_kind::S_expr_undefined: // expr_undefined case symbol_kind::S_expr_undefined: // expr_undefined
value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value)); value.move< ast::expr_undefined::ptr > (YY_MOVE (s.value));
break; break;
@ -5547,7 +5593,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::s2 } } } // xsk::gsc::s2
#line 5551 "parser.hpp" #line 5597 "parser.hpp"

View File

@ -47,7 +47,7 @@ auto resolver::opcode_id(const std::string& name) -> std::uint8_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve opcode id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve opcode id for name '%s'!", name.data()));
} }
auto resolver::opcode_name(std::uint8_t id) -> std::string auto resolver::opcode_name(std::uint8_t id) -> std::string
@ -59,7 +59,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
return std::string(itr->second); return std::string(itr->second);
} }
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id)); throw error(utils::string::va("couldn't resolve opcode name for id '0x%hhX'!", id));
} }
auto resolver::function_id(const std::string& name) -> std::uint16_t auto resolver::function_id(const std::string& name) -> std::uint16_t
@ -76,7 +76,7 @@ auto resolver::function_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin function id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin function id for name '%s'!", name.data()));
} }
auto resolver::function_name(std::uint16_t id) -> std::string auto resolver::function_name(std::uint16_t id) -> std::string
@ -105,7 +105,7 @@ auto resolver::method_id(const std::string& name) -> std::uint16_t
return itr->second; return itr->second;
} }
throw error(utils::string::va("Couldn't resolve builtin method id for name '%s'!", name.data())); throw error(utils::string::va("couldn't resolve builtin method id for name '%s'!", name.data()));
} }
auto resolver::method_name(std::uint16_t id) -> std::string auto resolver::method_name(std::uint16_t id) -> std::string

View File

@ -176,7 +176,7 @@ auto opcode_size(std::uint8_t id) -> std::uint32_t
case opcode::OP_GetVector: case opcode::OP_GetVector:
return 13; return 13;
default: default:
throw error("Couldn't resolve instruction size for " + std::to_string(id)); throw error("couldn't resolve instruction size for " + std::to_string(id));
} }
} }

View File

@ -439,7 +439,7 @@ void assembler::assemble_instruction(const instruction::ptr& inst)
assemble_far_call(inst, true); assemble_far_call(inst, true);
break;*/ break;*/
default: default:
throw asm_error(utils::string::va("Unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index)); throw asm_error(utils::string::va("unhandled opcode 0x%X at index '%04X'!", inst->opcode, inst->index));
} }
} }
@ -546,6 +546,10 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
index += 3; index += 3;
} }
else
{
throw asm_error("invalid switch case '" + inst->data[1 + (3 * i)] + "'!");
}
} }
} }
@ -623,7 +627,7 @@ auto assembler::resolve_function(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve local function address of '" + name + "'!"); throw asm_error("couldn't resolve local function address of '" + name + "'!");
} }
auto assembler::resolve_label(const std::string& name) -> std::int32_t auto assembler::resolve_label(const std::string& name) -> std::int32_t
@ -636,7 +640,7 @@ auto assembler::resolve_label(const std::string& name) -> std::int32_t
} }
} }
throw asm_error("Couldn't resolve label address of '" + name + "'!"); throw asm_error("couldn't resolve label address of '" + name + "'!");
} }
} // namespace xsk::gsc::s4 } // namespace xsk::gsc::s4

View File

@ -40,7 +40,7 @@ auto compiler::parse_buffer(const std::string& file, char* data, size_t size) ->
if (parser.parse() || result == nullptr) if (parser.parse() || result == nullptr)
{ {
throw comp_error(location(&file), "An unknown error ocurred while parsing gsc file."); throw comp_error(location(&file), "an unknown error ocurred while parsing gsc file");
} }
return result; return result;
@ -91,7 +91,7 @@ void compiler::emit_include(const ast::include::ptr& include)
{ {
if (inc.name == path) if (inc.name == path)
{ {
throw comp_error(include->loc(), "error duplicated include file '" + path + "'."); throw comp_error(include->loc(), "duplicated include file '" + path + "'");
} }
} }
@ -113,7 +113,7 @@ void compiler::emit_include(const ast::include::ptr& include)
if (funcs.size() == 0) if (funcs.size() == 0)
{ {
throw comp_error(include->loc(), "error empty include file '" + path + "'."); throw comp_error(include->loc(), "empty include file '" + path + "'");
} }
includes_.push_back(include_t(path, funcs)); includes_.push_back(include_t(path, funcs));
@ -151,13 +151,18 @@ void compiler::emit_declaration(const ast::decl& decl)
void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree) void compiler::emit_decl_usingtree(const ast::decl_usingtree::ptr& animtree)
{ {
if (developer_thread_) if (developer_thread_)
throw comp_error(animtree->loc(), "cannot put #using_animtree inside /# ... #/ comment"); throw comp_error(animtree->loc(), "cannot put #using_animtree inside developer block comment");
animtrees_.push_back({ animtree->name->value, false }); animtrees_.push_back({ animtree->name->value, false });
} }
void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant) void compiler::emit_decl_constant(const ast::decl_constant::ptr& constant)
{ {
const auto itr = constants_.find(constant->name->value);
if (itr != constants_.end())
throw comp_error(constant->loc(), "duplicated constant '" + constant->name->value + "'");
constants_.insert({ constant->name->value, std::move(constant->value) }); constants_.insert({ constant->name->value, std::move(constant->value) });
} }
@ -395,7 +400,7 @@ void compiler::emit_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const blo
for (const auto& entry : stmt->args->list) for (const auto& entry : stmt->args->list)
{ {
create_variable(entry.as_identifier, blk); variable_create(entry.as_identifier, blk);
emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk)); emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, variable_access_index(entry.as_identifier, blk));
} }
@ -1044,11 +1049,18 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
if (expr->rvalue == ast::kind::expr_undefined) if (expr->rvalue == ast::kind::expr_undefined)
{ {
emit_expr_clear(expr->lvalue, blk); emit_expr_clear(expr->lvalue, blk);
return; }
else if (expr->lvalue == ast::kind::expr_tuple)
{
emit_expr(expr->rvalue, blk);
emit_expr_tuple(expr->lvalue.as_tuple, blk);
}
else
{
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
} }
emit_expr(expr->rvalue, blk);
emit_expr_variable_ref(expr->lvalue, blk, true);
return; return;
} }
@ -1580,7 +1592,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
for (const auto& entry : expr->list) for (const auto& entry : expr->list)
{ {
initialize_variable(entry, blk); variable_initialize(entry, blk);
data.push_back(variable_create_index(entry, blk)); data.push_back(variable_create_index(entry, blk));
} }
@ -1644,6 +1656,29 @@ void compiler::emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr&
emit_opcode(opcode::OP_size); emit_opcode(opcode::OP_size);
} }
void compiler::emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
emit_expr_variable_ref(expr->temp, blk, true);
auto index = 0;
for (const auto& entry : expr->list)
{
if (index == 0)
emit_opcode(opcode::OP_GetZero);
else
emit_opcode(opcode::OP_GetByte, utils::string::va("%d", index));
index++;
emit_opcode(opcode::OP_EvalLocalArrayCached, variable_access_index(expr->temp.as_identifier, blk));
emit_expr_variable_ref(entry, blk, true);
}
emit_expr_clear_local(expr->temp.as_identifier, blk);
}
void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set) void compiler::emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set)
{ {
switch (expr.kind()) switch (expr.kind())
@ -1683,7 +1718,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
{ {
if (!variable_initialized(expr->obj.as_identifier, blk)) if (!variable_initialized(expr->obj.as_identifier, blk))
{ {
initialize_variable(expr->obj.as_identifier, blk); variable_initialize(expr->obj.as_identifier, blk);
emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk)); emit_opcode(opcode::OP_EvalNewLocalArrayRefCached0, variable_create_index(expr->obj.as_identifier, blk));
if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!"); if (!set) throw comp_error(expr->loc(), "INTERNAL: VAR CREATED BUT NOT SET!");
@ -1769,7 +1804,7 @@ void compiler::emit_expr_local_ref(const ast::expr_identifier::ptr& expr, const
{ {
if (!variable_initialized(expr, blk)) if (!variable_initialized(expr, blk))
{ {
initialize_variable(expr, blk); variable_initialize(expr, blk);
emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk)); emit_opcode(opcode::OP_SetNewLocalVariableFieldCached0, variable_create_index(expr, blk));
} }
else if (variable_stack_index(expr, blk) == 0) else if (variable_stack_index(expr, blk) == 0)
@ -2298,7 +2333,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable"); throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
} }
register_variable(entry.as_identifier->value, blk); variable_register(entry.as_identifier->value, blk);
} }
} }
@ -2365,11 +2400,11 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2392,11 +2427,11 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2424,7 +2459,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
continue_blks_.push_back(stmt->blk.get()); continue_blks_.push_back(stmt->blk.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_stmt(stmt->iter, stmt->blk_iter); process_stmt(stmt->iter, stmt->blk_iter);
@ -2433,7 +2468,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
if (const_cond) blk->append(break_blks_); if (const_cond) blk->append(break_blks_);
blk->merge({stmt->blk.get()}); blk->merge({ stmt->blk.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2441,8 +2476,8 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk) void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block::ptr& blk)
{ {
auto array_name = utils::string::va("temp_%d", ++label_idx_); auto array_name = utils::string::va("_temp_%d", ++label_idx_);
auto key_name = utils::string::va("temp_%d", ++label_idx_); auto key_name = utils::string::va("_temp_%d", ++label_idx_);
stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name)); stmt->array = ast::expr(std::make_unique<ast::expr_identifier>(stmt->loc(), array_name));
@ -2474,13 +2509,13 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
continue_blks_.push_back(stmt->ctx.get()); continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0u; i < continue_blks_.size(); i++) for (auto i = 0u; i < continue_blks_.size(); i++)
blk->append({continue_blks_.at(i)}); blk->append({ continue_blks_.at(i) });
process_expr(stmt->key_expr, stmt->ctx_post); process_expr(stmt->key_expr, stmt->ctx_post);
blk->append({ stmt->ctx_post.get() }); blk->append({ stmt->ctx_post.get() });
blk->merge({ stmt->ctx_post.get() }); blk->merge({ stmt->ctx_post.get() });
blk->merge({stmt->ctx.get()}); blk->merge({ stmt->ctx.get() });
break_blks_ = old_breaks; break_blks_ = old_breaks;
continue_blks_ = old_continues; continue_blks_ = old_continues;
@ -2640,23 +2675,40 @@ void compiler::process_expr(const ast::expr& expr, const block::ptr& blk)
{ {
if (expr == ast::kind::expr_identifier) if (expr == ast::kind::expr_identifier)
{ {
register_variable(expr.as_identifier->value, blk); variable_register(expr.as_identifier->value, blk);
} }
else if (expr == ast::kind::expr_array) else if (expr == ast::kind::expr_array)
{ {
process_expr(expr.as_array->obj, blk); process_expr(expr.as_array->obj, blk);
} }
else if (expr == ast::kind::expr_tuple)
{
process_expr_tuple(expr.as_tuple, blk);
}
}
void compiler::process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk)
{
auto array = utils::string::va("_temp_%d", ++label_idx_);
expr->temp = ast::expr(std::make_unique<ast::expr_identifier>(expr->loc(), array));
process_expr(expr->temp, blk);
for (const auto& entry : expr->list)
{
process_expr(entry, blk);
}
} }
void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk) void compiler::process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk)
{ {
for (const auto& entry : decl->list) for (const auto& entry : decl->list)
{ {
register_variable(entry->value, blk); variable_register(entry->value, blk);
} }
} }
void compiler::register_variable(const std::string& name, const block::ptr& blk) void compiler::variable_register(const std::string& name, const block::ptr& blk)
{ {
auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(), auto it = std::find_if (blk->local_vars.begin(), blk->local_vars.end(),
[&](const gsc::local_var& v) { return v.name == name; }); [&](const gsc::local_var& v) { return v.name == name; });
@ -2683,7 +2735,7 @@ void compiler::register_variable(const std::string& name, const block::ptr& blk)
} }
} }
void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::uint32_t i = 0; i < blk->local_vars.size(); i++) for (std::uint32_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2697,7 +2749,6 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
{ {
emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create)); emit_opcode(opcode::OP_CreateLocalVariable, utils::string::va("%d", blk->local_vars[j].create));
blk->local_vars[j].init = true; blk->local_vars[j].init = true;
//ctx->local_vars_create_count++;
} }
} }
blk->local_vars[i].init = true; blk->local_vars[i].init = true;
@ -2710,7 +2761,7 @@ void compiler::initialize_variable(const ast::expr_identifier::ptr& name, const
throw comp_error(name->loc(), "local variable '" + name->value + "' not found."); throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
} }
void compiler::create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk) void compiler::variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk)
{ {
for (std::size_t i = 0; i < blk->local_vars.size(); i++) for (std::size_t i = 0; i < blk->local_vars.size(); i++)
{ {
@ -2888,8 +2939,7 @@ auto compiler::is_constant_condition(const ast::expr& expr) -> bool
auto compiler::create_label() -> std::string auto compiler::create_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); return utils::string::va("loc_%d", label_idx_);
return name;
} }
auto compiler::insert_label() -> std::string auto compiler::insert_label() -> std::string
@ -2904,7 +2954,7 @@ auto compiler::insert_label() -> std::string
{ {
label_idx_++; label_idx_++;
auto name = utils::string::va("loc_%d", label_idx_); auto name = utils::string::va("loc_%d", label_idx_);
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
return name; return name;
} }
} }
@ -2937,7 +2987,7 @@ void compiler::insert_label(const std::string& name)
} }
else else
{ {
function_->labels.insert({index_, name}); function_->labels.insert({ index_, name });
} }
} }

View File

@ -98,6 +98,7 @@ private:
void emit_expr_istrue(const ast::expr_istrue::ptr& expr, const block::ptr& blk); void emit_expr_istrue(const ast::expr_istrue::ptr& expr, const block::ptr& blk);
void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk); void emit_expr_reference(const ast::expr_reference::ptr& expr, const block::ptr& blk);
void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk); void emit_expr_size(const ast::expr_size::ptr& expr, const block::ptr& blk);
void emit_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set); void emit_expr_variable_ref(const ast::expr& expr, const block::ptr& blk, bool set);
void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set); void emit_expr_array_ref(const ast::expr_array::ptr& expr, const block::ptr& blk, bool set);
void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set); void emit_expr_field_ref(const ast::expr_field::ptr& expr, const block::ptr& blk, bool set);
@ -139,10 +140,11 @@ private:
void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk); void process_stmt_continue(const ast::stmt_continue::ptr& stmt, const block::ptr& blk);
void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk); void process_stmt_return(const ast::stmt_return::ptr& stmt, const block::ptr& blk);
void process_expr(const ast::expr& expr, const block::ptr& blk); void process_expr(const ast::expr& expr, const block::ptr& blk);
void process_expr_tuple(const ast::expr_tuple::ptr& expr, const block::ptr& blk);
void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk); void process_expr_parameters(const ast::expr_parameters::ptr& decl, const block::ptr& blk);
void register_variable(const std::string& name, const block::ptr& blk); void variable_register(const std::string& name, const block::ptr& blk);
void initialize_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_initialize(const ast::expr_identifier::ptr& name, const block::ptr& blk);
void create_variable(const ast::expr_identifier::ptr& name, const block::ptr& blk); void variable_create(const ast::expr_identifier::ptr& name, const block::ptr& blk);
auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t; auto variable_stack_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::uint8_t;
auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_create_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;
auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string; auto variable_access_index(const ast::expr_identifier::ptr& name, const block::ptr& blk) -> std::string;

Some files were not shown because too many files have changed in this diff Show More