Binary Operators support for non-Integer types #141

Open
opened 2023-07-11 09:50:33 +01:00 by deavmi · 3 comments
Owner

What is this?

Currently when doing typechecking we handle these cases:

  1. Ptr+Integral
  2. Integral+Ptr
  3. Integral+Integral

But the last case is not handled (we show various examples):

  1. Ptr+Ptr
  2. Anything else == anything else
## What is this? Currently when doing typechecking we handle these cases: 1. `Ptr+Integral` 2. `Integral+Ptr` 3. `Integral+Integral` But the last case is not handled (we show various examples): 1. `Ptr+Ptr` 2. `Anything else == anything else`
deavmi self-assigned this 2023-07-11 09:50:33 +01:00
deavmi added the
typing
label 2023-07-11 09:54:22 +01:00
deavmi added this to the Basics milestone 2023-07-11 09:54:25 +01:00
deavmi added this to the Dependency tree, type-checking and codegen project 2023-07-11 09:54:28 +01:00
deavmi started working 2023-07-11 10:13:58 +01:00
deavmi stopped working 2023-07-11 10:14:02 +01:00
4 seconds
deavmi added spent time 2023-07-11 10:14:06 +01:00
5 minutes
Author
Owner

Note

Once it is done we will then be able to remove the isSameType() call, the chosenType logic will stay ofc:

/** 
                 * We now will check to make sure the types
                 * match, if not an error is thrown.
                 *
                 * We will also then set the instruction's
                 * type to one of the two (they're the same
                 * so it isn't as if it matters). But the
                 * resulting instruction should be of the type
                 * of its components - that's the logic.
                 */
                Type chosenType;
                if(isSameType(vLhsType, vRhsType))
                {
                    /* Left type + Right type = left/right type (just use left - it doesn't matter) */
                    chosenType = vLhsType;
                }
                else
                {
                    throw new TypeMismatchException(this, vLhsType, vRhsType, "Binary operator expression requires both types be same");
                }
## Note Once it is done we will then be able to remove the `isSameType()` call, the `chosenType` logic will stay ofc: ```d /** * We now will check to make sure the types * match, if not an error is thrown. * * We will also then set the instruction's * type to one of the two (they're the same * so it isn't as if it matters). But the * resulting instruction should be of the type * of its components - that's the logic. */ Type chosenType; if(isSameType(vLhsType, vRhsType)) { /* Left type + Right type = left/right type (just use left - it doesn't matter) */ chosenType = vLhsType; } else { throw new TypeMismatchException(this, vLhsType, vRhsType, "Binary operator expression requires both types be same"); } ```
deavmi started working 2023-07-11 10:19:10 +01:00
deavmi added the due date 2023-07-30 2023-07-11 10:19:24 +01:00
deavmi stopped working 2023-07-11 10:19:29 +01:00
19 seconds
deavmi added a new dependency 2023-07-11 11:02:27 +01:00
deavmi added spent time 2023-07-17 11:59:18 +01:00
10 minutes
deavmi started working 2023-07-17 11:59:19 +01:00
Author
Owner

I have now added support for:

module simple_function_recursion_factorial;

ubyte factorial(ubyte i)
{
    if(i == 0)
    {
        return 1;
    }
    else
    {
        return i*factorial(i-1);
    }
}

As in, np explicit cast is required for the i == 0 (as in no cast(byte)0)) (same goes for the i-1 (the 1). What we have now is implicit casting for the literal value instructions (LiteralValue) which helps a lot.


Added in commit a73e8308db33a8ac0203c49df01bb9078c89de70

I have now added support for: ```d module simple_function_recursion_factorial; ubyte factorial(ubyte i) { if(i == 0) { return 1; } else { return i*factorial(i-1); } } ``` As in, np explicit cast is required for the `i == 0` (as in no `cast(byte)0)`) (same goes for the `i-1` (the `1`). What we have now is implicit casting for the literal value instructions (`LiteralValue`) which helps a lot. --- Added in commit `a73e8308db33a8ac0203c49df01bb9078c89de70`
deavmi stopped working 2023-07-17 12:01:03 +01:00
1 minute 44 seconds
deavmi started working 2023-07-17 12:03:03 +01:00
deavmi stopped working 2023-07-17 12:03:31 +01:00
28 seconds
deavmi removed a dependency 2023-08-10 18:45:00 +01:00
deavmi started working 2023-08-10 18:45:10 +01:00
Author
Owner

Since we have merged #115 into vardec)varass_dependency we will now considfer this there.

Since we have merged #115 into `vardec)varass_dependency` we will now considfer this there.
deavmi changed reference from feature/universal_coercion to vardec_varass_dependency 2023-08-10 18:45:38 +01:00
deavmi stopped working 2023-08-10 18:45:40 +01:00
30 seconds
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Total Time Spent: 18 minutes 5 seconds
deavmi
18 minutes 5 seconds
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-07-30

Dependencies

No dependencies set.

Reference: tlang/tlang#141
No description provided.