Skip to content

Support transpiling class methods as named functions #1544

@luis-j-soares

Description

@luis-j-soares

(apologies if this topic has been covered before, I looked but couldn't find anything about it)

Given the following class:

class MyKlass
    sub new()
    end sub

    function abc() as integer
    end function

    function def() as object
    end function
end class

We currently transpile it like so:

function __MyKlass_builder()
    instance = {}
    instance.new = sub()
    end sub
    instance.abc = function() as integer
    end function
    instance.def = function() as object
    end function
    return instance
end function
function MyKlass()
    instance = __MyKlass_builder()
    instance.new()
    return instance
end function

However, when it comes to crash logs and profiling, all of the class' methods will appear as $anon_....

To improve this, I was wondering if it would be possible to transpile them with all methods being named instead:

sub __MyKlass_new()
end sub
function __MyKlass_abc() as integer
end function
function __MyKlass_def() as object
end function
function __MyKlass_builder()
    instance = {}
    instance.new = __MyKlass_new
    instance.abc = __MyKlass_abc
    instance.def = __MyKlass_def
    return instance
end function
function MyKlass()
    instance = __MyKlass_builder()
    instance.new()
    return instance
end function

This would make it so that in class-heavy projects, Roku's crash logs would become a lot more readable at a glance, and we'd be able to more easily use tools such as the BrightScript Profiler without having to repeatedly check for filenames and line numbers.

Thoughts? Has this been considered in the past?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions