Κυριακή 25 Δεκεμβρίου 2022

Revision 25 Version 11

Revision 25 is the last revision for version 11. The new version 12 prepared now. This release remove two things:

1. Fix in lambda some fault code (introduced by last revision), the conv2 module in Info can be run.

2. Change of a system timer (now using one from Kernel32). The old one cause problems in Windows 10 (returning negative values earlier than 25 days, unexpected). So this bug removed (which logical is impossible to return negative value - the timer has a cycle of 49 days, so the timer beginning  from 0 at startup, has to run for the half of that duration, to became negative (as VB6 read it as signed Long - it is unsigned although, but the bits are the same, so when 32th bit turned to 1, we get  negative value by the casting to signed Long, which VB6 use). When the bug happen, the M2000 which just called not show the console and stay in a step before opening the console. So we have to close it from Task Manager.


About the 12th version (I do some additions and tomorrow expected to finish it) :

1. We have a new way to define/redefine local variables:

Double a, b=100 ,c

if variable a exist as long then change to double (the old value erased).

Version 11 has the Def double a, which works in Version 12. This statement if find a as local raise error.

2. We can use the new types string and variant..

The string type make string using names like the numbers. Until version 11 we have to use $ for the names of strings, so A$ is a string variable (a$ and A$ are the same). Now we can use A as string too (but isn't the same as A$, these are two different variable names). Functions like Mid$() now take A too if A is string type.

version 11 and 12

alfa("George")
alfa()
sub alfa(a$="World")
Print "Hello "+a$
end sub

Version 12

alfa("George")
alfa()
sub alfa(a as string="World")
Print "Hello "+a
end sub

Variant Type.

The variant type is a variable which can change types. Here we pass it by reference and change type in the Beta sub.

Version 11, no variant type, a variable can't change type (only for those we make in console, as global variables, can change types, and array items.

Module TestThis{
// when a variable get first value then the type locked
a=100
// if string has numeric value the this value change to number
a="12345"
Print a=12345
}
TestThis

This is the same for Version 12, but we have the Variant type, which do the job:

Variant a=100

Print a=100, type$(a)="Double"
a="Hello"
a+=" World"
Print a="Hello World", Type$(a)="String"
Beta(&a)
Print Type$(a)="mArray"
Sub Beta(&z as variant)
z=(1,2,3,4)
End sub

As you see, to use the Variant Type and String with same name as the numeric variables, there was a big step, because there are changes to evaluator, the IsExp and IsStrExp internal variables which use a look ahead function to find before execution if the code seams to be numerical expression (including comparisons and logical expressions) and  or seams to be string expression. So in Version 11 the expression a$+b$=c$+d$ and X>10  without checking if identifiers exist, looking the $ and the symbols + = (and others like this in other expressions) get the idea that is a numerical expression (this return a Boolean value, we have two comparisons and the AND - the knowing as logical gate AND). The look ahead procedure skip anything in parenthesis. So the A*(B+12)+C is like A*X+C for that system. Also M2000 execute all the subexpressions (even if the result for first operand is False). M2000 always execute an expression in the order we write, and process the subexpressions when the results computed. So 1*2*3+4*5*6, get 1 , find * and from that point see if there is an open parenthesis and if true then start a new IsExp, For version 12 the string variable can be found in an accepted numeric expression as the look ahead system found it: so a+a can be an addition for strings or numbers. I found a way to overcome this without breaking the normal look ahead system for numeric expressions. I have to handle the way in IsStrExp  using a bypass of the lookahead. For some code which written using for a parameter (from M2000 user code, the source) either type, string or numeric, I don't use the bypass and if isn't say string expression, the isExp do a better job and find it.

Version 12

function alfa {
// ="alfa"  // can't use "bare" this, we get error, expected numeric type
variant a="hello"
=a
}
Print alfa()+" World"

See that if we use ="alfa" for return value we get error (the look ahead function check if the result is compatible with function type (only by name, if  character $ exist). (we need to check this for the normal use of functions, this language designed for pupils). The Print function call IsExp first, which use the look ahead and find that this has a numeric something  (parenthesis skipped) at least, so begin to execute, and get the string type from alfa() and then take the symbol "+" and check to see what come next and find string literal and start to process a string expression, and at the end return the string value " World"  and at the  "+" checking that there are two operands of type string so do the addition and return the result (as a numeric result). At the returning I have to use a type checking, and if I can use the string value is ok, if not the return value is 0.

What happen to these statements: 

a="Hello"
z$=a
Print z$

The z$ expect a string expression. In Version 11 the look ahead works and see there is no string expression, so return error without process the expression. In Version 12, the expression processed, and the return type is string so it accepted. This is an error for Version 12 (and for Version 11), but in Version we don't have process of the expression after the Z$=.

a=10
z$=a

So now I will fix the Variants for Groups. I have to add arrays of specific types, Version 11 and smaller use variant type, so the name only used to get the number or the string from the value.

// version 11 and version 12
Dim A(2)
A(0):="hello",2
Link A() to A$()
Print A(0), A(1) ' print  0  for A(0) the hello isn't numeric
Print A$(0), A$(1) ' print 2 as string left justified
Print A() ' print automatic all elements in each tab position, finding types
Print A$() ' the same as before
A$(0)="12345"
Print A(0)=12345 ' convert to number each time we use A(0)
A(0)=12345
Print A(0)=12345 ' now we have number
Print A() ' print automatic all elements in each tab position, finding types
Print A$() ' the same as before

After the Version 12 complete with arrays of specific types like this Dim a() as string, b() as long I have to go to a new Interpreter using a Virtual Machine,  I have made the variable system look here



Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.