Skip to content

Conversation

@alexnask
Copy link

@alexnask alexnask commented May 16, 2016

This remains backwards compatible as free is not generated if it already exists.
To start using this feature, simply declare __destroy__ instead of free methods.
The only required change in the SDK (ooc-kean) is removing the (virtual) __destroy__ call from Object free as well as any __onheap__ keyword usage.

Here is a trivial example:

MyCell: class <T> {
    val: T

    init: func (=val)

    __destroy__: func {
        "Destroy" println()
    }


}

MySubCell: class <T> extends MyCell <T> {
    init: super func

    __destroy__: func {
        "Subdestroy" println()
    }


}

cell := MySubCell new(42)
cell val toString() println()
cell free()

Output:

42
Subdestroy
Destroy

(Additional 'Subdestroy' if __destroy__() is present in Object free)

EDIT:
Closes #48


mustReturn? := false
meat variables each(|vName, vDecl|
if (!vDecl getType()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Meat"? :o

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't name it but rock is fulled with amusing variable names :P

@thomasfanell
Copy link

@Shamanas did you test this with ooc-kean?
rock segfaults when I run test.sh:

(SIGSEGV) segmentation fault
[fancy backtrace]
0     Backtrace class()                                                   in lang/Backtrace               (at ../rock/sdk/lang/Backtrace.ooc:293)
1     Exception getCurrentBacktrace()                                     in lang/Exception               (at ../rock/sdk/lang/Exception.ooc:223)
2     _signalHandler()                                                    in lang/Exception               (at ../rock/sdk/lang/Exception.ooc:283)
3     killpg()                                                            in                              (at (null):0)
4     Type isGeneric()                                                    in rock/middle/Type             (at ../rock/source/rock/middle/Type.ooc:80)
5     __rock_middle_ClassDecl_rock_middle_ClassDecl_closure26()           in rock/middle/ClassDecl        (at ../rock/source/rock/middle/ClassDecl.ooc:115)
6     HashMap each_withKeys_impl()                                        in structs/HashMap              (at ../rock/sdk/structs/HashMap.ooc:493)
7     ClassDecl resolve_impl()                                            in rock/middle/ClassDecl        (at ../rock/source/rock/middle/ClassDecl.ooc:124)
8     TypeDecl resolve_impl()                                             in rock/middle/TypeDecl         (at ../rock/source/rock/middle/TypeDecl.ooc:944)
9     ClassDecl resolve_impl()                                            in rock/middle/ClassDecl        (at ../rock/source/rock/middle/ClassDecl.ooc:136)
10    Module resolve_impl()                                               in rock/middle/Module           (at ../rock/source/rock/middle/Module.ooc:547)
11    Resolver process_impl()                                             in rock/middle/tinker/Resolver  (at ../rock/source/rock/middle/tinker/Resolver.ooc:59)
12    Tinkerer process_impl()                                             in rock/middle/tinker/Tinkerer  (at ../rock/source/rock/middle/tinker/Tinkerer.ooc:90)
13    __rock_frontend_CommandLine_rock_frontend_CommandLine_closure329()  in rock/frontend/CommandLine    (at ../rock/source/rock/frontend/CommandLine.ooc:692)
14    Time runTime()                                                      in os/Time                      (at ../rock/sdk/os/Time.ooc:134)
15    CommandLine postParsing_impl()                                      in rock/frontend/CommandLine    (at ../rock/source/rock/frontend/CommandLine.ooc:696)
16    CommandLine parse_impl()                                            in rock/frontend/CommandLine    (at ../rock/source/rock/frontend/CommandLine.ooc:666)
17    CommandLine init()                                                  in rock/frontend/CommandLine    (at ../rock/source/rock/frontend/CommandLine.ooc:563)
18    CommandLine new()                                                   in rock/frontend/CommandLine    (at ../rock/source/rock/frontend/CommandLine.ooc:30)
19    main()                                                              in                              (at ../rock/source/rock/rock.ooc:2)
20    libc_start_main()                                                   in                              (at /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321)
21    _start()      

@alexnask
Copy link
Author

alexnask commented Jul 10, 2016

@thomasfanell

Sorry, was out of town.
It's true I haven't been so diligent in checking against the ooc-kean tests when it comes to testing language features.

I will be taking a look at what is causing the crash (from the backtrace, it seems to be coming from Type isGeneric() which is surprising).

EDIT: Probably a null variable decl type
EDIT2: Yeah, the code seems to be pretty fail, the if that checks for a generic type should be an else if, we check for null types and then immediately go on to call a method on them.

@alexnask
Copy link
Author

Tests no longer segfault, although they do fail for some seemingly unrelated reasons

C:\dev\ooc_libs\ooc-kean\source\math/FloatVectorList.ooc:18:27 error No such function __getcount__() for `FloatVectorList`

    mean ::= this sum / this count
                             ~~~~~

Looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants