Browse Source

Added StackAlloc built-in function.

woollybah 5 years ago
parent
commit
45252c1391
5 changed files with 48 additions and 2 deletions
  1. 4 0
      ctranslator.bmx
  2. 27 1
      expr.bmx
  3. 1 1
      options.bmx
  4. 12 0
      parser.bmx
  5. 4 0
      translator.bmx

+ 4 - 0
ctranslator.bmx

@@ -1619,6 +1619,10 @@ t:+"NULLNULLNULL"
 		InternalErr "TCTranslator.TransSizeOfExpr"
 	End Method
 
+	Method TransStackAllocExpr:String(expr:TStackAllocExpr)
+		Return "bbStackAlloc" + Bra(expr.expr.Trans())
+	End Method
+
 	'***** Expressions *****
 
 	Method TransConstExpr$( expr:TConstExpr )

+ 27 - 1
expr.bmx

@@ -3503,4 +3503,30 @@ Type TIdentEnumExpr Extends TExpr
 		Return value.Value()
 	End Method
 
-End Type
+End Type
+
+Type TStackAllocExpr Extends TBuiltinExpr
+
+	Method Create:TStackAllocExpr( expr:TExpr )
+		Self.id="stackalloc"
+		Self.expr=expr
+		Return Self
+	End Method
+
+	Method Semant:TExpr(options:Int = 0)
+		If exprType Return Self
+
+		expr = expr.SemantAndCast( New TSizeTType )
+		exprType = TType.MapToPointerType(New TByteType)
+		Return Self
+	End Method
+
+	Method Copy:TExpr()
+		Return New TStackAllocExpr.Create( CopyExpr(expr) )
+	End Method
+
+	Method ToString$()
+		Return "TStackAllocExpr("+expr.ToString()+")"
+	End Method
+
+End Type

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.113"
+Const version:String = "0.114"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1

+ 12 - 0
parser.bmx

@@ -1339,6 +1339,18 @@ Type TParser Extends TGenProcessor
 			ParseConstNumberType()
 
 			expr=New TInvokeSuperExpr.Create( id,ParseArgs( stmt ) )
+		Case "stackalloc"
+			NextToke
+			
+			' optional brackets
+			If CParse( "(" )
+				expr=ParseExpr()
+				Parse ")"
+				expr=New TStackAllocExpr.Create( expr )
+			Else
+				expr=ParseExpr()
+				expr=New TStackAllocExpr.Create( expr )
+			EndIf
 		Default
 			Select _tokeType
 			Case TOKE_IDENT

+ 4 - 0
translator.bmx

@@ -1337,6 +1337,7 @@ End Rem
 		If TChrExpr(expr) Return TransChrExpr(TChrExpr(expr))
 		If TLenExpr(expr) Return TransLenExpr(TLenExpr(expr))
 		If TSizeOfExpr(expr) Return TransSizeOfExpr(TSizeOfExpr(expr))
+		If TStackAllocExpr(expr) Return TransStackAllocExpr(TStackAllocExpr(expr))
 		Err "TODO : TransBuiltinExpr()"
 	End Method
 	
@@ -1351,6 +1352,9 @@ End Rem
 
 	Method TransSizeOfExpr:String(expr:TSizeOfExpr)
 	End Method
+
+	Method TransStackAllocExpr:String(expr:TStackAllocExpr)
+	End Method
 	
 	Method TransIdentTypeExpr:String(expr:TIdentTypeExpr) Abstract