Author Topic: MY-BASIC  (Read 84763 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #120 on: October 21, 2015, 08:57:07 pm »
Things are back to normal again.

Code: Script BASIC
  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 bar()
  10.  PRINT "It Works!";
  11. enddef
  12.  
  13. bar()
  14. """
  15. mb_init()
  16. mb_open()
  17. mb_load_str(mb_code)
  18. mb_run()
  19. mb_close()
  20. mb_dispose()
  21.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mbnoprams.sb
It Works!
jrs@laptop:~/sb/sb22/mybasic$


Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #121 on: October 22, 2015, 01:42:22 am »
Yes, it works again, also with TCC.

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #122 on: January 01, 2016, 09:54:09 pm »
I added a Stack Implementation in script wiki page, which would explain how to use prototype-based class in MY-BASIC quickly. Prototype-based programming is what I've done during last month. I'll add more explanation and complex sample script later.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #123 on: January 01, 2016, 10:19:48 pm »
Looks great Tony!

Addig OOP to MyBASIC is big step forward.

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #124 on: January 08, 2016, 11:01:07 pm »
Lambda abstraction supported by MY-BASIC now. Have a glance?

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #125 on: January 09, 2016, 02:21:54 pm »
Looks interesting!

I will have to embed your latest in Script BASIC as an extension module and give it a spin.

I'm happy to see you making such great progress with MyBASIC.

BTW: I'm jealous of your outstanding markup language skills. You really make your docs look great!

Update:

I compiled a new 64 bit mb.so extension module using your new code base and all seems well.

setvars.bas
Code: [Select]
a = 0
b = 0.0
c$ = ""

Code: Script BASIC
  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_load_file ALIAS "mbas_load_file" LIB "mb"
  7. DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"
  8. DECLARE SUB mb_getint ALIAS "mbas_getint" LIB "mb"
  9. DECLARE SUB mb_getdbl ALIAS "mbas_getdbl" LIB "mb"
  10. DECLARE SUB mb_getstr ALIAS "mbas_getstr" LIB "mb"
  11. DECLARE SUB mb_setint ALIAS "mbas_setint" LIB "mb"
  12. DECLARE SUB mb_setdbl ALIAS "mbas_setdbl" LIB "mb"
  13. DECLARE SUB mb_setstr ALIAS "mbas_setstr" LIB "mb"
  14. DECLARE SUB mb_reset ALIAS "mbas_reset" LIB "mb"
  15.  
  16. mb_init
  17. mb_open
  18. mb_load_file "setvars.bas"
  19. mb_run
  20. mb_setint "A", 123
  21. mb_setdbl "B", 1.23
  22. mb_setstr "C$", "One,Two,Three"
  23. PRINT mb_getint("A"),"\n"
  24. PRINT FORMAT("%g\n", mb_getdbl("B"))
  25. PRINT mb_getstr("C$"),"\n"
  26. mb_close
  27. mb_dispose
  28.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mbvars.sb
123
1.23
One,Two,Three
jrs@laptop:~/sb/sb22/mybasic$


Code: [Select]
class animal
def speak(a)
print "default" + a;
enddef
endclass

class cat(animal)
def speak(a)
print "meow" + a;
enddef
endclass

class dog(animal)
def speak(a)
print "bark" + a;
enddef
endclass

c = new(cat)
d = new(dog)

c.speak("!")
d.speak("!")


jrs@laptop:~/sb/sb22/mybasic$ scriba mbclass.sb
meow!
bark!
jrs@laptop:~/sb/sb22/mybasic$


Code: [Select]
f = lambda (x, y) (return x * x + y * y)
print f(3, 4);


jrs@laptop:~/sb/sb22/mybasic$ scriba invoke.sb
25
jrs@laptop:~/sb/sb22/mybasic$



Code: Script BASIC
  1. FUNCTION f(x,y)
  2.   f = x * x + y * y
  3. END FUNCTION
  4.  
  5. PRINT f(3, 4),"\n"
  6.  


jrs@laptop:~/sb/sb22/mybasic$ scriba lame_dah
25
jrs@laptop:~/sb/sb22/mybasic$


;D
« Last Edit: January 10, 2016, 01:15:58 am by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #126 on: January 10, 2016, 02:35:53 am »
Thank you John, MY-BASIC will keep on evolving.

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #127 on: January 10, 2016, 07:09:33 am »
Hi Wang I've got a question. Maybe I do something wrong but my implemation of a drawtext function gives a memory leak if I add something to the output. For example the following BASIC code  gives that memory leak:
Code: [Select]
' mousetest
KEY_ESC          = 59
screen (640,480,"Mousetest")
hidemouse
do
cls

drawtext (100,100,"MouseX: "+str(mouseX))
drawtext (100,112,"MouseY: "+str(mouseY))
drawtext (100,124,"MouseButton: "+str(mousebutton))
drawtext (100,136,"MouseWheel: "+str(mousewheel))
if mousebutton = 1 then showmouse
if mousebutton = 2 then hidemouse
sync
until keystate (KEY_ESC) = true
end

I tried another way with the same result...
Code: [Select]
' mousetest
KEY_ESC          = 59
screen (640,480,"Mousetest")
hidemouse
do
cls
xm=str (mouseX)
drawtext (100,100,"MouseX: ")
drawtext (160,100,xm)
if mousebutton = 1 then showmouse
if mousebutton = 2 then hidemouse
sync
until keystate (KEY_ESC) = true
end

If I comment the line with str() out and do the following
Code: [Select]
xm="320"then there's no memory leak. So it seems to me that there is a problem with the str() function...?

EDIT: Seems to be confirmed. The following program which does not output anything has a memory leak:
Code: [Select]
' mousetest
KEY_ESC          = 59
screen (640,480,"Mousetest")
hidemouse
do
cls
xm=str (mouseX) 'instead of mousex I can also use a number but the result is still the same: memory leak
sync
until keystate (KEY_ESC) = true
end
« Last Edit: January 10, 2016, 07:50:57 am by Cybermonkey342 »

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #128 on: January 19, 2016, 03:47:39 pm »
FYI:

The MyBASIC STR() memory leak issue has been resolved. The info on that was lost in the forum restore from Jan. 10th 2016.

@OldBasicUser - Please rejoin the forum as your prior registration was lost in the restore.

@Charles Pegge - If you are reading this, please contact me so I can get your OxygenBasic site running on the new server.
« Last Edit: January 20, 2016, 10:19:54 pm by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #129 on: January 20, 2016, 02:17:02 am »
Happy to get back.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #130 on: January 20, 2016, 12:03:22 pm »
It's good to test your disaster recovery from time to time.  ::)

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #131 on: January 24, 2016, 08:41:26 am »
You can now download AllegroBASIC on: http://allegrobasic.pulsar2d.org/
Be sure to read the notes for Windows 10 if you are a Windows 10 user.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #132 on: January 24, 2016, 10:29:47 am »
Thanks for allowing us to take your new BASIC for a test drive. It seems I had better luck than Tomaaz did.  :)









Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #133 on: January 25, 2016, 08:50:36 pm »
Here is AllegroBASIC running on Ubuntu 14.04 64 bit.

FYI: Console only, no IDE.









« Last Edit: January 25, 2016, 08:53:17 pm by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #134 on: January 26, 2016, 03:00:34 am »
Hi Markus,

The mandelbrot sample code came along with AllegroBASIC takes ~63 seconds on my i7 PC. Then I modified the code by commenting all graphics related lines, it costs almost the same duration. After that I tried to port it to a MY-BASIC shell version without graphics as well, it takes only ~15 seconds. I guess you were not using the memory pool, I recommend you to add a pool to optimize the memory performance of small chucks, since a simple implementation can even improve it more than 4 times faster. You can search for _open_mem_pool, mb_set_memory_manager(_pop_mem, _push_mem), _close_mem_pool() in shell/main.c to find my implementation.

MY-BASIC shell version without graphics:
Code: [Select]
miter=128
zm=120
time1=ticks()
for y=0 to 479
  for x=0 to 639
    zx=0
    zy=0
    cx= (x-320)/zm
    cy= (y-240)/zm
    i = miter
  while (zx*zx+zy*zy <4) and (i >0)
    tmp = zx * zx - zy * zy + cx
    zy = 2 * zx * zy + cy
    zx = tmp
    i=i-1
  wend
  next
next
time2=ticks()
time=(time2-time1)/1000
print time, " seconds.";
input