Stack-based array support #102

Closed
opened 2023-02-11 12:20:02 +00:00 by deavmi · 5 comments
Owner

What is this?

We want to add support for doing the followjg declaration in T:

int[2] myArray;

What this entails:

  1. Which should have type int[2] (which is different to say now, int[3]), this should also make a stack-based array.
  2. Coercion when passing to a function myArray should become a pointer to myArray
## What is this? We want to add support for doing the followjg declaration in T: ```d int[2] myArray; ``` What this entails: 1. Which should have type `int[2]` (which is different to say now, `int[3]`), this should also make a stack-based array. 2. Coercion when passing to a function `myArray` should become a pointer to `myArray`
deavmi added a new dependency 2023-02-11 12:20:21 +00:00
deavmi added reference arrays 2023-02-11 12:20:46 +00:00
deavmi added the
typing
dependency
parser
emit
labels 2023-02-11 12:21:00 +00:00
deavmi added this to the Basics milestone 2023-02-11 12:21:04 +00:00
deavmi added this to the Dependency tree, type-checking and codegen project 2023-02-11 12:21:07 +00:00
deavmi self-assigned this 2023-02-11 12:21:09 +00:00
Author
Owner

I need to look at this stuff.

I need to look at this stuff.
Author
Owner

We will need to add the following:

  • A new instruction type which is a kind-of Value and is called StackArrayIndexInstruction
  • The type checker must generate such an instruction (mentioned in point 3) on line 1714
  • Add handling for StackArrayIndexInstruction in DGen
  • We need a StackArrayAssignmentInstruction generated which holds a StackArrayIndexInstruction as left-hand side and a Value instruction as right-hand side (the assignment)

All of the above were completed in commit 98b3ab42848e940ef60a21f2755178148338ba6f.

We will need to add the following: - [x] A new instruction type which is a kind-of `Value` and is called `StackArrayIndexInstruction` - [x] The type checker must generate such an instruction (mentioned in point 3) on line 1714 - [x] Add handling for `StackArrayIndexInstruction` in DGen - [x] We need a `StackArrayAssignmentInstruction` generated which holds a `StackArrayIndexInstruction` as left-hand side and a `Value` instruction as right-hand side (the assignment) All of the above were completed in commit `98b3ab42848e940ef60a21f2755178148338ba6f`.
deavmi added the due date 2023-03-12 2023-03-07 09:01:51 +00:00
Author
Owner

New instructions

There are a few new instructions we are using now:

StackArrayIndexInstruction

This is used to disambiguiate between the ArrayIndex for pointer-based arrays and the stack-based array indexes StackArrayIndexInstruction:

// TODO: StackArrayIndexInstruction
public final class StackArrayIndexInstruction : Value
{
    /* Index-to instruction */
    private Value indexTo;

    /* The index */
    private Value index;

    this(Value indexTo, Value index)
    {
        this.indexTo = indexTo;
        this.index = index;
    }

    public Value getIndexInstr()
    {
        return index;
    }

    public Value getIndexedToInstr()
    {
        return indexTo;
    }

    public override string toString()
    {
        return "StackArrayIndexInstr [IndexTo: "~indexTo.toString()~", Index: "~index.toString()~"]";
    }
}

Available in commit 270ca64106e98358d474efff5bde9e5402f4362c.

StackArrayIndexAssignmentInstruction

This is used for assigning into a stack-based array.

// TODO: StackArrayIndexAssignmentInstruction
public final class StackArrayIndexAssignmentInstruction
{
    // TODO: We need a `string` field here which is looked up with the 
    // ... associated context of this instruction and refers to the
    // ... stack-array being index-assigned into

    // TODO: We then also need a `Value` field for the index expression instruction

    // TODO: We then also need another `Value` field for the expression instruction
    // ... being assigned into the stack-array at said index
}

Available in commit b8612ebbc852f8aba6f257d53fa876b0593b20c3.

## New instructions ✅ There are a few new instructions we are using now: ### `StackArrayIndexInstruction` This is used to disambiguiate between the `ArrayIndex` for pointer-based arrays and the stack-based array indexes `StackArrayIndexInstruction`: ```d // TODO: StackArrayIndexInstruction public final class StackArrayIndexInstruction : Value { /* Index-to instruction */ private Value indexTo; /* The index */ private Value index; this(Value indexTo, Value index) { this.indexTo = indexTo; this.index = index; } public Value getIndexInstr() { return index; } public Value getIndexedToInstr() { return indexTo; } public override string toString() { return "StackArrayIndexInstr [IndexTo: "~indexTo.toString()~", Index: "~index.toString()~"]"; } } ``` Available in commit `270ca64106e98358d474efff5bde9e5402f4362c`. ### `StackArrayIndexAssignmentInstruction` This is used for assigning into a stack-based array. ```d // TODO: StackArrayIndexAssignmentInstruction public final class StackArrayIndexAssignmentInstruction { // TODO: We need a `string` field here which is looked up with the // ... associated context of this instruction and refers to the // ... stack-array being index-assigned into // TODO: We then also need a `Value` field for the index expression instruction // TODO: We then also need another `Value` field for the expression instruction // ... being assigned into the stack-array at said index } ``` Available in commit `b8612ebbc852f8aba6f257d53fa876b0593b20c3`.
Author
Owner

We have this working now in 98b3ab42848e940ef60a21f2755178148338ba6f, stack arrays seem to be working.

We have this working now in `98b3ab42848e940ef60a21f2755178148338ba6f`, stack arrays seem to be working.
Author
Owner

I'm closing this now as #81 (super issue) is closing. This seems to work as expected.

I'm closing this now as #81 (super issue) is closing. This seems to work as expected.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-03-12

Blocks
Reference: tlang/tlang#102
No description provided.