Author Topic: Compilation error  (Read 2952 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
Compilation error
« on: March 21, 2018, 12:40:05 PM »
i was trying to compile a simple program but encounter a compilation error

Code: [Select]
ASM error

unidentified operation (xor) for this type (extended)

at line 22



the problem code is
Code: [Select]

$ filename "Testc.exe"
use rtl64
use corewin

'=======================================================
FUNCTION BigXOR(BYVAL value1 AS STRING, BYVAL value2 AS STRING) AS STRING
  LOCAL valueans AS STRING
  LOCAL loopit , tempnum AS LONG
  Local    insXor as LONG

      tempnum = LEN(value1) - LEN(value2)
      IF tempnum < 0 THEN
          valueans = LEFT(value2, ABS(tempnum))
          value2 = MID(value2, ABS(tempnum) + 1)
      ELSEIF tempnum > 0 THEN
          valueans = LEFT(value1, ABS(tempnum))
          value1 = MID(value1, tempnum + 1)
      END IF

      FOR loopit = 1 TO LEN(value1)
          insXor = VAL("&H" + MID(value1, loopit, 1))   XOR   VAL("&H" + MID(value2, loopit, 1))
          valueans = valueans +   HEX(insXor)
      NEXT loopit

      FUNCTION = RIGHT(valueans, 8)
END FUNCTION

this is the error line
Code: [Select]
insXor = VAL("&H" + MID(value1, loopit, 1))   XOR   VAL("&H" + MID(value2, loopit, 1))

how to rectify this error?

 

Charles Pegge

  • Guest
Re: Compilation error
« Reply #1 on: March 21, 2018, 02:28:12 PM »
The problem is that val processes numbers on the FPU as potential floating point values.

It always pays to break complex expressions down into simpler components for readability. The compiler has to do it anyway.

Code: [Select]
' insXor = VAL("&H" + MID(value1, loopit, 1))   XOR   VAL("&H" + MID(value2, loopit, 1))
int i1,i2
i1="&H" + MID(value1, loopit, 1)
i2="&H" + MID(value2, loopit, 1)
insXor=i1 xor i2

chrisc

  • Guest
Re: Compilation error
« Reply #2 on: March 21, 2018, 04:11:39 PM »
That was a good catch, Thanxx Charles

chrisc

  • Guest
Re: Compilation error
« Reply #3 on: March 22, 2018, 09:53:46 AM »
Code: [Select]
int i1,i2
i1="&H" + MID(value1, loopit, 1)
i2="&H" + MID(value2, loopit, 1)

@Charles

in your solution above,  O2 seems to be able to defy some assignment rules

           bcos in                     i1="&H" + MID(value1, loopit, 1)

            the left hand side is an integer  while the right hand side result in
            a string?

  Is this mix and match ok for O2  only for this situation whenever  there is a prefix of  "&H"    and this
  is then regarded as an integer ?






Charles Pegge

  • Guest
Re: Compilation error
« Reply #4 on: March 22, 2018, 10:03:06 AM »
You can do this with any numeric variable and any string expression, and vice-versa.

This autoconverting feature is mostly used in print expressions with numbers and strings combined.

chrisc

  • Guest
Re: Compilation error
« Reply #5 on: March 22, 2018, 10:07:29 AM »
this is very flexible and adaptive, bravo Charles  :)


JRS

  • Guest
Re: Compilation error
« Reply #6 on: March 22, 2018, 10:17:26 AM »
Quote from: Charles
You can do this with any numeric variable and any string expression, and vice-versa.

Can O2 provide this functionality?

Code: Script BASIC
  1. a = 1
  2. b = "2"
  3. PRINT a + b, "\n"
  4. PRINT a & b, "\n"
  5.  


jrs@jrs-laptop:~/sb/examples/test$ scriba strnum.sb
3
12
jrs@jrs-laptop:~/sb/examples/test$

chrisc

  • Guest
Re: Compilation error
« Reply #7 on: March 22, 2018, 10:22:36 AM »

Bravo Charles,  i luv it

Code: [Select]
              int a ,b
             a = 1
             b = "2"
           '  this results in 3
            PRINT a + b
           '  this results in 0
            PRINT a & b


Mike Lobanovsky

  • Guest
Re: Compilation error
« Reply #8 on: March 22, 2018, 07:42:48 PM »
Oxygen's C-ish & is either bitwise AND or address (a.k.a. reference) operator partly synonymous to HLL @. Pretty much guess work for the parser to determine the true meaning of actual use cases as-is. Overloading it with yet another option and especially decode possible 1 & "2" bad programming practices would be just a bit too much, don't you think?

Oxygen is smart enough to correct kiddie 1 + "2" exercises but generally it is advisable to try and not lose one's face in the eyes of someone who might happen to be looking through one's codez later on.

Prefer to supply the compiler with all possible hints at your disposal as to what you would like it to do for you, rather than try and dump the load of human intellection on the shoulders of a machine.

For it is written: "It always pays to break complex expressions down into simpler components for readability. The compiler has to do it anyway." (Gospel of Charles, Reply #1)

JRS

  • Guest
Re: Compilation error
« Reply #9 on: March 22, 2018, 07:47:57 PM »
I would love to see O2 be able to support variant style variables.

The SB example was a cheap shot.  :-[

Mike Lobanovsky

  • Guest
Re: Compilation error
« Reply #10 on: March 22, 2018, 07:56:47 PM »
( ;) )

That'd make just one more possible front end for the O2 engine. :D

Charles Pegge

  • Guest
Re: Compilation error
« Reply #11 on: March 22, 2018, 08:04:04 PM »
The autoconversion features are there to aid casual programming, not forgetting what the B in Basic stands for.

It should be as easy to use as a calculator. Remember the early days of home computers. Plug in the telly, switch on and start programming in Basic

JRS

  • Guest
Re: Compilation error
« Reply #12 on: March 22, 2018, 08:45:14 PM »
The autoconversion features are there to aid casual programming, not forgetting what the B in Basic stands for.

It should be as easy to use as a calculator. Remember the early days of home computers. Plug in the telly, switch on and start programming in Basic

The BASIC language goal is to minimize the number of steps to accomplish any task.

Mike Lobanovsky

  • Guest
Re: Compilation error
« Reply #13 on: March 22, 2018, 10:02:34 PM »
The autoconversion features are there to aid casual programming, not forgetting what the B in Basic stands for.

That's justifiable in a PRINT statement only, which is where the B phase usually ends.

Otherwise, int i1="&H" + MID(value1, loopit, 1) may only appear in:

either
  • developer's own stress tests to verify the compiler is bullet proof against BSOD's running goofy code
or
  • goofy code proper

Don't forget what A(ll-purpose) stands for in BASIC, either. My all-purposefulness implies being able to write industrial quality applications.

What you're seeing below is a pro-grade 3D model viewer displaying a model (courtesy of Patrice Terrier) that totals 2 million fully textured polygons, at a speed of 30 frames per second.

The viewer is written entirely in FBSL under a totally header-less and unprototyped environment.

Otherwise, the entire B-eginner level functionality a newcomer may ever need (PRINT, GDI graphics primitives, etc.) amounts to a 2K lines long #include file the FBSL Eclecta editor would plug in transparently whenever it sees #Option Implicit (a.k.a. don't require variable declaration) at the top of user code.

Do you think Dartmouth or BBC BASIC could ever do the same? We're living in the 21st century, Charles. :)

JRS

  • Guest
Re: Compilation error
« Reply #14 on: March 22, 2018, 10:10:46 PM »
If a complex task only requires two parameters to run, should the BASIC programmer care beyond the intended results  and the arguments presented?