aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.24k stars 121 forks source link

Lobsters crash #259

Closed oconnor0 closed 11 months ago

oconnor0 commented 11 months ago

I noticed https://github.com/aardappel/lobster/blob/master/dev/TODO.txt#L394-L397 and so figured I'd take a stab at it, at least for myself, since Lobster looked interesting and I wanted to learn it. But I got this crash log:

===== Crash Log =====
Date: 2023-09-13, Time: 04:51:45
CMD: E:\Source\lobster\bin\lobster.exe .\lox.lobster 
ExpCode: 0xC0000005, ExpFlags: 0, ExpAddress: 0x71018491
SymInit: Symbol-SearchPath: '.;E:\Source\lobster;E:\Source\lobster\bin;C:\WINDOWS;C:\WINDOWS\system32;SRV*C:\websymbols*http://msdl.microsoft.com/download/symbols;', symOptions: 530, UserName: 'Oconnor'
OS-Version: 6.2.9200 () 0x300-0x1
ERROR: SymGetSymFromAddr64, GetLastError: 487 (Address: 00007FF771018491)
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF771018491)
00007FF771018491 (lobster): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 487 (Address: 00007FF771018757)
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF771018757)
00007FF771018757 (lobster): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 487 (Address: 00007FF771019AEB)
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF771019AEB)
00007FF771019AEB (lobster): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 487 (Address: 00007FF771019E6E)
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF771019E6E)
00007FF771019E6E (lobster): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 487 (Address: 00007FF771012FEC)
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF771012FEC)
00007FF771012FEC (lobster): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 00000205987CBAD4)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 00000205987CBAD4)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 00000205987CBAD4)
00000205987CBAD4 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 00000205987C54A0)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 00000205987C54A0)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 00000205987C54A0)
00000205987C54A0 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 000000F0D0F4EFD8)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 000000F0D0F4EFD8)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 000000F0D0F4EFD8)
000000F0D0F4EFD8 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 00000205987BAE88)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 00000205987BAE88)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 00000205987BAE88)
00000205987BAE88 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 00000205987BAE88)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 00000205987BAE88)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 00000205987BAE88)
00000205987BAE88 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 000002059A194FA8)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 000002059A194FA8)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 000002059A194FA8)
000002059A194FA8 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 000002059A194FA8)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 000002059A194FA8)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 000002059A194FA8)
000002059A194FA8 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 000002059A193FE8)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 000002059A193FE8)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 000002059A193FE8)
000002059A193FE8 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 000002059A192FB8)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 000002059A192FB8)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 000002059A192FB8)
000002059A192FB8 ((module-name not available)): (filename not available): (function-name not available)
ERROR: SymGetSymFromAddr64, GetLastError: 126 (Address: 000002059A194F48)
ERROR: SymGetLineFromAddr64, GetLastError: 126 (Address: 000002059A194F48)
ERROR: SymGetModuleInfo64, GetLastError: 1114 (Address: 000002059A194F48)
000002059A194F48 ((module-name not available)): (filename not available): (function-name not available)

While running this code:

enum token_type:
    LEFT_PAREN, RIGHT_PAREN, LEFT_BRACE, RIGHT_BRACE,
    COMMA, DOT, MINUS, PLUS, SEMICOLON, SLASH, SHAR

    BANG, BANG_EQUAL,
    EQUAL, EQUAL_EQUAL,
    GREATER, GREATER_EQUAL,
    LESS, LESS_EQUAL,

    IDENTIFIER, STRING, NUMBER,

    AND, CLASS, ELSE, FALSE, FUN, FOR, IF, NIL, OR
    PRINT, RETURN, SUPER, THIS, TRUE, VAR, WHILE,

    EOF

//struct value:
    //i:int

abstract struct value

struct Int : value
    i:int

struct Str : value
    s:string

struct token:
    type:token_type
    lexeme:string
    literal:value
    line:int

    def to_string(): return "{type} {lexeme} {literal}"

var had_error = false

def report(line, where, message):
    print "[line {line}] Error{where}: {message}"

def error(line, message): report(line, "", message)

class Scanner:
    source:string

    def scan_tokens():
        return tokenize(source, " \t\n\r", " \t\n\r", false)

def run(source):
    let scanner = Scanner { source }
    let tokens = scanner.scan_tokens()
    for (tokens) t, i: print "{i}: {t}"
    let t = token {AND, "and", Int { 3 }, 2 }
    print t

def run_prompt():
    while true:
        let line = get_line "> "
        if not line: return
        run line
        had_error = false

run_prompt()
if had_error:
    set_exit_code 65

I just start it up and hit "enter" and get the crash. I'm on Windows 10 and am using https://github.com/aardappel/lobster/releases/tag/v2023.11

aardappel commented 11 months ago

Hah, interesting.. the problem is created by literal:value which can't work, because you've used struct for all of these, which are by value inline, but somehow the typechecker doesn't mind you constructing an Int there and then the codegen falls over :)

It should disallow substituting a subclass for a struct. Let me see what is the best way to error that.

You may want to use class for building up an AST.

aardappel commented 11 months ago

I am actually going to fix this by:

But I'll do that this weekend.. for now, just use class for the AST :)

oconnor0 commented 11 months ago

Awesome, thanks!

aardappel commented 11 months ago

All the above has been implemented.