Re: Unions, program proofs and the Halting Problem
Posted: Fri Mar 14, 2014 3:55 am
It means you want to access the value of "union.asmdata", but for some reason is unable to use "union.asmdata" construct from C directly. Then may be it would be better if the code will look like:Brendan wrote:In this case EDI contains the address of the structure, "offset" is a keyword (not a variable) which means "get the offset of a member within a structure", and "union.asmdata" says which member of which structure to get the offset of.
Code: Select all
void fieldAccessFunction(GPR32 objectAddressReg, GPR32 fieldOffsetReg, GPR32 resultReg)
{
mov resultReg, [objectAddressReg + fieldOfffsetReg]
}
As I understand your language is able to mix C-like code with Assembler-like one. Why not to use the same algorithm for type determination in case of assembly part, that is already used for C part of a program?Brendan wrote:but that's strange in assembly (where square brackets are used for the equivalent of pointer dereferencing) and would mean the assembler has to know the types of all registers (which would be complicated and likely to fail in non-trivial cases) just to figure out what type of structure it is.
It's a nice idea. But it is important to describe the area where the idea will be applicable. To my opinion the area is just a connection between high level code and the hardware level. And such connection, if exposed to the high level code, will compromise the "high" part of the level definition. Then such properties should be exposed in the connection level only. And a whole connection level should be rarely used by a developer to allow the high level view to be the most important for developer. In jEmbryoS I just wrap low level structure details within high level classes even when assembly is used, so it lets me to concentrate on the high level code.Brendan wrote:I do have a concept called "data properties" though. For example, if you've got a variable "foo" then "foo.max" gets the maximum value the variable can hold, "foo.size" gets the amount of bytes the variable consumes, etc.
But even if it was decided to use such access method - why not to use compiler's ability to determine variable's type? Then it will be possible to write function like this:Brendan wrote:What I'm considering doing is adding an "offset" property, so that people can do "myStructure.myMember.offset" to get the offset of myMember in the structure. In that case the original instruction would become "mov eax,[edi+union.asmdata.offset]" or (using the structure type's name directly instead of the function's input parameter name) "mov eax,[edi+myTaggedUnion.asmdata.offset]"
Code: Select all
mov(eax, myTaggedUnion.asmdata);
// mov definition
void mov(GPR32 resultReg, int sourceValueAddress)
{
...
}