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

Typed Objects #31

Open
Naddiseo opened this issue Jun 12, 2015 · 9 comments
Open

Typed Objects #31

Naddiseo opened this issue Jun 12, 2015 · 9 comments
Assignees

Comments

@Naddiseo
Copy link
Collaborator

How will we interact with: https://github.com/dslomov-chromium/typed-objects-es7
This also plays into #23

@lukescott
Copy link
Owner

I think group types (uint8, int8, uint16, int16, uint32, int32, float32, float64) are like the existing types number, string, and boolean (passed by value). They should have defaults according to their type. Anything that is always passed by reference, such as an Array/Object, should default to undefined.

Should probably be a note on how we would handle it. Probably shouldn't be in the syntax yet.

@Naddiseo
Copy link
Collaborator Author

Well, also how does it work with:

let PointType = StructType({
    x: uint8,  // Our current syntax would allow `x number: uint8`
    y: uint8
});

let p PointType; // does this default to undefined or to PointType({x: 0, y: 0}) ?

@Naddiseo
Copy link
Collaborator Author

@lukescott
Copy link
Owner

I think they are assuming no type hinting exists and uint8 are values themselves representing a type. That would likely change to:

let PointType = StructType({
    x uint8,
    y uint8
});

or even:

let PointType = {
    x uint8,
    y uint8
};

Does StructType get passed by value?

@Naddiseo
Copy link
Collaborator Author

They're treating all types as first class objects/functions, whereas we're treating them as "hints". We might need to think about that, but it does look like this proposal still works with theirs given your examples. If it is changed to what you suggest, then we'll have to write into our semantics that the type of something is stored:

Static Semantics:
PropertyDefinition : IdentifierReference TypeHint

1. Assert Type(TypeHint) is not undefined
2. Set the [[TypeHint]] internal slot of IdentifierReference to TypeHint

@lukescott
Copy link
Owner

Given that this is already stage 1, I would take this proposal seriously.

@Naddiseo
Copy link
Collaborator Author

From #32:

Does typed objects in #31 have a symbol type that we can use? It has Type Objects. Would that qualify?

The type objects get defined in terms of [[structure]]s, which I think we could piggyback onto for base types, and would possibly work with reflection as well. I'm still not sure how it would work with forward references:

function getA() A { // In temporal deadzone...
    return new A();
}

let A = new StructType();

// desugared:
function getA() { return new A(); }
%Set(getA, [[TypeDescriptor]], A); // temporal deadzone...

let A = new StructType();

I guess that's more of something for a transpiler/engine, so that type descriptors of functions get set at the end of the file, or after everything they reference. I'm not sure.

@Naddiseo
Copy link
Collaborator Author

@Naddiseo
Copy link
Collaborator Author

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

No branches or pull requests

2 participants