neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

Compiler exception not managed #95

Closed ArturoDente closed 4 years ago

ArturoDente commented 4 years ago

Compiler gives exception not managed when running the following code:

dim a$[5]
let a$[0]="up":let a$[1]="down":let a$[2]="left":let a$[3]="right":let a$[4]="fire"

fun concat$(a$,b$)
        let aa!=strlen!(a$):let bb=strlen!(b$)
        dim buff![aa+bb]
        for t=0 to aa
                buff![t]=peek(a$+t)
        next t
        r$=@buff!
        return r$
endfun

print concat$(a$[0],a$[1])

This is the stacktrace of the error:

core.exception.SwitchError@source\language\number.d(28): No appropriate switch clause found
----------------
0x00410280 in pure nothrow @nogc core.exception.SwitchError core.exception.staticError!(core.exception.SwitchError, immutable(char)[], uint, ).staticError(ref immutable(char)[], ref uint, ) at C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\exception.d(687)
0x0041025D in pure nothrow @nogc @safe void object.__switch_error!().__switch_error(immutable(char)[], uint) at C:\D\dmd2\windows\bin\..\..\src\druntime\import\object.d(3960)
0x00518522 in language.number.Number language.number.Number.__ctor(pegged.peg.ParseTree, program.Program) at F:\Workspace\XC-BASIC\source\language\number.d(85)
0x0052E2B2 in void statement.dim_stmt.Dim_stmt.process() at F:\Workspace\XC-BASIC\source\statement\dim_stmt.d(52)
0x0052BAFF in void program.Program.processLine(pegged.peg.ParseTree, ubyte) at F:\Workspace\XC-BASIC\source\program.d(653)
0x0052C0AE in void program.Program.processAst(pegged.peg.ParseTree).walkAst(pegged.peg.ParseTree, ubyte) at F:\Workspace\XC-BASIC\source\program.d(733)
0x0052C0F7 in void program.Program.processAst(pegged.peg.ParseTree).walkAst(pegged.peg.ParseTree, ubyte) at F:\Workspace\XC-BASIC\source\program.d(738)
0x0052C0F7 in void program.Program.processAst(pegged.peg.ParseTree).walkAst(pegged.peg.ParseTree, ubyte) at F:\Workspace\XC-BASIC\source\program.d(738)
0x0052C05D in void program.Program.processAst(pegged.peg.ParseTree) at F:\Workspace\XC-BASIC\source\program.d(751)
0x00402710 in _Dmain at F:\Workspace\XC-BASIC\source\app.d(47)
0x005B8A9F in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().__lambda1()
0x005B8A21 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
0x005B88BB in _d_run_main
0x004457DC in main at F:\Workspace\XC-BASIC\source\statement\asm_stmt.d(7)
0x0060B759 in mainCRTStartup
0x75326359 in BaseThreadInitThunk
0x76F87B74 in RtlGetAppContainerNamedObjectPath
0x76F87B44 in RtlGetAppContainerNamedObjectPath
neilsf commented 4 years ago

Hi. Thanks for reporting this bug. The compiler indeed doesn't handle this error in the right way. The problem is here:

dim buff![aa+bb]

Unfortunately this is not going to work in XC=BASIC. DIM is a compile-time directive, it can't allocate memory in runtime and therefore the array length can only be a constant.

I'll update the compiler to emit a proper error in this situation.

neilsf commented 4 years ago

Fixed in the upcoming v2.3