瀏覽代碼

Merge branch 'master' of https://github.com/felixbrendel/ftb

master
Felix Brendel 5 年之前
父節點
當前提交
ae09f3b78e
共有 5 個檔案被更改,包括 55 行新增36 行删除
  1. +1
    -0
      macros.hpp
  2. +9
    -0
      platform.hpp
  3. +20
    -18
      print.hpp
  4. +6
    -4
      testing.hpp
  5. +19
    -14
      types.hpp

+ 1
- 0
macros.hpp 查看文件

@@ -96,6 +96,7 @@ expands to:
goto TOKENPASTE2(finished, __LINE__); \ goto TOKENPASTE2(finished, __LINE__); \
} \ } \
else TOKENPASTE2(body,__LINE__): else TOKENPASTE2(body,__LINE__):
;




/** /**


+ 9
- 0
platform.hpp 查看文件

@@ -0,0 +1,9 @@
#pragma once

#if defined(_WIN32) || defined(_WIN64)
// #pragma message ("Compiling for Windows")
#define FTB_WINDOWS
#else
// #pragma message ("Compiling for Linux")
#define FTB_LINUX
#endif

+ 20
- 18
print.hpp 查看文件

@@ -8,6 +8,7 @@
#include <string.h> #include <string.h>


#include "hashmap.hpp" #include "hashmap.hpp"
#include "hooks.hpp"


FILE* ftb_stdout = stdout; FILE* ftb_stdout = stdout;


@@ -443,27 +444,28 @@ auto print_str_line(FILE* f, char* str) -> s32 {
return print_to_file(f, "%.*s", length, str); return print_to_file(f, "%.*s", length, str);
} }


void deinit_printer() {
printer_map.dealloc();
type_map.dealloc();
}

void init_printer() { void init_printer() {
color_stack.alloc(); color_stack.alloc();
printer_map.alloc(); printer_map.alloc();
type_map.alloc(); type_map.alloc();


register_printer("u32", print_u32, Printer_Function_Type::_32b);
register_printer("u64", print_u64, Printer_Function_Type::_64b);
register_printer("bool", print_bool, Printer_Function_Type::_32b);
register_printer("s64", print_s64, Printer_Function_Type::_64b);
register_printer("s32", print_s32, Printer_Function_Type::_32b);
register_printer("f32", print_flt, Printer_Function_Type::_flt);
register_printer("f64", print_flt, Printer_Function_Type::_flt);
register_printer("->char", print_str, Printer_Function_Type::_ptr);
register_printer("->", print_ptr, Printer_Function_Type::_ptr);
register_printer("color<", print_color_start, Printer_Function_Type::_ptr);
register_printer(">color", print_color_end, Printer_Function_Type::_void);
register_printer("->Str", print_Str, Printer_Function_Type::_ptr);
register_printer("->char_line", print_str_line, Printer_Function_Type::_ptr);
system_shutdown_hook << [](){
color_stack.dealloc();
printer_map.dealloc();
type_map.dealloc();
};

register_printer("u32", print_u32, Printer_Function_Type::_32b);
register_printer("u64", print_u64, Printer_Function_Type::_64b);
register_printer("bool", print_bool, Printer_Function_Type::_32b);
register_printer("s64", print_s64, Printer_Function_Type::_64b);
register_printer("s32", print_s32, Printer_Function_Type::_32b);
register_printer("f32", print_flt, Printer_Function_Type::_flt);
register_printer("f64", print_flt, Printer_Function_Type::_flt);
register_printer("->char", print_str, Printer_Function_Type::_ptr);
register_printer("->", print_ptr, Printer_Function_Type::_ptr);
register_printer("color<", print_color_start, Printer_Function_Type::_ptr);
register_printer(">color", print_color_end, Printer_Function_Type::_void);
register_printer("->Str", print_Str, Printer_Function_Type::_ptr);
register_printer("->char_line", print_str_line, Printer_Function_Type::_ptr);
} }

+ 6
- 4
testing.hpp 查看文件

@@ -1,3 +1,5 @@
#include "./types.hpp"

typedef s32 testresult; typedef s32 testresult;


#define epsilon 2.2204460492503131E-16 #define epsilon 2.2204460492503131E-16
@@ -84,8 +86,8 @@ typedef s32 testresult;
for(s32 i = -1; i < 70; ++i) \ for(s32 i = -1; i < 70; ++i) \
fputs((i%3==1)? "." : " ", stdout); \ fputs((i%3==1)? "." : " ", stdout); \
fputs(console_red "failed\n" console_normal, stdout); \ fputs(console_red "failed\n" console_normal, stdout); \
if(error) { \
free(error); \
error = nullptr; \
if(error) { \
free(error); \
error = nullptr; \
} \ } \
} \
}

+ 19
- 14
types.hpp 查看文件

@@ -1,5 +1,6 @@
#pragma once #pragma once


#include "platform.hpp"
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>


@@ -22,24 +23,33 @@ typedef wchar_t path_char;
typedef char path_char; typedef char path_char;
#endif #endif


struct String {
struct StringSlice {
const char* data;
u64 length; u64 length;
char* data;
}; };


struct StringSlice {
struct String {
char* data;
u64 length; u64 length;
const char* data;
}; };



inline auto heap_copy_c_string(const char* str) -> char* {
#ifdef FTB_WINDOWS
return _strdup(str);
#else
return strdup(str);
#endif
}

inline auto make_heap_string(const char* str) -> String { inline auto make_heap_string(const char* str) -> String {
String ret; String ret;
ret.length = strlen(str); ret.length = strlen(str);
ret.data = _strdup(str);
ret.data = heap_copy_c_string(str);
return ret; return ret;
} }


inline const StringSlice make_static_string(const char* str) {
inline auto make_static_string(const char* str) -> const StringSlice {
StringSlice ret; StringSlice ret;
ret.length = strlen(str); ret.length = strlen(str);
ret.data = str; ret.data = str;
@@ -50,26 +60,21 @@ auto inline string_equal(const char* input, const char* check) -> bool {
return strcmp(input, check) == 0; return strcmp(input, check) == 0;
} }


template <typename Str>
auto inline string_equal(Str str, const char* check) -> bool {
auto inline string_equal(StringSlice str, const char* check) -> bool {
if (str.length != strlen(check)) if (str.length != strlen(check))
return false; return false;
return strncmp(str.data, check, str.length) == 0; return strncmp(str.data, check, str.length) == 0;
} }


template <typename Str>
auto inline string_equal(const char* check, Str str) -> bool {
auto inline string_equal(const char* check, StringSlice str) -> bool {
if (str.length != strlen(check)) if (str.length != strlen(check))
return false; return false;
return strncmp(str.data, check, str.length) == 0; return strncmp(str.data, check, str.length) == 0;
} }


template <typename StrA, typename StrB>
auto inline string_equal(StrA str1, StrB str2) -> bool {
auto inline string_equal(StringSlice str1, StringSlice str2) -> bool {
if (str1.length != str2.length) if (str1.length != str2.length)
return false; return false;


return strncmp(str1.data, str2.data, str2.length) == 0; return strncmp(str1.data, str2.data, str2.length) == 0;
} }

template auto string_equal(StringSlice str1, StringSlice str2) -> bool;

Loading…
取消
儲存