Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Apr 10, 2019
2 parents 9d401c2 + 058fc7f commit d3a3c3d
Show file tree
Hide file tree
Showing 39 changed files with 1,773 additions and 1,921 deletions.
42 changes: 39 additions & 3 deletions IL2C.Core/ILConveters/NewConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public override Func<IExtractContext, string[]> Apply(
type.FriendlyName);
}

if (!(ctor.Parameters.Length == 2) &&
(ctor.Parameters[0].TargetType.IsObjectType) &&
(ctor.Parameters[0].TargetType.IsIntPtrType))
if ((ctor.Parameters.Length != 3) ||
!ctor.Parameters[1].TargetType.IsObjectType ||
!ctor.Parameters[2].TargetType.IsIntPtrType)
{
throw new InvalidProgramSequenceException(
"Invalid delegate constructor: Location={0}, Method={1}",
Expand All @@ -135,6 +135,42 @@ public override Func<IExtractContext, string[]> Apply(
};
}

// Specialized the thread type:
if (type.UniqueName == "System.Threading.Thread")
{
if (!type.IsClass || !type.IsSealed)
{
throw new InvalidProgramSequenceException(
"Invalid thread type: Location={0}, Method={1}",
codeInformation.RawLocation,
type.FriendlyName);
}

if ((ctor.Parameters.Length != 2) ||
((ctor.Parameters[1].TargetType.UniqueName != "System.Threading.ThreadStart") &&
(ctor.Parameters[1].TargetType.UniqueName != "System.Threading.ParameterizedThreadStart")))
{
throw new InvalidProgramSequenceException(
"Invalid thread constructor: Location={0}, Method={1}",
codeInformation.RawLocation,
ctor.FriendlyName);
}

return extractContext =>
{
var parameterString = Utilities.GetGivenParameterDeclaration(
pairParameters.Skip(1).ToArray(), extractContext, codeInformation);

return new[]
{
string.Format(
"{0} = il2c_new_thread({1})",
extractContext.GetSymbolName(thisSymbol),
parameterString)
};
};
}

var overloadIndex = ctor.OverloadIndex;

return extractContext =>
Expand Down
39 changes: 39 additions & 0 deletions IL2C.Runtime/include/System/AppDomain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef System_AppDomain_H__
#define System_AppDomain_H__

#pragma once

#include <il2c.h>

#ifdef __cplusplus
extern "C" {
#endif

/////////////////////////////////////////////////////////////
// System.AppDomain

typedef struct System_AppDomain System_AppDomain;

typedef System_Object_VTABLE_DECL__ System_AppDomain_VTABLE_DECL__;

struct System_AppDomain
{
System_AppDomain_VTABLE_DECL__* vptr0__;
System_UnhandledExceptionEventHandler* unhandledExceptionEventHandler__;
};

#define System_AppDomain_VTABLE__ System_Object_VTABLE__

IL2C_DECLARE_RUNTIME_TYPE(System_AppDomain);

extern void System_AppDomain_add_UnhandledException(System_AppDomain* this__, System_UnhandledExceptionEventHandler* value);
extern void System_AppDomain_remove_UnhandledException(System_AppDomain* this__, System_UnhandledExceptionEventHandler* value);
extern /* static */ System_AppDomain* System_AppDomain_get_CurrentDomain(void);

extern void il2c_invoke_unhandled_exception_on_the_current_domain__(System_Object* exception);

#ifdef __cplusplus
}
#endif

#endif
35 changes: 35 additions & 0 deletions IL2C.Runtime/include/System/EventArgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef System_EventArgs_H__
#define System_EventArgs_H__

#pragma once

#include <il2c.h>

#ifdef __cplusplus
extern "C" {
#endif

/////////////////////////////////////////////////////////////
// System.EventArgs

typedef struct System_EventArgs System_EventArgs;
typedef struct System_Object_VTABLE_DECL__ System_EventArgs_VTABLE_DECL__;

struct System_EventArgs
{
System_EventArgs_VTABLE_DECL__* vptr0__;
};

#define System_EventArgs_VTABLE__ System_Object_VTABLE__

IL2C_DECLARE_RUNTIME_TYPE(System_EventArgs);

static inline void System_EventArgs__ctor(System_EventArgs* this__)
{
}

#ifdef __cplusplus
}
#endif

#endif
4 changes: 2 additions & 2 deletions IL2C.Runtime/include/System/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef const struct
// IL2C_REF_HEADER
void* pNext; // Const string will not collect by GC, so this link is always NULL.
IL2C_RUNTIME_TYPE type; // Const string always fixed runtime type pointer from "System_String_RUNTIME_TYPE__."
interlock_t characteristic; // Const string always marked (IL2C_CHARACTERISTIC_CONST)
interlock_t characteristic; // Const string always marked (IL2C_CHARACTERISTIC_CONST | IL2C_CHARACTERISTIC_INITIALIZED)

// Instance's vptr
System_String_VTABLE_DECL__* vptr0__; // Const string always fixed VTable pointer from "System_String_VTABLE__."
Expand All @@ -105,7 +105,7 @@ typedef const struct

#define IL2C_CONST_STRING(name, string_body) \
static IL2C_CONST_STRING_DECL name##_CONST_STRING__ = { \
NULL, il2c_typeof(System_String), /* IL2C_CHARACTERISTIC_CONST */ (interlock_t)0x80000000UL, &System_String_VTABLE__, string_body }; \
NULL, il2c_typeof(System_String), /* IL2C_CHARACTERISTIC_CONST | IL2C_CHARACTERISTIC_INITIALIZED */ (interlock_t)0xc0000000UL, &System_String_VTABLE__, string_body }; \
System_String* const name = ((System_String*)&(name##_CONST_STRING__.vptr0__))

#ifdef __cplusplus
Expand Down
20 changes: 9 additions & 11 deletions IL2C.Runtime/include/System/Threading/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,29 @@ typedef System_Object_VTABLE_DECL__ System_Threading_Thread_VTABLE_DECL__;
struct System_Threading_Thread
{
System_Threading_Thread_VTABLE_DECL__* vptr0__;

/* IL2C_THREAD_CONTEXT: Important field order! */
IL2C_EXECUTION_FRAME* pFrame__;
IL2C_EXCEPTION_FRAME* pTopUnwindTarget__;
volatile intptr_t rawHandle__;
int32_t id__;

System_Delegate* start__;
System_Object* parameter__;
};

extern System_Threading_Thread_VTABLE_DECL__ System_Threading_Thread_VTABLE__;

IL2C_DECLARE_RUNTIME_TYPE(System_Threading_Thread);

extern void System_Threading_Thread__ctor(System_Threading_Thread* this__, System_Threading_ThreadStart* start);
extern void System_Threading_Thread__ctor_1(System_Threading_Thread* this__, System_Threading_ParameterizedThreadStart* start);
extern void System_Threading_Thread_Finalize(System_Threading_Thread* this__);
extern void System_Threading_Thread_Start(System_Threading_Thread* this__);
extern void System_Threading_Thread_Start_2(System_Threading_Thread* this__, System_Object* parameter);
extern void System_Threading_Thread_Join(System_Threading_Thread* this__);
#define System_Threading_Thread_get_ManagedThreadId(this__) ((int32_t)(this__->id__))
extern int32_t System_Threading_Thread_get_ManagedThreadId(System_Threading_Thread* this__);
extern /* static */ System_Threading_Thread* System_Threading_Thread_get_CurrentThread(void);
extern /* static */ void System_Threading_Thread_Sleep(int millisecondsTimeout);

#if defined(IL2C_USE_LINE_INFORMATION)
extern System_Threading_Thread* il2c_new_thread__(System_Delegate* start, const char* pFile, int line);
#define il2c_new_thread(start) il2c_new_thread__(start, __FILE__, __LINE__)
#else
extern System_Threading_Thread* il2c_new_thread__(System_Delegate* start);
#define il2c_new_thread(start) il2c_new_thread__(start)
#endif

#ifdef __cplusplus
}
#endif
Expand Down
39 changes: 39 additions & 0 deletions IL2C.Runtime/include/System/UnhandledExceptionEventArgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef System_UnhandledExceptionEventArgs_H__
#define System_UnhandledExceptionEventArgs_H__

#pragma once

#include <il2c.h>

#ifdef __cplusplus
extern "C" {
#endif

/////////////////////////////////////////////////////////////
// System.UnhandledExceptionEventArgs

typedef struct System_UnhandledExceptionEventArgs System_UnhandledExceptionEventArgs;
typedef struct System_EventArgs_VTABLE_DECL__ System_UnhandledExceptionEventArgs_VTABLE_DECL__;

struct System_UnhandledExceptionEventArgs
{
System_UnhandledExceptionEventArgs_VTABLE_DECL__* vptr0__;
System_Object* exception__;
bool isTerminating__;
};

#define System_UnhandledExceptionEventArgs_VTABLE__ System_EventArgs_VTABLE__

IL2C_DECLARE_RUNTIME_TYPE(System_UnhandledExceptionEventArgs);

extern void System_UnhandledExceptionEventArgs__ctor(
System_UnhandledExceptionEventArgs* this__, System_Object* exception, bool isTerminating);

extern System_Object* System_UnhandledExceptionEventArgs_get_ExceptionObject(System_UnhandledExceptionEventArgs* this__);
extern bool System_UnhandledExceptionEventArgs_get_IsTerminating(System_UnhandledExceptionEventArgs* this__);

#ifdef __cplusplus
}
#endif

#endif
30 changes: 30 additions & 0 deletions IL2C.Runtime/include/System/UnhandledExceptionEventHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef System_UnhandledExceptionEventHandler_H__
#define System_UnhandledExceptionEventHandler_H__

#pragma once

#include <il2c.h>

#ifdef __cplusplus
extern "C" {
#endif

/////////////////////////////////////////////////////////////
// System.UnhandledExceptionEventHandler

typedef System_MulticastDelegate System_UnhandledExceptionEventHandler;

typedef System_MulticastDelegate_VTABLE_DECL__ System_UnhandledExceptionEventHandler_VTABLE_DECL__;

#define System_UnhandledExceptionEventHandler_VTABLE__ System_MulticastDelegate_VTABLE__

IL2C_DECLARE_RUNTIME_TYPE(System_UnhandledExceptionEventHandler);

extern void System_UnhandledExceptionEventHandler_Invoke(
System_UnhandledExceptionEventHandler* this__, System_Object* sender, System_UnhandledExceptionEventArgs* e);

#ifdef __cplusplus
}
#endif

#endif
21 changes: 13 additions & 8 deletions IL2C.Runtime/include/il2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" {
#define il2c_assume__(expr) __assume(expr)
#define il2c_likely__(expr) (expr)
#define il2c_unlikely__(expr) (expr)
#define il2c_noreturn__ __declspec(noreturn)

#elif defined(__GNUC__)

Expand All @@ -35,6 +36,7 @@ extern "C" {
#define il2c_assume__(expr) do { if (!(expr)) __builtin_unreachable(); } while (0)
#define il2c_likely__(expr) __builtin_expect(!!(expr), 1)
#define il2c_unlikely__(expr) __builtin_expect(!!(expr), 0)
#define il2c_noreturn__ __attribute__((noreturn))

#else

Expand All @@ -43,6 +45,7 @@ extern "C" {
#define il2c_assume__(expr) ((void)0)
#define il2c_likely__(expr) (expr)
#define il2c_unlikely__(expr) (expr)
#define il2c_noreturn__

#endif

Expand Down Expand Up @@ -223,10 +226,10 @@ extern void il2c_register_static_fields(/* IL2C_STATIC_FIELDS* */ volatile void*
///////////////////////////////////////////////////////
// Basic exceptions

extern void il2c_throw_nullreferenceexception__(void);
extern void il2c_throw_invalidcastexception__(void);
extern void il2c_throw_indexoutofrangeexception__(void);
extern void il2c_throw_formatexception__(void);
extern il2c_noreturn__ void il2c_throw_nullreferenceexception__(void);
extern il2c_noreturn__ void il2c_throw_invalidcastexception__(void);
extern il2c_noreturn__ void il2c_throw_indexoutofrangeexception__(void);
extern il2c_noreturn__ void il2c_throw_formatexception__(void);

///////////////////////////////////////////////////////
// The basis types
Expand Down Expand Up @@ -275,6 +278,10 @@ typedef void* untyped_ptr;
#include "System/Threading/ThreadStart.h"
#include "System/Threading/ParameterizedThreadStart.h"
#include "System/Threading/Thread.h"
#include "System/EventArgs.h"
#include "System/UnhandledExceptionEventArgs.h"
#include "System/UnhandledExceptionEventHandler.h"
#include "System/AppDomain.h"

// Independent types for IL2C core.
#include "System/Console.h"
Expand Down Expand Up @@ -319,11 +326,11 @@ extern void* il2c_unbox__(
/////////////////////////////////////////////////
// Exception special functions

extern void il2c_throw__(System_Exception* ex);
extern il2c_noreturn__ void il2c_throw__(System_Exception* ex);
#define il2c_throw(ex) \
il2c_throw__((System_Exception*)ex)
extern il2c_noreturn__ void il2c_rethrow(void);

extern void il2c_rethrow(void);
extern void il2c_link_unwind_target__(IL2C_EXCEPTION_FRAME* pUnwindTarget, IL2C_EXCEPTION_FILTER filter);
extern void il2c_unlink_unwind_target__(IL2C_EXCEPTION_FRAME* pUnwindTarget);

Expand All @@ -344,13 +351,11 @@ extern void il2c_unlink_unwind_target__(IL2C_EXCEPTION_FRAME* pUnwindTarget);
break

#define il2c_catch(nestedIndex, filteredNumber, symbolName) \
il2c_assert(0); /* reached if don't emit leave. */ \
case filteredNumber : \
il2c_assert(unwind_target_##nestedIndex##__.ex != NULL); \
symbolName = unwind_target_##nestedIndex##__.ex;

#define il2c_finally(nestedIndex) \
il2c_assert(0); /* reached if don't emit leave. */ \
} \
break; \
} \
Expand Down
1 change: 1 addition & 0 deletions IL2C.Runtime/src/Private/arduino_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern void il2c_free(void* p);

#define il2c_iand(pDest, newValue) __sync_fetch_and_and((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ior(pDest, newValue) __sync_fetch_and_or((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ixor(pDest, newValue) __sync_fetch_and_xor((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_iinc(pDest) __sync_add_and_fetch((interlock_t*)(pDest), 1)
#define il2c_idec(pDest) __sync_sub_and_fetch((interlock_t*)(pDest), 1)
#define il2c_ixchg(pDest, newValue) __sync_lock_test_and_set((interlock_t*)(pDest), (interlock_t)(newValue))
Expand Down
1 change: 1 addition & 0 deletions IL2C.Runtime/src/Private/gcc_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern void il2c_free(void* p);

#define il2c_iand(pDest, newValue) __sync_fetch_and_and((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ior(pDest, newValue) __sync_fetch_and_or((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ixor(pDest, newValue) __sync_fetch_and_xor((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_iinc(pDest) __sync_add_and_fetch((interlock_t*)(pDest), 1)
#define il2c_idec(pDest) __sync_sub_and_fetch((interlock_t*)(pDest), 1)
#define il2c_ixchg(pDest, newValue) __sync_lock_test_and_set((interlock_t*)(pDest), (interlock_t)(newValue))
Expand Down
1 change: 1 addition & 0 deletions IL2C.Runtime/src/Private/gcc_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern wchar_t* il2c_u64tow(uint64_t value, wchar_t* buffer, int radix);

#define il2c_iand(pDest, newValue) __sync_fetch_and_and((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ior(pDest, newValue) __sync_fetch_and_or((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ixor(pDest, newValue) __sync_fetch_and_xor((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_iinc(pDest) __sync_add_and_fetch((interlock_t*)(pDest), 1)
#define il2c_idec(pDest) __sync_sub_and_fetch((interlock_t*)(pDest), 1)
#define il2c_ixchg(pDest, newValue) __sync_lock_test_and_set((interlock_t*)(pDest), (interlock_t)(newValue))
Expand Down
1 change: 1 addition & 0 deletions IL2C.Runtime/src/Private/msvc_uefi.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern void il2c_free(void* p);

#define il2c_iand(pDest, newValue) _InterlockedAnd((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ior(pDest, newValue) _InterlockedOr((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ixor(pDest, newValue) _InterlockedXor((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_iinc(pDest) _InterlockedIncrement((interlock_t*)(pDest))
#define il2c_idec(pDest) _InterlockedDecrement((interlock_t*)(pDest))
#define il2c_ixchg(pDest, newValue) _InterlockedExchange((interlock_t*)(pDest), (interlock_t)(newValue))
Expand Down
1 change: 1 addition & 0 deletions IL2C.Runtime/src/Private/msvc_wdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern "C" {

#define il2c_iand(pDest, newValue) _InterlockedAnd((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ior(pDest, newValue) _InterlockedOr((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ixor(pDest, newValue) _InterlockedXor((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_iinc(pDest) _InterlockedIncrement((interlock_t*)(pDest))
#define il2c_idec(pDest) _InterlockedDecrement((interlock_t*)(pDest))
#define il2c_ixchg(pDest, newValue) _InterlockedExchange((interlock_t*)(pDest), (interlock_t)(newValue))
Expand Down
1 change: 1 addition & 0 deletions IL2C.Runtime/src/Private/msvc_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extern wchar_t* il2c_u64tow(uint64_t value, wchar_t* buffer, int radix);

#define il2c_iand(pDest, newValue) _InterlockedAnd((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ior(pDest, newValue) _InterlockedOr((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_ixor(pDest, newValue) _InterlockedXor((interlock_t*)(pDest), (interlock_t)(newValue))
#define il2c_iinc(pDest) _InterlockedIncrement((interlock_t*)(pDest))
#define il2c_idec(pDest) _InterlockedDecrement((interlock_t*)(pDest))
#define il2c_ixchg(pDest, newValue) _InterlockedExchange((interlock_t*)(pDest), (interlock_t)(newValue))
Expand Down
Loading

0 comments on commit d3a3c3d

Please sign in to comment.