Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's wrong with this? (*solved*)
#1
Maybe I'm just being thick:

Code:
Sub Fastcall tdPutChar (c as uByte)
    Asm
        rst 16
    End Asm
End Sub

Sub tdPrint (cad As String)
    Dim i As uByte
    For i = 1 To Len (cad)
        tdPutChar (cad (i))
    Next i
End Sub

Compiler output:

Code:
H:\Dev\Speccy\mt64x32lib\zxbasic>c:\zxb\zxb textdongle.bas
Traceback (most recent call last):
  File "zxb.py", line 312, in <module>
  File "zxb.py", line 241, in main
  File "ply\yacc.pyc", line 263, in parse
  File "ply\yacc.pyc", line 710, in parseopt
  File "zxbparser.pyc", line 1744, in p_statement_call
  File "zxbparser.pyc", line 1137, in make_proc_call
  File "zxbparser.pyc", line 744, in check_call_arguments
  File "zxbparser.pyc", line 432, in typecast
  File "zxbparser.pyc", line 1019, in make_typecast
  File "obj\errmsg.pyc", line 22, in syntax_error
TypeError: %d format: a number is required, not NoneType
Reply
#2
The compiler seems to crash whenever I add a subroutine which gets a String parameter. I remove such subs, it works. I add them, even empty, the compiler crashes. Unless I'm missing something quite obvious.
Reply
#3
Maybe it is not a good idea to try to put a string into byte?

Quote:cad As String -> tdPutChar (cad (i)) -> tdPutChar (c as uByte)
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#4
I've tried that. The compiler crashes on the assignment. It doesn't like it.

Code:
Sub Fastcall tdPutChar (c as uByte)
    Asm
        rst 16
    End Asm
End Sub

Sub tdPrint (cad As String)
    Dim i As uByte
    Dim c As uByte
    For i = 1 To Len (cad)
        c = cad (i)
        tdPutChar (c)
    Next i
End Sub

Output:

Code:
H:\Dev\Speccy\mt64x32lib\zxbasic>c:\zxb\zxb textdongle.bas
Traceback (most recent call last):
  File "zxb.py", line 312, in <module>
  File "zxb.py", line 241, in main
  File "ply\yacc.pyc", line 263, in parse
  File "ply\yacc.pyc", line 710, in parseopt
  File "zxbparser.pyc", line 1793, in p_assignment
  File "zxbparser.pyc", line 1019, in make_typecast
  File "obj\errmsg.pyc", line 23, in syntax_error
TypeError: %d format: a number is required, not NoneType

The problem has to be the cad (i) thing. Any other way to access a single char within a string?

EDIT: I've found "mid$" inside string.bas in the library. If I take just that function and add it to my code, replacing the cad (i) for mid (cad, i, 1), I still get the same crash, but inside the mid$ function.

Code:
function mid$ (ByVal s$, ByVal x As Uinteger, ByVal n As Uinteger)
    return s$(x to x + n - 1)
end function

Broken compiler?
Reply
#5
Solved. I was missing a "VAL" (I was just being thick and I was "thinking in C")

Code:
c = val (cad (i))

I got the clue from v.1.2.8 (which raises an error telling you about VAL being needed).

Anyways, v.1.2.9-s888 should be fixed not to crash on such error :-)
Reply
#6
na_th_an Wrote:Maybe I'm just being thick:

Code:
Sub Fastcall tdPutChar (c as uByte)
    Asm
        rst 16
    End Asm
End Sub

Sub tdPrint (cad As String)
    Dim i As uByte
    For i = 1 To Len (cad)
        tdPutChar (cad (i))
    Next i
End Sub

Compiler output:

[code]H:\Dev\Speccy\mt64x32lib\zxbasic>c:\zxb\zxb textdongle.bas
Traceback (most recent call last):
File "zxb.py", line 312, in <module>
Despite of the syntactic/semantic error, this is a compiler bug: the compiler should *NEVER* crash, regardless of the input source code. This is something to be fixed. Also, check for IX/IY when using your routines or IM, since ZX BASIC requires IX for functions, and IY are used for some ROM routines called by ZX BASIC (even for Timer/Interrupt routines). So if you're experiencing some strange crashed, try to push/pop IX and IY on your routines to see if it works.

Also, remember the stack is at 32767 or even lower, so when it reaches the BASIC or ROM Variables zone, it could also crash your program.

PD: I'm on vacation (yes in the Canaries 8) ) => <!-- m --><a class="postlink" href="http://p.twimg.com/AykD5bpCMAA7Fhp.jpg">http://p.twimg.com/AykD5bpCMAA7Fhp.jpg</a><!-- m -->
Reply
#7
Hah nice picture Smile

The compiler tends to crash on me quite a lot :lol: I promise I will report next time (most of the time I don't have internet around, I find a walkaround, and then forget, sorry).
Reply
#8
na_th_an Wrote:Hah nice picture Smile

The compiler tends to crash on me quite a lot :lol: I promise I will report next time (most of the time I don't have internet around, I find a walkaround, and then forget, sorry).
If you get to crash the compiler, please, paste the code sequence here. It will help me a lot :!:

PD: I'm back at home 8)
Reply
#9
Update: Notice the compiler crash at syntax_error function. In fact, your program effectively has a syntax (semantic) error. BASIC is not C: cad$(i) is not a char; it's a String of length 1. You're trying to coerce cad$(i) into Ubyte. Use CODE(cad$(i)) for that, or ASC:
Code:
Sub Fastcall tdPutChar (c as uByte)
   Asm
      rst 16
   End Asm
End Sub

Sub tdPrint (cad As String)
   Dim i As uByte
   For i = 1 To Len (cad)
      tdPutChar(CODE(cad(i))) ' <= Here
   Next i
End Sub
Reply
#10
Thats what i meant with:
cad As String -> tdPutChar (cad (i)) -> tdPutChar (c as uByte)

cad is defined as string, tdPutChar call sends a string char but SUB tdPutChar expects a uByte. To avoid this mistake String should have the $ suffix.
The only reason for using STRING would be POKE STRING or PEEK(STRING) but it does not work.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#11
Plaese, download the latest version: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Archive#Latest_Development_Version">http://www.boriel.com/wiki/en/index.php ... nt_Version</a><!-- m -->
the compiler should not crash with this error anymore.
Reply
#12
Thank you Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)