Commits

KS Sreeram  committed 4d70af2

oldclay: replace addAssign, subtractAssign, multiplyAssign, divideAssign, remainderAssign with a single updateAssign(op, dest, src).

  • Participants
  • Parent commits 71edede

Comments (0)

Files changed (8)

File compiler/src/codegen.cpp

         PValuePtr pvLeft = safeAnalyzeOne(x->left, env);
         if (pvLeft->isTemp)
             error(x->left, "cannot assign to a temporary");
-        CallPtr call = new Call(updateOperatorExpr(x->op), new ExprList());
+        CallPtr call = new Call(prelude_expr_updateAssign(), new ExprList());
+        call->args->add(updateOperatorExpr(x->op));
         call->args->add(x->left);
         call->args->add(x->right);
         return codegenStatement(new ExprStatement(call.ptr()), env, ctx);

File compiler/src/desugar.cpp

 
 ExprPtr updateOperatorExpr(int op) {
     switch (op) {
-    case UPDATE_ADD : return prelude_expr_addAssign();
-    case UPDATE_SUBTRACT : return prelude_expr_subtractAssign();
-    case UPDATE_MULTIPLY : return prelude_expr_multiplyAssign();
-    case UPDATE_DIVIDE : return prelude_expr_divideAssign();
-    case UPDATE_REMAINDER : return prelude_expr_remainderAssign();
+    case UPDATE_ADD : return prelude_expr_add();
+    case UPDATE_SUBTRACT : return prelude_expr_subtract();
+    case UPDATE_MULTIPLY : return prelude_expr_multiply();
+    case UPDATE_DIVIDE : return prelude_expr_divide();
+    case UPDATE_REMAINDER : return prelude_expr_remainder();
     default :
         assert(false);
         return NULL;

File compiler/src/evaluator.cpp

         PValuePtr pvLeft = safeAnalyzeOne(x->left, env);
         if (pvLeft->isTemp)
             error(x->left, "cannot assign to a temporary");
-        CallPtr call = new Call(updateOperatorExpr(x->op), new ExprList());
+        CallPtr call = new Call(prelude_expr_updateAssign(), new ExprList());
+        call->args->add(updateOperatorExpr(x->op));
         call->args->add(x->left);
         call->args->add(x->right);
         return evalStatement(new ExprStatement(call.ptr()), env, ctx);

File compiler/src/libclaynames.hpp

 ObjectPtr prelude_destroy();
 ObjectPtr prelude_move();
 ObjectPtr prelude_assign();
-ObjectPtr prelude_addAssign();
-ObjectPtr prelude_subtractAssign();
-ObjectPtr prelude_multiplyAssign();
-ObjectPtr prelude_divideAssign();
-ObjectPtr prelude_remainderAssign();
+ObjectPtr prelude_updateAssign();
 ObjectPtr prelude_ByRef();
 ObjectPtr prelude_setArgcArgv();
 ObjectPtr prelude_callMain();
 ExprPtr prelude_expr_destroy();
 ExprPtr prelude_expr_move();
 ExprPtr prelude_expr_assign();
-ExprPtr prelude_expr_addAssign();
-ExprPtr prelude_expr_subtractAssign();
-ExprPtr prelude_expr_multiplyAssign();
-ExprPtr prelude_expr_divideAssign();
-ExprPtr prelude_expr_remainderAssign();
+ExprPtr prelude_expr_updateAssign();
 ExprPtr prelude_expr_ByRef();
 ExprPtr prelude_expr_setArgcArgv();
 ExprPtr prelude_expr_callMain();

File compiler/src/loader.cpp

 DEFINE_PRELUDE_ACCESSOR(destroy)
 DEFINE_PRELUDE_ACCESSOR(move)
 DEFINE_PRELUDE_ACCESSOR(assign)
-DEFINE_PRELUDE_ACCESSOR(addAssign)
-DEFINE_PRELUDE_ACCESSOR(subtractAssign)
-DEFINE_PRELUDE_ACCESSOR(multiplyAssign)
-DEFINE_PRELUDE_ACCESSOR(divideAssign)
-DEFINE_PRELUDE_ACCESSOR(remainderAssign)
+DEFINE_PRELUDE_ACCESSOR(updateAssign)
 DEFINE_PRELUDE_ACCESSOR(ByRef)
 DEFINE_PRELUDE_ACCESSOR(setArgcArgv)
 DEFINE_PRELUDE_ACCESSOR(callMain)

File lib-clay/deques/deques.clay

     dec(i.current);
 }
 
-[T, I | Integer?(I)] overload addAssign(i: DequeCoordinate[T], n: I) { addAssign(i, PtrInt(n)); }
+[T, I | Integer?(I)] overload updateAssign(static add, i: DequeCoordinate[T], n: I) {
+    i += PtrInt(n);
+}
 
-[T] overload addAssign(i: DequeCoordinate[T], n: PtrInt) {
+[T] overload updateAssign(static add, i: DequeCoordinate[T], n: PtrInt) {
     var offset = n + PtrInt(i.current - i.first);
     if (offset >= 0 and offset < DequeBufferSize(T))
         i.current += n;
     j += n;
 }
 
-[T, I | Integer?(I)] overload subtractAssign(i: DequeCoordinate[T], n: I) {
+[T, I | Integer?(I)] overload updateAssign(static subtract, i: DequeCoordinate[T], n: I) {
     i += -n;
 }
 

File lib-clay/operators/operators.clay

 procedure moveUnsafe;
 procedure resetUnsafe;
 procedure assign;
+procedure updateAssign;
 
 procedure equals?;
 procedure lesser?;
 procedure divide;
 procedure remainder;
 
-procedure addAssign;
-procedure subtractAssign;
-procedure multiplyAssign;
-procedure divideAssign;
-procedure remainderAssign;
-
 procedure inc;
 procedure dec;
 
     swap(dest, src);
 }
 
+[F]
+inline overload updateAssign(static F, dest, src) {
+    dest = F(dest, src);
+}
+
 inline notEquals?(a, b) = not equals?(a, b);
 
 inline ordered?(a, b) = (a <= b) or (b <= a);
 
 inline overload greaterEquals?(a, b) = not lesser?(a, b);
 
-inline overload addAssign(a, b)       { a = a + b; }
-inline overload subtractAssign(a, b)  { a = a - b; }
-inline overload multiplyAssign(a, b)  { a = a * b; }
-inline overload divideAssign(a, b)    { a = a / b; }
-inline overload remainderAssign(a, b) { a = a % b; }
-
 inline overload bitwiseAnd(a, b, c, ...rest) =
     bitwiseAnd(bitwiseAnd(a,b), c, ...rest);
 

File lib-clay/sequences/lazy/grouped/grouped.clay

 overload subtract(i: RAGroupCoordinate[C], n: I)
     = RAGroupCoordinate(i.coord - n * i.groupSize, i.groupSize);
 [C, I | Integer?(I)]
-overload addAssign(i: RAGroupCoordinate[C], n: I) {
+overload updateAssign(static add, i: RAGroupCoordinate[C], n: I) {
     i.coord += n * i.groupSize;
 }
 [C, I | Integer?(I)]
-overload subtractAssign(i: RAGroupCoordinate[C], n: I) {
+overload updateAssign(static subtract, i: RAGroupCoordinate[C], n: I) {
     i.coord -= n * i.groupSize;
 }