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

invalid generated C for HashMap of Func #268

Closed
fperrad opened this issue Jan 8, 2011 · 5 comments
Closed

invalid generated C for HashMap of Func #268

fperrad opened this issue Jan 8, 2011 · 5 comments
Labels
Milestone

Comments

@fperrad
Copy link

fperrad commented Jan 8, 2011

the following code generates invalid (incomplete) C code :

import structs/HashMap
HFunc: class extends HashMap<String, Func> {
    init: func { super() }
}

C generated :

void hashfunc__HFunc___defaults___impl(hashfunc__HFunc* this) {
     ((structs_HashMap__HashMap*) this)->K = (void*) lang_String__String_class();
     ((structs_HashMap__HashMap*) this)->V = (void*) ;  // HERE, incomplete
     structs_HashMap__HashMap___defaults___impl((structs_HashMap__HashMap*) this);
}
@nddrylliog
Copy link
Member

Yeah well, you see, the problem is that.. functions don't really have a class (technically, a Func is, often an instance of the cover 'Closure', defined in the sdk, and
sometimes it's just a Pointer to some C function's address)

Does it work when you just instantiate a HashMap<String, Func> ? (Instead of trying to extend it?)

@fperrad
Copy link
Author

fperrad commented Jan 9, 2011

this code works fine :

map := HashMap<String, Func> new()
map put("name", func() {
    "hello" println()
})
fct := map get("name")
fct()

and generates somewhere

 hashfunc__map = structs_HashMap__HashMap_new((lang_types__Class*)lang_String__String_class(), (lang_types__Class*)lang_types__Pointer_class());

so, I think that the missing part is :

lang_types__Pointer_class()

@alexnask
Copy link
Collaborator

So this must be a problem in type-resolving of parent class when extending, right?

@nddrylliog
Copy link
Member

@Shamanas I wouldn't say it's a problem of resolving. As said above, Func is a weird, weird type.

If I were you I'd begin to search for when the place these lines are written out:

 ((structs_HashMap__HashMap*) this)->K = (void*) lang_String__String_class();
 ((structs_HashMap__HashMap*) this)->V = (void*) ;  // HERE, incomplete

It's proably some codepath that doesn't account for Func's dual nature :)

@alexnask
Copy link
Collaborator

alexnask commented Sep 2, 2011

Tried to fix that but it was too difficult xO Will check it out another time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants