<commit_before>Strict

Public

' Preprocessor related:
#SIZEOF_IMPLEMENTED = True

#If LANG = "cpp"
	#SIZEOF_NATIVE = True
#End

' Imports:
'Import vector

' Constant variable(s):

' Standard type sizes (In bytes):
#If Not SIZEOF_NATIVE
	Const SizeOf_Integer:Int = 4 ' 8
	
	#If CPP_DOUBLE_PRECISION_FLOATS And LANG = "cpp" And TARGET <> "win8"
		Const SizeOf_FloatingPoint:Int = 8
	#Else
		Const SizeOf_FloatingPoint:Int = 4
	#End
	
	Const SizeOf_Boolean:Int = 1
#Else
	Const SizeOf_Integer:Int = SizeOf(0)
	Const SizeOf_FloatingPoint:Int = SizeOf(0.0)
	Const SizeOf_Boolean:Int = SizeOf(False)
#End

' External bindings:
#If SIZEOF_NATIVE
	Extern
	
	' Functions (Native):
	Function SizeOf:Int(I:Int)="(int)sizeof"
	Function SizeOf:Int(F:Float)="(int)sizeof"
	Function SizeOf:Int(B:Bool)="(int)sizeof"
	
	Public
#End

' Functions (Monkey):
Function IntSize:Int(Size:Int)
	If (Size > 1) Then
		If (Size > 4) Then
			Return 8
		Elseif (Size < 4) Then
			Return 2
		Else
			Return 4
		Endif
	Endif
	
	Return 1
End

#If Not SIZEOF_NATIVE
	Function SizeOf:Int(I:Int)
		Return SizeOf_Integer
	End
	
	Function SizeOf:Int(F:Float)
		Return SizeOf_FloatingPoint
	End
	
	Function SizeOf:Int(B:Bool)
		Return SizeOf_Boolean
	End
#End

Function SizeOf:Int(S:String)
	' Make the input-string upper-case.
	S = S.ToUpper()
	
	If (S.Find("INT") <> -1) Then
		Return SizeOf(0)
	Elseif (S.Find("FLOAT") <> -1) Then
		Return SizeOf(0.0)
	Elseif (S.Find("BOOL") <> -1) Then
		Return SizeOf(False)
	#Rem
		Elseif (S.Find("VEC") <> -1) Then
			Return Max(Int(S), 1)
	#End
	Endif
	
	' Return the default response.
	Return 1
End<commit_msg>Added support for strings, sizes in bits, and non-standard byte sizes. Fixed problems with constants using function calls. Not the best of methods, but it gets the job done.<commit_after>Strict

Public

' Preprocessor related:
#SIZEOF_IMPLEMENTED = True

#If LANG = "cpp"
	#SIZEOF_NATIVE = True
	
	#If TARGET <> "win8"
		#SIZEOF_NORMAL_CPP_TARGET = True
	#End
#End

' Imports:
'Import vector

' Global & Constant variable(s):

' Standard type sizes (In bytes):
Const SizeOf_Octet:Int = 1
Const SizeOf_Octet_InBits:Int = 8

Const SizeOf_Byte:Int = SizeOf_Octet
Const SizeOf_Byte_InBits:Int = SizeOf_Octet_InBits

#If Not SIZEOF_NATIVE
	Const SizeOf_Integer:Int = 4 * SizeOf_Octet ' 8
	
	#If CPP_DOUBLE_PRECISION_FLOATS And SIZEOF_NORMAL_CPP_TARGET
		Const SizeOf_FloatingPoint:Int = 8 * SizeOf_Octet
	#Else
		Const SizeOf_FloatingPoint:Int = 4 * SizeOf_Octet
	#End
	
	Const SizeOf_Boolean:Int = SizeOf_Byte ' 1
#Else
	' Global variable(s) (External):
	
	' Modifying these values is considered non-standard, and should not be attempted:
	Extern
	
	Global SizeOf_Integer:Int = "(int)sizeof(int)"
	Global SizeOf_FloatingPoint:Int = "(int)sizeof(Float)"
	Global SizeOf_Boolean:Int = "(int)sizeof(bool)"
	
	Public
#End

#If SIZEOF_NATIVE And LANG = "cpp" And SIZEOF_NORMAL_CPP_TARGET
	' Global variable(s) (External):
	
	Extern
	
	' Modifying the value of this variable is considered non-standard, and should not be attempted.
	Global SizeOf_Char:Int = "(int)sizeof(Char)"
	
	Public
#Else
	Const SizeOf_Char:Int = SizeOf_Byte ' 1
#End

Global SizeOf_Integer_InBits:Int = SizeOf_Integer * SizeOf_Octet_InBits
Global SizeOf_FloatingPoint_InBits:Int = SizeOf_FloatingPoint * SizeOf_Octet_InBits
Global SizeOf_Boolean_InBits:Int = SizeOf_Boolean * SizeOf_Byte_InBits ' SizeOf_Octet_InBits

' External bindings:
#If SIZEOF_NATIVE
	Extern
	
	' Functions (Native):
	Function SizeOf:Int(I:Int)="(int)sizeof"
	Function SizeOf:Int(F:Float)="(int)sizeof"
	Function SizeOf:Int(B:Bool)="(int)sizeof"
	
	Public
#End

' Functions (Monkey):
Function IntSize:Int(Size:Int)
	If (Size > 1) Then
		If (Size > 4) Then
			Return 8
		Elseif (Size < 4) Then
			Return 2
		Else
			Return 4
		Endif
	Endif
	
	Return 1
End

#If Not SIZEOF_NATIVE
	Function SizeOf:Int(I:Int)
		Return SizeOf_Integer
	End
	
	Function SizeOf:Int(F:Float)
		Return SizeOf_FloatingPoint
	End
	
	Function SizeOf:Int(B:Bool)
		Return SizeOf_Boolean
	End
#End

Function SizeOf:Int(S:String, IsString:Bool=False)
	' Make the input-string upper-case.
	S = S.ToUpper()
	
	If (Not IsString) Then
		If (S.Find("INT") <> -1) Then
			Return SizeOf(0)
		Elseif (S.Find("FLOAT") <> -1) Then
			Return SizeOf(0.0)
		Elseif (S.Find("BOOL") <> -1) Then
			Return SizeOf(False)
		#Rem
			Elseif (S.Find("VEC") <> -1) Then
				Return Max(Int(S), 1)
		#End
		
		#Rem
			Elseif (S.Find("BYTE")) Then
				Return SizeOf_Byte
		#End
		Endif
	Endif
	
	' Return the default response.
	Return SizeOf_Char * S.Length()
End

Function InBits:Int(I:Int)
	Return SizeOf_Integer_InBits
End

Function InBits:Int(F:Float)
	Return SizeOf_FloatingPoint_InBits
End

Function InBits:Int(B:Bool)
	Return SizeOf_Boolean_InBits
End

Function InBits:Int(S:String, IsString:Bool=False)
	Local Output:= SizeOf(S, IsString)
	
	If (Not IsString) Then
		Return Output * SizeOf_Octet_InBits
	Endif
	
	Return Output * SizeOf_Char_InBits
End
{'fraction_non_alphanumeric': 0.10357359176256814, 'fraction_numerical': 0.009892994144962648, 'mean_word_length': 4.585118376550169, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677865', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1865, 'n_words': 486}