L1VM - mem string
L1VM mem module string
I did finally add string arrays to my memory module for L1VM! You have to set the total array size and the single string size.
Here is the example program:
#include <intr.l1h>
(main func)
(set int64 1 zero 0)
(set int64 1 one 1)
(set int64 1 memaddr 0)
(set int64 1 stringindex 0)
(set int64 1 stringsize 256000)
(set int64 1 stringlen 256)
(set int64 1 ret 0)
(set int64 1 f 0)
(set string s meminitstr "ERROR can't init memory")
(set string s memerrstr "ERROR can't allocate memory!")
(set string s write_str "Hello world!")
(set string 256 read_str "")
(zero one :mem_init call)
(ret stpopi)
(loadreg)
(((ret zero !=) f =) f if)
// ERROR can't allocate memory
print_s (meminitstr)
print_n
exit (one)
(endif)
// allocate
(stringsize :alloc_byte call)
(memaddr stpopi)
(loadreg)
(((memaddr zero <) f =) f if)
// ERROR can't allocate memory
print_s (memerrstr)
print_n
exit (one)
(endif)
// copy string to array
(memaddr stringindex write_str stringlen :string_to_array !)
// read string from array
(memaddr stringindex read_str stringlen :array_to_string !)
print_s (read_str)
print_n
// dealloc mem
(memaddr :dealloc call)
(:free_mem call)
// exit OK
exit (zero)
(funcend)
#include <mem-lib.l1h>