Author Topic: DLLC  (Read 28672 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: DLLC
« Reply #15 on: November 01, 2014, 04:09:52 PM »
A hello world for the SB O2 connection via DLLC.



Code: Script BASIC
  1. ' SBO2 Hello World
  2.  
  3. INCLUDE "DLLCO2.sb"
  4.  
  5. oxygen "PRINT \"Hello World!\""
  6. dllfile
  7.  

JRS

  • Guest
Re: DLLC
« Reply #16 on: November 02, 2014, 11:27:46 AM »
I was thinking that encapsulating O2 JIT functions in SB MODULE/END MODULE name spaces as a need for speed library could be cool.


JRS

  • Guest
Re: DLLC
« Reply #17 on: November 02, 2014, 07:28:15 PM »
I started the new O2 extension module encapsulating Charles's string reverse function in assembly. (JIT function)

Code: Script BASIC
  1. IMPORT O2.inc
  2.  
  3. FOR x = 65 TO 90
  4.   alpha &= CHR(x)
  5. NEXT
  6. PRINT alpha,"\n"
  7. PRINT O2::RevStr(alpha),"\n"
  8.  
  9. O2::Done()
  10.  

Output

C:\scriptbasic\o2dev>scriba testrev.sb
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZYXWVUTSRQPONMLKJIHGFEDCBA

C:\scriptbasic\o2dev>


This is the O2.inc file. I still need to tidy it up but it's a foundation to add more OxygenBasic functions to the library.

Code: Script BASIC
  1. MODULE O2
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy=dllfile("/scriptbasic/Debugger/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall o2_mode,1
  15.  
  16. function oxygen(src)
  17. dllcall o2_basic,src
  18. if (dllcall(o2_errno)<>0) then
  19.   dllprnt dllcall(o2_error)
  20.   a=0
  21.   line input q
  22. else
  23.   a=dllcall(o2_exec,0)
  24. end if
  25. oxygen=a
  26. end function
  27.  
  28. src = """
  29.  extern
  30.  
  31.  function reverse(char*s)
  32.  ========================
  33.  addr ecx,s
  34.  mov edx,0
  35. .rlen
  36.  mov al,[ecx]
  37.  cmp al,0
  38.  jz xlen
  39.  inc edx
  40.  inc ecx
  41.  jmp rlen
  42. .xlen
  43.  ;
  44.  addr ecx,s
  45.  add  edx,ecx
  46.  dec ecx
  47.  ;
  48. .rswap
  49.  inc ecx
  50.  dec edx
  51.  cmp edx,ecx
  52.  jle xswap
  53.  mov al,[ecx]
  54.  mov ah,[edx]
  55.  mov [ecx],ah
  56.  mov [edx],al
  57.  jmp rswap
  58. .xswap
  59.  end function
  60.  
  61.  sub finish()
  62.  terminate
  63.  end sub
  64.  
  65.  function link(sys n) as sys
  66.  select n
  67.  case 0 : return @finish
  68.  case 1 : return @reverse
  69.  end select
  70.  end function
  71.  
  72.  end extern
  73.  
  74.  
  75.  addr link
  76. """
  77.  
  78.   a = oxygen(src)
  79.   Finish  = dllproc(a,"Finish     ()        ", dllcald(a,0) )
  80.   Reverse = dllproc(a,"Reverse    (c*value) ", dllcald(a,1) )
  81.  
  82. FUNCTION RevStr(strarg)
  83.   dllcall(Reverse, strarg)
  84.   RevStr = strarg
  85. END FUNCTION    
  86.  
  87. FUNCTION Done
  88.   rtnval = dllcall(Finish)
  89.   dllfile
  90.   Done = rtnval
  91. END FUNCTION    
  92.  
  93. END MODULE
  94.  
« Last Edit: November 02, 2014, 09:16:55 PM by John »

JRS

  • Guest
Re: DLLC
« Reply #18 on: November 02, 2014, 11:12:11 PM »
How the OxygenBasic project is doing.

.

JRS

  • Guest
Re: DLLC
« Reply #19 on: November 03, 2014, 01:06:06 PM »
Charles,

I thought I would add your Word parser for Basic - (getword) function for the SB O2.inc library. I'm getting an exception error calling the O2 getword function and don't know why.

Code: Script BASIC
  1. IMPORT O2.inc
  2.  
  3. FOR x = 65 TO 90
  4.   alpha &= CHR(x)
  5. NEXT
  6. PRINT alpha,"\n"
  7. PRINT O2::RevStr(alpha),"\n"
  8.  
  9. Next_Word:
  10.   wd = O2::GetWords("abc(d[xx]+7/6,`qwerty`)", 1)
  11. PRINT "Got Here\n"
  12.  
  13.   IF NOT wd=undef THEN
  14.     PRINT wd,"\n"
  15.     GOTO Next_Word
  16.   END IF
  17.  
  18. O2::Done()
  19.  

O2.inc
Code: Script BASIC
  1. MODULE O2
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy=dllfile("/scriptbasic/Debugger/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall o2_mode,1
  15.  
  16. src = """
  17.  extern
  18.  
  19. function reverse(char*s)
  20. '=======================
  21.  addr ecx,s
  22.  mov edx,0
  23. .rlen
  24.  mov al,[ecx]
  25.  cmp al,0
  26.  jz xlen
  27.  inc edx
  28.  inc ecx
  29.  jmp rlen
  30. .xlen
  31.  ;
  32.  addr ecx,s
  33.  add  edx,ecx
  34.  dec ecx
  35.  ;
  36. .rswap
  37.  inc ecx
  38.  dec edx
  39.  cmp edx,ecx
  40.  jle xswap
  41.  mov al,[ecx]
  42.  mov ah,[edx]
  43.  mov [ecx],ah
  44.  mov [edx],al
  45.  jmp rswap
  46. .xswap
  47.  end function
  48.  
  49. function getword(char*ss,sys*b) as char*
  50. '=======================================
  51. if b=0 then b=1
  52. byte s at @ss
  53. byte c,d
  54. sys bb,bc
  55. static char z[128]
  56. a=0
  57. bb=b
  58.  
  59. 'SKIP LEADING SPACES
  60. do
  61.  c=s[b]
  62.  select c
  63.   case 33 to 255,0 : exit do 'SKIP SPACE
  64.  end select
  65.  b++
  66. end do
  67. bc=b
  68. '
  69. 'QUOTES
  70. select c
  71. case 34,39
  72.   do
  73.     b+=1
  74.     d=s[b]
  75.     if d=0 or d=c then b+=1 : jmp fwd done
  76.   end do
  77. end select
  78. 'WORDS AND SYMBOLS
  79. do
  80.  c=s[b]
  81.  select c
  82.  case 0 to 32    : exit do
  83.  case 35         : jmp fwd more
  84.  case 33 to 47   : 'symbols
  85.  case 48 to 57   : jmp fwd more 'numbers
  86.  case 58 to 64   : 'symbols
  87.  case 65 to 90   : jmp fwd more 'capitals
  88.  case 95         : jmp fwd more 'underscore
  89.  case 91 to 96   : 'symbols
  90.  case 97 to 122  : jmp fwd more 'lower case
  91.  case 123 to 127 : 'symbols
  92.  case 128 to 255 : jmp fwd more 'higher ascii
  93. end select
  94.  
  95. if b=bc then b++
  96.  exit do
  97.  
  98.  more:
  99.  b++
  100. end do
  101.  
  102. done:
  103.  
  104. if b > bb then
  105.  z=mid ss,bc,b-bc
  106. else
  107.  z = ""
  108. end if
  109. return z
  110.  
  111. end function
  112.  
  113. sub finish()
  114. '===========
  115.  terminate
  116. end sub
  117.  
  118. function link(sys n) as sys
  119. '==========================
  120.  select n
  121.  case 0 : return @finish
  122.  case 1 : return @reverse
  123.  case 2 : return @getword
  124.  end select
  125. end function
  126.  
  127. end extern
  128.  
  129. addr link
  130. """
  131.  
  132. a = oxygen(src)
  133. Finish  = dllproc(a,"Finish ()", dllcald(a,0))
  134. Reverse = dllproc(a,"Reverse (c*value)", dllcald(a,1))
  135. Words   = dllproc(a,"getword c* = (c* strraw, i* start)", dllcald(a,2))
  136.  
  137. FUNCTION oxygen(src)
  138.   dllcall o2_basic,src
  139.   IF (dllcall(o2_errno)<> 0) THEN
  140.     dllprnt dllcall(o2_error)
  141.     a = 0
  142.   ELSE
  143.     a = dllcall(o2_exec,0)
  144.   END IF
  145.   oxygen = a
  146. END FUNCTION
  147.  
  148. FUNCTION RevStr(strarg)
  149.   dllcall(Reverse, strarg)
  150.   RevStr = strarg
  151. END FUNCTION
  152.  
  153. FUNCTION GetWords(strarg, longarg)
  154.   GetWords = dllcall(Words, strarg, longarg)
  155. END FUNCTION
  156.  
  157. FUNCTION Done
  158.   rtnval = dllcall(Finish)
  159.   dllfile
  160.   Done = rtnval
  161. END FUNCTION
  162.  
  163. END MODULE
  164.  
« Last Edit: November 04, 2014, 02:14:45 AM by John »

Charles Pegge

  • Guest
Re: DLLC
« Reply #20 on: November 03, 2014, 01:25:12 PM »
Hi John,

String is a bstring, not a char*. Best to create Getword returning static char* words.

Code: OxygenBasic
  1.   function getword(char*s,sys*b) as char*
  2.   '======================================
  3.  'b=1
  4.  sys a,c,d,bb,bc
  5.   static char z[128]
  6.   a=0
  7.   bb=b
  8.   do
  9.     c=asc s,b
  10.     if c=0 then exit do
  11.     if c>32 then exit do
  12.     b+=1
  13.   end do
  14.   bc=b
  15.   if c=34 or c=96 then 'quotes
  16.   do
  17.       b+=1
  18.       d=asc s,b
  19.       if d=0 or d=c then b+=1 : jmp fwd done
  20.    end do
  21.   end if
  22.   do
  23.     c=asc s,b
  24.     select c
  25.     case 0 to 32 : exit do
  26.     case 33 to 47
  27.       if c=35 then jmp fwd more '#
  28.     if b=bc then b+=1
  29.       exit do
  30.     case 48 to 57 : jmp fwd more 'numbers
  31.   case 58 to 64
  32.       if b=bc then b+=1
  33.       exit do
  34.     case 65 to 90 : jmp fwd more 'capitals
  35.   case 91 to 96
  36.       if c=95 then jmp fwd more 'underscore
  37.     if b=bc then b+=1
  38.       exit do    
  39.     case 97 to 122 : jmp fwd more 'lower case
  40.   case 123 to 127
  41.       if b=bc then b+=1
  42.       exit do
  43.     end select
  44.     '
  45.   'higher ascii chars treated as part of word
  46.   '
  47.   more:
  48.     '
  49.   b+=1
  50.   end do
  51.   '
  52.  done:
  53.   '
  54.  if b>bb then
  55.     z=mid s,bb,b-bb
  56.   else
  57.     z=""
  58.   end if
  59.   return z
  60.  
  61.   end function
  62.  
« Last Edit: November 03, 2014, 01:45:06 PM by Charles Pegge »

JRS

  • Guest
Re: DLLC
« Reply #21 on: November 03, 2014, 01:49:28 PM »
Hi Charles and thanks for your help.

I replaced the getword function with your latest and it still exception errors.

Code: Script BASIC
  1. Words   = dllproc(a,"getword static c*=(c*strraw, i start)", dllcald(a,2) )
  2.  

I changed the DLLC function define and it doesn't exception error anymore but wd is returning undef. Should I define the second argument as a variable? Is this being updated with the start of the next find?
« Last Edit: November 03, 2014, 01:56:50 PM by John »

Charles Pegge

  • Guest
Re: DLLC
« Reply #22 on: November 03, 2014, 02:13:24 PM »
Yes, should be i*

starting value 1,  then updated by getword.
« Last Edit: November 03, 2014, 02:29:52 PM by Charles Pegge »

JRS

  • Guest
Re: DLLC
« Reply #23 on: November 03, 2014, 02:31:31 PM »
Got it working. Thanks for the help & code Charles! A very handy function to have in the extended SB toolbox.

Note: The O2.inc code includes Charles's improved getword() function.

Code: Script BASIC
  1. IMPORT O2.inc
  2.  
  3. FOR x = 65 TO 90
  4.   alpha &= CHR(x)
  5. NEXT
  6. PRINT alpha,"\n"
  7. PRINT O2::RevStr(alpha),"\n"
  8. p = 1
  9. Next_Word:
  10. wd = O2::GetWords("abc(d[xx]+7/6,`qwerty`)", p)
  11. IF wd <> "" THEN
  12.   PRINT wd,"\n"
  13.   GOTO Next_Word
  14. END IF
  15.  
  16. O2::Done()
  17.  

O2.inc
Code: Script BASIC
  1. MODULE O2
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy=dllfile("/scriptbasic/Debugger/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall o2_mode,1
  15.  
  16. src = """
  17.  extern
  18.  
  19. function reverse(char*s)
  20. '=======================
  21.  addr ecx,s
  22.  mov edx,0
  23. .rlen
  24.  mov al,[ecx]
  25.  cmp al,0
  26.  jz xlen
  27.  inc edx
  28.  inc ecx
  29.  jmp rlen
  30. .xlen
  31.  ;
  32.  addr ecx,s
  33.  add  edx,ecx
  34.  dec ecx
  35.  ;
  36. .rswap
  37.  inc ecx
  38.  dec edx
  39.  cmp edx,ecx
  40.  jle xswap
  41.  mov al,[ecx]
  42.  mov ah,[edx]
  43.  mov [ecx],ah
  44.  mov [edx],al
  45.  jmp rswap
  46. .xswap
  47.  end function
  48.  
  49. function getword(char*ss,sys*b) as char*
  50. '=======================================
  51. if b=0 then b=1
  52. byte s at @ss
  53. byte c,d
  54. sys bb,bc
  55. static char z[128]
  56. a=0
  57. bb=b
  58.  
  59. 'SKIP LEADING SPACES
  60. do
  61.  c=s[b]
  62.  select c
  63.   case 33 to 255,0 : exit do 'SKIP SPACE
  64.  end select
  65.  b++
  66. end do
  67. bc=b
  68. '
  69. 'QUOTES
  70. select c
  71. case 34,39
  72.   do
  73.     b+=1
  74.     d=s[b]
  75.     if d=0 or d=c then b+=1 : jmp fwd done
  76.   end do
  77. end select
  78. 'WORDS AND SYMBOLS
  79. do
  80.  c=s[b]
  81.  select c
  82.  case 0 to 32    : exit do
  83.  case 35         : jmp fwd more
  84.  case 33 to 47   : 'symbols
  85.  case 48 to 57   : jmp fwd more 'numbers
  86.  case 58 to 64   : 'symbols
  87.  case 65 to 90   : jmp fwd more 'capitals
  88.  case 95         : jmp fwd more 'underscore
  89.  case 91 to 96   : 'symbols
  90.  case 97 to 122  : jmp fwd more 'lower case
  91.  case 123 to 127 : 'symbols
  92.  case 128 to 255 : jmp fwd more 'higher ascii
  93. end select
  94.  
  95. if b=bc then b++
  96.  exit do
  97.  
  98.  more:
  99.  b++
  100. end do
  101.  
  102. done:
  103.  
  104. if b > bb then
  105.  z=mid ss,bc,b-bc
  106. else
  107.  z = ""
  108. end if
  109. return z
  110.  
  111. end function
  112.  
  113. sub finish()
  114. '===========
  115.  terminate
  116. end sub
  117.  
  118. function link(sys n) as sys
  119. '==========================
  120.  select n
  121.  case 0 : return @finish
  122.  case 1 : return @reverse
  123.  case 2 : return @getword
  124.  end select
  125. end function
  126.  
  127. end extern
  128.  
  129. addr link
  130. """
  131.  
  132. a = oxygen(src)
  133. Finish  = dllproc(a,"Finish ()", dllcald(a,0))
  134. Reverse = dllproc(a,"Reverse (c*value)", dllcald(a,1))
  135. Words   = dllproc(a,"getword c* = (c* strraw, i* start)", dllcald(a,2))
  136.  
  137. FUNCTION oxygen(src)
  138.   dllcall o2_basic,src
  139.   IF (dllcall(o2_errno)<> 0) THEN
  140.     dllprnt dllcall(o2_error)
  141.     a = 0
  142.   ELSE
  143.     a = dllcall(o2_exec,0)
  144.   END IF
  145.   oxygen = a
  146. END FUNCTION
  147.  
  148. FUNCTION RevStr(strarg)
  149.   dllcall(Reverse, strarg)
  150.   RevStr = strarg
  151. END FUNCTION
  152.  
  153. FUNCTION GetWords(strarg, longarg)
  154.   GetWords = dllcall(Words, strarg, longarg)
  155. END FUNCTION
  156.  
  157. FUNCTION Done
  158.   rtnval = dllcall(Finish)
  159.   dllfile
  160.   Done = rtnval
  161. END FUNCTION
  162.  
  163. END MODULE
  164.  

Output

C:\scriptbasic\o2dev>scriba testrev.sb
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZYXWVUTSRQPONMLKJIHGFEDCBA
abc
(
d
[
xx
]
+
7
/
6
,
`qwerty`
)

C:\scriptbasic\o2dev>

« Last Edit: November 03, 2014, 10:59:15 PM by John »

Charles Pegge

  • Guest
Re: DLLC
« Reply #24 on: November 03, 2014, 09:47:22 PM »
Very good, John.

I checked out c* return to ensure DLLC is casting this value correctly.

Improved version of GetWord:
Code: OxygenBasic
  1.   function getword(char*ss,sys*b) as char*
  2.   '=======================================
  3.  if b=0 then b=1
  4.   byte s at @ss
  5.   byte c,d
  6.   sys bb,bc
  7.   static char z[128]
  8.   a=0
  9.   bb=b
  10.   '
  11.  'SKIP LEADING SPACES
  12.  do
  13.     c=s[b]
  14.     select c
  15.     case 33 to 255,0 : exit do 'SKIP SPACE
  16.    end select
  17.     b++
  18.   end do
  19.   bc=b
  20.   '
  21.  'QUOTES
  22.  select c
  23.   case 34,39
  24.    do
  25.       b+=1
  26.       d=s[b]
  27.       if d=0 or d=c then b+=1 : jmp fwd done
  28.    end do
  29.   end select
  30.   'WORDS AND SYMBOLS
  31.  do
  32.     c=s[b]
  33.     select c
  34.     case 0 to 32    : exit do
  35.     case 35         : jmp fwd more
  36.     case 33 to 47   : 'symbols
  37.    case 48 to 57   : jmp fwd more 'numbers
  38.    case 58 to 64   : 'symbols
  39.    case 65 to 90   : jmp fwd more 'capitals
  40.    case 95         : jmp fwd more 'underscore
  41.    case 91 to 96   : 'symbols
  42.    case 97 to 122  : jmp fwd more 'lower case
  43.    case 123 to 127 : 'symbols
  44.    case 128 to 255 : jmp fwd more 'higher ascii
  45.    end select
  46.     '
  47.    '
  48.    if b=bc then b++
  49.     exit do
  50.     '
  51.    more:
  52.     b++
  53.   end do
  54.   '
  55.  done:
  56.   '
  57.  if b>bb then
  58.     z=mid ss,bc,b-bc
  59.   else
  60.     z=""
  61.   end if
  62.   return z
  63.  
  64.   end function
  65.  
« Last Edit: November 03, 2014, 09:58:16 PM by Charles Pegge »

JRS

  • Guest
Re: DLLC
« Reply #25 on: November 03, 2014, 10:09:44 PM »
Thanks Charles!

What are the improvements and can you post an example showing the improvements?

FYI The new getword() function works fine with the old example string.
« Last Edit: November 03, 2014, 10:17:36 PM by John »

Charles Pegge

  • Guest
Re: DLLC
« Reply #26 on: November 03, 2014, 10:32:38 PM »
Improvements: :)

Strip leading spaces,
tolerant of 0 index,
faster parsing with bytes,
cleaner layout of cases,
elimination of duplicated code.

JRS

  • Guest
Re: DLLC
« Reply #27 on: November 03, 2014, 10:35:29 PM »
Sweet!

On to my next must have O2 function.  :D

JRS

  • Guest
Re: DLLC
« Reply #28 on: November 03, 2014, 11:56:10 PM »
I think I found my next O2 function to steal.  ;)

Aligned Text

For this function I would like to show the bstr feature of DLLC so I can use additional O2 functions out of the box.

One of my goals with the O2 interface is fast array functions. Dave did a nice job of flushing out array handling in the SB IDE/Debugger. Building dynamic matrix structures quickly would lead to a more robust SDL interface in SB.

« Last Edit: November 04, 2014, 12:03:18 AM by John »

JRS

  • Guest
Re: DLLC
« Reply #29 on: November 04, 2014, 02:28:47 AM »
Charles,

I'm getting a missing END IF with the aligned text example in O2.

If you have time to get this working in SB with bstr support, I should be able to carry on from there.

It would also be nice if the user could select the delimiter to use. $ looks like a bunch of string variable references.

.