package me.august.lumen.compile.parser.ast.expr;

import me.august.lumen.compile.parser.ast.Typed;

public class CastExpr extends Typed implements Expression {

    private Expression value;

    public CastExpr(Expression value, String type) {
        super(type);
        this.value = value;
    }

    public Expression getValue() {
        return value;
    }

    @Override
    public Expression[] getChildren() {
        return new Expression[]{value};
    }
}

@@ -73,29 +73,231 @@
 .com
-pile.parser.ast.Typed
+mon.BytecodeUtil;%0Aimport me.august.lumen.compile.codegen.BuildContext;%0Aimport me.august.lumen.compile.parser.ast.Typed;%0Aimport org.objectweb.asm.MethodVisitor;%0Aimport org.objectweb.asm.Opcodes;%0Aimport org.objectweb.asm.Type
 ;%0A%0Ap
@@ -589,76 +589,1420 @@
 lic 
-Expression%5B%5D getChildren() %7B%0A        return new Expression%5B%5D%7Bvalue%7D;
+Type expressionType() %7B%0A        return getResolvedType();%0A    %7D%0A%0A    @Override%0A    public Expression%5B%5D getChildren() %7B%0A        return new Expression%5B%5D%7Bvalue%7D;%0A    %7D%0A%0A    @Override%0A    public void generate(MethodVisitor visitor, BuildContext context) %7B%0A        value.generate(visitor, context);%0A%0A        Type orig   = value.expressionType();%0A        Type target = getResolvedType();%0A%0A%0A        // ensure orig and target are either both primitive, or both objects%0A        if (BytecodeUtil.isPrimitive(orig) != BytecodeUtil.isPrimitive(target)) %7B%0A            throw new RuntimeException(%22Incomptable types%22);%0A        %7D%0A%0A        // if both are primitives%0A        if (BytecodeUtil.isPrimitive(orig)) %7B%0A            if (orig.getSort() %3C Type.INT) %7B%0A                visitor.visitInsn(BytecodeUtil.castNumberOpcode(Type.INT_TYPE, target));%0A            %7D else if (orig.getSort() %3E Type.INT && target.getSort() %3C Type.INT) %7B%0A                visitor.visitInsn(BytecodeUtil.castNumberOpcode(orig, Type.INT_TYPE));%0A                visitor.visitInsn(BytecodeUtil.castNumberOpcode(Type.INT_TYPE, target));%0A            %7D else if (orig.getSort() %3E= Type.INT && target.getSort() %3E= Type.INT) %7B%0A                visitor.visitInsn(BytecodeUtil.castNumberOpcode(orig, target));%0A            %7D%0A        %7D else %7B // if both are objects, just checkcast%0A            visitor.visitTypeInsn(Opcodes.CHECKCAST, target.getInternalName());%0A        %7D
 %0A   

Add codegen for CastExpr