View Full Version : Nested UDT
ErosOlmi
25-04-2007, 10:14
ATTENTION - ATTENTION
_________________________________________________
very unstable thinCore.dll. Use only to test simple UDT nesting._________________________________________________
State of the art of nested UDT inside thinBasic scripts.
Find here attached a lab version of thinCore.dll used to test usage of nested UDT inside scripts.
What is possible to do right now other than simple UDT:
_________________________________________________
2007.10.29 read data from elements of UDT inside UDT, any level, both numeric or string
2007.10.31 added numeric assignment, any level, even for arrays
2007.11.01 added string assignment, any level, also arrays of string elements
improved speed and stability
improved testing script
2007.11.01 removed an optimization process that was generating some bugs
ADDED: Attachment removed because developed features are now included into current thinBasic preview version 1.5.0.1
Petr Schreiber
25-04-2007, 13:13
Hi,
I can't wait to this preview,
this is very nice feature !
Thanks a lot,
Petr
Michael Hartlef
25-04-2007, 15:34
With each preview, TB beocmes more and more complete on the general language features. Great addition!
ErosOlmi
25-04-2007, 19:08
Thanks guy. I knew you would have liked it.
We still need to find some "clever" solution in few specific coding point.
Parsing of nested UDT in terms of declaration will be present I think in next preview.
Parsing when assigning data or getting data in numeric and string expressions or passing sub/function parameters will take some more time but we are not so far from the solution.
Eros
That sort of power will really be welcome with complex projects as topdown. THanks for the preview, very exciting news indeed!
Michael Hartlef
27-10-2007, 10:18
Hi Eros,
how far is this in development?
I am curious too, as it will be a very wonderful feature for so many things!!
ErosOlmi
28-10-2007, 10:22
I'm working on those little creatures going around connected by a dot (.) sometimes in little queues (arrays).
:-[
Michael Hartlef
28-10-2007, 14:18
No problem, I was just curious.
Thanks for the update Eros and good luck on sorting through all the things you have to do to make it all work :)
ErosOlmi
29-10-2007, 01:34
OK, something to try about nested UDT.
Find here attached a new thinCore.dll I'm working on plus a little console example showing the creation of a nested UDT (multilevel) and data retriving (still no data assignment). So far ONLY numeric value retrieve is working without any GPF and no array of UDT is supported (it will give GPF). Even if quite limited, it seems the road is open now. I need to give stability and speed to the process of parsing and finding exact position of the element inside the nested UDT. After that, implementation of all missing features seems quite easy.
Thanks Eros, so nice to see it at such a progressed state. It ran fine on my computer!
Michael Hartlef
29-10-2007, 08:09
Thanks Eros, I will try it soon.
ErosOlmi
29-10-2007, 17:03
Attahced to the first post of this thread please find an ongoing version of thinCore.dll and a sample script showing current state of the art on nested UDT development.
Script will show what is possible to do right now. I will update as long as there will be an improvement, giving note with a new post in this thread.
Complex UDT can be already defined of whatever type and complexity. If you find an error on defining complex UDT, let me know.
Currently I'm working on reading data from the structure, just simple nesting, that is no arrays of nested UDT for the moment.
Regards
Eros
Thanks Eros, this is a great idea to release this as we can start to define our UDT's and once you are finished we can write the functions to use them. Thanks, it is so great you release often, I hate how powerBasic is SOOOOO Quiet and you have know idea of where they are going!!!
ErosOlmi
31-10-2007, 01:42
Updated thinCore.dll and example in first post of this thread.
Added possibility to assign values to numeric elements in nested udt, also on array elements.
This update seem adding also some more speed into execution of standard UDT.
See attached example and report any strange behave.
Let me know.
Eros
Michael Hartlef
31-10-2007, 07:43
Hi Eros,
thanks for the update. I'm sorry that I can't test right now. I'm switching computers at home and at the moment
I have no developing machine. My wife wanted a notebook and till she can effort a new one, she ask me to let her have mine and I take her desktop. Gosh, does she have stuff on her machine. Transfering everything via WLAN is a pain. Today I'll get some DVD's to burn the stuff.
ErosOlmi
31-10-2007, 10:57
No problem Mike.
In any case I'm quite close to have nested UDT 100% working.
I think in one week all the missing parts will be operative.
Petr Schreiber
31-10-2007, 13:17
Fantastic Eros!,
here are results on my PC ( while scanning drives with AVG on the background :P ):
----------------------------------------------------------------------
This script is used to test how thinBasic is able to handle simple and
complex UDT (User Defined Types).
Press a key to continue
----------------------------------------------------------------------
----------------------------------------------------------------------
| MT type
----------------------------------------------------------------------
Size of MT var is: 8
Value of MT.x is: 1234
Value of MT.c.x is: 10
Value of MT.c.y is: 20
----------------------------------------------------------------------
| TMT type
----------------------------------------------------------------------
Size of mx var is: 232
Structure of mx variable is the following:
type tmt
mt as MainUDT
|--> x as long
|--> c as coord
|--> x AS INTEGER
|--> y AS INTEGER
ee(10) as ext
mtt as MainUDT
|--> x as long
|--> c as coord
|--> x AS INTEGER
|--> y AS INTEGER
ss as string * 100
vv as variant
end type
----------------------
Value of Mx.mt.x is: 4321
Value of Mx.mt.c.x is: 11
Value of Mx.mt.c.y is: 21
Value of Mx.ee(1) is: 9876.54321
Value of Mx.ee(10) is: -12345.6789
Value of Mx.mtt.x is: 12345
Value of Mx.mtt.c.x is: -27
Value of Mx.mtt.c.y is: -250
Value of Mx.ss (string) is: ABCDEFGHIJ
Speed Test 001: 100000 loops : 0.093 secs (2 levels of UDT)
Speed Test 002: 100000 loops : 0.125 secs (3 levels of UDT)
Speed Test 003: 100000 loops : 0.141 secs (array element)
Speed Test 004: 100000 loops : 0.141 secs (String)
Speed Test 005: 100000 loops : 0.234 secs (operations on 3rd UDT levels)
----------------------------------------------------------------------
Press any key to finish
Great,
Petr
ErosOlmi
31-10-2007, 13:38
Good Petr.
Seems the logic I'm following is giving some good results and at the same time is simple to manage. I'm surprised new logic is much simpler than before so my code is much easier to handle.
As Dr Edsger Dijkstra said in the past: "Simplicity is prerequisite for reliability" :D
Ciao
Eros
The output looks really cool, I like it. Looks like something that will be good for a texture file on a sci-fi display screen :)
----------------------------------------------------------------------
This script is used to test how thinBasic is able to handle simple and
complex UDT (User Defined Types).
Press a key to continue
----------------------------------------------------------------------
----------------------------------------------------------------------
| MT type
----------------------------------------------------------------------
Size of MT var is: 8
Value of MT.x is: 1234
Value of MT.c.x is: 10
Value of MT.c.y is: 20
----------------------------------------------------------------------
| TMT type
----------------------------------------------------------------------
Size of mx var is: 232
Structure of mx variable is the following:
type tmt
mt as MainUDT
|--> x as long
|--> c as coord
|--> x AS INTEGER
|--> y AS INTEGER
ee(10) as ext
mtt as MainUDT
|--> x as long
|--> c as coord
|--> x AS INTEGER
|--> y AS INTEGER
ss as string * 100
vv as variant
end type
----------------------
Value of Mx.mt.x is: 4321
Value of Mx.mt.c.x is: 11
Value of Mx.mt.c.y is: 21
Value of Mx.ee(1) is: 9876.54321
Value of Mx.ee(10) is: -12345.6789
Value of Mx.mtt.x is: 12345
Value of Mx.mtt.c.x is: -27
Value of Mx.mtt.c.y is: -250
Value of Mx.ss (string) is: ABCDEFGHIJ
Speed Test 001: 100000 loops : 0.062 secs (2 levels of UDT)
Speed Test 002: 100000 loops : 0.079 secs (3 levels of UDT)
Speed Test 003: 100000 loops : 0.093 secs (array element)
Speed Test 004: 100000 loops : 0.125 secs (String)
Speed Test 005: 100000 loops : 0.172 secs (operations on 3rd UDT levels)
----------------------------------------------------------------------
Press any key to finish
ErosOlmi
01-11-2007, 13:17
;D Ken you are right. I'm preparing something more ... sci-fi movie ready.
If someone have a complex UDT to test, please post here the structure and I will use for testing.
Thanks
Eros
ErosOlmi
01-11-2007, 17:21
Updated thinCore.dll attach in first post of this thread.
Added string assignment, any level, also arrays of string elements
Improved speed and stability
Improved testing script
Petr Schreiber
01-11-2007, 20:07
Thanks Eros,
ran fine on my box:
This script is used to test how thinBasic is able to handle simple and
complex UDT (User Defined Types).
Press a key to continue
[Simple 1 level nested UDT] -----------------------------------------------------------------------
- Type name .....................................: MainUDT
- Variable name .................................: mt
- Size of MT var is .............................: 8
- Assignment ....................................: OK, done
- Value of MT.x .................................: 1234
- Value of MT.c.x ...............................: 10
- Value of MT.c.y ...............................: 20
[A more complex UDT with up to 3 nested level] ----------------------------------------------------
- Type name .....................................: TMT
- Variable name .................................: mx
- Size of mx var is .............................: 2142
- Assignment ....................................: OK, done
- Structure of mx variable ......................: see below
> TYPE TMT
> mt as MainUDT
> |--> x AS LONG
> |--> c AS COORD
> |--> x AS INTEGER
> |--> y AS INTEGER
> ee(10) AS EXT
> mtt AS MainUDT
> |--> x AS LONG
> |--> c AS COORD
> |--> x AS INTEGER
> |--> y AS INTEGER
> sn AS STRING * 10
> ss(20) AS STRING * 100
> vv AS VARIANT
> END TYPE
- Value of Mx.mt.x ..............................: 4321
- Value of Mx.mt.c.x ............................: 11
- Value of Mx.mt.c.y ............................: 21
- Value of Mx.ee(1) .............................: 9876.54321
- Value of Mx.ee(10) ............................: -12345.6789
- Value of Mx.mtt.x .............................: 12345
- Value of Mx.mtt.c.x ...........................: -27
- Value of Mx.mtt.c.y ...........................: -250
- Value of Mx.ss(10) (excluded "-") .............: -[1234567890]-
- Value of Mx.ss( 1) (excluded "-") .............: -[ABCDEFGHIJ]-
[Some speed tests] --------------------------------------------------------------------------------
- Speed Test 1: 100000 loops ....................: 0.094 secs (2 levels of UDT)
- Speed Test 2: 100000 loops ....................: 0.125 secs (3 levels of UDT)
- Speed Test 3: 100000 loops ....................: 0.140 secs (array element)
- Speed Test 4: 100000 loops ....................: 0.235 secs (String)
- Speed Test 5: 100000 loops ....................: 0.234 secs (operations on 3rd UDT levels)
- Speed Test 6: 100000 loops ....................: 0.094 secs (3rd UDT level assign)
- Speed Test 7: 100000 loops ....................: 0.187 secs (3rd UDT level assign/read)
---------------------------------------------------------------------------------------------------
Press any key to finish
Thanks,
Petr
P.S. Nice colors :)
Worth to run the new update just to see the new cool looking color output, very tech looking and ready to be made a texture :)
This script is used to test how thinBasic is able to handle simple and
complex UDT (User Defined Types).
Press a key to continue
[Simple 1 level nested UDT] -----------------------------------------------------------------------
- Type name .....................................: MainUDT
- Variable name .................................: mt
- Size of MT var is .............................: 8
- Assignment ....................................: OK, done
- Value of MT.x .................................: 1234
- Value of MT.c.x ...............................: 10
- Value of MT.c.y ...............................: 20
[A more complex UDT with up to 3 nested level] ----------------------------------------------------
- Type name .....................................: TMT
- Variable name .................................: mx
- Size of mx var is .............................: 2142
- Assignment ....................................: OK, done
- Structure of mx variable ......................: see below
> TYPE TMT
> mt as MainUDT
> |--> x AS LONG
> |--> c AS COORD
> |--> x AS INTEGER
> |--> y AS INTEGER
> ee(10) AS EXT
> mtt AS MainUDT
> |--> x AS LONG
> |--> c AS COORD
> |--> x AS INTEGER
> |--> y AS INTEGER
> sn AS STRING * 10
> ss(20) AS STRING * 100
> vv AS VARIANT
> END TYPE
- Value of Mx.mt.x ..............................: 4321
- Value of Mx.mt.c.x ............................: 11
- Value of Mx.mt.c.y ............................: 21
- Value of Mx.ee(1) .............................: 9876.54321
- Value of Mx.ee(10) ............................: -12345.6789
- Value of Mx.mtt.x .............................: 12345
- Value of Mx.mtt.c.x ...........................: -27
- Value of Mx.mtt.c.y ...........................: -250
- Value of Mx.ss(10) (excluded "-") .............: -[1234567890]-
- Value of Mx.ss( 1) (excluded "-") .............: -[ABCDEFGHIJ]-
[Some speed tests] --------------------------------------------------------------------------------
- Speed Test 1: 100000 loops ....................: 0.078 secs (2 levels of UDT)
- Speed Test 2: 100000 loops ....................: 0.078 secs (3 levels of UDT)
- Speed Test 3: 100000 loops ....................: 0.109 secs (array element)
- Speed Test 4: 100000 loops ....................: 0.204 secs (String)
- Speed Test 5: 100000 loops ....................: 0.171 secs (operations on 3rd UDT levels)
- Speed Test 6: 100000 loops ....................: 0.063 secs (3rd UDT level assign)
- Speed Test 7: 100000 loops ....................: 0.141 secs (3rd UDT level assign/read)
---------------------------------------------------------------------------------------------------
Press any key to finish
ErosOlmi
01-11-2007, 21:32
I'm working on UDT and not on colors :P
You are too much Aesthetics ;D
Petr Schreiber
01-11-2007, 23:41
:D
Eros,
there is just one trouble with latest UDT core, your trick for returning multiple values from functions does not work anymore :( : Get code here (http://community.thinbasic.com/index.php?topic=1106.msg7459#msg7459).
I think following hack is passed ok:
dim xyz1 as t_xyz at dBodyGetPosition ( myBody1 )
... but when trying to get value out of xyz1.x and others, it is GPFing.
I know core posted in this thread is not official and just work in progress, but I wanted to let you know there is possible problem.
Thanks,
Petr
EDIT: Just noticed I get GPF even with "clean" 1.5.0.1 preview
ErosOlmi
01-11-2007, 23:54
Petr,
seems dBodyGetPosition ( myBody1 ) returns ZERO.
I do not understand why.
Eros
ErosOlmi
01-11-2007, 23:58
Problem found. It has nothing to do with nested UDT job I'm doing.
DECLARE FUNCTION dBodyGetPosition LIB "ode.dll" ALIAS "dBodyGetPosition" (BYVAL dBodyIDlike AS dBodyID) AS dReal
should be
DECLARE FUNCTION dBodyGetPosition LIB "ode.dll" ALIAS "dBodyGetPosition" (BYVAL dBodyIDlike AS dBodyID) AS DWORD
in thinbasic_ode.inc include file because it returns a pointer.
Reason before it was working is due to more resticted checking in return value from external functions recently introduced.
It external function is declared to return a floating point number, floating point unit is used to get back the value, while before value was taken from the calling stack always.
Let me know
Eros
ErosOlmi
02-11-2007, 00:13
Yes,
I've checked some C code and dBodyGetPosition is defined as returning a float* that is a pointer to a floating point variable. So function is returning a DWORD in reality and not a dReal (SINGLE).
I suspect there are other functions to adjust in thinbasic_ode.inc :(
Ciao
Eros
Petr Schreiber
02-11-2007, 00:35
Hi Eros,
I am waiting for shot from Beretta - there was lot of mistakes,
I sent new version of header on your mail to be distributed.
You were right - it really caused all the troubles!
I am sorry,
Petr
ErosOlmi
02-11-2007, 00:39
Sorry?
The next time you will say "sorry" I will ban from this board !!! ;D
You can make another zillion errors before you will need to say "sorry" !
ErosOlmi
02-11-2007, 00:43
Seems there are other problems with the version you sent me.
No GPF but half of the physical structures is not on screen.
Petr Schreiber
02-11-2007, 00:48
In which sample ? :-[
( 2 DECRs from the zillion in one day, oh no )
Petr
ErosOlmi
02-11-2007, 00:50
All examples I have.
I'm getting old ODE inc file and see.
Petr Schreiber
02-11-2007, 00:52
I see,
for me it does the same, but only using new core.
Latest 1.5.0.1 + new header works good ???
Petr
ErosOlmi
02-11-2007, 00:55
OK, sorry, now it was me.
A last minute change in thinCore.dll was not ok.
Did I say sorry? Impossible ! :D
New thinbasic_ODE.inc file is fine. I will distribute in next release (maybe next week I think)
Ciao
Eros
Petr Schreiber
02-11-2007, 00:59
;D Perfect !
I added latest header here (http://community.thinbasic.com/index.php?topic=820.msg5084#msg5084) in case somebody needs it sooner :)
Bye,
Petr
ErosOlmi
02-11-2007, 01:01
Updated thinCore.dll attach in first post of this thread.
Removed an optimization process that was generating some weird behave.
Will try to optimize more later in a next release.
Eros
I am glad you guys are able to find what is wrong and is not wrong so quickly, pretty amazing to trace down problems as quickly as you guys do!!
Eros. sorry I am not in programming mode for a while as trying to learn Blender better, but am anxious to get back to all the new thinBasic stuff soon as I can!!
ErosOlmi
02-11-2007, 09:05
@Ken
Solving those problems is a pleasure because it improves thinBasic reliability.
And regarding your time, do what you prefer for your life. It is important to follow personal feeling and ideas.
In any case I will never thank you enough for the passion you give us with your presence here, so, you too have to stop to say sorry !!! ;D
@Petr
A little modification that will be present in next release:
DECLARE FUNCTION dBodyGetPosition _
LIB "ode.dll" _
ALIAS "dBodyGetPosition" _
( _
BYVAL dBodyIDlike AS dBodyID _
) AS dReal PTR
... PTR at the end of a function declare will clearly let people understand that it will return a pointer to something, in this case a dReal (alias for SINGLE in ODE inc file). Internally thinBasic will manage the proper setup to return a DWORD number.
Do you like?
Ciao
Eros
Michael Hartlef
02-11-2007, 11:56
Sounds good Eros.
Petr Schreiber
02-11-2007, 13:59
Do you like?
I love it ! Can it be used also for parameter definition ?
Thanks,
Petr
ErosOlmi
02-11-2007, 16:57
Yes sure but not immediately ;)
PTR and dereferencing will be one of the next big steps after nested UDT will work 100%
Ciao
Eros
Need some help in understanding... how is PTR and dereferencing different than what we have now with passing byval and byref?
ErosOlmi
02-11-2007, 19:26
Yes, from a tech point of view it is similar but here I'm not talking about parameters but real pointers to data.
You know Power Basic and how pointers are handled there. I want similar things in thinBasic:
DIM MyVar AS LONG
DIM pMyVar AS LONG PTR
'---Assign to the pointer the memory address to point to
pMyVar = VARPTR(MyVar)
'---Assign value to MyVar using a LONG Pointer to it
@pMyVar = 123
But this is just an example with simple var. Imagine it with complex structures and pointers inside structures that point to other UDT.
Some of this can already be done in thinBasic using DIM ... AT at GETAT/SETAT but it is not so elegant as pointers.
Anyhow we will see. For the moment I will use only for external function return value because just defining ... AS DWORD does not give any info while ... AS SINGLE PTR or ... AS DOUBLE PTR is much better to me.
Ciao
Eros
Petr Schreiber
02-11-2007, 19:50
No problem Eros,
take your time on pointers !
Bye,
Petr
ErosOlmi
04-11-2007, 11:29
Petr,
I've made some experiment and I can add PTR functionality also to parameters in DECLARE statement.
The problem is that I have to change BYVAL automatically even if used specified BYREF because all pointers are values (exact memory address allocation) and not references. So I'm in doubt if to generate a RunTime Error when DECLARE contains something like:
..., BYREF MyParam AS DOUBLE PTR, ...
while in reality is will be considered
..., BYVAL MyParam AS DOUBLE PTR, ...
I think I will generate a RunTime Error indicating the exact problem. Better to be aware of it.
What do you think?
Ciao
Eros
Petr Schreiber
04-11-2007, 15:17
Hi Eros,
yes, I agree with you on this.
Even if it means to correct some headers, better to say clearly how feature is handled than do some automatics on backgorund.
Bring the RTE :)
Petr
ErosOlmi
10-11-2007, 09:45
All features talked about in this thread are now present in current thinBasic preview version 1.5.0.1
I've removed thinCore.dll attachment in first post of this thread.
Nested UDT are still not perfect, some checking or arrays of UDT are to be done. Also I've not yet done optimization parsing so in some cases UDT will be slower even for simple UDT usage. In any case, it seems we are at good point. Consider it still in heavy under development stage but ... not for long :D
Thanks
Eros
Michael Hartlef
10-11-2007, 11:07
All features talked about in this thread are now present in current thinBasic preview version 1.5.0.1
I've removed thinCore.dll attachment in first post of this thread.
Nested UDT are still not perfect, some checking or arrays of UDT are to be done. Also I've not yet done optimization parsing so in some cases UDT will be slower even for simple UDT usage. In any case, it seems we are at good point. Consider it still in heavy under development stage but ... not for long :D
Thanks
Eros
Thanks Eros,
arrays of nested UDTs is what I'm looking forward to.
ErosOlmi
10-11-2007, 13:12
It is quite ready Mike.
I think all will be working and ready to be tested by real scripts by next week.
In the meantime, any test on current version will be appreciated. I made some tests but, you know, it is never enough.
Thanks
Eros
ErosOlmi
13-11-2007, 19:47
Assignment with nested UDT and any kind of arrays seems quite OK. Any number of arrays at any level of the structure.
Now I will work on data value retrieving.
Mike, pay attention: you will not have other excuses when I will finish this job! ;D
And you know ... what ... I mean 8) (http://community.thinbasic.com/index.php?topic=1332.msg9399#msg9399)
Michael Hartlef
14-11-2007, 09:53
Ouch ;D