Open Naddiseo opened 9 years ago
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.
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}) ?
I think we have some overlap with https://github.com/dslomov-chromium/typed-objects-es7#convertandcopytotypedescriptor-dimensions-buffer-offset-value
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?
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
Given that this is already stage 1, I would take this proposal seriously.
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.
More information: https://github.com/nikomatsakis/typed-objects-explainer
Also solves the forward referencing problem: https://github.com/nikomatsakis/typed-objects-explainer/blob/master/ootypes.md#cyclic-type-definitions
How will we interact with: https://github.com/dslomov-chromium/typed-objects-es7 This also plays into #23