Author Topic: O2 Arrays / BASIC Standardization  (Read 2538 times)

0 Members and 1 Guest are viewing this topic.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 879
  • User-Rate: +33/-1
    • Charles Pegge
Re: O2 Arrays / BASIC Standardization
« Reply #45 on: September 17, 2022, 10:30:39 PM »
Hi Theo,

Iam always looking for opportunities to reduce OxygenBasics core-code! Quite a large part of the language is soft-coded in macros, which can be found in inc/self/lang.inc.

Here are familiar BASIC words which do not need to be core-coded:

Code: [Select]
true  18 -1
false 18 0
use 18 include once
uses 18 include once
using 18 include once
global 18 dim static 'global is deprecated
lobyte 18 ((%1) and 0xff)
loword 18 ((%1) and 0xffff)
hibyte 18 (((%1)>>8) and 0xff)
hiword 18 (((%1)>>16) and 0xffff)
chr_ 18 mid_
wchr_ 18 mid_

Most of the maths functions are directly coded into FPU Asm:
Code: [Select]
abs 17 fabs
acos 17 fld st0 : fmul st0 : fld1 : fsubp st1,st0 : fchs : fsqrt : fxch : fpatan
asin 17 fld st0 : fmul st0 : fld1 : fsubp st1,st0 : fchs : fsqrt : fpatan
atan  17 fpatan
atn 17 fld1 : fpatan
cos 17 fcos
deg 17 fldpi : fdivp st1 : |sp -8 : mov [rsp],180 : fimul dword [rsp] : |sp 8
frac 17 fld1 : fxch : fprem : fstp st1
hypot 17 fmul st0 : fxch : fmul st0 : faddp st1 : fsqrt
lin 17 fldln2 : fxch : fyl2x
...

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 1058
  • User-Rate: +30/-4
  • Gender: Male
    • it-berater
Re: O2 Arrays / BASIC Standardization
« Reply #46 on: September 18, 2022, 06:04:42 AM »
You know that Bob treated DWORD often like FP to prevent Overflow.
Thats why LONGS in PB were originally faster then DWORDS.
How is your position on DWORD vs. LONG ?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 879
  • User-Rate: +33/-1
    • Charles Pegge
Re: O2 Arrays / BASIC Standardization
« Reply #47 on: September 18, 2022, 08:54:16 AM »
Both longs and dwords are normally processed in the CPU, but an expression containing a '/' float division will be processed in the FPU.

Offline Eduardo Jorge

  • Full Member
  • ***
  • Posts: 117
  • User-Rate: +0/-0
Re: O2 Arrays / BASIC Standardization
« Reply #48 on: September 19, 2022, 11:56:30 PM »
The TestLog entries are primarily for functional testing. They give an indication of syntax, but they are not ideal examples. That will take time.

it may be insufficient, but it's better than nothing, it would be more like a starting point for testing.
it would also be interesting if you put the tests in some selection structure

Offline Eduardo Jorge

  • Full Member
  • ***
  • Posts: 117
  • User-Rate: +0/-0
Re: O2 Arrays / BASIC Standardization
« Reply #49 on: September 22, 2022, 06:36:26 PM »
Charles, I think a quick and simple solution for O2 would be to start from scratch.
a new name, you see what is more basic, stable and simple and start from there.
and only make changes that don't change the functionality for things written in older versions, only add and never take away, so it's important to start with only important and functional things.
if you can have O2 in parallel as a test version only, everything that is added or modified is done only on O2 and after the test period add it to the new project.

I say this because of the big changes that the O2 had, harming the understanding of what works or doesn't work.
someone new can take the o2 to test and paste something they find here on the forum and it just doesn't work because it was written in a previous version, myself these days I took something simple to test and it only had errors, imagine someone new who doesn't know of the changes that the O2 had.

Offline Eduardo Jorge

  • Full Member
  • ***
  • Posts: 117
  • User-Rate: +0/-0
Re: O2 Arrays / BASIC Standardization
« Reply #50 on: September 23, 2022, 01:36:32 AM »
charles, I don't know how far this is possible, or if it is possible.
but an idea would be to take advantage of an existing "basic" platform that is open source, in this new project, maybe freebasic itself.
use as a syntax base, thus having what already exists for freebasic,
of course it would only be as a base, but add the facilities that you have already added in O2.
Of course I'm just talking as an idea, I don't even know how far this is really possible or viable.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 879
  • User-Rate: +33/-1
    • Charles Pegge
Re: O2 Arrays / BASIC Standardization
« Reply #51 on: September 23, 2022, 07:15:07 PM »
Hi Eduardo,

My main interest is in producing clear easy-to-read code efficiently. I am not particularly interested in classical BASIC and its redundant syntactical forms.

Nor do I have any ambitions to 'mass-market' o2. Anyone is welcome to make use of it for their own purposes.

The future is unclear, but in the long-term we may see programming delegated entirely to AI, and arguments about different languages become irrelevant.

Self-compiling is a very interesting paradigm. The circularity of it refines the code structure, and I enjoy removing redundant code as much as creating new code :)

Offline Zlatko Vid

  • Sr. Member
  • ****
  • Posts: 298
  • User-Rate: +2/-2
Re: O2 Arrays / BASIC Standardization
« Reply #52 on: September 23, 2022, 08:03:47 PM »
Good answer ...i like it!

Offline Eduardo Jorge

  • Full Member
  • ***
  • Posts: 117
  • User-Rate: +0/-0
Re: O2 Arrays / BASIC Standardization
« Reply #53 on: September 24, 2022, 08:01:29 AM »
Good answer ...i like it!

yes, a good answer,
but do you remember how this discussion started?
It was with you talking about why people weren't coming to the O2.
and with that some theories were emerging, until arriving at the ideas of solutions.
and one of the solutions would be a new name to disassociate O2 from an unstable project that changes something all the time

but if the O2 is a personal project of charles, as a hobby, none of this discussion makes sense.
as I had reported, my use is amateur and I use O2 for the ease of creating DLLs for excel vba, and I do it sporadically.
so for me what charles does on the O2 makes little difference in my use, but for someone who wants something more stable it does make a difference.

Charles, about AI programming, there are a couple of factors about it,
the logical ideas of what you want to program, it is not always easy to define these ideas in a logic, it is like mathematics that is a language, everything has its place of importance, and the Ia themselves need to be programmed.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 879
  • User-Rate: +33/-1
    • Charles Pegge
Re: O2 Arrays / BASIC Standardization
« Reply #54 on: September 25, 2022, 11:03:06 AM »
Hi Eduardo,

Please let me know when you encounter any broken code. I monitor the demo code frequently but it takes time to cover hundreds of examples.

Multidimensional array table in 050P8
Code: [Select]
'24/09/2022
'multidim read/write check
uses console
indexbase 1
#minormajor 'default is majorminor
'dim int yx(4,5) 'static
int ym=4,xm=5
'redim int yx(ym,xm) 'dynamic
redim int yx[ym,xm] 'dynamic
dim int y,x,i
for y=1 to 4
  for x=1 to 5
    i++
    yx(y,x)=i
    print yx(y,x) tab
  next
  printl
next
printl
if #minormajor
  printl "column major order"
else
  printl "row major order"
endif
'test storage order for
'minrmajor and major minor
dim int nn at @yx
printl nn(1) tab nn(2) tab nn(3) tab nn[4]
wait

Offline Eduardo Jorge

  • Full Member
  • ***
  • Posts: 117
  • User-Rate: +0/-0
Re: O2 Arrays / BASIC Standardization
« Reply #55 on: October 01, 2022, 05:48:45 AM »
good morning charles, i saw that o2 is already on 050P9
Has there been any significant changes or just bug fixes?
I'm having problems on the pc, so I won't be able to test
in the last example you posted the lines with "printl" alone, they gave an error.
  does it have something to do with my windows?, i still use win7 because of my pc that is a wagon, i was going to buy a 3rd generation xeon, but now the motherboard is giving a lot of critical error, now i'll have to wait having money to assemble a new pc because even if you buy used it is expensive since the Brazilian currency has devalued a lot, and I still suffer the risk of being taxed if I import the parts to get cheaper

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 879
  • User-Rate: +33/-1
    • Charles Pegge
Re: O2 Arrays / BASIC Standardization
« Reply #56 on: October 01, 2022, 10:19:20 AM »
Hi Eduardo,

I fixed a few problems with P9, including one affecting single dimensional redim. The printl problem is also resolved. Most of the bugs are from the library files, not core o2. I posted the last P9 about 5 housrs ago.

You may find the motherboard problems are most likely caused by dirty memory card / socket connections, especially if your climate is humid.

My apologies to anyone  emailing me. We have landline and slow internet problems making it impossible to access my bt mail.

This is a test for multidimensional objects. With the last P9, destructors are called in reverse order when the array is reduced in size.

Code: [Select]
uses console
printl "redimensioning objects"
printl
indexbase 1
int c
class obc
  int id
  method constructor()
    c++
    id=c
    printl "ob constructor " c
  end method
  method destructor
    printl "ob destructor "  id 
  end method
end class
'
printl "minimal array"
redim obc ob(1,1,1)
printl
printl "increase array"
redim obc ob(2,2,2)
printl
printl "reduce array"
c=0
redim obc ob(1,2,2)
wait

Github link to 050P9:
https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenBasic050P9.zip
« Last Edit: October 01, 2022, 10:36:39 AM by Charles Pegge »

Offline Nicola_Piano

  • Full Member
  • ***
  • Posts: 111
  • User-Rate: +0/-0
Re: O2 Arrays / BASIC Standardization
« Reply #57 on: October 23, 2022, 10:08:35 PM »
Hi Charles.
I really like this implementation on multidimensional arrays.
Cheers

24-10-2022
I tried (with P12) your example and pleasantly noticed that UBOUND also works correctly for the size of the array.
Very good.

Code: [Select]
'24/09/2022
'multidim read/write check
uses console
indexbase 1
#minormajor 'default is majorminor
int ym=4,xm=5
redim int yx[ym,xm] 'dynamic
dim int y,x,i
for y=1 to 4
  for x=1 to 5
    i++
    yx(y,x)=i
    print yx(y,x) tab
  next
  printl
next
printl
if #minormajor
  printl "column major order"
else
  printl "row major order"
endif
'test storage order for
'minrmajor and major minor
dim int nn at @yx
printl ubound(yx,1)
printl ubound(yx,2)
printl nn(1) tab nn(2) tab nn(3) tab nn[4]
wait
« Last Edit: October 24, 2022, 12:47:07 PM by Nicola_Piano »

Offline Zlatko Vid

  • Sr. Member
  • ****
  • Posts: 298
  • User-Rate: +2/-2
Re: O2 Arrays / BASIC Standardization
« Reply #58 on: October 25, 2022, 12:00:30 AM »
I don't understand purpose of LBOUND and UBOUND for arrays
i found it in other dialects ..but why is there anyway ? ...never need to use it?
is that some kind of protections for array size ?

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 1058
  • User-Rate: +30/-4
  • Gender: Male
    • it-berater
Re: O2 Arrays / BASIC Standardization
« Reply #59 on: October 25, 2022, 11:38:28 AM »
Assume that you get an ARRAY in a FUNCTION BYREF.
So how can you find out the dimensions of that ARRAY?
Yes, you can use L/UBOUND()

Example. Make a Function in PB that will REDIM an Array that is given as Parameter, conserving the Content.
You will only be able to make the function using LBOUND and UBOUND.
« Last Edit: October 25, 2022, 11:43:22 AM by Theo Gottwald »