Pointer to an array of wzString pointers

Started by Pierre Bellisle, June 06, 2023, 06:07:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

#15
Why i asking is just simple message as error message
from interpreter to code editor.

Like :

Error -Varible Not Forund [var] - line- 100

then if is want to parse this text that is on code editor side.
  •  

Theo Gottwald

Quote from: Pierre Bellisle on June 09, 2023, 07:35:40 AMBecause I show a way when you don't want parsing. 
If you do, you use previous code. (-:~

I never understand your coding. Its even worse then code from Jose :-).

Today I asked ChatGPT and i understand the code from ChatGPT.

FUNCTION CalculateInformationValue(BYVAL c AS DWORD) AS LONG
  LOCAL R, G, B AS BYTE
  LOCAL fR, fG, fB AS SINGLE
  LOCAL gray AS SINGLE

  ; Extract R, G, B values from color
  R = (c SHR 16) AND &HFF
  G = (c SHR 8) AND &HFF
  B = c AND &HFF

  fR = R : fG = G : fB = B

  ASM
    ; load constants into floating point registers
    FLD DWORD PTR [fR]
    FMUL DWORD PTR [0.2989]
    FLD DWORD PTR [fG]
    FMUL DWORD PTR [0.5870]
    FADD ST(1), ST(0) ; Add
    FLD DWORD PTR [fB]
    FMUL DWORD PTR [0.1140]
    FADD ST(1), ST(0) ; Add

    ; store result and empty FPU stack
    FSTP DWORD PTR [gray]
  END ASM

  FUNCTION = gray
END FUNCTION

Charles Pegge

I was toying with the idea of combining parser functionality with pointer tables. The following code uses character offsets instead of a pointer, and takes the top byte to encode the character count of each word. The lower 3 bytes are used for the offset, allowing strings of up to 16Meg (4 bibles) to be referenced. By using word length it is no longer necessary to patch null terminators into the string. Furthermore self-terminating symbols like ( ) @ & can be properly parsed.

This is configured for ANSI strings:
'string mapping
'
'uses corewin
uses console
'
'USING LOWER 3 BYTES TO STORE WORD INDEX
'USING THE TOP BYTE TO STORE WORD LENGTH
'MUST STORE .DX FIRST
'THEN OVERLAY .LEN
'
type MapLen
===========
int idx
= 'UNION WITH
byte a,b,c,len
end type
'
procedure MapStrLenWord(sys ps,pm,int *ct)
==========================================
'WORD MAPPING FOR ANSI
'ps source string pointer
'pm map array of pointers
'ct word count
'
if ps=0 or pm=0
  exit procedure
endif
'
byte   *s = ps         'pointer to string bytes
MapLen *m = pm         'string indexes
int    iw = 0          'in-word flag
int    st = sizeof MapLen 'index stride
ct=0
'
subroutine LogIndex
  if iw=0
    ct++
    m.idx=@s-ps
    iw=1
  endif
end subroutine
'
subroutine LogLen
  if iw=1
    m.len=@s-ps-m.idx
    @m+=st 'PTR NEXT WORD
    iw=0
  endif
end subroutine
'
macro LogSymbol
  if iw=0
    gosub LogIndex
    @s++
    gosub loglen
    continue do
  endif
  gosub LogLen
  continue do
end macro
'
begin:
'
do
  select s
  case 0
    gosub LogLen
    exit do
  case 1 to 32
    gosub LogLen
    iw=0 'READY FOR NEXT WORD
  case 34
    'SKIP QUOTE
    gosub LogIndex
    do
      @s++
      if s=0
        @s--
        exit do
      endif
      if s=34
        exit do
      endif
    loop
  case 35,46,95   ' #._
    gosub logindex
  case 33  to 47, ' !$%&'()*+,-/
       58  to 64, ' :;<=>?@
       91  to 96, ' [\]^`
       123 to 126 '{|}~
    LogSymbol()
  case 48 to 255
    gosub LogIndex
  end select
  @s++
loop
end procedure
'
'
'TEST
'====
string s=` one+7, two (three) "four x" five `
sys     ps=strptr s
'sys ps=GetCommandLine
char*ch=ps
print ch cr
int     ee 'word count
MapLen  m[0x400]
MapStrLenWord ps, @m, ee
'
indexbase 1
print cr cr ee " words" cr cr
int i
for i=1 to ee
  char *ch=m[i].idx and 0xffffff 'lower 3 bytes
  int le=m[i].len
  @ch+=ps 'add string pointer
  print i tab left(ch,le) cr
next
print cr "ok" cr
wait

Nicola

Hi Charles,
I tried your program and it gives me this error:

Cheers

Charles Pegge

#19
It works for me. Have you got the complete source script?  Are you using an old version of o2 that does not recognize 'procedure'.

Nicola

are 121 lines of program and I use the version that I attach.
Cheers

Charles Pegge

Yes, you are still running 050. Replace it with 070 :)

Nicola

#22
Ok, he was going to get the dll of the P50 of another dir.
I had to delete it   ;D

Charles Pegge

In 070, I fixed some deep-seated errors which exposed themselves in 64bit self-compiling, including a few of my OpenGl pieces.

Nicola


Hi Charles,
I saw that in this program you use PROCEDURE and in this are inserted various SUBs and MACROs.
I wanted to ask you if PROCEDURE is like a module? And, the SUBs and MACROs contained in it can also be called from the outside in an autonomous way or not?

Charles Pegge

procedure is just a more formal name for sub, but I think it reads better on larger scripts.

Theo Gottwald

But then you should provide an Editor with autocompletion, else its a lot to type.

Charles Pegge

I've never used autocompletion. As I see it, most code is derived from existing pieces of code, and the major task of programming is finding the right scripts, which is a higher level operation.