src/compiler/HIR.cpp
changeset 236 072f1114ea5d
parent 234 26e3035cdffc
child 245 9371f058625a
     1.1 --- a/src/compiler/HIR.cpp	Mon Dec 24 02:56:02 2012 -0800
     1.2 +++ b/src/compiler/HIR.cpp	Mon Dec 24 16:09:13 2012 -0800
     1.3 @@ -75,11 +75,8 @@
     1.4  {
     1.5      __ object(hir->array());
     1.6  
     1.7 -    if (!hir->type()->isConst()) {
     1.8 -        // If the type isn't const, we have to assume a consumer may modify
     1.9 -        // the array, and therefore we have to duplicate it here.
    1.10 +    if (hir->duplicate())
    1.11          __ duparray(); 
    1.12 -    }
    1.13  }
    1.14  
    1.15  void
    1.16 @@ -355,16 +352,30 @@
    1.17  HIRTranslator::visitStore(HStore *store)
    1.18  {
    1.19      store->lval()->bind(this, emitter_);
    1.20 +
    1.21      if (store->kind() == TOK_ASSIGN) {
    1.22 -        store->rval()->accept(this);
    1.23 +        // Fixed-length arrays and structs have copy semantics.
    1.24 +        Local<Type> type(zone_, store->lval()->type());
    1.25 +        if (type->isArray() && ArrayType::cast(type)->isFixedLength()) {
    1.26 +            store->lval()->load(emitter_);
    1.27 +            store->rval()->accept(this);
    1.28 +            __ copyarray();
    1.29 +        } else if (type->isStruct()) {
    1.30 +            store->lval()->load(emitter_);
    1.31 +            store->rval()->accept(this);
    1.32 +            __ copystruct();
    1.33 +        } else {
    1.34 +            store->rval()->accept(this);
    1.35 +            store->lval()->store(emitter_);
    1.36 +        }
    1.37      } else {
    1.38          // Advanced case: dup the ref, load, op, store.
    1.39          store->lval()->hold(emitter_);
    1.40          store->lval()->load(emitter_);
    1.41          store->rval()->accept(this);
    1.42          __ binary(TokenToOpcode(store->kind()));
    1.43 +        store->lval()->store(emitter_);
    1.44      }
    1.45 -    store->lval()->store(emitter_);
    1.46  }
    1.47  
    1.48  void