From cdccd7d9124c01e537788065dfce777293df1c32 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 10 Sep 2017 15:14:41 -0400 Subject: [PATCH] zip coroutine functions --- platform_all/4ed_coroutine_functions.cpp | 76 ++++++++++++++++++++++++ platform_linux/linux_4ed.cpp | 59 +----------------- platform_mac/mac_4ed.cpp | 5 +- platform_win32/win32_4ed.cpp | 57 +----------------- 4 files changed, 83 insertions(+), 114 deletions(-) create mode 100644 platform_all/4ed_coroutine_functions.cpp diff --git a/platform_all/4ed_coroutine_functions.cpp b/platform_all/4ed_coroutine_functions.cpp new file mode 100644 index 00000000..154267cb --- /dev/null +++ b/platform_all/4ed_coroutine_functions.cpp @@ -0,0 +1,76 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 10.09.2017 + * + * Mac C++ layer for 4coder + * + */ + +// TOP + +#if !defined(FRED_COROUTINE_FUNCTIONS_CPP) +#define FRED_COROUTINE_FUNCTIONS_CPP + +// +// Coroutine +// + +internal +Sys_Create_Coroutine_Sig(system_create_coroutine){ + Coroutine *coroutine = coroutine_system_alloc(&coroutines); + Coroutine_Head *result = 0; + if (coroutine != 0){ + coroutine_set_function(coroutine, func); + result = &coroutine->head; + } + return(result); +} + +internal +Sys_Launch_Coroutine_Sig(system_launch_coroutine){ + Coroutine *coroutine = (Coroutine*)head; + coroutine->head.in = in; + coroutine->head.out = out; + + Coroutine *active = coroutine->sys->active; + Assert(active != 0); + coroutine_launch(active, coroutine); + Assert(active == coroutine->sys->active); + + Coroutine_Head *result = &coroutine->head; + if (coroutine->state == CoroutineState_Dead){ + coroutine_system_free(&coroutines, coroutine); + result = 0; + } + return(result); +} + +Sys_Resume_Coroutine_Sig(system_resume_coroutine){ + Coroutine *coroutine = (Coroutine*)head; + coroutine->head.in = in; + coroutine->head.out = out; + + Coroutine *active = coroutine->sys->active; + Assert(active != 0); + coroutine_resume(active, coroutine); + Assert(active == coroutine->sys->active); + + Coroutine_Head *result = &coroutine->head; + if (coroutine->state == CoroutineState_Dead){ + coroutine_system_free(&coroutines, coroutine); + result = 0; + } + return(result); +} + +Sys_Yield_Coroutine_Sig(system_yield_coroutine){ + Coroutine *coroutine = (Coroutine*)head; + coroutine_yield(coroutine); +} + +#endif + +// BOTTOM + + diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 70aa7d9a..5f1b9636 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -304,6 +304,8 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ linuxvars.keep_running = false; } +#include "4ed_coroutine_functions.cpp" + // // Clipboard // @@ -314,63 +316,6 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ XSetSelectionOwner(linuxvars.XDisplay, linuxvars.atom_CLIPBOARD, linuxvars.XWindow, CurrentTime); } -// -// Coroutine -// - -internal -Sys_Create_Coroutine_Sig(system_create_coroutine){ - Coroutine *coroutine = coroutine_system_alloc(&coroutines); - Coroutine_Head *result = 0; - if (coroutine != 0){ - coroutine_set_function(coroutine, func); - result = &coroutine->head; - } - return(result); -} - -internal -Sys_Launch_Coroutine_Sig(system_launch_coroutine){ - Coroutine *coroutine = (Coroutine*)head; - coroutine->head.in = in; - coroutine->head.out = out; - - Coroutine *active = coroutine->sys->active; - Assert(active != 0); - coroutine_launch(active, coroutine); - Assert(active == coroutine->sys->active); - - Coroutine_Head *result = &coroutine->head; - if (coroutine->state == CoroutineState_Dead){ - coroutine_system_free(&coroutines, coroutine); - result = 0; - } - return(result); -} - -Sys_Resume_Coroutine_Sig(system_resume_coroutine){ - Coroutine *coroutine = (Coroutine*)head; - coroutine->head.in = in; - coroutine->head.out = out; - - Coroutine *active = coroutine->sys->active; - Assert(active != 0); - coroutine_resume(active, coroutine); - Assert(active == coroutine->sys->active); - - Coroutine_Head *result = &coroutine->head; - if (coroutine->state == CoroutineState_Dead){ - coroutine_system_free(&coroutines, coroutine); - result = 0; - } - return(result); -} - -Sys_Yield_Coroutine_Sig(system_yield_coroutine){ - Coroutine *coroutine = (Coroutine*)head; - coroutine_yield(coroutine); -} - // // CLI // diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 9573350d..9700bab6 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -91,6 +91,8 @@ OSX_Vars osx; //////////////////////////////// +#include "4ed_coroutine_functions.cpp" + // // Clipboard // @@ -108,7 +110,8 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ } memcpy(osx.clipboard_space, str.str, str.size); osx.clipboard_space[str.size] = 0; - string = osx.clipboard_space; + string = osx.clipboard_space + ; } osx_post_to_clipboard(string); } diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index f8a94740..78d0de08 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -262,62 +262,7 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ win32vars.send_exit_signal = true; } -// -// Coroutines -// - -internal -Sys_Create_Coroutine_Sig(system_create_coroutine){ - Coroutine *coroutine = coroutine_system_alloc(&coroutines); - Coroutine_Head *result = 0; - if (coroutine != 0){ - coroutine_set_function(coroutine, func); - result = &coroutine->head; - } - return(result); -} - -internal -Sys_Launch_Coroutine_Sig(system_launch_coroutine){ - Coroutine *coroutine = (Coroutine*)head; - coroutine->head.in = in; - coroutine->head.out = out; - - Coroutine *active = coroutine->sys->active; - Assert(active != 0); - coroutine_launch(active, coroutine); - Assert(active == coroutine->sys->active); - - Coroutine_Head *result = &coroutine->head; - if (coroutine->state == CoroutineState_Dead){ - coroutine_system_free(&coroutines, coroutine); - result = 0; - } - return(result); -} - -Sys_Resume_Coroutine_Sig(system_resume_coroutine){ - Coroutine *coroutine = (Coroutine*)head; - coroutine->head.in = in; - coroutine->head.out = out; - - Coroutine *active = coroutine->sys->active; - Assert(active != 0); - coroutine_resume(active, coroutine); - Assert(active == coroutine->sys->active); - - Coroutine_Head *result = &coroutine->head; - if (coroutine->state == CoroutineState_Dead){ - coroutine_system_free(&coroutines, coroutine); - result = 0; - } - return(result); -} - -Sys_Yield_Coroutine_Sig(system_yield_coroutine){ - Coroutine *coroutine = (Coroutine*)head; - coroutine_yield(coroutine); -} +#include "4ed_coroutine_functions.cpp" // // Clipboard