1. @mattlewis: I have some questions about memstruct if you're around
- Posted by ghaberek (admin) Aug 30, 2019
- 1003 views
I noticed several TODO's in c_struct.e regarding MEMUNION and MEMSTRUCT in the various peek/poke routines. Any suggestions on how to implement these correctly?
procedure poke_array_value( integer pointer, integer depth, integer data_type, sequence access_path, sequence type_name, sequence struct_name ) switch data_type do case MS_FLOAT, MS_DOUBLE, MS_LONGDOUBLE, MS_EUDOUBLE then c_stmt0( "if( IS_ATOM_INT( _1 ) ){\n" ) c_stmt( sprintf("((%s*)@)%s[ax%d] = (%s)_1;\n", {struct_name, access_path, depth, type_name}), pointer ) c_stmt0( "}\n" ) c_stmt0( "else{\n") c_stmt( sprintf("((%s*)@)%s[ax%d] = (%s)DBL_PTR( _1 )->dbl;\n", {struct_name, access_path, depth, type_name}), pointer ) c_stmt0( "}\n") case MEMUNION then -- TODO case MEMSTRUCT then -- TODO case else c_stmt0( "if( IS_ATOM_INT( _1 ) ){\n" ) c_stmt( sprintf("((%s*)@)%s[ax%d] = (%s) _1;\n", {struct_name, access_path, depth, type_name} ), pointer ) c_stmt0("}\n" ) c_stmt0( "else{\n") c_stmt( sprintf("((%s*)@)%s[ax%d] = (%s) DBL_PTR( _1 )->dbl;\n", {struct_name, access_path, depth, type_name } ), pointer ) c_stmt0("}\n" ) end switch end procedure
What are your thoughts on making the name of the memstruct optional for accessing structure members? I was basically thinking that we treat memstruct like a type.
For example, this...
memstruct POINT int x int y end memstruct atom point = allocate( sizeof( POINT ) ) point.POINT.x = 1 point.POINT.y = 2
Would just look like this...
POINT point = allocate( sizeof( POINT ) ) point.x = 1 point.y = 2
-Greg
2. Re: @mattlewis: I have some questions about memstruct if you're around
- Posted by ghaberek (admin) Sep 09, 2019
- 948 views
I had emailed Matt directly the other day and this was his reply.
I think it should be possible to make the memstruct name optional when you know the type you're dealing with already. However, if the pointer is stored in a sequence or something then you wouldn't have any way to know what to look for. But it would certainly be nice to have where you could use it. I suspect it's probably something I would have gotten around to eventually.
As for poking a union or a struct...I guess they'd probably be a memcpy or similar of the appropriate size.
Matt
-Greg