Browse Source

Added parser support for $z and $w types.
Added more Types.
Added pub.math test.

woollybah 11 years ago
parent
commit
8ae60afe85
6 changed files with 258 additions and 8 deletions
  1. 11 0
      ctranslator.bmx
  2. 7 0
      iparser.bmx
  3. 7 1
      parser.bmx
  4. 28 0
      tests/framework/mod/brl/math/math_01.bmx
  5. 20 0
      tests/framework/mod/brl/math/math_01.res
  6. 185 7
      type.bmx

+ 11 - 0
ctranslator.bmx

@@ -57,6 +57,9 @@ Type TCTranslator Extends TTranslator
 		If TFloatPtrPtrType( ty ) Return "BBFLOAT **"
 		If TDoublePtrPtrType( ty ) Return "BBDOUBLE **"
 		If TLongPtrPtrType( ty ) Return "BBLONG **"
+		If TStringCharPtrType( ty ) Return "BBBYTE *"
+		If TStringShortPtrType( ty ) Return "BBSHORT *"
+		If TIntVarPtrType( ty ) Return "BBINT *"
 		InternalErr
 	End Method
 
@@ -91,6 +94,14 @@ Type TCTranslator Extends TTranslator
 		If TDoubleVarPtrType( ty ) Return "! Var"
 		If TLongVarPtrType( ty ) Return "%% Var"
 		If TStringVarPtrType( ty ) Return "$ Var"
+		If TByteVarPtrPtrType( ty ) Return "@* Var"
+		If TShortVarPtrPtrType( ty ) Return "@@* Var"
+		If TIntVarPtrPtrType( ty ) Return "%* Var"
+		If TFloatVarPtrPtrType( ty ) Return "#* Var"
+		If TDoubleVarPtrPtrType( ty ) Return "!* Var"
+		If TLongVarPtrPtrType( ty ) Return "%%* Var"
+		If TStringCharPtrType( ty ) Return "$z"
+		If TStringShortPtrType( ty ) Return "$w"
 		InternalErr
 	End Method
 

+ 7 - 0
iparser.bmx

@@ -877,6 +877,13 @@ End Rem
 		Case "$"
 			NextToke
 			ty=TType.stringType
+
+			If CParse("z") Then
+				ty = TType.stringToCharPointerType
+			Else If CParse("w") Then
+				ty = TType.stringToShortPointerType
+			End If
+
 			If CParse( "&" )
 				attrs :| DECL_GLOBAL
 				attrs :~ DECL_CONST

+ 7 - 1
parser.bmx

@@ -661,7 +661,13 @@ Type TParser
 		Case "$"
 			NextToke
 			ty=TType.stringType
-
+			
+			If CParse("z") Then
+				ty = TType.stringToCharPointerType
+			Else If CParse("w") Then
+				ty = TType.stringToShortPointerType
+			End If
+			
 			If CParse("var") Then
 				ty = TType.MapToVarPointerType(ty)
 			End If

+ 28 - 0
tests/framework/mod/brl/math/math_01.bmx

@@ -0,0 +1,28 @@
+'
+' Test brl.math functions
+'
+SuperStrict
+
+Framework BRL.Math
+Import BRL.StandardIO
+
+Print "Sqr(100) = " + Sqr(100)
+Print "Sin(90)  = " + Sin(90)
+Print "Sin(45)  = " + Sin(45)
+Print "Cos(90)  = " + Cos(90)
+Print "Cos(45)  = " + Cos(45)
+Print "Tan(45)  = " + Tan(45)
+Print "Tan(100) = " + Tan(100)
+Print "ASin(90) = " + ASin(90)
+Print "ASin(45) = " + ASin(45)
+Print "ACos(90) = " + ACos(90)
+Print "ACos(45) = " + ACos(45)
+Print "ATan(45) = " + ATan(45)
+Print "ATan(100)= " + ATan(100)
+Print "ATan2(3, 4)= " + ATan2(3, 4)
+Print "Tanh(33) = " + Tanh(33)
+Print "Exp(15) = " + Exp(15)
+Print "Log(20) = " + Log(20)
+Print "Log10(25) = " + Log10(25)
+Print "Ceil(355.5) = " + Ceil(355.5)
+Print "Floor(355.5) = " + Floor(355.5)

+ 20 - 0
tests/framework/mod/brl/math/math_01.res

@@ -0,0 +1,20 @@
+Sqr(100) = 10.000000000000000
+Sin(90)  = 1.0000000000000000
+Sin(45)  = 0.70710678118654746
+Cos(90)  = 6.1232339957367660e-17
+Cos(45)  = 0.70710678118654757
+Tan(45)  = 0.99999999999999989
+Tan(100) = -5.6712818196177111
+ASin(90) = nan
+ASin(45) = nan
+ACos(90) = nan
+ACos(45) = nan
+ATan(45) = 88.726969979943291
+ATan(100)= 89.427061302316517
+ATan2(3, 4)= 36.869897645844020
+Tanh(33) = 1.0000000000000000
+Exp(15) = 3269017.3724721107
+Log(20) = 2.9957322735539909
+Log10(25) = 1.3979400086720377
+Ceil(355.5) = 356.00000000000000
+Floar(355.5) = 355.00000000000000

+ 185 - 7
type.bmx

@@ -81,6 +81,17 @@ Type TType
 	Global doublePointerPtrType:TDoublePtrPtrType=New TDoublePtrPtrType
 	Global longPointerPtrType:TLongPtrPtrType=New TLongPtrPtrType
 
+	Global byteVarPointerPtrType:TByteVarPtrPtrType=New TByteVarPtrPtrType
+	Global intVarPointerPtrType:TIntVarPtrPtrType=New TIntVarPtrPtrType
+	Global shortVarPointerPtrType:TShortVarPtrPtrType=New TShortVarPtrPtrType
+	Global floatVarPointerPtrType:TFloatVarPtrPtrType=New TFloatVarPtrPtrType
+	Global doubleVarPointerPtrType:TDoubleVarPtrPtrType=New TDoubleVarPtrPtrType
+	Global longVarPointerPtrType:TLongVarPtrPtrType=New TLongVarPtrPtrType
+
+	' these represent $z and $w respectively.
+	Global stringToCharPointerType:TStringCharPtrType=New TStringCharPtrType
+	Global stringToShortPointerType:TStringShortPtrType=New TStringShortPtrType
+
 	Rem
 	bbdoc: map to a pointer type
 	End Rem
@@ -119,13 +130,12 @@ Type TType
 		If TStringType(ty) Return stringVarPointerType
 		
 		' pointer pointer
-' TODO ??
-'		If TBytePtrType(ty) Return bytePointerPtrType
-'		If TIntPtrType(ty) Return intPointerPtrType
-'		If TShortPtrType(ty) Return shortPointerPtrType
-'		If TFloatPtrType(ty) Return floatPointerPtrType
-'		If TDoublePtrType(ty) Return doublePointerPtrType
-'		If TLongPtrType(ty) Return longPointerPtrType
+		If TBytePtrType(ty) Return byteVarPointerPtrType
+		If TIntPtrType(ty) Return intVarPointerPtrType
+		If TShortPtrType(ty) Return shortVarPointerPtrType
+		If TFloatPtrType(ty) Return floatVarPointerPtrType
+		If TDoublePtrType(ty) Return doubleVarPointerPtrType
+		If TLongPtrType(ty) Return longVarPointerPtrType
 		
 		Return Null
 	End Function
@@ -636,6 +646,27 @@ Type TByteVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TByteVarPtrPtrType Extends TVarPtrType
+
+	Method EqualsType:Int( ty:TType )
+		Return TByteVarPtrPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "Byte Ptr Var"
+	End Method
+
+End Type
+
 Type TShortPtrType Extends TPointerType
 
 	Method EqualsType:Int( ty:TType )
@@ -678,6 +709,27 @@ Type TShortVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TShortVarPtrPtrType Extends TVarPtrType
+
+	Method EqualsType:Int( ty:TType )
+		Return TShortVarPtrPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "Short Ptr Var"
+	End Method
+
+End Type
+
 Type TIntPtrType Extends TPointerType
 
 	Method EqualsType:Int( ty:TType )
@@ -720,6 +772,27 @@ Type TIntVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TIntVarPtrPtrType Extends TVarPtrType
+
+	Method EqualsType:Int( ty:TType )
+		Return TIntVarPtrPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "Int Ptr Var"
+	End Method
+
+End Type
+
 Type TFloatPtrType Extends TPointerType
 
 	Method EqualsType:Int( ty:TType )
@@ -762,6 +835,27 @@ Type TFloatVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TFloatVarPtrPtrType Extends TVarPtrType
+
+	Method EqualsType:Int( ty:TType )
+		Return TFloatVarPtrPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "Float Ptr Var"
+	End Method
+
+End Type
+
 Type TDoublePtrType Extends TPointerType
 
 	Method EqualsType:Int( ty:TType )
@@ -804,6 +898,27 @@ Type TDoubleVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TDoubleVarPtrPtrType Extends TVarPtrType
+
+	Method EqualsType:Int( ty:TType )
+		Return TDoubleVarPtrPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "Double Ptr Var"
+	End Method
+
+End Type
+
 Type TLongPtrType Extends TPointerType
 
 	Method EqualsType:Int( ty:TType )
@@ -846,6 +961,27 @@ Type TLongVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TLongVarPtrPtrType Extends TVarPtrType
+
+	Method EqualsType:Int( ty:TType )
+		Return TLongVarPtrPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "Long Ptr Var"
+	End Method
+
+End Type
+
 Type TStringPtrType Extends TPointerType
 
 	Method EqualsType:Int( ty:TType )
@@ -888,6 +1024,48 @@ Type TStringVarPtrType Extends TVarPtrType
 
 End Type
 
+Type TStringCharPtrType Extends TPointerType
+
+	Method EqualsType:Int( ty:TType )
+		Return TStringCharPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "$z"
+	End Method
+
+End Type
+
+Type TStringShortPtrType Extends TPointerType
+
+	Method EqualsType:Int( ty:TType )
+		Return TStringShortPtrType( ty )<>Null
+	End Method
+	
+	Method ExtendsType:Int( ty:TType )
+		If TObjectType( ty )
+			Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
+			Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
+			Return ctor And ctor.IsCtor()
+		EndIf
+		Return TPointerType( ty )<>Null
+	End Method
+	
+	Method ToString$()
+		Return "$w"
+	End Method
+
+End Type
+
 Type TFunctionPtrType Extends TPointerType
 
 	Field func:TFuncDecl