Verified Commit 6a94aa13 authored by Adam Matoušek's avatar Adam Matoušek
Browse files

Local arrays (quite limited).

parent d38ac56e
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -13,9 +13,12 @@ Nejvýraznějšími rozdíly oproti jazyku C jsou:
- neexistují typy `unsigned`,
- neexistují typy `float` a `double`,
- neexistují konstantní a `volatile` proměnné a ukazatele,
- neexistují statická pole,
- neexistují součtové typy (`union`),
- neexistují struktury (`struct`), součtové typy (`union`) ani výčtové typy
  (`enum`),
- neexistují návěstí a související řídicí konstrukce (`goto`, `switch`),
- pole jsou jen lokální, jednorozměrná a nelze je rovnou inicialisovat, jejich
  velikost ale nemusí být známa v době překladu,
- `sizeof` na polích vrací velikost ukazatele,
- neexistuje operátor čárka (sekvence výrazů),
- podobně jako v C++ sdílí datové struktury jmenný prostor s jinými
  identifikátory a není nutné před ně při použití psát `struct`,
+11 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ void chk_and_add_arg( seagol::CallInfo* ci, const seagol::ExprInfo &arg,
%type <std::string> nodecl_fresh_identifier
%type <seagol::IdentifierInfo*> argument_decl
%type <seagol::IdentifierInfo*> declaration
%type <seagol::IdentifierInfo*> array_declaration

%type <seagol::ArgumentList> arguments
%type <seagol::ArgumentList> argument_decl_list
@@ -364,6 +365,7 @@ statement
    | ';'
    | expression ';'
    | declaration ';'
    | array_declaration ';'
    | declaration[l] '=' expression <llvm::Type*>{ $$ = $l->type; } _coerce[r] ';'
        { IRB.CreateStore( $r.llval, $l->llval ); }
    | _loop_prepare loop_stmt _loop_finish
@@ -378,6 +380,13 @@ declaration
        $$->llval = IRB.CreateAlloca( $$->type, nullptr, $$->name + ".addr" );
    }
    ;
array_declaration
    : complete_type fresh_identifier '[' expression _i64 _coerce[sz] ']' {
        $$ = $2;
        $$->type = llvm::ArrayType::get( $1, 0 );
        $$->llval = IRB.CreateAlloca( $1, $sz.llval, $$->name );
    }
    ;

if_stmt
    : IF _if[br] '(' expression _bool _coerce ')' _then statement ELSE _else statement
@@ -652,6 +661,8 @@ primary_expr
        $$.llval = $1->llval;
        if ( llvm::isa< llvm::Function >( $$.llval ) ) {
            $$.cat = seagol::Value::FVALUE;
        } else if ( $1->type->isArrayTy() ) {
            $$.cat = seagol::Value::RVALUE;
        } else {
            $$.cat = seagol::Value::LVALUE;
        }