'basic.sbp

#_core

' Unicodeが不安定な間の暫定対応
#define __STRING_IS_NOT_ALWAYS_UNICODE


#ifndef _INC_BASIC
#define _INC_BASIC

Sub _System_InitDllGlobalVariables()	'dummy
End Sub

Const QWORD_MAX = &HFFFFFFFFFFFFFFFF As QWord
Const INT64_MAX = &H7FFFFFFFFFFFFFFF As Int64
Const INT64_MIN = &H8000000000000000 As Int64

Const DWORD_MAX = &HFFFFFFFF As DWord
Const LONG_MAX = &H7FFFFFFF As Long
Const LONG_MIN = &H80000000 As Long

Const WORD_MAX = &HFFFF As Word
Const INTEGER_MAX = &H7FFF As Integer
Const INTEGER_MIN = &H8000 As Integer

Const BYTE_MAX = &HFF As Byte
Const SBYTE_MAX = &H7F As SByte
Const SBYTE_MIN = &H80 As SByte

Const DBL_MAX = 1.7976931348623158e+308
Const DBL_MIN = 2.2250738585072014e-308

Const FLT_MAX = 3.402823466e+38
Const FLT_MIN = 1.175494351e-38

'-------------
' Basic Types
'-------------

'Char
'Byte
'Integer
'Word
'Long
'TypeDef Int32 = Long
'DWord
'Int64
'QWord
'Single
'Double

TypeDef Int16 = Integer
TypeDef Int8 = SByte

' Boolena型の定数
Const True = 1 As Boolean
Const False = 0 As Boolean

' 文字型の定義
TypeDef WCHAR = Word
#ifdef UNICODE
TypeDef Char = WCHAR
#else
TypeDef Char = SByte
#endif

' 文字型
#ifdef UNICODE
TypeDef Char = Word
#else
TypeDef Char = SByte
#endif


'------------------
' Types of pointer
'------------------
TypeDef BytePtr =   *Byte
TypeDef WordPtr =   *Word
TypeDef DWordPtr =  *DWord
TypeDef SinglePtr = *Single
TypeDef DoublePtr = *Double

Sub SetPointer(pPtr As VoidPtr, p As VoidPtr)
	Set_LONG_PTR(pPtr, p As LONG_PTR)
End Sub

Function GetPointer(pPtr As VoidPtr) As VoidPtr
	GetPointer = Get_LONG_PTR(pPtr) As VoidPtr
End Function

Sub Set_LONG_PTR(pPtr As VoidPtr, lpData As LONG_PTR)
#ifdef _WIN64
	SetQWord(pPtr,lpData)
#else
	SetDWord(pPtr,lpData)
#endif
End Sub

Function Get_LONG_PTR(pPtr As VoidPtr) As LONG_PTR
#ifdef _WIN64
	Get_LONG_PTR = GetQWord(pPtr)
#else
	Get_LONG_PTR = GetDWord(pPtr)
#endif
End Function

Sub SetChar(p As *Char, c As Char)
	p[0] = c
End Sub

Function GetChar(p As *Char) As Char
	GetChar = p[0]
End Function


'--------------------------
' Specify elements number
'--------------------------
Const ELM(n) = ((n) - 1)

#require <windows.sbp>
#require <crt.sbp>


Sub _System_GetEip()	'dummy
End Sub


Dim _System_CriticalSection As CRITICAL_SECTION
Dim _System_hProcessHeap As HANDLE

Sub _System_StartupProgram()
	'Unsafe

		'この関数はアプリケーションの起動時にシステムからコールバックされます

		InitializeCriticalSection(_System_CriticalSection)

		_System_hProcessHeap=HeapCreate(HEAP_GENERATE_EXCEPTIONS,0,0)

		' GC管理オブジェクトを初期化
		_System_CGarbageCollection.Initialize()

		' 動的型情報を生成
		ActiveBasic.Core._System_TypeBase.Initialize()

		'Initialize static variables
		_System_InitStaticLocalVariables()

		'TODO:
		' Set current thread priority
		'Dim thread = Thread.CurrentThread()
		'thread.Priority = ThreadPriority.Normal

	'End Unsafe
End Sub

Sub _System_EndProgram()
	'Unsafe

		_System_Call_Destructor_of_GlobalObject()

		' GC管理オブジェクトを破棄
		_System_pGC->Finish()
'		_System_free( _System_pGC )

		DeleteCriticalSection(_System_CriticalSection)

		HeapDestroy( _System_hProcessHeap )

	'End Unsafe
End Sub


#require <system\built_in.ab>
#require <system\string.sbp>
#require <system\debug.sbp>
#require <system\gc.sbp>
#require <system\enum.sbp>
#require <system\exception.ab>

#require <Classes\index.ab>


#require <basic\function.sbp>
#require <basic\command.sbp>


#endif '_INC_BASIC
