Преглед изворни кода

Fixes from macOS, first working build

Brian Fiete пре 6 година
родитељ
комит
67ee302451

+ 1 - 1
BeefBoot/BootApp.cpp

@@ -166,7 +166,7 @@ BootApp::BootApp()
 
 #ifdef BF_PLATFORM_WINDOWS
 	mTargetTriple = "x86_64-pc-windows-msvc";
-#elif defined BF_PLATFORM_OSX
+#elif defined BF_PLATFORM_MACOS
 	mTargetTriple = "x86_64-apple-macosx10.14.0";
 #else
 	mTargetTriple = "x86_64-unknown-linux-gnu";

Разлика између датотеке није приказан због своје велике величине
+ 11 - 0
BeefBuild/BeefProj.toml


+ 1 - 1
BeefRT/gperftools/src/tcconfig.h

@@ -10,7 +10,7 @@
 #endif
 #include "windows/config.h"
 #include "windows/gperftools/tcmalloc.h"
-#elif defined BF_PLATFORM_OSX
+#elif defined BF_PLATFORM_MACOS
 #include "osx/config.h"
 #include "osx/gperftools/tcmalloc.h"
 #elif defined BF_PLATFORM_IOS

+ 8 - 2
BeefRT/rt/Thread.cpp

@@ -76,8 +76,10 @@ bool Thread::GetIsThreadPoolThread()
 
 bool Thread::JoinInternal(int millisecondsTimeout)
 {
-	bool success = BfpThread_WaitFor(GetInternalThread()->mThreadHandle, millisecondsTimeout);
-	//((BFInternalThread*) thread)->ClrState(Threading::ThreadState::WaitSleepJoin);
+	auto internalThread = GetInternalThread();
+	if (internalThread == NULL)
+		return true;
+	bool success = BfpThread_WaitFor(internalThread->mThreadHandle, millisecondsTimeout);	
 	return success;
 }
 
@@ -176,6 +178,8 @@ void Thread::ManualThreadInit()
 {	
 #ifdef BF_THREAD_TLS
 	sCurrentThread = this;
+#else
+	BfpTLS_SetValue(BfTLSManager::sInternalThreadKey, this);
 #endif
 	
 	BfInternalThread* internalThread = SetupInternalThread();
@@ -207,6 +211,8 @@ void Thread::SetStackStart(void* ptr)
 void Thread::InternalFinalize()
 {
 	auto internalThread = GetInternalThread();
+	if (internalThread == NULL)
+		return;
 
 	bool wantsJoin = false;
 	//

+ 1 - 1
BeefTools/BeefMem/gperftools/src/tcconfig.h

@@ -3,7 +3,7 @@
 #ifdef BF_PLATFORM_WINDOWS
 #include "windows/config.h"
 #include "windows/gperftools/tcmalloc.h"
-#elif defined BF_PLATFORM_OSX
+#elif defined BF_PLATFORM_MACOS
 #include "osx/config.h"
 #include "osx/gperftools/tcmalloc.h"
 #elif defined BF_PLATFORM_IOS

+ 88 - 13
BeefySysLib/platform/darwin/DarwinCommon.cpp

@@ -27,6 +27,8 @@
 #include <cxxabi.h>
 #include <random>
 
+#include <mach-o/dyld.h>
+
 USING_NS_BF;
 
 
@@ -293,6 +295,48 @@ static Array<CrashInfoFunc> gCrashInfoFuncs;
 static String gCmdLine;
 static String gExePath;
 
+typedef struct _Unwind_Context _Unwind_Context;   // opaque
+
+typedef enum {
+  _URC_NO_REASON = 0,
+  _URC_OK = 0,
+  _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
+  _URC_FATAL_PHASE2_ERROR = 2,
+  _URC_FATAL_PHASE1_ERROR = 3,
+  _URC_NORMAL_STOP = 4,
+  _URC_END_OF_STACK = 5,
+  _URC_HANDLER_FOUND = 6,
+  _URC_INSTALL_CONTEXT = 7,
+  _URC_CONTINUE_UNWIND = 8,
+  _URC_FAILURE = 9
+} _Unwind_Reason_Code;
+
+typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, void *);
+extern "C" _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
+extern "C" uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
+
+static String gUnwindExecStr;
+static int gUnwindIdx = 0;
+
+static _Unwind_Reason_Code UnwindHandler(struct _Unwind_Context* context, void* ref)
+{   
+    gUnwindIdx++;
+    if (gUnwindIdx < 2)
+        return _URC_NO_REASON;
+
+    dl_info dyldInfo;
+    void* addr = (void*)_Unwind_GetIP(context);
+    gUnwindExecStr += StrFormat(" %p", addr);
+    return _URC_NO_REASON;
+}
+
+static bool FancyBacktrace()
+{
+    gUnwindExecStr += StrFormat("atos -p %d", getpid());    
+    _Unwind_Backtrace(&UnwindHandler, NULL);
+    return system(gUnwindExecStr.c_str()) == 0;
+}
+
 static void Crashed()
 {
     //
@@ -315,18 +359,21 @@ static void Crashed()
         fprintf(stderr, "%s", debugDump.c_str());
     }
 
-    void* array[64];
-    size_t size;
-    char** strings;
-    size_t i;
+    if (!FancyBacktrace())
+    {
+        void* array[64];
+        size_t size;
+        char** strings;
+        size_t i;
 
-    size = backtrace(array, 64);
-    strings = backtrace_symbols(array, size);
+        size = backtrace(array, 64);
+        strings = backtrace_symbols(array, size);
 
-    for (i = 0; i < size; i++)
-        fprintf(stderr, "%s\n", strings[i]);
+        for (i = 0; i < size; i++)
+            fprintf(stderr, "%s\n", strings[i]);
 
-    free(strings);
+        free(strings);
+    }
 
     exit(1);
 }
@@ -372,11 +419,12 @@ BFP_EXPORT void BFP_CALLTYPE BfpSystem_Init(int version, BfpSystemInitFlags flag
 }
 
 BFP_EXPORT void BFP_CALLTYPE BfpSystem_SetCommandLine(int argc, char** argv)
-{
+{ 
     char* relPath = argv[0];
 
     char* cwd = getcwd(NULL, 0);
     gExePath = GetAbsPath(relPath, cwd);
+    
     free(cwd);
 
     for (int i = 0; i < argc; i++)
@@ -501,6 +549,19 @@ BFP_EXPORT void BFP_CALLTYPE BfpSystem_GetCommandLine(char* outStr, int* inOutSt
 
 BFP_EXPORT void BFP_CALLTYPE BfpSystem_GetExecutablePath(char* outStr, int* inOutStrSize, BfpSystemResult* outResult)
 {
+    //printf("Setting BfpSystem_GetExecutablePath %s %p\n", gExePath.c_str(), &gExePath);
+
+    if (gExePath.IsEmpty())
+    {
+        char path[4096];
+        uint32_t size = sizeof(path);
+        if (_NSGetExecutablePath(path, &size) == 0)
+            gExePath = path;
+
+        // When when running with a './file', we end up with an annoying '/./' in our path
+        gExePath.Replace("/./", "/");        
+    }
+
     TryStringOut(gExePath, outStr, inOutStrSize, (BfpResult*)outResult);
 }
 
@@ -1101,6 +1162,8 @@ BFP_EXPORT bool BFP_CALLTYPE BfpThread_WaitFor(BfpThread* thread, int waitMS)
         return true;
     }
 
+    if (thread == NULL)
+        BF_FATAL("Invalid thread with non-infinite wait");
     return BfpEvent_WaitFor(thread->mDoneEvent, waitMS);    
 }
 
@@ -1505,12 +1568,14 @@ BFP_EXPORT BfpFile* BFP_CALLTYPE BfpFile_Create(const char* inName, BfpFileCreat
         if ((createFlags & BfpFileCreateFlag_Pipe) != 0)
         {
             name = "/tmp/" + name;
+
             if ((createKind == BfpFileCreateKind_CreateAlways) ||
                 (createKind == BfpFileCreateKind_CreateIfNotExists))
             {
                 for (int pass = 0; pass < 2; pass++)
                 {
-                    int result = mknod(name.c_str(), S_IFIFO | ALLPERMS, 0);
+                    int result = mknod(name.c_str(), S_IFIFO | 0666, 0);
+
                     if (result == 0)
                         break;
 
@@ -1821,10 +1886,20 @@ BFP_EXPORT void BFP_CALLTYPE BfpFile_Copy(const char* oldPath, const char* newPa
         return;
     }
 
-    fd_to = open(newPath, O_WRONLY | O_CREAT | O_EXCL, 0666);
+    int flags = O_WRONLY | O_CREAT;
+    if (copyKind == BfpFileCopyKind_IfNotExists)
+        flags |= O_EXCL;
+
+    fd_to = open(newPath, flags, 0666);
     if (fd_to < 0)
     {
-        OUTRESULT(BfpFileResult_AlreadyExists);
+        if (errno == EEXIST)
+        {
+            OUTRESULT(BfpFileResult_AlreadyExists);
+            goto out_error;
+        }
+
+        OUTRESULT(BfpFileResult_UnknownError);
         goto out_error;
     }
 

+ 4 - 9
BeefySysLib/platform/darwin/DarwinCommon.h

@@ -58,8 +58,6 @@ typedef int16_t int16;
 typedef int8_t int8;
 typedef unsigned int uint;
 
-#define BF_PLATFORM_LINUX
-#define BF_PLATFORM_NAME "BF_PLATFORM_LINUX"
 //#define BF_PLATFORM_SDL
 
 #define NOP
@@ -67,13 +65,8 @@ typedef unsigned int uint;
 //#define BF_NOTHROW noexcept
 #define BF_NOTHROW
 
-#ifdef BF64
-typedef int64 intptr;
-typedef uint64 uintptr;
-#else
-typedef int32 intptr;
-typedef uint32 uintptr;
-#endif
+typedef intptr_t intptr;
+typedef uintptr_t uintptr;
 
 typedef wchar_t* BSTR;
 typedef int HRESULT;
@@ -85,6 +78,8 @@ typedef int32 LONG;
 typedef pthread_key_t BFTlsKey;
 typedef pthread_t BF_THREADID;
 typedef pthread_t BF_THREADHANDLE;
+
+#define BF_HAS_TLS_DECLSPEC
 #define BF_TLS_DECLSPEC thread_local
 
 //:int64 abs(int64 val);

+ 1 - 0
BeefySysLib/platform/linux/BFPlatform.h

@@ -5,6 +5,7 @@
 #include "LinuxCommon.h"
 
 #define BF_PLATFORM_LINUX
+#define BF_PLATFORM_NAME "BF_PLATFORM_LINUX"
 
 #define BF_IMPORT extern "C"
 

+ 61 - 52
BeefySysLib/platform/linux/LinuxCommon.cpp

@@ -28,7 +28,6 @@
 
 USING_NS_BF;
 
-
 struct BfpPipeInfo
 {
 	String mPipePath;
@@ -431,7 +430,7 @@ BFP_EXPORT void BFP_CALLTYPE BfpSystem_Init(int version, BfpSystemInitFlags flag
 }
 
 BFP_EXPORT void BFP_CALLTYPE BfpSystem_SetCommandLine(int argc, char** argv)
-{
+{    
 	char* relPath = argv[0];
 
 	char* cwd = getcwd(NULL, 0);
@@ -1565,7 +1564,7 @@ BFP_EXPORT BfpFile* BFP_CALLTYPE BfpFile_Create(const char* inName, BfpFileCreat
 			{
 				for (int pass = 0; pass < 2; pass++)
 				{
-					int result = mknod(name.c_str(), S_IFIFO | ALLPERMS, 0);
+					int result = mknod(name.c_str(), S_IFIFO | 0666, 0);
 					if (result == 0)
 						break;
 
@@ -1865,64 +1864,74 @@ BFP_EXPORT void BFP_CALLTYPE BfpFile_SetAttributes(const char* path, BfpFileAttr
 
 BFP_EXPORT void BFP_CALLTYPE BfpFile_Copy(const char* oldPath, const char* newPath, BfpFileCopyKind copyKind, BfpFileResult* outResult)
 {
-	int fd_to, fd_from;
-	char buf[4096];
-	ssize_t nread;	
+    int fd_to, fd_from;
+    char buf[4096];
+    ssize_t nread;  
 
-	fd_from = open(oldPath, O_RDONLY);
-	if (fd_from < 0)
-	{
-		OUTRESULT(BfpFileResult_NotFound);
-		return;
-	}
+    fd_from = open(oldPath, O_RDONLY);
+    if (fd_from < 0)
+    {
+        OUTRESULT(BfpFileResult_NotFound);
+        return;
+    }
 
-	fd_to = open(newPath, O_WRONLY | O_CREAT | O_EXCL, 0666);
-	if (fd_to < 0)
-	{
-		OUTRESULT(BfpFileResult_AlreadyExists);
-		goto out_error;
-	}
+    int flags = O_WRONLY | O_CREAT;
+    if (copyKind == BfpFileCopyKind_IfNotExists)
+        flags |= O_EXCL;
 
-	while (nread = read(fd_from, buf, sizeof buf), nread > 0)
-	{
-		char *out_ptr = buf;
-		ssize_t nwritten;
+    fd_to = open(newPath, flags, 0666);
+    if (fd_to < 0)
+    {
+        if (errno == EEXIST)
+        {
+            OUTRESULT(BfpFileResult_AlreadyExists);
+            goto out_error;
+        }
 
-		do {
-			nwritten = write(fd_to, out_ptr, nread);
+        OUTRESULT(BfpFileResult_UnknownError);
+        goto out_error;
+    }
 
-			if (nwritten >= 0)
-			{
-				nread -= nwritten;
-				out_ptr += nwritten;
-			}
-			else if (errno != EINTR)
-			{
-				OUTRESULT(BfpFileResult_UnknownError);
-				goto out_error;
-			}
-		} while (nread > 0);
-	}
+    while (nread = read(fd_from, buf, sizeof buf), nread > 0)
+    {
+        char *out_ptr = buf;
+        ssize_t nwritten;
 
-	if (nread == 0)
-	{
-		if (close(fd_to) < 0)
-		{
-			fd_to = -1;
-			OUTRESULT(BfpFileResult_UnknownError);
-			goto out_error;
-		}
-		close(fd_from);
+        do {
+            nwritten = write(fd_to, out_ptr, nread);
 
-		/* Success! */
-		OUTRESULT(BfpFileResult_Ok);
-		return;
-	}
+            if (nwritten >= 0)
+            {
+                nread -= nwritten;
+                out_ptr += nwritten;
+            }
+            else if (errno != EINTR)
+            {
+                OUTRESULT(BfpFileResult_UnknownError);
+                goto out_error;
+            }
+        } while (nread > 0);
+    }
+
+    if (nread == 0)
+    {
+        if (close(fd_to) < 0)
+        {
+            fd_to = -1;
+            OUTRESULT(BfpFileResult_UnknownError);
+            goto out_error;
+        }
+        close(fd_from);
+
+        /* Success! */
+        OUTRESULT(BfpFileResult_Ok);
+        return;
+    }
 
 out_error:
-	close(fd_from);
-	if (fd_to >= 0)
-		close(fd_to);	
+    close(fd_from);
+    if (fd_to >= 0)
+        close(fd_to);   
 }
 
 BFP_EXPORT void BFP_CALLTYPE BfpFile_Rename(const char* oldPath, const char* newPath, BfpFileResult* outResult)

+ 0 - 2
BeefySysLib/platform/linux/LinuxCommon.h

@@ -55,8 +55,6 @@ typedef int16_t int16;
 typedef int8_t int8;
 typedef unsigned int uint;
 
-#define BF_PLATFORM_LINUX
-#define BF_PLATFORM_NAME "BF_PLATFORM_LINUX"
 //#define BF_PLATFORM_SDL
 
 #define NOP

+ 2 - 1
BeefySysLib/platform/osx/BFPlatform.h

@@ -5,7 +5,8 @@
 #include "../darwin/DarwinCommon.h"
 #include <string>
 
-#define BF_PLATFORM_OSX
+#define BF_PLATFORM_MACOS
+#define BF_PLATFORM_NAME "BF_PLATFORM_MACOS"
 
 #define BF_IMPORT extern "C"
 


+ 9 - 5
IDE/src/BuildContext.bf

@@ -171,9 +171,15 @@ namespace IDE
 
 		    //String error = scope String();
 
-			bool isExe = project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib;
+		    TestManager.ProjectInfo testProjectInfo = null;
+			if (gApp.mTestManager != null)
+				testProjectInfo = gApp.mTestManager.GetProjectInfo(project);
+
+			bool isExe = (project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib) || (testProjectInfo != null);
 			if (isExe)
 			{
+				CopyLibFiles(targetPath, workspaceOptions, options);
+
 			    String linkLine = scope String(isDebug ? "-g " : "-g -O2 "); //-O2 -Rpass=inline 
 																 //(doClangCPP ? "-lc++abi " : "") +
 			    
@@ -459,9 +465,9 @@ namespace IDE
 				String toPath = scope String();
 				Path.GetDirectoryPath(targetPath, toPath);
 				toPath.Append("/", dllName);
-				if (File.CopyIfNewer(fromPath, toPath) case .Err)
+				if (File.CopyIfNewer(fromPath, toPath) case .Err(let err))
 				{
-					gApp.OutputLine("Failed to copy lib file {0}", fromPath);
+					gApp.OutputLine("Failed to copy lib file '{0}' to '{1}'", fromPath, toPath);
 					return false;
 				}
 				return true;
@@ -1048,8 +1054,6 @@ namespace IDE
 		        return true;
 		    }
 
-			CopyLibFiles(targetPath, workspaceOptions, options);
-
 		    String objectsArg = scope String();
 			var argBuilder = scope IDEApp.ArgBuilder(objectsArg, workspaceOptions.mToolsetType != .GNU);
 		    for (var bfFileName in bfFileNames)

+ 5 - 1
IDE/src/IDEApp.bf

@@ -7178,7 +7178,11 @@ namespace IDE
 				}
 
 				if (!startInfo.mFileName.IsEmpty)
-                	OutputLine("Executing: {0} {1}", startInfo.mFileName, showArgs);
+                {
+                	OutputLine("Executing: {0} {1}", startInfo.mFileName, showArgs);                	
+                	if ((mVerbosity >= .Diagnostic) && (useArgsFile != .None))
+                		OutputLine("Arg file contents: {0}", args);
+                }
 				else
 					OutputLine("Executing: {0}", showArgs);
 			}

+ 2 - 2
IDE/src/SpellChecker.bf

@@ -45,13 +45,13 @@ namespace IDE
 			scope AutoBeefPerf("SpellChecker.Init");
 
 			mLangPath = new String(langPath);
+            
             mNativeSpellChecker = SpellChecker_Create(langPath);
 			if (mNativeSpellChecker == null)
 				return .Err;
             
 			String fileName = scope String();
-			GetUserDirectFileName(fileName);
-			//if (File.ReadLines(fileName) case .Ok(var lineEnumeratorVal))
+			GetUserDirectFileName(fileName);			
 
 			let streamReader = scope StreamReader();
 			if (streamReader.Open(fileName) case .Ok)

+ 1 - 0
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -17551,6 +17551,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfType* resultType, BfIRValue convL
 		case BfBinaryOp_RightShift:			
 			mResult = BfTypedValue(mModule->mBfIRBuilder->CreateShr(convLeftValue, convRightValue, resultType->IsSigned()), resultType);			
 			return;
+		default: break;
 		}
 	}
 	

+ 27 - 11
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -8028,10 +8028,15 @@ bool BfModule::CanImplicitlyCast(BfTypedValue typedVal, BfType* toType, BfCastFl
 					}
 					else if (toType->IsSigned())
 					{
-						int64 minVal = -(1LL << (8 * toType->mSize - 1));
-						int64 maxVal = (1LL << (8 * toType->mSize - 1)) - 1;
-						if ((srcVal >= minVal) && (srcVal <= maxVal))
-							return true;
+                        if (toType->mSize == 8) // int64
+                            return true;
+                        else
+                        {
+                            int64 minVal = -(1LL << (8 * toType->mSize - 1));
+                            int64 maxVal = (1LL << (8 * toType->mSize - 1)) - 1;
+                            if ((srcVal >= minVal) && (srcVal <= maxVal))
+                                return true;
+                        }
 					}
 					else if (toType->mSize == 8) // ulong
 					{
@@ -9155,12 +9160,17 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
 					}
 					else if (toType->IsSigned())
 					{
-						int64 minVal = -(1LL << (8 * toType->mSize - 1));
-						int64 maxVal = (1LL << (8 * toType->mSize - 1)) - 1;
-						if ((srcVal >= minVal) && (srcVal <= maxVal))
-							explicitCast = true;
+                        if (toType->mSize == 8) // int64
+                            explicitCast = true;
+                        else
+                        {
+                            int64 minVal = -(1LL << (8 * toType->mSize - 1));
+                            int64 maxVal = (1LL << (8 * toType->mSize - 1)) - 1;
+                            if ((srcVal >= minVal) && (srcVal <= maxVal))
+                                explicitCast = true;
+                        }
 					}
-					else if (toType->mSize == 8) // ulong
+					else if (toType->mSize == 8) // uint64
 					{
 						if (srcVal >= 0)
 							explicitCast = true;
@@ -9703,10 +9713,16 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
 
 	if ((castFlags & BfCastFlags_SilentFail) == 0)
 	{
-		const char* errStr = explicitCast ?
+		if (mIgnoreErrors)
+			return BfIRValue();
+
+		const char* errStrF = explicitCast ?
 			"Unable to cast '%s' to '%s'" :
 			"Unable to implicitly cast '%s' to '%s'";
-		auto error = Fail(StrFormat(errStr, TypeToString(typedVal.mType).c_str(), TypeToString(toType).c_str()), srcNode);
+
+		String errStr = StrFormat(errStrF, TypeToString(typedVal.mType).c_str(), TypeToString(toType).c_str());
+		printf("Err: %s\n", errStr.c_str());
+		auto error = Fail(errStr, srcNode);
 		if ((error != NULL) && (srcNode != NULL))
 		{
 			if ((mCompiler->IsAutocomplete()) && (mCompiler->mResolvePassData->mAutoComplete->CheckFixit((srcNode))))

+ 3 - 1
IDEHelper/Tests/BeefSpace.toml

@@ -14,7 +14,9 @@ ConfigSelections = {TestsB = {Config = "Test"}}
 
 [Configs.Test.Linux64]
 IntermediateType = "ObjectAndIRCode"
-COptimizationLevel = "O2"
+ConfigSelections = {TestsB = {Config = "Test"}}
+
+[Configs.Test.macOS]
 ConfigSelections = {TestsB = {Config = "Test"}}
 
 [Configs.TestFail.Win64]

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
bin/build.sh


Неке датотеке нису приказане због велике количине промена