Commits

Anonymous committed 8a70674

oldclay: added support for indexUpdateAssign, fieldRefUpdateAssign, staticIndexUpdateAssign.

Comments (0)

Files changed (4)

compiler/src/codegen.cpp

         PValuePtr pvLeft = safeAnalyzeOne(x->left, env);
         if (pvLeft->isTemp)
             error(x->left, "cannot assign to a temporary");
+        if (x->left->exprKind == INDEXING) {
+            Indexing *y = (Indexing *)x->left.ptr();
+            PValuePtr pvIndexable = safeAnalyzeOne(y->expr, env);
+            if (pvIndexable->type->typeKind != STATIC_TYPE) {
+                CallPtr call = new Call(
+                    prelude_expr_indexUpdateAssign(), new ExprList()
+                );
+                call->args->add(updateOperatorExpr(x->op));
+                call->args->add(y->expr);
+                call->args->add(y->args);
+                call->args->add(x->right);
+                return codegenStatement(new ExprStatement(call.ptr()), env, ctx);
+            }
+        }
+        else if (x->left->exprKind == STATIC_INDEXING) {
+            StaticIndexing *y = (StaticIndexing *)x->left.ptr();
+            CallPtr call = new Call(
+                prelude_expr_staticIndexUpdateAssign(), new ExprList()
+            );
+            call->args->add(updateOperatorExpr(x->op));
+            call->args->add(y->expr);
+            ValueHolderPtr vh = sizeTToValueHolder(y->index);
+            call->args->add(new StaticExpr(new ObjectExpr(vh.ptr())));
+            call->args->add(x->right);
+            return codegenStatement(new ExprStatement(call.ptr()), env, ctx);
+        }
+        else if (x->left->exprKind == FIELD_REF) {
+            FieldRef *y = (FieldRef *)x->left.ptr();
+            PValuePtr pvBase = safeAnalyzeOne(y->expr, env);
+            if (pvBase->type->typeKind != STATIC_TYPE) {
+                CallPtr call = new Call(
+                    prelude_expr_fieldRefUpdateAssign(), new ExprList()
+                );
+                call->args->add(updateOperatorExpr(x->op));
+                call->args->add(y->expr);
+                call->args->add(new ObjectExpr(y->name.ptr()));
+                call->args->add(x->right);
+                return codegenStatement(new ExprStatement(call.ptr()), env, ctx);
+            }
+        }
         CallPtr call = new Call(prelude_expr_updateAssign(), new ExprList());
         call->args->add(updateOperatorExpr(x->op));
         call->args->add(x->left);

compiler/src/libclaynames.hpp

 ObjectPtr prelude_assign();
 ObjectPtr prelude_updateAssign();
 ObjectPtr prelude_indexAssign();
+ObjectPtr prelude_indexUpdateAssign();
 ObjectPtr prelude_fieldRefAssign();
+ObjectPtr prelude_fieldRefUpdateAssign();
 ObjectPtr prelude_staticIndexAssign();
+ObjectPtr prelude_staticIndexUpdateAssign();
 ObjectPtr prelude_ByRef();
 ObjectPtr prelude_setArgcArgv();
 ObjectPtr prelude_callMain();
 ExprPtr prelude_expr_assign();
 ExprPtr prelude_expr_updateAssign();
 ExprPtr prelude_expr_indexAssign();
+ExprPtr prelude_expr_indexUpdateAssign();
 ExprPtr prelude_expr_fieldRefAssign();
+ExprPtr prelude_expr_fieldRefUpdateAssign();
 ExprPtr prelude_expr_staticIndexAssign();
+ExprPtr prelude_expr_staticIndexUpdateAssign();
 ExprPtr prelude_expr_ByRef();
 ExprPtr prelude_expr_setArgcArgv();
 ExprPtr prelude_expr_callMain();

compiler/src/loader.cpp

 DEFINE_PRELUDE_ACCESSOR(assign)
 DEFINE_PRELUDE_ACCESSOR(updateAssign)
 DEFINE_PRELUDE_ACCESSOR(indexAssign)
+DEFINE_PRELUDE_ACCESSOR(indexUpdateAssign)
 DEFINE_PRELUDE_ACCESSOR(fieldRefAssign)
+DEFINE_PRELUDE_ACCESSOR(fieldRefUpdateAssign)
 DEFINE_PRELUDE_ACCESSOR(staticIndexAssign)
+DEFINE_PRELUDE_ACCESSOR(staticIndexUpdateAssign)
 DEFINE_PRELUDE_ACCESSOR(ByRef)
 DEFINE_PRELUDE_ACCESSOR(setArgcArgv)
 DEFINE_PRELUDE_ACCESSOR(callMain)

lib-clay/operators/operators.clay

 procedure staticIndex;
 
 procedure fieldRefAssign;
+procedure fieldRefUpdateAssign;
 procedure staticIndexAssign;
+procedure staticIndexUpdateAssign;
 procedure indexAssign;
+procedure indexUpdateAssign;
+
 
 
 //
     assign(fieldRef(dest, static FIELD), src);
 }
 
+[F, FIELD]
+inline overload fieldRefUpdateAssign(static F, dest, static FIELD, forward src) {
+    updateAssign(static F, fieldRef(dest, static FIELD), src);
+}
+
 [i]
 inline overload staticIndexAssign(dest, static i, forward src) {
     assign(staticIndex(dest, static i), src);
 }
 
+[F, i]
+inline overload staticIndexUpdateAssign(static F, dest, static i, forward src) {
+    updateAssign(static F, staticIndex(dest, static i), src);
+}
+
 [...T | countValues(...T) >= 2]
 inline overload indexAssign(dest, forward ...indicesAndSrc:T) {
     assign(
     );
 }
 
+[F, ...T | countValues(...T) >= 2]
+inline overload indexUpdateAssign(static F, dest, forward ...indicesAndSrc:T) {
+    updateAssign(
+        static F,
+        index(dest, ...withoutNthValue(
+            static countValues(...T)-1,
+            ...indicesAndSrc
+        )),
+        lastValue(...indicesAndSrc),
+    );
+}
+
+
 
 
 //