bytecode - How to handle struct variables in byte code and stack-based VMs? -
i writing compiler compiles language has similar concepts c byte code should interpreted corresponding stack-based vm. stuck @ moment when comes how compile structs, e.g.
struct my_struct_s { int anint; char* astring; } my_struct_t; /* ... */ my_struct_t my_struct_var;
where should best put my_struct_var in byte code? how c compilers handle such stuff? later on, vm must handle memory needed represent struct var, since should write- , reabable.
where put kind of variable? onto stack? put memory address of var onto stack?
thanks, jonas
when compiling c higher level languages, hard part handling pointers.
if aren't concerned that, things easier. i'd compile struct class given fields. work long use struct 'normally', i.e. getting , setting fields explicitly. don't need worry allocating memory or address placed, jvm handles automatically.
if take pointer members of field, things more problematic. 2 approaches can think of representing memory giant byte array , manually interpreting values @ runtime (very slow) or replacing pointers code or set appropriate field (hopefully not slow, since invokedynamic lets similar).
edit: assuming you're targeting jvm above. cil nicer because has explicit struct variables , support unsafe memory access.
Comments
Post a Comment