Skip to content

Commit

Permalink
use abstract types for basic types (Int,Float,Bool,Void) and for Clas…
Browse files Browse the repository at this point in the history
…s,Enum,EnumValue
  • Loading branch information
ncannasse committed Oct 22, 2012
1 parent 5b4dda2 commit 29a2bce
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 90 deletions.
2 changes: 1 addition & 1 deletion codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ let make_generic ctx ps pt p =
let path = (match follow t with
| TInst (ct,_) -> ct.cl_path
| TEnum (e,_) -> e.e_path
| TAbstract (a,_) when has_meta ":runtime_value" a.a_meta -> a.a_path
| TAbstract (a,_) when has_meta ":runtimeValue" a.a_meta -> a.a_path
| TMono _ -> raise (Generic_Exception (("Could not determine type for parameter " ^ s), p))
| t -> raise (Generic_Exception (("Type parameter must be a class or enum instance (found " ^ (s_type (print_context()) t) ^ ")"), p))
) in
Expand Down
5 changes: 4 additions & 1 deletion gencs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ let configure gen =
| TType ({ t_path = ["cs"],"Ref" },_)
| TType ({ t_path = ["cs"],"Out" },_)
| TType ({ t_path = [],"Single" },[]) -> Some t
| TInst( { cl_path = ([], "EnumValue") }, _ ) -> Some t_dynamic
| TAbstract( { a_path = ([], "EnumValue") }, _ ) -> Some t_dynamic
| TInst( { cl_path = ([], "EnumValue") }, _ ) -> Some t_dynamic
| _ -> None);

let path_s path = match path with
Expand All @@ -569,6 +570,8 @@ let configure gen =
let ret = match t with
| TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64
| TAbstract( { a_path = [],"Class" }, _ )
| TAbstract( { a_path = [],"Enum" }, _ ) -> TInst(ttype,[])
| TInst( { cl_path = ([], "Class") }, _ )
| TInst( { cl_path = ([], "Enum") }, _ ) -> TInst(ttype,[])
| TEnum(_, [])
Expand Down
6 changes: 5 additions & 1 deletion genjava.ml
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ let configure gen =
| TType ({ t_path = ["java"],"Char16" },[])
| TType ({ t_path = [],"Single" },[])
| TType ({ t_path = [],"Null" },[_]) -> Some t
| TInst( { cl_path = ([], "EnumValue") }, _ ) -> Some t_dynamic
| TAbstract( { a_path = ([], "EnumValue") }, _ ) -> Some t_dynamic
| TInst( { cl_path = ([], "EnumValue") }, _ ) -> Some t_dynamic
| _ -> None);

let change_path path = (change_ns (fst path), change_clname (snd path)) in
Expand All @@ -720,6 +721,8 @@ let configure gen =
match t with
| TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64
| TAbstract( { a_path = ([], "Class") }, p )
| TAbstract( { a_path = ([], "Enum") }, p ) -> TInst(cl_cl,[t_dynamic])
| TInst( { cl_path = ([], "Class") }, p )
| TInst( { cl_path = ([], "Enum") }, p ) -> TInst(cl_cl,[t_dynamic])
| TEnum _
Expand Down Expand Up @@ -774,6 +777,7 @@ let configure gen =
| TInst ({ cl_kind = KTypeParameter _; cl_path=p }, []) -> snd p
| TMono r -> (match !r with | None -> "java.lang.Object" | Some t -> t_s (run_follow gen t))
| TInst ({ cl_path = [], "String" }, []) -> "java.lang.String"
| TAbstract ({ a_path = [], "Class" }, _) | TAbstract ({ a_path = [], "Enum" }, _) -> assert false (* should have been converted earlier *)
| TInst ({ cl_path = [], "Class" }, _) | TInst ({ cl_path = [], "Enum" }, _) -> assert false (* should have been converted earlier *)
| TEnum (({e_path = p;} as e), params) -> (path_param_s (TEnumDecl e) p params)
| TInst (({cl_path = p;} as cl), params) -> (path_param_s (TClassDecl cl) p params)
Expand Down
2 changes: 1 addition & 1 deletion std/Class.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
An abstract type that represents a Class.
See [Type] for the haXe Reflection API.
**/
extern class Class<T> {
@:runtimeValue abstract Class<T> {
}
2 changes: 1 addition & 1 deletion std/Enum.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
An abstract type that represents an Enum.
See [Type] for the haXe Reflection API.
**/
extern class Enum<T> {
@:runtimeValue abstract Enum<T> {
}
2 changes: 1 addition & 1 deletion std/EnumValue.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
An abstract type that represents any enum value.
See [Type] for the haXe Reflection API.
**/
extern class EnumValue {
abstract EnumValue {
}
16 changes: 7 additions & 9 deletions std/StdTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@
/**
The standard Void type. Only [null] values can be of the type [Void].
**/
extern enum Void { }
abstract Void { }

/**
The standard Float type, this is a double-precision IEEE 64bit float.
**/
extern class Float { }
@:notNull @:runtimeValue abstract Float { }

/**
The standard Int type. Its precision depends on the platform.
**/
extern class Int extends Float { }
@:notNull @:runtimeValue abstract Int <= Float { }

#if (flash9 || flash9doc || cs)
/**
The unsigned Int type is only defined for Flash9. It's currently
handled the same as a normal Int.
**/
typedef UInt = Int
@:notNull @:runtimeValue abstract UInt => Int, <= Int { }
#end

#if (java || cs)
typedef Single = Float;
@:notNull @:runtimeValue abstract Single => Float, <= Float {}
#end

/**
Expand All @@ -63,16 +63,14 @@ typedef Null<T> = T
/**
The standard Boolean type is represented as an enum with two choices.
**/
extern enum Bool {
true;
false;
@:notNull @:runtimeValue abstract Bool {
}

/**
Dynamic is an internal compiler type which has special behavior.
See the haXe language reference for more informations.
**/
extern class Dynamic<T> {
@:runtimeValue abstract Dynamic<T> {
}

/**
Expand Down
8 changes: 4 additions & 4 deletions std/cs/Pointer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cs;
/**
This type represents pointer types for C# function parameters. It should only
be used inside an unsafe context (not checked by the Haxe compiler)
C# code:
int[] src;
fixed (int* pSrc = src)
Expand All @@ -16,13 +16,13 @@ package cs;
{
...
});
**/
#if !unsafe
#error "You need to define 'unsafe' to be able to use unsafe code in hxcs"
#else
extern class Pointer<T> extends Int, implements ArrayAccess<T>
extern class Pointer<T> /*extends Int,*/ implements ArrayAccess<T>
{

}
#end
8 changes: 4 additions & 4 deletions std/cs/_std/Type.hx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ import cs.internal.Runtime;
{
switch(name)
{
case #if no-root "haxe.root.Int" #else "Int" #end: return Int;
case #if no-root "haxe.root.Float" #else "Float" #end: return Float;
case #if no-root "haxe.root.Class" #else "Class" #end: return Class;
//case #if no-root "haxe.root.Int" #else "Int" #end: return Int;
//case #if no-root "haxe.root.Float" #else "Float" #end: return Float;
//case #if no-root "haxe.root.Class" #else "Class" #end: return Class;
//case #if no-root "haxe.root.Dynamic" #else "Dynamic" #end: return Dynamic;
case #if no-root "haxe.root.String" #else "String" #end: return String;
case #if no-root "haxe.root.Dynamic" #else "Dynamic" #end: return Dynamic;
default: return null;
}
} else if (t.IsInterface && cast(untyped __typeof__(IGenericObject), cs.system.Type).IsAssignableFrom(t)) {
Expand Down
58 changes: 29 additions & 29 deletions std/cs/_std/haxe/Int64.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,146 +30,146 @@ private typedef NativeUInt64 = Int;
@:coreApi
@:nativegen class Int64
{
@:extern private static inline function asNative(i:haxe.Int64):NativeInt64 return untyped i
@:extern private static inline function ofNative(i:NativeInt64):haxe.Int64 return untyped i
@:extern private static inline function asNative(i:Int64):NativeInt64 return untyped i
@:extern private static inline function ofNative(i:NativeInt64):Int64 return untyped i
@:extern private static inline function mkNative(i:Dynamic):NativeInt64 return i

#if haxe3

public static inline function make( high : Int, low : Int ) : haxe.Int64
public static inline function make( high : Int, low : Int ) : Int64
{
return ((cast(high, NativeInt64) << 32 ) | (cast(low, NativeInt64))).ofNative();
}

public static inline function getLow( x : haxe.Int64 ) : Int
public static inline function getLow( x : Int64 ) : Int
{
return cast (x.asNative() & 0xFFFFFFFF.mkNative());
}

public static inline function getHigh( x : haxe.Int64 ) : Int {
public static inline function getHigh( x : Int64 ) : Int {
return cast(x,NativeUInt64) >> 32;
}

#else

public static inline function make( high : Int32, low : Int32 ) : haxe.Int64
public static inline function make( high : Int32, low : Int32 ) : Int64
{
return ((cast(high, NativeInt64) << 32 ) | (cast(low, NativeInt64))).ofNative();
}

public static inline function ofInt32( x : Int32 ) : haxe.Int64 {
public static inline function ofInt32( x : Int32 ) : Int64 {
return cast x;
}

public static inline function getLow( x : haxe.Int64 ) : Int32
public static inline function getLow( x : Int64 ) : Int32
{
return cast (x.asNative() & 0xFFFFFFFF.mkNative());
}

public static inline function getHigh( x : haxe.Int64 ) : Int32
public static inline function getHigh( x : Int64 ) : Int32
{
return cast(cast(x,NativeUInt64) >> 32,Int32);
}


#end

public static inline function ofInt( x : Int ) : haxe.Int64 {
public static inline function ofInt( x : Int ) : Int64 {
return cast x;
}

public static inline function toInt( x : haxe.Int64 ) : Int
public static inline function toInt( x : Int64 ) : Int
{
return cast x;
}

public static inline function add( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64
public static inline function add( a : Int64, b : Int64 ) : Int64
{
return (a.asNative() + b.asNative()).ofNative();
}

public static inline function sub( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64
public static inline function sub( a : Int64, b : Int64 ) : Int64
{
return (a.asNative() - b.asNative()).ofNative();
}

public static inline function mul( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64 {
public static inline function mul( a : Int64, b : Int64 ) : Int64 {
return (a.asNative() * b.asNative()).ofNative();
}

static function divMod( modulus : haxe.Int64, divisor : haxe.Int64 )
static function divMod( modulus : Int64, divisor : Int64 ) : { quotient : Int64, modulus : Int64 }
{
var q:Int64 = (modulus.asNative() / divisor.asNative()).mkNative().ofNative();
var m:Int64 = (modulus.asNative() % divisor.asNative()).mkNative().ofNative();
return { quotient : q, modulus : m };
}

public static inline function div( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64 {
public static inline function div( a : Int64, b : Int64 ) : Int64 {
return (a.asNative() / b.asNative()).mkNative().ofNative();
}

public static inline function mod( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64 {
public static inline function mod( a : Int64, b : Int64 ) : Int64 {
return (a.asNative() % b.asNative()).mkNative().ofNative();
}

public static inline function shl( a : haxe.Int64, b : Int ) : haxe.Int64 {
public static inline function shl( a : Int64, b : Int ) : Int64 {
return (a.asNative() << b).ofNative();
}

public static inline function shr( a : haxe.Int64, b : Int ) : haxe.Int64 {
public static inline function shr( a : Int64, b : Int ) : Int64 {
return (a.asNative() >> b).ofNative();
}

public static inline function ushr( a : haxe.Int64, b : Int ) : haxe.Int64 {
public static inline function ushr( a : Int64, b : Int ) : Int64 {
return ( cast(a, NativeUInt64) >> b).ofNative();
}

public static inline function and( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64
public static inline function and( a : Int64, b : Int64 ) : Int64
{
return (a.asNative() & b.asNative()).ofNative();
}

public static inline function or( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64
public static inline function or( a : Int64, b : Int64 ) : Int64
{
return (a.asNative() | b.asNative()).ofNative();
}

public static inline function xor( a : haxe.Int64, b : haxe.Int64 ) : haxe.Int64
public static inline function xor( a : Int64, b : Int64 ) : Int64
{
return (a.asNative() ^ b.asNative()).ofNative();
}

public static inline function neg( a : haxe.Int64 ) : haxe.Int64
public static inline function neg( a : Int64 ) : Int64
{
return (~a.asNative()).ofNative();
}

public static inline function isNeg( a : haxe.Int64 ) : Bool
public static inline function isNeg( a : Int64 ) : Bool
{
return (a.asNative() < 0.mkNative());
}

public static inline function isZero( a : haxe.Int64 ) : Bool
public static inline function isZero( a : Int64 ) : Bool
{
return (a.asNative() == 0.mkNative());
}

public static inline function compare( a : haxe.Int64, b : haxe.Int64 ) : Int
public static inline function compare( a : Int64, b : Int64 ) : Int
{
return cast (a.asNative() - b.asNative());
}

/**
Compare two Int64 in unsigned mode.
**/
public static function ucompare( a : haxe.Int64, b : haxe.Int64 ) : Int
public static function ucompare( a : Int64, b : Int64 ) : Int
{
if (a.asNative() < 0.mkNative())
return (b.asNative() < 0.mkNative()) ? compare( (~a.asNative()).ofNative(), (~b.asNative()).ofNative()) : 1;
return (b.asNative() < 0.mkNative()) ? -1 : compare(a, b);
}

public static inline function toStr( a : haxe.Int64 ) : String {
public static inline function toStr( a : Int64 ) : String {
return a + "";
}
}
4 changes: 2 additions & 2 deletions std/flash/_std/haxe/Resource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Resource {
return untyped __new__(n);
}

static function __init__() {
static function __init__() : Void {
untyped __resources__.__init__();
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ class Resource {
}
}

static function __init__() {
static function __init__() : Void {
content = untyped __resources__();
}
}
Expand Down
Loading

0 comments on commit 29a2bce

Please sign in to comment.