I am trying to use the new Vector class introduced in Flash 10. Tried compiling the code using mxmlc but am getting this error message:
Error: Type was not found or was not a compile-time constant: Vector.
public var selectedRoutes:Vector.<Route>;
^
What could be the problem?
What is the general consensus about the viability of using this feature?
Can you do introspection of the Vector with describeType and get the type the Vector contains at runtime?
At a guess, you are compiling for FP9 instead of FP10, or perhaps against an older version of the SDK. Make sure everything is up to date.
The Vector type is more performant than using an Array and casting entries to the desired type.
I can't help feeling that they had to hack the compiler to make it work though. The generic-style syntax is valid only for the Vector type, and not a general language feature, which sucks.
If you need the performance or like the type-safety of using the Vector class then it's worth it.
I don't know what describeType gives you back on a Vector type. Why don't you give it a whirl?
I tried a describeType on a Vector declaration:
trace(describeType(Vector.<Route>))
The result was:
<type name="AS3.vec::Vector.<components::Route>" base="Class" isDynamic="true" isFinal="false" isStatic="true"> <extendsClass type="Class"/> <extendsClass type="Object"/> <accessor name="prototype" access="readonly" type="" declaredBy="Class"/> <factory type="AS3.vec::Vector.<components::Route>"> <extendsClass type="AS3.vec::Vector.<>"/> <extendsClass type="Object"/> <accessor name="fixed" access="readwrite" type="Boolean" declaredBy="AS3.vec::Vector.<>"/> <accessor name="length" access="readwrite" type="uint" declaredBy="AS3.vec::Vector.<>"/> </factory></type>
So, yes, it does provide the type information. You can pick it out from either the type tag's name or from the factory tag's type.
You should open flex-config.xml and change the target player:
target-player>10.0.0
That will solve the problem.
Related
I get ERROR: LoadError: UndefVarError: Expression not defined for the following code:
struct IntLiteral
value::Int
end
struct Plus
left::Expression
right::Expression
end
struct Minus
left::Expression
right::Expression
end
const Expression = Union{IntLiteral, Plus, Minus}
If I declare Expression ahead of Plus and Minus, I get a similar error. Wrapping the code in a module doesn't change anything, either.
Is there a way to reference a type ahead of its declaration in Julia? If not, what is the recommended solution for cases like this, where two types depend on each other? Just remove the type annotations?
In this particular case, I believe I could make Expression an abstract type, and have the others be subtypes of it. Is that recommended in this case? What about the general case?
Not currently, no. See issue #269 for more details.
Using BaseX 8.6 the following use of the serialize function with a map as the second argument works fine:
serialize(<root><foo><bar>test</bar></foo></root>, map { 'indent' : 'yes'})
and outputs the indented code
<root>
<foo>
<bar>test</bar>
</foo>
</root>
However, when I try to run the same code with Saxon 9.7 or AltovaXML Spy they don't compile the query and complain about map { 'indent' : 'yes'} not being a boolean value but a string. https://www.w3.org/TR/xpath-functions-31/#func-serialize defines
indent xs:boolean? true() means "yes", false() means "no"
so I am not quite sure whether that allows only a boolean and is meant to explain its meaning in relation to the serialization values of yes/no or whether it also means using yes or no is allowed.
In BaseX, the map argument was added before it was integrated in the XQFO 3.1 specification. Back then, the most obvious choice was to use the syntax for output declarations in the query prolog (in which only strings can be used for values of serialization parameters). – The new official syntax will be made available in a future version of BaseX.
I am using custom LLVM pass where if I encounter a store to
where the compiler converts the value to a Constant; e.g. there is an explicit store:
X[gidx] = 10;
Then LLVM will generate this error:
aoc: ../../../Instructions.cpp:1056: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
The inheritance order goes as: Value<-User<-Constant, so this shouldn't be an issue, but it is. Using an a cast on the ConstantInt or ConstantFP has no effect on this error.
So I've tried this bloated solution:
Value *new_value;
if(isa<ConstantInt>(old_value) || isa<ConstantFP>(old_value)){
Instruction *allocInst = builder.CreateAlloca(old_value->getType());
builder.CreateStore(old_value, allocInst);
new_value = builder.CreateLoad(allocResultInst);
}
However this solution creates its own register errors when different type are involved, so I'd like to avoid it.
Does anyone know how to convert a Constant to a Value? It must be a simple issue that I'm not seeing. I'm developing on Ubuntu 12.04, LLVM 3, AMD gpu, OpenCL kernels.
Thanks ahead of time.
EDIT:
The original code that produces the first error listed is simply:
builder.CreateStore(old_value, store_addr);
EDIT2:
This old_value is declared as
Value *old_value = current_instruction->getOperand(0);
So I'm grabbing the value to be stored, in this case "10" from the first code line.
You didn't provide the code that caused this first assertion, but its wording is pretty clear: you are trying to create a store where the value operand and the pointer operand do not agree on their types. It would be useful for the question if you'd provide the code that generated that error.
Your second, so-called "bloated" solution, is the correct way to store old_value into the stack and then load it again. You write:
However this solution creates its own register errors when different type are involved
These "register errors" are the real issue you should be addressing.
In any case, the whole premise of "converting a constant to a value" is flawed - as you have correctly observed, all constants are values. There's no point storing a value into the stack with the sole purpose of loading it again, and indeed the standard LLVM pass "mem2reg" will completely remove such a sequence, replacing all uses of the load with the original value.
What generic type should i use, if I have to assign a Character value to it?
For now I'm using type Char is(<>); at the generic declaration,
and assign the character value like this:
XY:GenericChar;
CharacterVariable: Character:='A';
XY:=GenericChar'Value(Character'Image(CharacterVariable));
It works, but i think there should be a better way.
You could use 'Pos and 'Val.
Converting between non-related enumeration types is non-trivial. Best would be to use a conversion function like:
generic
type Generic_Char is (<>);
with function To_Generic_Char (Source : Character) return Generic_Char is <>;
package Foo is
...
That way your generic package wouldn't have to care about converting.
For instantiating the package you would have to create the function.
That generic formal parameter you are using can be supplied with any "discrete type". That means that the client can use any kind of integer-related type, or an enumeration, to instantiate your generic. It also means that only operations available to both integers and enumerations are available inside the routine.
For the most part that means you can assign Chars, you can compare them, and you have access to any attribute available to "discretes". Checking our handy-dandy online LRM page for language-defined attributes (keep this bookmarked while working with generics), looking for ones that work with "discrete" or "scalar" objects/types, we see that this includes:
'first
'image
'last
'max
'min
'pred
'range
'succ
'val
'value
(assorted wide_ variants of 'image and 'value)
The usual suspects available to all objects of any type (eg: 'size, 'input, etc.)
Given the following CRTP type in C#:
public abstract class DataProviderBase<TProvider>
where TProvider : DataProviderBase<TProvider> { }
How would I get its generic type definition in F#?
let typeDef = typedefof<DataProviderBase<_>>
yields the error:
Type constraint mismatch when applying the default type 'DataProviderBase<'a>' for a type inference variable. The resulting type would be infinite when unifying ''a' and 'DataProviderBase<'a>' Consider adding further type constraints
In C#, it would be:
var typeDef = typeof(DataProviderBase<>);
UPDATE
I found a workaround:
[<AbstractClass>]
type DummyProvider() =
inherit DataProviderBase<DummyProvider>()
let typeDef = typeof<DummyProvider>.BaseType.GetGenericTypeDefinition()
Is there another way to do it, without the extra type?
I think this is actually a very good question. I didn't find a better workaround for this.
You can slightly simplify your workaround by using typedefof like this:
let typeDef = typedefof<DataProviderBase<DummyProvider>>
TECHNICAL DETAILS
The problem is that F#'s typedefof<'T> is just an ordinary function that takes a type argument (unlike typeof in C#, which is an operator). In order to call it, you need to give it an actual type and the function will then call GetGenericTypeDefinition under the cover.
The reason why typedefof<option<_>> works is that F# specifies a default type as an argument (in this case obj). In general, F# chooses the less concrete type that matches the constraints. In your case:
DataProviderBase<_> will become DataProviderBase<DataProviderBase<_>> and so on.
Unless you define a new type (as in your workaround), there is no concrete type that could be used as a type argument of typedefof<...>. In this case, the defaulting mechanism simply doesn't work...