Author Topic: MY-BASIC  (Read 108450 times)

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #90 on: September 18, 2015, 01:11:38 AM »
It's wonderful, John.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #91 on: September 18, 2015, 02:23:50 AM »
I'll give it a try running in a thread tomorrow.  8)

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #92 on: September 18, 2015, 08:24:52 AM »
Oh, I found one issue: you can't assign real numbers to variables anymore.
Quite a bug... Fixed in latest revision. Thanks for telling me.

Thanks for fixing the bug. It works again as expected.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #93 on: September 19, 2015, 08:55:34 PM »
Tony,

I tried a simple SUB recursion test and it didn't work and segmentation faulted.

Code: [Select]
def plusone(a)
    if a <= 10 then
      a = a + 1
      print a, "\n"
      plusone(a)
    endif
enddef
 
plusone(1)

This works in Script BASIC.

Code: ScriptBasic
  1. sub plusone(a)
  2.   if a <= 10 then
  3.     a = a + 1
  4.     print a, "\n"
  5.     plusone(a)
  6.   end if
  7. end sub
  8.  
  9. plusone(1)
  10.  


jrs@laptop:~/sb/sb22/test$ scriba plusone.sb
2
3
4
5
6
7
8
9
10
11
jrs@laptop:~/sb/sb22/test$
« Last Edit: September 19, 2015, 09:16:01 PM by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #94 on: September 19, 2015, 11:04:35 PM »
I tried a simple SUB recursion test and it didn't work and segmentation faulted.
I'll look over to fix it, and post it when it's done. Thanks for report.

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #95 on: September 20, 2015, 06:41:42 AM »
Hi John,

I've added recursive sub routine support in the latest revision.

Further more, I plan to implement tail recursion optimization later.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #96 on: September 22, 2015, 06:38:52 PM »
Seems to work. Have you also tested it with FUNCTIONs returning a value in a recursive mode?

Code: ScriptBasic
  1. DECLARE SUB mb_init ALIAS "mbas_init" LIB "mb"
  2. DECLARE SUB mb_dispose ALIAS "mbas_dispose" LIB "mb"
  3. DECLARE SUB mb_open ALIAS "mbas_open" LIB "mb"
  4. DECLARE SUB mb_close ALIAS "mbas_close" LIB "mb"
  5. DECLARE SUB mb_load_str ALIAS "mbas_load_str" LIB "mb"
  6. DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"
  7.  
  8. mb_code = """
  9. def plusone(a)
  10.    if a <= 10 then
  11.      a = a + 1
  12.      print a, "\n"
  13.      plusone(a)
  14.    endif
  15. enddef
  16.  
  17. plusone(1)
  18. """
  19. mb_init
  20. mb_open
  21. mb_load_str mb_code
  22. mb_run
  23. mb_close
  24. mb_dispose
  25.  
  26.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mbrecur.sb
2
3
4
5
6
7
8
9
10
11
jrs@laptop:~/sb/sb22/mybasic$

« Last Edit: September 22, 2015, 06:47:56 PM by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #97 on: September 23, 2015, 10:33:25 PM »
Seems to work. Have you also tested it with FUNCTIONs returning a value in a recursive mode?

I've fixed some bugs with sub routines in latest revision.

Now sub routines return a value in a recursive mode work fine, eg:

Code: ScriptBasic
  1. def fac(a)
  2.     if a = 0 then
  3.         return 1
  4.     endif
  5.  
  6.     return a * fac(a - 1)
  7. enddef
  8.  
  9. print fac(6);
  10.  

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #98 on: September 24, 2015, 12:52:07 AM »
Tony,

No errors and I assume the value returned is correct. Can you show an example of CLASS/ENDCLASS? I couldn't find anything about it in the docs. It looks like you implemented the optimize tail recursion based on your Github readme.

Code: ScriptBasic
  1. DECLARE SUB mb_init ALIAS "mbas_init" LIB "mb"
  2. DECLARE SUB mb_dispose ALIAS "mbas_dispose" LIB "mb"
  3. DECLARE SUB mb_open ALIAS "mbas_open" LIB "mb"
  4. DECLARE SUB mb_close ALIAS "mbas_close" LIB "mb"
  5. DECLARE SUB mb_load_str ALIAS "mbas_load_str" LIB "mb"
  6. DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"
  7.  
  8. mb_code = """
  9. def fac(a)
  10.    if a = 0 then
  11.        return 1
  12.    endif
  13.  
  14.    return a * fac(a - 1)
  15. enddef
  16.  
  17. print fac(6);
  18. """
  19. mb_init
  20. mb_open
  21. mb_load_str mb_code
  22. mb_run
  23. mb_close
  24. mb_dispose
  25.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mbfac.sb
720
jrs@laptop:~/sb/sb22/mybasic$


Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #99 on: September 24, 2015, 01:08:16 AM »
I thought I would give your precompiled Windows version a try in Wine and notice this error with a simple FOR/NEXT structure.

Interestingly it works fine in Script BASIC using your latest code base.

Code: ScriptBasic
  1. DECLARE SUB mb_init ALIAS "mbas_init" LIB "mb"
  2. DECLARE SUB mb_dispose ALIAS "mbas_dispose" LIB "mb"
  3. DECLARE SUB mb_open ALIAS "mbas_open" LIB "mb"
  4. DECLARE SUB mb_close ALIAS "mbas_close" LIB "mb"
  5. DECLARE SUB mb_load_str ALIAS "mbas_load_str" LIB "mb"
  6. DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"
  7.  
  8. mb_code = """
  9. for x = 1 to 5
  10. print x;
  11. next x
  12. """
  13. mb_init
  14. mb_open
  15. mb_load_str mb_code
  16. mb_run
  17. mb_close
  18. mb_dispose
  19.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mbfornext.sb
1
2
3
4
5
jrs@laptop:~/sb/sb22/mybasic$



« Last Edit: September 24, 2015, 01:13:48 AM by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #100 on: September 24, 2015, 01:23:23 AM »
Can you show an example of CLASS/ENDCLASS?

It's not implemented yet, I just reserved those keywords.

I thought I would give your precompiled Windows version a try in Wine and notice this error with a simple FOR/NEXT structure.

Sounds odd and interesting, I'll take a look on Linux natively and on Wine.

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #101 on: September 26, 2015, 02:21:20 PM »
Sorry to tell you that I can't use the latest update. I can compile AllegroBASIC but it won't even start it gives me just a memory access error. The version before that update works fine, though. Seems to be the recursive subroutine support ...

EDIT: Hm, I tried compiling with GCC and it works, seems only TCC to be affected ...
« Last Edit: September 26, 2015, 02:24:29 PM by Cybermonkey342 »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #102 on: September 26, 2015, 02:45:28 PM »
Quote
EDIT: Hm, I tried compiling with GCC and it works, seems only TCC to be affected ...

That sure adds an interesting spin.

I wonder what Tony used to compile the .exe version he includes in the distribution?

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #103 on: September 27, 2015, 08:09:51 PM »
Hi guys,

I figured out that the memory corruption was caused by character list integers (I don't know the exact English term of it):

Code: C
  1. #define _SCOPE_META_ROOT 'ROOT'
  2. #define _SCOPE_META_REF 'REFS'
  3.  

VS, BCB, Clang, GCC support it properly, however, PellesC, TCC don't.

I fixed it by modifying it to:

Code: C
  1. #define _SCOPE_META_ROOT (1 << 0)
  2. #define _SCOPE_META_REF (1 << 1)
  3.  

Note: precompiled binaries are not updated.

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #104 on: October 19, 2015, 11:49:07 AM »
Thanks for fixing that. I am working again on AllegroBASIC and actually found another issue (although I do not know, if this is intended).
Let's assume you want to use a sub without a paramater something like:
Code: [Select]
def drawbackground()
...
enddef
If you call now the sub I got a memory allocation error.
Workaround at the moment:
Code: [Select]
def drawbackground(void)
...
enddef
And this can be called like
Code: [Select]
drawbackground()without any errors.

I made another progress with AllegroBASIC - the timer works now correctly.

Best thing is that the memory leak isn't there anymore although I did nothing. Maybe because of the new version of MY-BASIC I use?