added int32 support

This commit is contained in:
Nicolas Cannasse
2009-01-08 10:41:18 +00:00
parent cb0182f612
commit c381a758a8
7 changed files with 28 additions and 6 deletions
+2
View File
@@ -16,6 +16,8 @@ class Test {
static function main() {
test("0",0);
test("0xFF",255);
test("n(0xBFFFFFFF)",0xBFFFFFFF,{ n : haxe.Int32.toNativeInt });
test("n(0x7FFFFFFF)",0x7FFFFFFF,{ n : haxe.Int32.toNativeInt });
test("-123",-123);
test("- 123",-123);
test("1.546",1.546);
+1 -1
View File
@@ -1,5 +1,5 @@
# HScript
-swf9 hscript.swf
-neko hscript.n
-main Test
-debug
+1 -1
View File
@@ -1,5 +1,5 @@
<haxe selected="0">
<output name="HScript" mode="swf9" out="hscript.swf" class="Test" lib="" cmd="" main="True" debug="True"></output>
<output name="HScript" mode="neko" out="hscript.n" class="Test" lib="" cmd="" main="True" debug="True"></output>
<files path="/">
<file path="hscript\Bytes.hx" />
<file path="hscript\Expr.hx" />
+12
View File
@@ -87,6 +87,13 @@ class Bytes {
bout.addByte((v >> 16) & 0xFF);
bout.addByte(v >>> 24);
}
case CInt32(v):
bout.addByte(4);
var mid = haxe.Int32.toInt(haxe.Int32.and(v,haxe.Int32.ofInt(0xFFFFFF)));
bout.addByte(mid & 0xFF);
bout.addByte((mid >> 8) & 0xFF);
bout.addByte(mid >> 16);
bout.addByte(haxe.Int32.toInt(haxe.Int32.ushr(v,24)));
case CFloat(f):
bout.addByte(2);
doEncodeString(Std.string(f));
@@ -108,6 +115,11 @@ class Bytes {
CFloat( Std.parseFloat(doDecodeString()) );
case 3:
CString( doDecodeString() );
case 4:
var i = bin.get(pin) | (bin.get(pin+1) << 8) | (bin.get(pin+2) << 16);
var j = bin.get(pin+3);
pin += 4;
CInt32(haxe.Int32.or(haxe.Int32.ofInt(i),haxe.Int32.shl(haxe.Int32.ofInt(j),24)));
default:
throw "Invalid code "+bin.get(pin-1);
}
+1
View File
@@ -28,6 +28,7 @@ enum Const {
CInt( v : Int );
CFloat( f : Float );
CString( s : String );
CInt32( v : haxe.Int32 );
}
enum Expr {
+1
View File
@@ -206,6 +206,7 @@ class Interp {
case EConst(c):
switch( c ) {
case CInt(v): return v;
case CInt32(v): return v;
case CFloat(f): return f;
case CString(s): return s;
}
+10 -4
View File
@@ -466,18 +466,23 @@ class Parser {
if( n > 0 || exp > 0 )
throw Error.EInvalidChar(char);
// read hexa
var n = haxe.Int32.ofInt(0);
while( true ) {
char = readChar(s);
switch( char ) {
case 48,49,50,51,52,53,54,55,56,57: // 0-9
n = (n << 4) + (char - 48);
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 48));
case 65,66,67,68,69,70: // A-F
n = (n << 4) + (char - 55);
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 55));
case 97,98,99,100,101,102: // a-f
n = (n << 4) + (char - 87);
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 87));
default:
this.char = char;
return TConst( CInt(n) );
// we allow to parse hexadecimal Int32 in Neko, but when the value will be
// evaluated by Interpreter, a failure will occur if no Int32 operation is
// performed
var v = try CInt(haxe.Int32.toInt(n)) catch( e : Dynamic ) CInt32(n);
return TConst(v);
}
}
default:
@@ -591,6 +596,7 @@ class Parser {
function constString( c ) {
return switch(c) {
case CInt(v): Std.string(v);
case CInt32(v): Std.string(v);
case CFloat(f): Std.string(f);
case CString(s): s; // TODO : escape + quote
}