L1VM - mem object
I did write a new memory object function for reading an object: “load_obj_array_memobj”. It gets the variable addresses and uses call by reference to copy the results:
(Peye_color~ Pheight~ Page~ Pgender~ Plast_name~ Pfirst_name~ variables~ zero~ memaddr~ :load_obj_array_memobj call)
The variables beginning with “P” are pointers. So their value will be changed to the memory objects readed. The pointers are got with this code:
// set pointers (person.first_name~ Pfirst_name~ pointer) (person.last_name~ Plast_name~ pointer) (person.gender~ Pgender~ pointer) (person.age~ Page~ pointer) (person.height~ Pheight~ pointer) (person.eye_color~ Peye_color~ pointer)
The variables with a dot “.” are the person variables. This is just a naming convention no real struct or object.
The memory object is created with this call:
// store person data in mem object using memory variable types: s_type, i_type and d_type // going from right to left with variable types first before variable (person.eye_color s_type person.height d_type person.age i_type person.gender s_type person.last_name s_type person.first_name s_type variables zero memaddr :save_obj_memobj !)
In “variables” is the number of the following variables stored. The “save_obj_memobj” takes the variables of the stack from right to the left! So the next variables will be: “s_type”, “person.first_name” and so on! The “s_type” tells the “save_obj_memobj” function that the following variable is a string type. You can store “int64” (i_type), “double” (d_type) and “string” (s_type) variables in a memory object. A memory object is a bit like a struct in other programming languages. It is powerful!
The following example is part of the GitHub repo: people-object.l1com