Author Topic: MY-BASIC  (Read 68294 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
MY-BASIC
« on: July 25, 2013, 12:03:49 AM »
I have compiled MY-BASIC for Windows (VS2008), Ubuntu 32/64 bit (gcc) and Android Linux (gcc). I view MY-BASIC as a SB-LITE like BASIC that is portable, extensible and embeddable. I modified it a bit and changed the ] prompt to be > with a space after it. I also took the startup info and made it part of the help screen. On startup of the shell, it displays MY-BASIC and the version number before dropping to the prompt. I optimized and stripped the Linux versions. The final executable sized range from 102 KB to 56 KB depending on the platform. The following is what MY-BASIC doesn't have that ScriptBasic does.

  • SUB/FUNCTION support
  • File support
  • Socket support
  • System calls
  • External library support

If all you're looking for is a simple to use embeddable BASIC, MY-BASIC is very well done and fast for being an interpreter. I see MY-BASIC as a great foundation for someone that wants to create there own BASIC but doesn't have the skills to start from scratch. MY-BASIC would be a good teaching tool for kids to learn BASIC programming.

Windows XP


Android Linux


Ubuntu Linux



« Last Edit: July 25, 2013, 01:25:11 AM by JRS »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #1 on: April 20, 2015, 08:41:30 AM »
Hi Tony,

Just noticed your post on the BP.org site. I have been playing with your BASIC for a couple of years. I even have it running native on Android. I had posted the info I had here on All BASIC on BP.org but there seemed to be very little interest.

I'm not surprised as the Bitter BASIC Boys (and their toys) spend most of their time feeling miserable and pissed off their attempts at creating a BASIC of their own wasn't as easy as they anticipated. Their way to deal with it is to trash those that have made the commitment to do it right. Sad really.

John
« Last Edit: April 20, 2015, 12:41:40 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #2 on: April 20, 2015, 11:25:03 AM »
I was able to compile the new release on Linux 64 bit.


jrs@laptop:~/mybasic/my_basic-master$ ./mybasic
MY-BASIC Interpreter Shell - 1.0.0050.
Copyright (C) 2011 - 2015 W. Renxin. All Rights Reserved.
For more information, see https://github.com/paladin-t/my_basic/.
Input HELP and hint enter to view help information.
]HELP
Commands:
  CLS   - Clear screen
  NEW   - Clear current program
  RUN   - Run current program
  BYE   - Quit interpreter
  LIST  - List current program
          Usage: LIST [l [n]], l is start line number, n is line count
  EDIT  - Edit a line in current program
          Usage: EDIT n, n is line number
  LOAD  - Load a file as current program
          Usage: LOAD *.*
  SAVE  - Save current program to a file
          Usage: SAVE *.*
  KILL  - Delete a file
          Usage: KILL *.*
]BYE
jrs@laptop:~/mybasic/my_basic-master$


Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #3 on: April 20, 2015, 12:14:27 PM »
Markus (Cybermonkey),

You must have been reading My_Mind. I have compiled MY-BASIC on all major platforms and wanted to create a Script BASIC extension module embedding My_Basic. It might make a nice addition to the TinyScheme and  Perl extension modules I did. The nice aspect of all three of the language extensions is they are interpretive and typeless. (like Script BASIC the host)

I'm slammed with a project at the moment but when I have some free time I'll take a shot of creating the Script BASIC MY-BASIC extension module using C BASIC.
« Last Edit: April 20, 2015, 12:36:36 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #4 on: April 20, 2015, 04:07:55 PM »
I put together a quick extension module for MY-BASIC and seem to have a problem passing a string.  ???

interface.c
Code: C
  1. // MY-BASIC - Script BASIC extension module
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <stdarg.h>
  7. #include <ctype.h>
  8. #include <math.h>
  9. #include <time.h>
  10. #include "../../basext.h"
  11. #include "cbasic.h"
  12.  
  13. #include "my_basic.h"
  14.  
  15.  
  16. /****************************
  17.  Extension Module Functions
  18. ****************************/
  19.  
  20. besVERSION_NEGOTIATE
  21.   RETURN_FUNCTION((int)INTERFACE_VERSION);
  22. besEND
  23.  
  24. besSUB_START
  25.   DIM AS long PTR p;
  26.   besMODULEPOINTER = besALLOC(sizeof(long));
  27.   IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  28.   p = (long PTR)besMODULEPOINTER;
  29.   RETURN_FUNCTION(0);
  30. besEND
  31.  
  32. besSUB_FINISH
  33.   DIM AS long PTR p;
  34.   p = (long PTR)besMODULEPOINTER;
  35.   IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  36.   RETURN_FUNCTION(0);
  37. besEND
  38.  
  39.  
  40. /********************
  41.  MY-BASIC Functions
  42. ********************/
  43.  
  44. struct mb_interpreter_t* bas = 0;
  45.  
  46. besFUNCTION(mbas_init)
  47.   DIM AS int rtnval;
  48.   rtnval = mb_init();
  49.   besRETURN_LONG(rtnval);
  50. besEND
  51.  
  52. besFUNCTION(mbas_dispose)
  53.   DIM AS int rtnval;
  54.   rtnval = mb_dispose();
  55.   besRETURN_LONG(rtnval);
  56. besEND
  57.  
  58. besFUNCTION(mbas_open)
  59.   DIM AS int rtnval;
  60.   rtnval = mb_open(AT bas);
  61.   besRETURN_LONG(rtnval);
  62. besEND
  63.  
  64. besFUNCTION(mbas_close)
  65.   DIM AS int rtnval;
  66.   rtnval = mb_close(AT bas);
  67.   besRETURN_LONG(rtnval);
  68. besEND
  69.  
  70. besFUNCTION(mbas_load_str)
  71.   DIM AS const char PTR pgm;
  72.   DIM AS int rtnval;  
  73.   besARGUMENTS("z")
  74.     AT pgm
  75.   besARGEND
  76.   rtnval = mb_load_string(AT bas, pgm);
  77.   besRETURN_LONG(rtnval);
  78. besEND
  79.  
  80. besFUNCTION(mbas_run)
  81.   DIM AS int rtnval;
  82.   rtnval = mb_run(AT bas);
  83.   besRETURN_LONG(rtnval);
  84. besEND
  85.  

testmb.sb
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_init
  9. mb_open
  10. mb_load_str("10 PRINT \"Hello MY-BASIC\"")
  11. mb_run
  12. mb_close
  13. mb_dispose
  14.  

Output

jrs@laptop:~/sb/sb22/mybasic$ scriba testmb.sb
scriba: my_basic.c:3736: mb_load_string: Assertion `s && s->parsing_context' failed.
Aborted (core dumped)
jrs@laptop:~/sb/sb22/mybasic$


Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #5 on: April 20, 2015, 04:35:49 PM »
I thought I would change the interface.c so that the bas  (MY-BASIC execution object pointer) wasn't a global variable. I also added code to the testmb.sb script to make sure I was getting proper return values prior to the mb_load_str() call.

Code: C
  1. // MY-BASIC - Script BASIC extension module
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <stdarg.h>
  7. #include <ctype.h>
  8. #include <math.h>
  9. #include <time.h>
  10. #include "../../basext.h"
  11. #include "cbasic.h"
  12.  
  13. #include "my_basic.h"
  14.  
  15.  
  16. /****************************
  17.  Extension Module Functions
  18. ****************************/
  19.  
  20. besVERSION_NEGOTIATE
  21.   RETURN_FUNCTION((int)INTERFACE_VERSION);
  22. besEND
  23.  
  24. besSUB_START
  25.   DIM AS long PTR p;
  26.   besMODULEPOINTER = besALLOC(sizeof(long));
  27.   IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  28.   p = (long PTR)besMODULEPOINTER;
  29.   RETURN_FUNCTION(0);
  30. besEND
  31.  
  32. besSUB_FINISH
  33.   DIM AS long PTR p;
  34.   p = (long PTR)besMODULEPOINTER;
  35.   IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  36.   RETURN_FUNCTION(0);
  37. besEND
  38.  
  39.  
  40. /********************
  41.  MY-BASIC Functions
  42. ********************/
  43.  
  44. besFUNCTION(mbas_init)
  45.   DIM AS int rtnval;
  46.   rtnval = mb_init();
  47.   besRETURN_LONG(rtnval);
  48. besEND
  49.  
  50. besFUNCTION(mbas_dispose)
  51.   DIM AS int rtnval;
  52.   rtnval = mb_dispose();
  53.   besRETURN_LONG(rtnval);
  54. besEND
  55.  
  56. besFUNCTION(mbas_open)
  57.   DIM AS struct mb_interpreter_t* bas = 0;
  58.   DIM AS int rtnval;
  59.   rtnval = mb_open(AT bas);
  60.   besRETURN_LONG(rtnval);
  61. besEND
  62.  
  63. besFUNCTION(mbas_close)
  64.   DIM AS struct mb_interpreter_t* bas;
  65.   DIM AS int rtnval;
  66.   rtnval = mb_close(AT bas);
  67.   besRETURN_LONG(rtnval);
  68. besEND
  69.  
  70. besFUNCTION(mbas_load_str)
  71.   DIM AS struct mb_interpreter_t* bas;
  72.   DIM AS const char PTR pgm;
  73.   DIM AS int rtnval;  
  74.   besARGUMENTS("z")
  75.     AT pgm
  76.   besARGEND
  77.   rtnval = mb_load_string(AT bas, pgm);
  78.   besRETURN_LONG(rtnval);
  79. besEND
  80.  
  81. besFUNCTION(mbas_run)
  82.   DIM AS struct mb_interpreter_t* bas;
  83.   DIM AS int rtnval;
  84.   rtnval = mb_run(AT bas);
  85.   besRETURN_LONG(rtnval);
  86. besEND
  87.  

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. CONST MB_FUNC_OK = 0
  9.  
  10. IF mb_init() = MB_FUNC_OK THEN PRINT "mb_init = OK\n"
  11. IF mb_open() = MB_FUNC_OK THEN PRINT "mb_open = OK\n"
  12. mb_load_str("10 PRINT \"Hello MY-BASIC\"")
  13. mb_run
  14. mb_close
  15. mb_dispose
  16.  


jrs@laptop:~/sb/sb22/mybasic$ scriba testmb.sb
mb_init = OK
mb_open = OK
scriba: my_basic.c:3736: mb_load_string: Assertion `s && s->parsing_context' failed.
Aborted (core dumped)
jrs@laptop:~/sb/sb22/mybasic$
« Last Edit: April 20, 2015, 04:43:10 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 685
Re: MY-BASIC
« Reply #6 on: April 20, 2015, 05:32:51 PM »
Code: [Select]
struct mb_interpreter_t* bas = 0;
...
rtnval = mb_load_string(AT bas, pgm);

Code: [Select]
MBAPI int mb_load_string(mb_interpreter_t* s, const char* l);

Your call doesn't match the function declaration.

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #7 on: April 20, 2015, 05:35:33 PM »
Code: Text
  1. jrs@laptop:~/mybasic/my_basic-master$ ./mybasic
  2. MY-BASIC Interpreter Shell - 1.0.0050.
  3. Copyright (C) 2011 - 2015 W. Renxin. All Rights Reserved.
  4. For more information, see https://github.com/paladin-t/my_basic/.
  5. Input HELP and hint enter to view help information.
  6. ]10 PRINT "Hello MY-BASIC"
  7. ]RUN
  8. Error:
  9.     [LINE] 1, [COL] 2,
  10.     [CODE] 44, [MESSAGE] Invalid expression, [ABORT CODE] 1003
  11.  
  12. ]
  13.  

I guess I forgot how to program in BASIC.  ???

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #8 on: April 20, 2015, 05:47:06 PM »
My-BASIC can't print literal strings?  I'm still getting the same error with code that works in the standalone interpreter.

Code: Text
  1. ]NEW
  2. ]a$ = "Hello"
  3. ]PRINT a$
  4. ]RUN
  5. Hello
  6. ]BYE
  7.  

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. CONST MB_FUNC_OK = 0
  9.  
  10. IF mb_init() = MB_FUNC_OK THEN PRINT "mb_init = OK\n"
  11. IF mb_open() = MB_FUNC_OK THEN PRINT "mb_open = OK\n"
  12. mb_code = """
  13. a$ = "Hello My-BASIC"
  14. PRINT a$
  15. """
  16. mb_load_str(mb_code)
  17. mb_run
  18. mb_close
  19. mb_dispose
  20.  


jrs@laptop:~/sb/sb22/mybasic$ scriba testmb.sb
mb_init = OK
mb_open = OK
scriba: my_basic.c:3736: mb_load_string: Assertion `s && s->parsing_context' failed.
Aborted (core dumped)
jrs@laptop:~/sb/sb22/mybasic$

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #9 on: April 20, 2015, 05:56:49 PM »
I changed the function but it still gives the same error. I guess I don't understand what you mean.

Code: C
  1. besFUNCTION(mbas_load_str)
  2.   DIM AS struct mb_interpreter_t* bas;
  3.   DIM AS const char PTR pgm;
  4.   DIM AS int rtnval;  
  5.   besARGUMENTS("z")
  6.     AT pgm
  7.   besARGEND
  8.   rtnval = mb_load_string(AT bas, AT pgm);
  9.   besRETURN_LONG(rtnval);
  10. besEND
  11.  


Offline AIR

  • BASIC Developer
  • Posts: 685
Re: MY-BASIC
« Reply #10 on: April 20, 2015, 06:01:14 PM »
That assertion error is thrown by this:

Code: [Select]
mb_assert(s && s->parsing_context);
Which means 's' is either wrong or is being _passed_ wrong.

Look more closely at what I posted above for the prototype, and look at how _you're_ passing the parameters.

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #11 on: April 20, 2015, 06:13:28 PM »
I guess I don't get what is obvious to you.  :-\

I thought what you meant was ALL struct mb_interpreter_t* bas = 0; needed to initialized NULL (zero). It still gives the same error so I'm lost.

Code: C
  1. // MY-BASIC - Script BASIC extension module
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <stdarg.h>
  7. #include <ctype.h>
  8. #include <math.h>
  9. #include <time.h>
  10. #include "../../basext.h"
  11. #include "cbasic.h"
  12.  
  13. #include "my_basic.h"
  14.  
  15.  
  16. /****************************
  17.  Extension Module Functions
  18. ****************************/
  19.  
  20. besVERSION_NEGOTIATE
  21.   RETURN_FUNCTION((int)INTERFACE_VERSION);
  22. besEND
  23.  
  24. besSUB_START
  25.   DIM AS long PTR p;
  26.   besMODULEPOINTER = besALLOC(sizeof(long));
  27.   IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  28.   p = (long PTR)besMODULEPOINTER;
  29.   RETURN_FUNCTION(0);
  30. besEND
  31.  
  32. besSUB_FINISH
  33.   DIM AS long PTR p;
  34.   p = (long PTR)besMODULEPOINTER;
  35.   IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  36.   RETURN_FUNCTION(0);
  37. besEND
  38.  
  39.  
  40. /********************
  41.  MY-BASIC Functions
  42. ********************/
  43.  
  44. besFUNCTION(mbas_init)
  45.   DIM AS int rtnval;
  46.   rtnval = mb_init();
  47.   besRETURN_LONG(rtnval);
  48. besEND
  49.  
  50. besFUNCTION(mbas_dispose)
  51.   DIM AS int rtnval;
  52.   rtnval = mb_dispose();
  53.   besRETURN_LONG(rtnval);
  54. besEND
  55.  
  56. besFUNCTION(mbas_open)
  57.   DIM AS struct mb_interpreter_t* bas = 0;
  58.   DIM AS int rtnval;
  59.   rtnval = mb_open(AT bas);
  60.   besRETURN_LONG(rtnval);
  61. besEND
  62.  
  63. besFUNCTION(mbas_close)
  64.   DIM AS struct mb_interpreter_t* bas = 0;
  65.   DIM AS int rtnval;
  66.   rtnval = mb_close(AT bas);
  67.   besRETURN_LONG(rtnval);
  68. besEND
  69.  
  70. besFUNCTION(mbas_load_str)
  71.   DIM AS struct mb_interpreter_t* bas = 0;
  72.   DIM AS const char PTR pgm;
  73.   DIM AS int rtnval;  
  74.   besARGUMENTS("z")
  75.     AT pgm
  76.   besARGEND
  77.   rtnval = mb_load_string(AT bas, pgm);
  78.   besRETURN_LONG(rtnval);
  79. besEND
  80.  
  81. besFUNCTION(mbas_run)
  82.   DIM AS struct mb_interpreter_t* bas = 0;
  83.   DIM AS int rtnval;
  84.   rtnval = mb_run(AT bas);
  85.   besRETURN_LONG(rtnval);
  86. besEND
  87.  

Since this works, I'm assuming the AT bas is correct.

Code: C
  1. besFUNCTION(mbas_open)
  2.   DIM AS struct mb_interpreter_t* bas = 0;
  3.   DIM AS int rtnval;
  4.   rtnval = mb_open(AT bas);
  5.   besRETURN_LONG(rtnval);
  6. besEND
  7.  

Can you give a clue I might understand?
« Last Edit: April 20, 2015, 06:20:17 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #12 on: April 20, 2015, 06:29:46 PM »
I was wrong. Just don't use line numbers. (Paul Dunn  :P )

Code: [Select]
jrs@laptop:~/mybasic/my_basic-master$ ./mybasic
MY-BASIC Interpreter Shell - 1.0.0050.
Copyright (C) 2011 - 2015 W. Renxin. All Rights Reserved.
For more information, see https://github.com/paladin-t/my_basic/.
Input HELP and hint enter to view help information.
]PRINT "HellO"
]RUN
HellO
]

Offline AIR

  • BASIC Developer
  • Posts: 685
Re: MY-BASIC
« Reply #13 on: April 20, 2015, 06:31:33 PM »
Again, look at the function DECLARATION. Ask yourself what "mb_interpreter_t* s" is.

Then compare it to what you are passing to the function. It's not what the function requires.

That is what the assert is trying to tell you.

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #14 on: April 20, 2015, 06:48:15 PM »
Here are the command lines I'm using to compile the module.

gcc -O2 -w -m64 -fPIC -c my_basic.c -lm -o my_basic.o
gcc -O2 -w -m64 -fPIC -c interface.c -lm -o interface.o
ld -shared -fPIC interface.o my_basic.o -lm -o mb.so



This is the example I used from the MY-BASIC docs. (PDF)

Code: C
  1. struct mb_interpreter_t* bas = 0;
  2. mb_open(&bas);
  3.  

The mb_open() function works in my code so I must be handling call correctly. IMHO

I'm totally clueless about the point you're trying to make.

« Last Edit: April 20, 2015, 07:02:37 PM by John »