L1VM - mem object

Der Text in deutsch ist unten!

In Brackets my language there is no OOP. So there are no objects like in other languages. But now I did add strings to my mem object module. A mem object can store different variable types in one memory object. So you set the type by storing the variables:

// note the variable types are set by "i_type", "d_type" and "s_type" !!!
(c d_type b i_type a i_type hellostr s_type variables zero memaddr :save_obj_memobj call)

Here “zero” is the start address in our mem object. The variable “variables” contains the number of variables we want to save. And the “s_type” sets the following variable “hellostr” as a string. And then this is set for the other variables too! So “a” and “b” are “int64” types and the “c” variable is a “double” type.

So this is how this works in Brackets. Here is the “load” function:

(three one memaddr :load_obj_memobj call)
// pop variables from stack
(ret stpopi)
(cread stpopd)
(bread stpopi)
(aread stpopi)

The “ret” variable is a return value, the code if all was ok. And we get the variables: “cread”, “bread” and “aread”. The variable “cread” is the double floating point number: it is get by “stpopd”!

The “three” argument means we want to get three variables. So this memory object functions are really powerful and easy to use.

To read a string something like this can be done:

(zero memaddr getstr :load_obj_string_memobj call)
(ret stpopi)

The return string is saved into the variable “getstr”. If the string size is too small you will get an error message!

A full example can be found here: lib/mem-obj-lib.l1com in my L1VM repository.


In Brackets meiner Sprache gibt es keine OOP. Es gibt also keine Objekte wie in anderen Sprachen. Aber jetzt fügte ich Strings zu meinem Objektmodul hinzu. Ein Memobjekt kann unterschiedliche Variablentypen in einem Memobjekt speichern. Man gibt die Variablentypen beim Speichern an:

// note the variable types are set by "i_type", "d_type" and "s_type" !!!
(c d_type b i_type a i_type hellostr s_type variables zero memaddr :save_obj_memobj call)

Hier ist “zero” die Startadresse in unserem Memobjekt. Die Variable “variables” enthält die Anzahl der Variablen die wir speichern wollen. Und die “s_type” Variable deklariert die folgende Variable “hellostr” als String. Und so wird das für die anderen Variablen auch gemacht! Also sind “a” und “b” “int64” Typen und die “c” Variable is ein “double” Typ.

So geht das in Brackets. Hier ist die “load” Funktion:

(three one memaddr :load_obj_memobj call)
// pop variables from stack
(ret stpopi)
(cread stpopd)
(bread stpopi)
(aread stpopi)

Die Variable “ret” ist der Returnwert, der Code ob alles ok ist. Und wir bekommen die Variablen: “cread”, “bread” und “aread”. Die Variable “cread” ist eine Fließkommazahl: die mit “stpopd” gelesen wird.

Die Variable “three” gibt an das wir drei Variablen lesen wollen. Die Memobjekt Funktionen sind mächtig und einfach zu verwenden.

Ein String kann man mit so was wie hier lesen:

(zero memaddr getstr :load_obj_string_memobj call)
(ret stpopi)

Der Returnstring wird in die Variable “getstr” gespeichert. Wenn der String nicht groß genug ist dann bekommt man eine Fehlermeldung!

Ein ganzes Beispiel kann in: lib/mem-obj-lib.l1com im L1VM Repository gefunden werden.