Feature: Add support for structs #118

Open
opened 2023-04-21 23:33:54 +01:00 by deavmi · 23 comments
Owner

What is this?

Add support for structs via the struct keyword.

## What is this? Add support for structs via the `struct` keyword.
deavmi added this to the Basics milestone 2023-04-21 23:33:54 +01:00
deavmi added the
typing
dependency
parser
emit
labels 2023-04-21 23:33:54 +01:00
deavmi self-assigned this 2023-04-21 23:33:55 +01:00
Author
Owner

Pretty sure dependency generation for paths will be needed before deoendenecy generation can work correctly for it.

Pretty sure dependency generation for paths will be needed before deoendenecy generation can work correctly for it.
deavmi removed the due date 2023-05-13 2023-07-17 13:36:31 +01:00
deavmi added spent time 2023-07-17 13:36:37 +01:00
30 minutes
deavmi started working 2023-07-17 13:36:40 +01:00
deavmi added the due date 2023-07-31 2023-07-17 13:36:45 +01:00
deavmi stopped working 2023-07-17 13:36:48 +01:00
8 seconds
deavmi changed title from Add support for structs to Feature: Add support for structs 2023-07-17 13:36:54 +01:00
deavmi added reference feature/structs 2023-07-17 13:38:44 +01:00
deavmi added a new dependency 2023-07-17 13:40:07 +01:00
deavmi started working 2023-07-17 15:18:59 +01:00
Author
Owner

Can continue working now that Struct has clone() support

Can continue working now that `Struct` has `clone()` support
deavmi stopped working 2023-07-17 16:01:57 +01:00
42 minutes 58 seconds
deavmi started working 2023-07-17 16:03:29 +01:00
deavmi stopped working 2023-07-17 16:09:11 +01:00
5 minutes 41 seconds
Author
Owner

Progress 🚧

Given the code:

module simple_structs_with_static_inits;

class Cart
{
    static int items;
    static int balance;
}

struct User
{
    Cart cart;
    byte* name;
    int age;
}

User u1;
User u2;

So far so good, looks like cloning helped. The queues are below:

[INFO] <<<<< FINAL ALLOCATE QUEUE >>>>>
[INFO] InitQueue: 1/1: [Instruction: tlang.compiler.codegen.instruction.ClassStaticInitAllocate:classStaticInitAllocate: simple_structs_with_static_inits.Cart]
[INFO] <<<<< FINAL CODE QUEUE >>>>>
[INFO] 1/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.Cart.items]
[INFO] 2/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.Cart.balance]
[INFO] 3/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.cart]
[INFO] 4/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.name]
[INFO] 5/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.age]
[INFO] 6/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.u1]
[INFO] 7/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.cart]
[INFO] 8/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.name]
[INFO] 9/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.age]
[INFO] 10/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.u2]
## Progress 🚧 Given the code: ```d module simple_structs_with_static_inits; class Cart { static int items; static int balance; } struct User { Cart cart; byte* name; int age; } User u1; User u2; ``` So far so good, looks like cloning helped. The queues are below: ``` [INFO] <<<<< FINAL ALLOCATE QUEUE >>>>> [INFO] InitQueue: 1/1: [Instruction: tlang.compiler.codegen.instruction.ClassStaticInitAllocate:classStaticInitAllocate: simple_structs_with_static_inits.Cart] [INFO] <<<<< FINAL CODE QUEUE >>>>> [INFO] 1/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.Cart.items] [INFO] 2/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.Cart.balance] [INFO] 3/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.cart] [INFO] 4/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.name] [INFO] 5/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.age] [INFO] 6/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.u1] [INFO] 7/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.cart] [INFO] 8/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.name] [INFO] 9/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.User.age] [INFO] 10/10: [Instruction: tlang.compiler.codegen.instruction.VariableDeclaration:varName: simple_structs_with_static_inits.u2] ```
deavmi started working 2023-07-17 16:11:01 +01:00
deavmi stopped working 2023-07-17 16:11:11 +01:00
10 seconds
deavmi started working 2023-07-17 21:14:46 +01:00
deavmi added this to the Dependency tree, type-checking and codegen project 2023-07-17 21:17:20 +01:00
deavmi modified the project from Dependency tree, type-checking and codegen to Parser 2023-07-17 21:17:31 +01:00
deavmi stopped working 2023-07-17 21:17:40 +01:00
2 minutes 54 seconds
deavmi added spent time 2023-07-21 22:10:18 +01:00
1 hour
deavmi started working 2023-07-21 22:10:20 +01:00
deavmi stopped working 2023-07-22 11:56:43 +01:00
13 hours 46 minutes
deavmi added spent time 2023-07-22 11:56:53 +01:00
1 minute
deavmi started working 2023-07-22 17:12:40 +01:00
deavmi stopped working 2023-07-22 17:18:29 +01:00
5 minutes 49 seconds
deavmi added spent time 2023-07-22 17:30:15 +01:00
6 minutes
deavmi started working 2023-07-22 17:30:18 +01:00
deavmi stopped working 2023-07-22 17:36:10 +01:00
5 minutes 52 seconds
deavmi added spent time 2023-07-26 16:11:26 +01:00
1 hour 10 minutes
deavmi started working 2023-07-26 16:11:29 +01:00
Author
Owner

Working on this again today, trying my new ideas out.

So far so good, cloned some stuff according to the Metaprocessor trick I am using. "Trick" is a bad word, it makes sense and is very logical considering how nice my language aims to be.

Working on this again today, trying my new ideas out. So far so good, cloned some stuff according to the Metaprocessor trick I am using. "Trick" is a bad word, it makes sense and is very logical considering how nice my language aims to be.
Author
Owner

Now just symbol mapper-related things to consider. This will be epic sussy.

Now just symbol mapper-related things to consider. This will be epic sussy.
deavmi stopped working 2023-07-26 16:12:50 +01:00
1 minute 21 seconds
deavmi started working 2023-07-26 17:55:10 +01:00
Author
Owner

A little drunk now but gonna continue

A **little** drunk now but gonna continue
deavmi stopped working 2023-07-26 18:19:08 +01:00
23 minutes 57 seconds
deavmi added spent time 2023-08-07 09:29:28 +01:00
20 minutes
deavmi started working 2023-08-07 09:29:31 +01:00
Author
Owner

Working on tis again now....

Working on tis again now....
deavmi stopped working 2023-08-07 09:29:45 +01:00
14 seconds
deavmi started working 2023-08-07 09:34:54 +01:00
deavmi stopped working 2023-08-07 09:50:43 +01:00
15 minutes 48 seconds
deavmi started working 2023-08-07 09:55:49 +01:00
deavmi stopped working 2023-08-07 09:56:42 +01:00
52 seconds
deavmi modified the due date from 2023-07-31 to 2023-08-06 2023-08-08 07:32:00 +01:00
deavmi modified the due date from 2023-08-06 to 2023-08-20 2023-08-08 07:32:11 +01:00
deavmi started working 2023-08-08 07:32:13 +01:00
deavmi stopped working 2023-08-08 07:32:17 +01:00
4 seconds
deavmi added spent time 2023-08-08 07:32:22 +01:00
10 minutes
deavmi started working 2023-08-08 07:32:24 +01:00
Author
Owner

Okay, I think I just got it working. Going to have to stage the changed files now.

Okay, I think I just got it working. Going to have to stage the changed files now.
Author
Owner

Todo

  • emit -> emit_c
    • It is for controlling the C emitter specifically, so we should do that maybe
  • More stringent test cases which test the struct hash path stuff more harshly
    • Struct typed variable instances as memebrs of other struct types
  • Pointer support for StructVariableInstance
    • Example, we want the & to work (currently gives Segmentation Fault)
    • Code: User* ptr = &u1;
    • Rudimentary support for &u1 has been added where u1 refers to a StructVariableInstance
    • Support &u1.name
## Todo - [ ] `emit` -> `emit_c` * It is for controlling the C emitter specifically, so we should do that **maybe** - [ ] More stringent test cases which test the struct hash path stuff more harshly - [ ] Struct typed variable instances as memebrs of other struct types - [ ] Pointer support for `StructVariableInstance` * Example, we want the `&` to work (currently gives Segmentation Fault) * Code: `User* ptr = &u1;` - [x] Rudimentary support for `&u1` has been added where `u1` refers to a `StructVariableInstance` - [ ] Support `&u1.name`
deavmi stopped working 2023-08-08 07:42:08 +01:00
9 minutes 44 seconds
deavmi modified the project from Parser to Dependency tree, type-checking and codegen 2023-08-08 07:42:39 +01:00
deavmi started working 2023-08-08 07:47:13 +01:00
deavmi stopped working 2023-08-08 07:47:18 +01:00
5 seconds
deavmi started working 2023-08-08 15:15:57 +01:00
deavmi stopped working 2023-08-08 18:01:10 +01:00
2 hours 45 minutes
deavmi started working 2023-08-08 18:07:45 +01:00
deavmi stopped working 2023-08-08 18:08:24 +01:00
39 seconds
deavmi started working 2023-08-10 18:50:15 +01:00
Author
Owner

I've merged newest changes of vardec_varass_dependency into here and now CI/CD is all green (due to #115 being merged in)

I've merged newest changes of `vardec_varass_dependency` into here and now CI/CD is all green ✅ (due to #115 being merged in)
deavmi stopped working 2023-08-10 18:54:26 +01:00
4 minutes 11 seconds
deavmi started working 2023-08-15 07:32:51 +01:00
Author
Owner

Working on this again now.

Working on this again now.
Author
Owner

New challenge

Currently testing out complex_structs.t which makes use of a variable of of a struct-based type (Cart) as a member of a struct type:

module complex_structs;

struct Cart
{
    int count;
}

struct User
{
    int age;
    Cart cart;
}

User u1;

void function()
{
    
}

Currently it segfaults:

[INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart)
[INFO] You cannot park da kar deerr
[INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'...
[INFO] Nah fr
[INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'...
[INFO] Nah fr
[INFO] getBuiltInType(User)
[ERROR] getBuiltInType(User): Failed to map to a built-in type
[INFO] resolveUp(1, User)
[INFO] Poes
[INFO] Struct (Name: User)
Segmentation fault (core dumped)
## New challenge Currently testing out `complex_structs.t` which makes use of a variable of of a `struct`-based type (`Cart`) as a member of a struct type: ```d module complex_structs; struct Cart { int count; } struct User { int age; Cart cart; } User u1; void function() { } ``` Currently it segfaults: ``` [INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart) [INFO] You cannot park da kar deerr [INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'... [INFO] Nah fr [INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'... [INFO] Nah fr [INFO] getBuiltInType(User) [ERROR] getBuiltInType(User): Failed to map to a built-in type [INFO] resolveUp(1, User) [INFO] Poes [INFO] Struct (Name: User) Segmentation fault (core dumped) ```
deavmi stopped working 2023-08-15 07:43:42 +01:00
10 minutes 51 seconds
deavmi started working 2023-08-15 07:43:44 +01:00
deavmi stopped working 2023-08-15 07:43:49 +01:00
5 seconds
deavmi started working 2023-08-15 07:54:53 +01:00
Author
Owner

New challenge

Currently testing out complex_structs.t which makes use of a variable of of a struct-based type (Cart) as a member of a struct type:

module complex_structs;

struct Cart
{
    int count;
}

struct User
{
    int age;
    Cart cart;
}

User u1;

void function()
{
    
}

Currently it segfaults:

[INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart)
[INFO] You cannot park da kar deerr
[INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'...
[INFO] Nah fr
[INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'...
[INFO] Nah fr
[INFO] getBuiltInType(User)
[ERROR] getBuiltInType(User): Failed to map to a built-in type
[INFO] resolveUp(1, User)
[INFO] Poes
[INFO] Struct (Name: User)
Segmentation fault (core dumped)

Seems like a post-AST replacement check issue, working on the fix now...

> ## New challenge > > Currently testing out `complex_structs.t` which makes use of a variable of of a `struct`-based type (`Cart`) as a member of a struct type: > > ```d > module complex_structs; > > struct Cart > { > int count; > } > > struct User > { > int age; > Cart cart; > } > > User u1; > > void function() > { > > } > ``` > > Currently it segfaults: > > ``` > [INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart) > [INFO] You cannot park da kar deerr > [INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'... > [INFO] Nah fr > [INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'... > [INFO] Nah fr > [INFO] getBuiltInType(User) > [ERROR] getBuiltInType(User): Failed to map to a built-in type > [INFO] resolveUp(1, User) > [INFO] Poes > [INFO] Struct (Name: User) > Segmentation fault (core dumped) > ``` Seems like a post-AST replacement check issue, working on the fix now...
Author
Owner

New challenge

Currently testing out complex_structs.t which makes use of a variable of of a struct-based type (Cart) as a member of a struct type:

module complex_structs;

struct Cart
{
    int count;
}

struct User
{
    int age;
    Cart cart;
}

User u1;

void function()
{
    
}

Currently it segfaults:

[INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart)
[INFO] You cannot park da kar deerr
[INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'...
[INFO] Nah fr
[INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'...
[INFO] Nah fr
[INFO] getBuiltInType(User)
[ERROR] getBuiltInType(User): Failed to map to a built-in type
[INFO] resolveUp(1, User)
[INFO] Poes
[INFO] Struct (Name: User)
Segmentation fault (core dumped)

Seems like a post-AST replacement check issue, working on the fix now...

The problem with this approach, or from what I can see is nested StructVariableInstances have the problem that when they appear inside of a struct we will affectively have the wrong things pushed to the end of the code queue for consumption.

However, actually - I am not sure how much this is to blame for this solution we have chosen. This more stems from the fact we have a Container-type node, the StructVariableInstance and it has members within. This would have been the case if we had done this during parse time too.

So I just have to find a neat work around for it in the type checker.

> > ## New challenge > > > > Currently testing out `complex_structs.t` which makes use of a variable of of a `struct`-based type (`Cart`) as a member of a struct type: > > > > ```d > > module complex_structs; > > > > struct Cart > > { > > int count; > > } > > > > struct User > > { > > int age; > > Cart cart; > > } > > > > User u1; > > > > void function() > > { > > > > } > > ``` > > > > Currently it segfaults: > > > > ``` > > [INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart) > > [INFO] You cannot park da kar deerr > > [INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'... > > [INFO] Nah fr > > [INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'... > > [INFO] Nah fr > > [INFO] getBuiltInType(User) > > [ERROR] getBuiltInType(User): Failed to map to a built-in type > > [INFO] resolveUp(1, User) > > [INFO] Poes > > [INFO] Struct (Name: User) > > Segmentation fault (core dumped) > > ``` > > Seems like a post-AST replacement check issue, working on the fix now... The problem with this approach, or from what I can see is nested `StructVariableInstance`s have the problem that when they appear inside of a struct we will affectively have the wrong things pushed to the end of the code queue for consumption. **However**, actually - I am not sure how much this is to blame for this solution we have chosen. This more stems from the fact we have a `Container`-type node, the `StructVariableInstance` and it has members within. This would have been the case if we had done this during parse time too. So I just have to find a neat work around for it in the type checker.
Author
Owner

New challenge

Currently testing out complex_structs.t which makes use of a variable of of a struct-based type (Cart) as a member of a struct type:

module complex_structs;

struct Cart
{
    int count;
}

struct User
{
    int age;
    Cart cart;
}

User u1;

void function()
{
    
}

Currently it segfaults:

[INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart)
[INFO] You cannot park da kar deerr
[INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'...
[INFO] Nah fr
[INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'...
[INFO] Nah fr
[INFO] getBuiltInType(User)
[ERROR] getBuiltInType(User): Failed to map to a built-in type
[INFO] resolveUp(1, User)
[INFO] Poes
[INFO] Struct (Name: User)
Segmentation fault (core dumped)

Seems like a post-AST replacement check issue, working on the fix now...

The problem with this approach, or from what I can see is nested StructVariableInstances have the problem that when they appear inside of a struct we will affectively have the wrong things pushed to the end of the code queue for consumption.

However, actually - I am not sure how much this is to blame for this solution we have chosen. This more stems from the fact we have a Container-type node, the StructVariableInstance and it has members within. This would have been the case if we had done this during parse time too.

So I just have to find a neat work around for it in the type checker.

Wait, no I think I am dumb. This isn't it, I can see the code queue - my method is correct. I just need to cast to the common type of StorageDeclaration and not VariableDeclaration (which is derived from Variable-based members) and then StructInstantiateInstruction (which is derived from StructInstanceVariable-based members).

> > > ## New challenge > > > > > > Currently testing out `complex_structs.t` which makes use of a variable of of a `struct`-based type (`Cart`) as a member of a struct type: > > > > > > ```d > > > module complex_structs; > > > > > > struct Cart > > > { > > > int count; > > > } > > > > > > struct User > > > { > > > int age; > > > Cart cart; > > > } > > > > > > User u1; > > > > > > void function() > > > { > > > > > > } > > > ``` > > > > > > Currently it segfaults: > > > > > > ``` > > > [INFO] Our replacement AST node: StructVariableInstance (name: cart, type: Cart) > > > [INFO] You cannot park da kar deerr > > > [INFO] MetaProcessor: Examining AST node 'Function (Name: function, ReturnType: void, Args: )'... > > > [INFO] Nah fr > > > [INFO] MetaProcessor: Examining AST node 'Variable (Ident: u1, Type: User)'... > > > [INFO] Nah fr > > > [INFO] getBuiltInType(User) > > > [ERROR] getBuiltInType(User): Failed to map to a built-in type > > > [INFO] resolveUp(1, User) > > > [INFO] Poes > > > [INFO] Struct (Name: User) > > > Segmentation fault (core dumped) > > > ``` > > > > Seems like a post-AST replacement check issue, working on the fix now... > > The problem with this approach, or from what I can see is nested `StructVariableInstance`s have the problem that when they appear inside of a struct we will affectively have the wrong things pushed to the end of the code queue for consumption. > > **However**, actually - I am not sure how much this is to blame for this solution we have chosen. This more stems from the fact we have a `Container`-type node, the `StructVariableInstance` and it has members within. This would have been the case if we had done this during parse time too. > > So I just have to find a neat work around for it in the type checker. Wait, no I think I am dumb. This isn't it, I can see the code queue - my method is correct. I just need to cast to the common type of `StorageDeclaration` and not `VariableDeclaration` (which is derived from `Variable`-based members) and then `StructInstantiateInstruction` (which is derived from `StructInstanceVariable`-based members).
deavmi stopped working 2023-08-15 08:42:39 +01:00
47 minutes 45 seconds
deavmi started working 2023-08-15 08:45:35 +01:00
Author
Owner

I may now be onto something, successful compilation of:

module complex_structs;

struct Cart
{
    int count;
}

struct User
{
    int age;
    Cart cart;
}

User u1;

void function()
{
    
}

To the C-emitted code:

/**
 * TLP compiler generated code
 *
 * Module name: complex_structs
 * Output C file: tlangout.c
 *
 * Place any extra information by code
 * generator here
 */
#include<stdint.h>
struct Cart
{
	int32_t count;
};
struct User
{
	int32_t age;
	struct Cart t_30ee962df44239321472851155e91eec;
};

struct User t_90cc2c8f72f9d7b295a5724406bb8e24;

void function();

void function()
{
}


int main()
{
    return 0;
}
I may now be onto something, successful compilation of: ```d module complex_structs; struct Cart { int count; } struct User { int age; Cart cart; } User u1; void function() { } ``` To the C-emitted code: ```c /** * TLP compiler generated code * * Module name: complex_structs * Output C file: tlangout.c * * Place any extra information by code * generator here */ #include<stdint.h> struct Cart { int32_t count; }; struct User { int32_t age; struct Cart t_30ee962df44239321472851155e91eec; }; struct User t_90cc2c8f72f9d7b295a5724406bb8e24; void function(); void function() { } int main() { return 0; } ```
deavmi stopped working 2023-08-15 08:57:18 +01:00
11 minutes 44 seconds
deavmi started working 2023-08-15 10:19:05 +01:00
deavmi stopped working 2023-08-15 10:25:03 +01:00
5 minutes 59 seconds
deavmi started working 2023-08-15 19:43:35 +01:00
deavmi stopped working 2023-08-15 20:03:05 +01:00
19 minutes 29 seconds
deavmi added a new dependency 2023-08-16 08:58:32 +01:00
deavmi started working 2023-08-16 09:56:40 +01:00
Author
Owner

Now that #153 is fixed the test case complex_structs.t now compiles.

Now that #153 is fixed the test case `complex_structs.t` now compiles.
deavmi stopped working 2023-08-16 09:58:40 +01:00
2 minutes 1 second
deavmi started working 2023-08-16 10:10:49 +01:00
deavmi stopped working 2023-08-16 10:12:45 +01:00
1 minute 56 seconds
deavmi started working 2023-08-27 12:02:32 +01:00
Author
Owner

Updated with latest code from vardec_varass_dependency. The code coverage should be higher now. 👍

Updated with latest code from `vardec_varass_dependency`. The code coverage should be higher now. 👍
deavmi stopped working 2023-08-27 12:04:09 +01:00
1 minute 37 seconds
deavmi modified the due date from 2023-08-20 to 2023-08-31 2023-08-27 12:08:03 +01:00
Author
Owner

Just added complex_structs.tandsimple_structs.tto run as part of the D-based unit tests (not _just_ having them ind.yml`).

This should also increase code coverage.

Just added complex_structs.t` and `simple_structs.t` to run as part of the D-based unit tests (not _just_ having them in `d.yml`). This should also increase code coverage.
deavmi added spent time 2023-08-27 12:44:26 +01:00
1 minute
deavmi started working 2023-10-27 09:09:38 +01:00
Author
Owner

I am thinking about how we have gone about this. I might want to open a similar PR that does this but differently.

I think that if we do it this way, which honestly does sound proper, we may run into issues regarding struct types with member variables of other struct types.

I believe that we may somehow, during parse time, need to build up a symbol table maybe.

If we parse a struct like so:

struct StrType1
{
    StrType2 varMem;
}

Mmmh, even with this we would need resolution at parse time which we do NOT have. Nor do I think it would be right to add that.


I will sit on and ponder this as within the parsing startergy there are various ways to go about this.

I am thinking about how we have gone about this. I might want to open a similar PR that does this but differently. I think that if we do it this way, which honestly does sound proper, we may run into issues regarding struct types with member variables of other struct types. I believe that we may somehow, during parse time, need to build up a symbol table maybe. If we parse a struct like so: ```d struct StrType1 { StrType2 varMem; } ``` Mmmh, even with this we would need resolution at parse time **which we do NOT have**. Nor do I think it would be right to add that. --- I will sit on and ponder this as within the parsing startergy there are various ways to go about this.
Author
Owner

I am thinking about how we have gone about this. I might want to open a similar PR that does this but differently.

I think that if we do it this way, which honestly does sound proper, we may run into issues regarding struct types with member variables of other struct types.

I believe that we may somehow, during parse time, need to build up a symbol table maybe.

If we parse a struct like so:

struct StrType1
{
    StrType2 varMem;
}

Mmmh, even with this we would need resolution at parse time which we do NOT have. Nor do I think it would be right to add that.


I will sit on and ponder this as within the parsing startergy there are various ways to go about this.

MMmh, is this correct? Let me check... 🧠

> I am thinking about how we have gone about this. I might want to open a similar PR that does this but differently. > > I think that if we do it this way, which honestly does sound proper, we may run into issues regarding struct types with member variables of other struct types. > > I believe that we may somehow, during parse time, need to build up a symbol table maybe. > > If we parse a struct like so: > > ```d > struct StrType1 > { > StrType2 varMem; > } > ``` > > Mmmh, even with this we would need resolution at parse time **which we do NOT have**. Nor do I think it would be right to add that. > > --- > > I will sit on and ponder this as within the parsing startergy there are various ways to go about this. MMmh, is this correct? Let me check... 🧠
Author
Owner

I am thinking about how we have gone about this. I might want to open a similar PR that does this but differently.

I think that if we do it this way, which honestly does sound proper, we may run into issues regarding struct types with member variables of other struct types.

I believe that we may somehow, during parse time, need to build up a symbol table maybe.

If we parse a struct like so:

struct StrType1
{
    StrType2 varMem;
}

Mmmh, even with this we would need resolution at parse time which we do NOT have. Nor do I think it would be right to add that.


I will sit on and ponder this as within the parsing startergy there are various ways to go about this.

MMmh, is this correct? Let me check... 🧠

Update of thoughts in October

Well, actually my system does support this:

module complex_structs;

struct Cart
{
    int count;
}

struct User
{
    int age;
    Cart cart;
}

User u1;

void function()
{
    int userAge = u1.age;
    Cart* userCart = &u1.cart;
    int userCartCount = u1.cart.count;
}

Also, we need not worry about a struct A which contains a member of type B which contains A. That is impossible in any language with a struct, it must be a DAG.


Mmh, well then. Maybe this method will then work. :)

I was thinking in the case of class-based types, in such a case we will need a similar type-init (for static inits) and then instance init, where instances can be of a type which has mutual references. Going to open thoughts for this on #158.

> > I am thinking about how we have gone about this. I might want to open a similar PR that does this but differently. > > > > I think that if we do it this way, which honestly does sound proper, we may run into issues regarding struct types with member variables of other struct types. > > > > I believe that we may somehow, during parse time, need to build up a symbol table maybe. > > > > If we parse a struct like so: > > > > ```d > > struct StrType1 > > { > > StrType2 varMem; > > } > > ``` > > > > Mmmh, even with this we would need resolution at parse time **which we do NOT have**. Nor do I think it would be right to add that. > > > > --- > > > > I will sit on and ponder this as within the parsing startergy there are various ways to go about this. > > MMmh, is this correct? Let me check... 🧠 ### Update of thoughts in October Well, actually my system _does_ support this: ```d module complex_structs; struct Cart { int count; } struct User { int age; Cart cart; } User u1; void function() { int userAge = u1.age; Cart* userCart = &u1.cart; int userCartCount = u1.cart.count; } ``` Also, we need not worry about a struct `A` which contains a member of type `B` which contains `A`. That is impossible in _any_ language with a struct, it must be a DAG. --- Mmh, well then. Maybe this method will then work. :) I was thinking in the case of class-based types, in such a case we will need a similar type-init (for static inits) and then instance init, where instances can be of a type which has mutual references. Going to open thoughts for this on #158.
deavmi removed the due date 2023-08-31 2023-10-27 09:19:24 +01:00
deavmi added the due date 2023-11-30 2023-10-27 09:19:33 +01:00
deavmi stopped working 2023-10-27 09:19:35 +01:00
9 minutes 57 seconds
Author
Owner

This should be finished prior to #157 as I want to get these changes in and upstream them into that issue's branch, rather than deal with many merge conflicts later.

This should be finished prior to #157 as I want to get these changes in and upstream them into that issue's branch, rather than deal with many merge conflicts later.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Total Time Spent: 23 hours 41 minutes
deavmi
23 hours 41 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-11-30

Depends on
You do not have permission to read 1 dependency
Reference: tlang/tlang#118
No description provided.