Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of nested continue will not compile #194

Closed
1 of 5 tasks
mrodz opened this issue Apr 19, 2024 · 1 comment · Fixed by #195
Closed
1 of 5 tasks

Use of nested continue will not compile #194

mrodz opened this issue Apr 19, 2024 · 1 comment · Fixed by #195
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mrodz
Copy link
Owner

mrodz commented Apr 19, 2024

Documentation Status

Snippet Responsible

length_of_longest_substring = fn(input: str) -> int {
    letter_frequency = map[str, bool]

    start_index = 0

    result = 0

    from 0 to input.len(), i {
        if letter_frequency[input[i]] != nil {
            length = i - start_index

            if length > result {
                result = length
            }

            letter_frequency.clear()
            letter_frequency[input[i]] = true

            start_index = i
            continue
        }
        
        letter_frequency[input[i]] = true
    }

    return result
}

print length_of_longest_substring("pwwkew")

Stack Trace of Error


    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target\debug\mscript.exe run .\examples\maps\leetcode_3.ms --verbose --no-pb`
[ Trace ] INIT Virtual Stack at MODULE
[ Debug ] pre-walk ".\\examples\\maps\\leetcode_3.ms"
[ Debug ] registering new file ".\\examples\\maps\\leetcode_3.ms" (File { declarations: RefCell { value: [] }, location: ".\\examples\\maps\\leetcode_3.mmm", exports: RefCell { value: [] }, public_types: RefCell { value: {} }, compiled: CompilationLock(Cell { value: false }) }) -- Adding to: []
[ Trace ] Gen. mod ".\\examples\\maps\\leetcode_3.ms" -- skipping print_statement
[ Info ] DONE preloading module .\examples\maps\leetcode_3.ms
[ Info ] + mod "./examples/maps/leetcode_3.ms" ModuleType { exported_members: RefCell { value: [] }, public_types: RefCell { value: {} }, name: ".\\examples\\maps\\leetcode_3.ms" }
[ Info ] + finished preload of ".\\examples\\maps\\leetcode_3.ms"
[ Trace ] Virtual Stack PUSH: fn(???) -> Should(Native(Int))
[ Trace ] + input: str
[ Trace ] + letter_frequency: map[str, bool]
[ Trace ] + start_index: int
[ Trace ] + result: int
[ Trace ] Virtual Stack PUSH: Number Loop -> ParentShould(Native(Int))
[ Trace ] + i: int
[ Trace ] Virtual Stack PUSH: If Block -> ParentShould(Native(Int))
[ Debug ] lhs:Native(Str(StrWrapper(None))) rhs:Native(Str(StrWrapper(None))) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] + length: int
[ Trace ] Virtual Stack PUSH: If Block -> ParentShould(Native(Int))
[ Trace ] + result: int
[ Debug ] lhs:Native(Int) rhs:Native(Int) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] Virtual Stack POP
[ Debug ] lhs:Native(Str(StrWrapper(None))) rhs:Native(Str(StrWrapper(None))) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Debug ] lhs:Native(Bool) rhs:Native(Bool) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: true, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] + start_index: int
[ Debug ] lhs:Native(Int) rhs:Native(Int) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] Virtual Stack POP
[ Debug ] lhs:Native(Str(StrWrapper(None))) rhs:Native(Str(StrWrapper(None))) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Debug ] lhs:Native(Bool) rhs:Native(Bool) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: true, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] Virtual Stack POP
[ Debug ] lhs:Native(Int) rhs:Native(Int) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: true, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] Virtual Stack POP
[ Trace ] + length_of_longest_substring: fn(str) -> int
[ Debug ] lhs:Native(Str(StrWrapper(None))) rhs:Native(Str(StrWrapper(Some(6)))) f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false }
[ Trace ] Added compilation step: ".\\examples\\maps\\leetcode_3.ms"
[ Debug ] [cc] FINAL COMPILATION LIST: [".\\examples\\maps\\leetcode_3.ms"]
[ Info ] checking validation of `".\\examples\\maps\\leetcode_3.ms"`: completed
[ Info ] [cc] @ .\examples\maps\leetcode_3.mmm
[ Trace ] reg. -n--- 0
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 3
[ Trace ] reg. F--em 0
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 3
[ Trace ] reg. -n--- 3
[ Trace ] reg. -n--- 4
[ Trace ] reg. -n--- 5
[ Trace ] reg. -n--- 6
[ Trace ] reg. -n--- 6
[ Trace ] reg. -n--- 7
[ Trace ] reg. -n--- 8
[ Trace ] reg. F--e- 7
[ Trace ] reg. F--e- 6
[ Trace ] reg. F--e- 4
[ Trace ] reg. F--e- 3
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 3
[ Trace ] reg. F--em 0
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 3
[ Trace ] reg. -n--- 4
[ Trace ] reg. -n--- 5
[ Trace ] reg. -n--- 5
[ Trace ] reg. -n--- 6
[ Trace ] reg. -n--- 7
[ Trace ] reg. F--e- 6
[ Trace ] reg. F--e- 5
[ Trace ] reg. F--e- 3
[ Trace ] reg. F--e- 2
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 2
[ Trace ] reg. -n--- 3
[ Trace ] reg. -n--- 4
[ Trace ] reg. -n--- 5
[ Trace ] reg. -n--- 5
[ Trace ] reg. -n--- 6
[ Trace ] reg. -n--- 7
[ Trace ] reg. F--e- 6
[ Trace ] reg. F--e- 5
[ Trace ] reg. F--e- 3
[ Trace ] reg. F--e- 2
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 0
[ Trace ] reg. -n--- 1
[ Trace ] reg. -n--- 1
[ Trace ] reg. -G--m 2
[ Trace ] reg. -G--m 2
[ Trace ] reg. F--em 1
Compiled in 28.9036ms

thread 'mscript-runtime' panicked at compiler\src\ast.rs:185:13:
not an instruction: Continue(2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior

This is valid code and is the solution to this Leetcode problem.

Any ideas where MScript breaks?

  • Bytecode Interpreter
  • Compiler
  • Optimizer
  • Not Sure (It's okay!)
  • Other: please explain

Brain Dump (Optional)

For some reason, the compiler isn't flagging the emitted continue signal and not updating it to a jmp instruction.

@mrodz mrodz added the bug Something isn't working label Apr 19, 2024
@mrodz mrodz self-assigned this Apr 19, 2024
@mrodz mrodz added this to the v1.0.0-rc.5 milestone Apr 19, 2024
mrodz added a commit that referenced this issue Apr 20, 2024
@mrodz
Copy link
Owner Author

mrodz commented Apr 20, 2024

This was caused by code that interpreted the end of an if statement scope as a loop terminator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant