Τετάρτη 25 Ιανουαρίου 2023

Version 12 now is ready (99%) and work nice.

 The new version has these:

New expression evaluator: -2^2-2^2 now return -8 (older versions return 0). So Version 12 on evaluator is not compatible with older versions. Although the difference is small, some programs may need work to used with Version 12.

String variables on older and this version can have suffix $, but for older versions this was mandatory. Now the new evaluator check the types and perform string concatenation if found a string in a series of addition. So new version do that ? 123+"mm" return 123mm as string value.? 

Example 1

a=100

? "["+a+"]"="[100]"

return true

Example 2

Greek

? 123.45

return 123,45  (in code decimal pointer is always dot but print use the current one. We can change it using Greek, Latin or Locale 1033 or other number, so according locale id we get the decimal point to be used for input and print from M2000. console.

Evaluator convert always like code, using dot for decimal point.

a=123.45

? "["+a+"]"="[123.45]"

? "["+str$(a, 1032)+"]"  'ising Str$() to choose locale id for specific conversion.

String internal functions have $ suffix (for compatibility with older versions).


I have to make the new manual, there are plenty of new thing, so stay tuned....

GK


Πέμπτη 12 Ιανουαρίου 2023

Version 12 Revision 3 (test only)

You can test this pre-release here: https://github.com/M2000Interpreter/Environment/releases/tag/Ver12Rev3

New type of arrays using [ ] 

These arrays are different, they are based on RefArray class, and can be any  type, numeric and string. Can be one dimension or two. But it isn't the same as the normal array. So a 2X3 array has two arrays of 1X3 (Normal arrays are flat inside, 1x6, for the example, and the mArray class handle the indexes according the Dimension definition).

Also the editor fixed for colorize these types. We can use them in classes also, and with pointers to objects. Actually, the V member has no [ ], so we can refer to V as is (without indexes) and that is the raw object, (the RefArray) which have some useful properties, like ArrPtr (which return the memory address of the first item (for each row). Also these arrays can expand easy, by using indexes greater than the last greater index. Also these arrays may expand in both dimensions and maybe some rows have different size. We can use a definition like this:

Long Long LL[99][99] and we take a 100X100 array of Long Long (64 bit, 8 bytes each).

There is no operators like +=, so to increase 1 to 5th element in 3rd row, we use:

LL[0][4]=LL[0][4]+1

We can extract a copy of 3rd row 

M=LL[2]

We can get a copy of 100X100 items

M=LL[]

We can get just a pointer 

M=LL


class alfa {
string V[4]
}
A->alfa()
A=>v[0]="ok"
? A=>v[0]

Using variant we can change type per item.

class alfa {
variant V[4]
}
A->alfa()
A=>v[0]="ok"
? A=>v[0]
A=>v[0]=123456789012345678&&
def typ$(x)=type$(x)
? A=>v[0], typ$(A=>v[0])="Long Long"

Using a simple group, we can pass the pointer to sub alfa()

group A {
string V[4]
}
A.v[0]="ok"
? A.v[0]


alfa(a.v, 0)
? A.v[0]


alfa(a.v, 1)
? A.v[1]


sub alfa(b, x)
b[x]=b[x]+"..."
end sub


A string array use a 4 byte pointer for each string,. A variant type like the tuple below, use 16 bytes for each item (for string use only  2 bytes  type+ 4 bytes pointer from the 16 bytes). So the above code produce 1/4 for memory which aren't string data. comparing with the default variant size array of M2000.


group A {
V=("","","","")
}
link A.v to A.v()
A.v(0)="ok"
? A.v(0)


alfa(&a.v(), 0)
? A.v(0)


alfa(&a.v(), 1)
? A.v(1)


sub alfa(&b(), x)
b(x)=b(x)+"..."
end sub


More tests here

c$="ok!!!"
global string k[10], s=string$(c$,4)
? s
m=k
m[2]="ok"
? k[2]


class alfa {
// k[] is a copy of array k
variant z=k[], m
// k is a pointer to array
variant z_ponter=k
Long long k[99]
}
alfa->alfa()
? alfa=>z[2]
alfa=>m=(1,2,3,4,5,6,7,8)
? alfa=>m
alfa=>m=1000
? alfa=>m
m[2]="ok1234"
? alfa=>z[2]<>m[2]
? alfa=>z_ponter[2]=m[2]
pk=alfa=>k
for alfa {
? len(.k)=100, type$(.k[0])="Long Long"
.k[0]=1
.z[2]="ok...this is z[2]"
}
? pk[0]
alfa=>k[0]=alfa=>k[0]+1
? pk[0]
? alfa=>z[2]

The above arrays have always 0 for the first item.

The nArray which handle dimensions (max 10), can combine with refArray so we have these types (which are mArray class, but have a connection with a RefArray class)

The mArray interface and the M2000 Interpreter utilize interesting operators, here we use the *=. The 0% literal is type of Integer (2 bytes). Also there are some function with hashtag, which are get the output (for mArray) and can produce another array (here we use the #REV() function, to get the reverse order, as a copy of  the original one.


This is the example DIMVER12 in Info.gsb (exist in the setup file).

dim base 1, M(10) as integer=10
? M()
Mult=lambda (n as integer)-> {
      //dim base 0, M(n) as integer
      dim M(0 to n-1) as integer
      For i=0% to n-1 : m(i)=(i+1)*n : Next
      =M()
}
? mult(4)


dim p(1 to 5) as long=500
group alfa {
dim p(1 to 5) as decimal=500 ' try currency, double, single
}
Print alfa.p(1)
z1->(alfa)
Print z1=>p(1)


for z1 {
for i=1 to 5: .p(i)*=.0005*i: next
}


z=group(z1)
Print z.p()
Print type$(z.p(1))
m=z.p()#REV()
Print m
m+=10
L=m#val(0)
Print type$(L)
Print type$(m)="mArray"
Print m#sum()
list


There are more to discuss about Version 12, but wait the new beta releases, or the first normal release (when all string/numeric functions checked).

Version 12 has enumarations using string also. 

Enumeration Names {
a="hello"
b="hello two"
}


m=b
select case m
case a
? "is a"
case b
? " is b"
end select
? "done"
? m


Also now can be any numeric type (this is Decimal type to be used as 64bit unsigned Integer - from literal):

enum alfa {
onebig=0xFFFF_FFFF_FFFF_FFF0
otherBig=0x7FFF_FFFF_FFFF_FFFF
}
list




Κυριακή 8 Ιανουαρίου 2023

Version 12 (Rev 2)

The first release of version 12. This version has different expression evaluator.  The unary minus has  priority  like in VB6. 

1) Unary minus: -2^2 return -4 (previous versions return 4,  because unary minus processed before exponent (-4)^2.

? -2^-3^-4

-0,991479137495678

2) Previous versions return 0, because the second minus was not unary so we get 4-4 = 0. Now -2^2 return as -(2^2) and the same for the second -(2^2), so we have -4-4=-8

? -2^2-2^2

-8

Also there are more new things. But still the work is in progress

 Download Here