Author Topic: MY-BASIC  (Read 108519 times)

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #45 on: April 22, 2015, 07:29:14 PM »
Script BASIC has a debugging mode (internal preprocessor) that Dave (SB VB/COM contributor) took advantage of in the IDE/Debugger he wrote.

Interesting, that's considerable.

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #46 on: April 23, 2015, 07:58:50 AM »
@John
I wrote some debug APIs, you can retrieve and set variable value with identifier now:
https://github.com/paladin-t/my_basic/wiki/Write-a-debugger

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #47 on: April 23, 2015, 08:20:06 AM »
Looks like you're on the road to a great debugger for MY-BASIC. I think it would be easier to follow along if you can create a C program like AIR did initially to help me get your BASIC going. I can try your new code in SB as an extension module as it unfolds.

Markus (admin / CM on BP.org) is interested in embedding your BASIC in his Pascal based interpreter. Maybe you can get him to join us here.


Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #48 on: April 23, 2015, 12:19:03 PM »
Hi Tony,

I took a shot at getting the mb_debug_get functions working with Script BASIC. It works GREAT!

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. static struct mb_interpreter_t* bas = 0;
  45.  
  46. static int watch(struct mb_interpreter_t* s, void** l) {
  47.   int result = MB_FUNC_OK;
  48.   int_t arg = 0;
  49.   mb_assert(s && l);
  50.   mb_check(mb_attempt_open_bracket(s, l));
  51.   mb_check(mb_pop_int(s, l, &arg)); // That's it!
  52.   mb_check(mb_attempt_close_bracket(s, l));
  53.   // arg is what you want.
  54.   return result;
  55. }
  56.  
  57. besFUNCTION(mbas_init)
  58.   besRETURN_LONG(mb_init());
  59. besEND
  60.  
  61. besFUNCTION(mbas_dispose)
  62.   besRETURN_LONG(mb_dispose());
  63. besEND
  64.  
  65. besFUNCTION(mbas_open)
  66.   besRETURN_LONG(mb_open(AT bas));
  67. besEND
  68.  
  69. besFUNCTION(mbas_close)
  70.   besRETURN_LONG(mb_close(AT bas));
  71. besEND
  72.  
  73. besFUNCTION(mbas_load_str)
  74.   DIM AS const char PTR pgm;
  75.   besARGUMENTS("z")
  76.     AT pgm
  77.   besARGEND
  78.   besRETURN_LONG(mb_load_string(bas, pgm));
  79. besEND
  80.  
  81. besFUNCTION(mbas_load_file)
  82.   DIM AS const char PTR pgm;
  83.   besARGUMENTS("z")
  84.     AT pgm
  85.   besARGEND
  86.   besRETURN_LONG(mb_load_file(bas, pgm));
  87. besEND
  88.  
  89. besFUNCTION(mbas_run)
  90.   besRETURN_LONG(mb_run(bas));
  91. besEND
  92.  
  93. besFUNCTION(mbas_reset)
  94.   besRETURN_LONG(mb_reset(bas, false));
  95. besEND
  96.  
  97. besFUNCTION(mbas_getint)
  98.   DIM AS mb_value_t mbval;
  99.   DIM AS const char PTR varname;
  100.   besARGUMENTS("z")
  101.     AT varname
  102.   besARGEND
  103.   mbval.type = MB_DT_INT;
  104.   mb_debug_get(bas, varname, &mbval);
  105.   besRETURN_LONG(mbval.value.integer);
  106. besEND
  107.  
  108. besFUNCTION(mbas_getdbl)
  109.   DIM AS mb_value_t mbval;
  110.   DIM AS const char PTR varname;
  111.   besARGUMENTS("z")
  112.     AT varname
  113.   besARGEND
  114.   mbval.type = MB_DT_REAL;
  115.   mb_debug_get(bas, varname, &mbval);
  116.   besRETURN_DOUBLE(mbval.value.float_point);
  117. besEND
  118.  
  119. besFUNCTION(mbas_getstr)
  120.   DIM AS mb_value_t mbval;
  121.   DIM AS const char PTR varname;
  122.   besARGUMENTS("z")
  123.     AT varname
  124.   besARGEND
  125.   mbval.type = MB_DT_STRING;
  126.   mb_debug_get(bas, varname, &mbval);
  127.   besRETURN_STRING(mbval.value.string);
  128. besEND
  129.  

mbvars.sb
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_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_reset ALIAS "mbas_reset" LIB "mb"
  12.  
  13. mb_init()
  14. mb_open()
  15. mb_load_file("testvars.bas")
  16. mb_run()
  17. PRINT mb_getint("A"),"\n"
  18. PRINT FORMAT("%g\n",mb_getdbl("B"))
  19. PRINT mb_getstr("C$"),"\n"
  20. mb_close()
  21. mb_dispose()
  22.  

testvars.bas (MY-BASIC test script)
Code: [Select]
a = 123
b = 1.23
c$ = "One,Two,Three"

Output

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

real   0m0.007s
user   0m0.000s
sys   0m0.005s
jrs@laptop:~/sb/sb22/mybasic$

« Last Edit: April 23, 2015, 04:29:28 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #49 on: April 23, 2015, 01:57:43 PM »
I'm not having as good of luck with the mb_debug_set. (core dump)

Code: C
  1. besFUNCTION(mbas_setint)
  2.   DIM AS mb_value_t mbval;
  3.   DIM AS int usrval;
  4.   DIM AS const char PTR varname;
  5.   besARGUMENTS("zi")
  6.     AT varname, AT usrval
  7.   besARGEND
  8.   mbval.type = MB_DT_INT;
  9.   mbval.value.integer = usrval;
  10.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  11. besEND
  12.  
  13. besFUNCTION(mbas_setdbl)
  14.   DIM AS mb_value_t mbval;
  15.   DIM AS double usrval;
  16.   DIM AS const char PTR varname;
  17.   besARGUMENTS("zr")
  18.     AT varname, AT usrval
  19.   besARGEND
  20.   mbval.type = MB_DT_REAL;
  21.   mbval.value.float_point = usrval;
  22.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  23. besEND
  24.  
  25. besFUNCTION(mbas_setstr)
  26.   DIM AS mb_value_t mbval;
  27.   DIM AS const char PTR usrval;
  28.   DIM AS const char PTR varname;
  29.   besARGUMENTS("zz")
  30.     AT varname, AT usrval
  31.   besARGEND
  32.   mbval.type = MB_DT_STRING;
  33.   mbval.value.string = usrval;
  34.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  35. besEND
  36.  

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_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. mb_run()
  24. mb_close()
  25. mb_dispose()
  26.  

setvars.bas
Code: [Select]
PRINT a;
PRINT b;
PRINT c$;


jrs@laptop:~/sb/sb22/mybasic$ scriba mbvars.sb
0
0
(empty)
scriba: my_basic.c:3977: mb_debug_set: Assertion `s && n' failed.
Aborted (core dumped)
jrs@laptop:~/sb/sb22/mybasic$


At this point I don't plan to add any of the debugging (single step) features to the SB MY-BASIC extension module version.

Can you show us some examples of your IF enhancements with this release?
« Last Edit: April 23, 2015, 03:09:23 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #50 on: April 23, 2015, 06:38:49 PM »
Tony,

I just noticed your profile on Github.



Wang Renxin

Chengdu City, China

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #51 on: April 23, 2015, 10:37:43 PM »
I was able to compile the Script BASIC MY-BASIC extension module for Windows 32 bit. I have attached the DLL and this example in a zip.

mbvars.sb
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_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_reset ALIAS "mbas_reset" LIB "mb"
  12.  
  13. mb_init()
  14. mb_open()
  15. mb_load_file("testvars.bas")
  16. mb_run()
  17. PRINT mb_getint("A"),"\n"
  18. PRINT FORMAT("%g\n",mb_getdbl("B"))
  19. PRINT mb_getstr("C$"),"\n"
  20. mb_close()
  21. mb_dispose()
  22.  

testvars.bas
Code: [Select]
a = 123
b = 1.23
c$ = "One,Two,Three"

Output

C:\scriptbasic32\mybasic>scriba mbvars.sb
123
1.23
One,Two,Three

C:\scriptbasic32\mybasic>


wangrenxin

  • Guest
Re: MY-BASIC
« Reply #52 on: April 23, 2015, 11:13:42 PM »
I just noticed your profile on Github.

Haw haw, you found me :)

I polished my_basic.c, or it will trigger an assertion when you write sequenced mb_run.

The set function works fine for me, eg. code:
Code: Text
  1. PRINT A;
  2.  

Code: C
  1. mb_value_t val;
  2. val.type = MB_DT_INT;
  3. val.value.integer = 12345;
  4. mb_run(bas);
  5. mb_debug_set(bas, "A", val);
  6. mb_run(bas);
  7.  

I guess there maybe something wrong in besFUNCTION(mbas_setXXX)

An eg. for enhanced multi line IF:
Code: Text
  1. INPUT n
  2. IF n = 1 THEN
  3.         PRINT "Uno"
  4. ELSEIF n = 2 THEN
  5.         PRINT "Dos"
  6. ELSEIF n = 3 THEN
  7.         PRINT "Thres"
  8. ELSE
  9.         PRINT "Many"
  10. ENDIF
  11.  

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #53 on: April 23, 2015, 11:16:20 PM »
Tony,

I'm getting a little farther with the Windows 32 bit version of mb.dll.

Do I need to download another version since you added the debug functions?

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_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. PRINT "Got Here\n"
  22. mb_setdbl("B", 1.23)
  23. mb_setstr("C$", "One,Two,Three")
  24. mb_close()
  25. mb_dispose()
  26.  

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


C:\sb22\mybasic>scriba mbvarset.sb
Got Here
Assertion failed!

Program: c:\scriptbasic\bin\scriba.exe
File: my_basic.c, Line 3889

Expression: 0 && "Memory already released"

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

C:\sb22\mybasic>

« Last Edit: April 23, 2015, 11:22:59 PM by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #54 on: April 23, 2015, 11:25:50 PM »
Use mb_memdup when setting a string like:
Code: C
  1. const char* str = "One,Two,Three";
  2. mb_setstr("C$", mb_memdup(str, strlen(str) + 1);
  3.  

Or it will trigger the assertion.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #55 on: April 23, 2015, 11:33:06 PM »
I'm able to set integers and real/double/float but it fails on the string. I'll try your suggestion.

That still doesn't solve the Linux 64 bit version failing on all mb_set operations.  :-[

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #56 on: April 23, 2015, 11:48:41 PM »
That still doesn't solve the Linux 64 bit version failing on all mb_set operations.  :-[

It runs ok in 64 bit mode with Win/VS, I don't have a Linux environment on hand now. Could you post your full code again?

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #57 on: April 23, 2015, 11:57:29 PM »
This code sets integer and double on Windows 32 but fails on Linux 64 bit.

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. static struct mb_interpreter_t* bas = 0;
  45.  
  46. static int watch(struct mb_interpreter_t* s, void** l) {
  47.   int result = MB_FUNC_OK;
  48.   int_t arg = 0;
  49.   mb_assert(s && l);
  50.   mb_check(mb_attempt_open_bracket(s, l));
  51.   mb_check(mb_pop_int(s, l, &arg)); // That's it!
  52.   mb_check(mb_attempt_close_bracket(s, l));
  53.   // arg is what you want.
  54.   return result;
  55. }
  56.  
  57. besFUNCTION(mbas_init)
  58.   besRETURN_LONG(mb_init());
  59. besEND
  60.  
  61. besFUNCTION(mbas_dispose)
  62.   besRETURN_LONG(mb_dispose());
  63. besEND
  64.  
  65. besFUNCTION(mbas_open)
  66.   besRETURN_LONG(mb_open(AT bas));
  67. besEND
  68.  
  69. besFUNCTION(mbas_close)
  70.   besRETURN_LONG(mb_close(AT bas));
  71. besEND
  72.  
  73. besFUNCTION(mbas_load_str)
  74.   DIM AS const char PTR pgm;
  75.   besARGUMENTS("z")
  76.     AT pgm
  77.   besARGEND
  78.   besRETURN_LONG(mb_load_string(bas, pgm));
  79. besEND
  80.  
  81. besFUNCTION(mbas_load_file)
  82.   DIM AS const char PTR pgm;
  83.   besARGUMENTS("z")
  84.     AT pgm
  85.   besARGEND
  86.   besRETURN_LONG(mb_load_file(bas, pgm));
  87. besEND
  88.  
  89. besFUNCTION(mbas_run)
  90.   besRETURN_LONG(mb_run(bas));
  91. besEND
  92.  
  93. besFUNCTION(mbas_reset)
  94.   besRETURN_LONG(mb_reset(bas, false));
  95. besEND
  96.  
  97. besFUNCTION(mbas_getint)
  98.   DIM AS mb_value_t mbval;
  99.   DIM AS const char PTR varname;
  100.   besARGUMENTS("z")
  101.     AT varname
  102.   besARGEND
  103.   mbval.type = MB_DT_INT;
  104.   mb_debug_get(bas, varname, &mbval);
  105.   besRETURN_LONG(mbval.value.integer);
  106. besEND
  107.  
  108. besFUNCTION(mbas_getdbl)
  109.   DIM AS mb_value_t mbval;
  110.   DIM AS const char PTR varname;
  111.   besARGUMENTS("z")
  112.     AT varname
  113.   besARGEND
  114.   mbval.type = MB_DT_REAL;
  115.   mb_debug_get(bas, varname, &mbval);
  116.   besRETURN_DOUBLE(mbval.value.float_point);
  117. besEND
  118.  
  119. besFUNCTION(mbas_getstr)
  120.   DIM AS mb_value_t mbval;
  121.   DIM AS const char PTR varname;
  122.   besARGUMENTS("z")
  123.     AT varname
  124.   besARGEND
  125.   mbval.type = MB_DT_STRING;
  126.   mb_debug_get(bas, varname, &mbval);
  127.   besRETURN_STRING(mbval.value.string);
  128. besEND
  129.  
  130. besFUNCTION(mbas_setint)
  131.   DIM AS mb_value_t mbval;
  132.   DIM AS int usrval;
  133.   DIM AS const char PTR varname;
  134.   besARGUMENTS("zi")
  135.     AT varname, AT usrval
  136.   besARGEND
  137.   mbval.type = MB_DT_INT;
  138.   mbval.value.integer = usrval;
  139.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  140. besEND
  141.  
  142. besFUNCTION(mbas_setdbl)
  143.   DIM AS mb_value_t mbval;
  144.   DIM AS double usrval;
  145.   DIM AS const char PTR varname;
  146.   besARGUMENTS("zr")
  147.     AT varname, AT usrval
  148.   besARGEND
  149.   mbval.type = MB_DT_REAL;
  150.   mbval.value.float_point = usrval;
  151.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  152. besEND
  153.  
  154. besFUNCTION(mbas_setstr)
  155.   DIM AS mb_value_t mbval;
  156.   DIM AS const char PTR usrval;
  157.   DIM AS const char PTR varname;
  158.   besARGUMENTS("zz")
  159.     AT varname, AT usrval
  160.   besARGEND
  161.   mbval.type = MB_DT_STRING;
  162.   mbval.value.string = usrval;
  163.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  164. besEND
  165.  

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_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. PRINT "Got Here\n"
  23. mb_close()
  24. mb_dispose()
  25.  

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


jrs@laptop:~/sb/sb22/mybasic$ scriba mbvars.sb
scriba: my_basic.c:3977: mb_debug_set: Assertion `s && n' failed.
Aborted (core dumped)
jrs@laptop:~/sb/sb22/mybasic$


I'm recompiling the Windows 32 bit version with your string function change. I will report my finding shortly.
« Last Edit: April 24, 2015, 12:03:48 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #58 on: April 24, 2015, 12:22:37 AM »
No luck with your change to fix the Windows mb_setstr() function. Here is my change to the function per your suggestion.

Code: C
  1. besFUNCTION(mbas_setstr)
  2.   DIM AS mb_value_t mbval;
  3.   DIM AS const char PTR usrval;
  4.   DIM AS const char PTR varname;
  5.   besARGUMENTS("zz")
  6.     AT varname, AT usrval
  7.   besARGEND
  8.   mbval.type = MB_DT_STRING;
  9.   usrval = mb_memdup(usrval, strlen(usrval) + 1);
  10.   mbval.value.string = usrval;
  11.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  12. besEND
  13.  


C:\sb22\mybasic>scriba mbvarset.sb
Got Here
Assertion failed: 0 && "Memory already released", file my_basic.c, line 3889

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

C:\sb22\mybasic>


wangrenxin

  • Guest
Re: MY-BASIC
« Reply #59 on: April 24, 2015, 12:27:29 AM »
Try add a debugging printf. Neither bas nor varname shouldn't be NULL under 64 bit.
Code: C
  1. besFUNCTION(mbas_setint)
  2.   DIM AS mb_value_t mbval;
  3.   DIM AS int usrval;
  4.   DIM AS const char PTR varname;
  5.   besARGUMENTS("zi")
  6.     AT varname, AT usrval
  7.   besARGEND
  8.   mbval.type = MB_DT_INT;
  9.   mbval.value.integer = usrval;
  10.   printf("0x%08x, 0x%08x\n", bas, varname);
  11.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  12. besEND
  13.  
  14. besFUNCTION(mbas_setdbl)
  15.   DIM AS mb_value_t mbval;
  16.   DIM AS double usrval;
  17.   DIM AS const char PTR varname;
  18.   besARGUMENTS("zr")
  19.     AT varname, AT usrval
  20.   besARGEND
  21.   mbval.type = MB_DT_REAL;
  22.   mbval.value.float_point = usrval;
  23.   printf("0x%08x, 0x%08x\n", bas, varname);
  24.   besRETURN_LONG(mb_debug_set(bas, varname, mbval));
  25. besEND
  26.