Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libqb refactor - Part 1 #453

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ all: $(EXE)
CLEAN_LIST :=
CLEAN_DEP_LIST :=

CXXFLAGS += -w -std=gnu++14
CXXFLAGS += -std=gnu++14

ifeq ($(OS),lnx)
CXXLIBS += -lGL -lGLU -lX11 -lpthread -ldl -lrt
Expand All @@ -154,7 +154,8 @@ ifeq ($(OS),osx)
endif
endif

QB_QBX_OBJ := $(PATH_INTERNAL_C)/qbx$(TEMP_ID).o
QB_QBX_SRC := $(PATH_INTERNAL_C)/qbx$(TEMP_ID).cpp
QB_QBX_OBJ := $(patsubst %.cpp,%.o,$(QB_QBX_SRC))

$(QB_QBX_OBJ): $(wildcard $(PATH_INTERNAL)/temp$(TEMP_ID)/*.txt)

Expand Down Expand Up @@ -389,6 +390,10 @@ EXE_OBJS := $(QBLIB) $(EXE_OBJS)
%.o: %.cpp
$(CXX) $(CXXFLAGS) $< -c -o $@

# qbx produces thousands of warnings due to passing NULL for every unused parameter
$(QB_QBX_OBJ): $(QB_QBX_SRC)
$(CXX) $(CXXFLAGS) $< -w -c -o $@

ifeq ($(OS),osx)
%.o: %.mm
$(CXX) $(CXXFLAGS) $< -c -o $@
Expand Down
146 changes: 3 additions & 143 deletions internal/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,126 +97,8 @@

# endif

# define QB_FALSE 0
# define QB_TRUE -1

# define QB_ERROR_NEXT_WITHOUT_FOR 1
# define QB_ERROR_SYNTAX_ERROR 2
# define QB_ERROR_RETURN_WITHOUT_GOSUB 3
# define QB_ERROR_OUT_OF_DATA 4
# define QB_ERROR_ILLEGAL_FUNCTION_CALL 5
# define QB_ERROR_OVERFLOW 6
# define QB_ERROR_OUT_OF_MEMORY 7
# define QB_ERROR_LABEL_NOT_DEFINED 8
# define QB_ERROR_SUBSCRIPT_OUT_OF_RANGE 9
# define QB_ERROR_DUPLICATE_DEFINITION 10
# define QB_ERROR_DIVISION_BY_ZERO 11
# define QB_ERROR_ILLEGAL_IN_DIRECT_MODE 12
# define QB_ERROR_TYPE_MISMATCH 13
# define QB_ERROR_OUT_OF_STRING_SPACE 14
# define QB_ERROR_STRING_FORMULA_TOO_COMPLEX 16
# define QB_ERROR_CANNOT_CONTINUE 17
# define QB_ERROR_FUNCTION_NOT_DEFINED 18
# define QB_ERROR_NO_RESUME 19
# define QB_ERROR_RESUME_WITHOUT_ERROR 20
# define QB_ERROR_DEVICE_TIMEOUT 24
# define QB_ERROR_DEVICE_FAULT 25
# define QB_ERROR_FOR_WITHOUT_NEXT 26
# define QB_ERROR_OUT_OF_PAPER 27
# define QB_ERROR_WHILE_WITHOUT_WEND 29
# define QB_ERROR_WEND_WITHOUT_WHILE 30
# define QB_ERROR_DUPLICATE_LABEL 33
# define QB_ERROR_SUBPROGRAM_NOT_DEFINED 35
# define QB_ERROR_ARGUMENT_COUNT_MISMATCH 37
# define QB_ERROR_ARRAY_NOT_DEFINED 38
# define QB_ERROR_VARIABLE_REQUIRED 40
# define QB_ERROR_FIELD_OVERFLOW 50
# define QB_ERROR_INTERNAL_ERROR 51
# define QB_ERROR_BAD_FILE_NAME_OR_NUMBER 52
# define QB_ERROR_FILE_NOT_FOUND 53
# define QB_ERROR_BAD_FILE_MODE 54
# define QB_ERROR_FILE_ALREADY_OPEN 55
# define QB_ERROR_FIELD_STATEMENT_ACTIVE 56
# define QB_ERROR_DEVICE_IO_ERROR 57
# define QB_ERROR_FILE_ALREADY_EXISTS 58
# define QB_ERROR_BAD_RECORD_LENGTH 59
# define QB_ERROR_DISK_FULL 61
# define QB_ERROR_INPUT_PAST_END_OF_FILE 62
# define QB_ERROR_BAD_RECORD_NUMBER 63
# define QB_ERROR_BAD_FILE_NAME 64
# define QB_ERROR_TOO_MANY_FILES 67
# define QB_ERROR_DEVICE_UNAVAILABLE 68
# define QB_ERROR_COMMUNICATION_BUFFER_OVERFLOW 69
# define QB_ERROR_PERMISSION_DENIED 70
# define QB_ERROR_DISK_NOT_READY 71
# define QB_ERROR_DISK_MEDIA_ERROR 72
# define QB_ERROR_FEATURE_UNAVAILABLE 73
# define QB_ERROR_RENAME_ACROSS_DISKS 74
# define QB_ERROR_PATH_FILE_ACCESS_ERROR 75
# define QB_ERROR_PATH_NOT_FOUND 76
# define QB_ERROR_OUT_OF_STACK_SPACE 256
# define QB_ERROR_OUT_OF_MEMORY_FATAL 257
# define QB_ERROR_INVALID_HANDLE 258
# define QB_ERROR_CANNOT_FIND_DYNAMIC_LIBRARY_FILE 259
# define QB_ERROR_FUNCTION_NOT_FOUND_IN_DYNAMIC_LIBRARY 260
# define QB_ERROR_FUNCTION_NOT_FOUND_IN_DYNAMIC_LIBRARY_261 261
# define QB_ERROR_GL_COMMAND_OUTSIDE_SUB_GL_SCOPE 270
# define QB_ERROR_END_SYSTEM_IN_SUB_GL_SCOPE 271
# define QB_ERROR_MEMORY_REGION_OUT_OF_RANGE 300
# define QB_ERROR_INVALID_SIZE 301
# define QB_ERROR_SOURCE_MEMORY_REGION_OUT_OF_RANGE 302
# define QB_ERROR_DESTINATION_MEMORY_REGION_OUT_OF_RANGE 303
# define QB_ERROR_BOTH_MEMORY_REGIONS_OUT_OF_RANGE 304
# define QB_ERROR_SOURCE_MEMORY_FREED 305
# define QB_ERROR_DESTINATION_MEMORY_FREED 306
# define QB_ERROR_MEMORY_ALREADY_FREED 307
# define QB_ERROR_MEMORY_HAS_BEEN_FREED 308
# define QB_ERROR_MEMORY_NOT_INITIALIZED 309
# define QB_ERROR_SOURCE_MEMORY_NOT_INITIALIZED 310
# define QB_ERROR_DESTINATION_MEMORY_NOT_INITIALIZED 311
# define QB_ERROR_BOTH_MEMORY_NOT_INITIALIZED 312
# define QB_ERROR_BOTH_MEMORY_FREED 313
# define QB_ERROR_ASSERT_FAILED 314
# define QB_ERROR_ASSERT_FAILED_WITH_DESCRIPTION 315
# define QB_ERROR_OUT_OF_MEMORY_FATAL_502 502
# define QB_ERROR_OUT_OF_MEMORY_FATAL_503 503
# define QB_ERROR_OUT_OF_MEMORY_FATAL_504 504
# define QB_ERROR_OUT_OF_MEMORY_FATAL_505 505
# define QB_ERROR_OUT_OF_MEMORY_FATAL_506 506
# define QB_ERROR_OUT_OF_MEMORY_FATAL_507 507
# define QB_ERROR_OUT_OF_MEMORY_FATAL_508 508
# define QB_ERROR_OUT_OF_MEMORY_FATAL_509 509
# define QB_ERROR_OUT_OF_MEMORY_FATAL_510 510
# define QB_ERROR_OUT_OF_MEMORY_FATAL_511 511
# define QB_ERROR_OUT_OF_MEMORY_FATAL_512 512
# define QB_ERROR_OUT_OF_MEMORY_FATAL_513 513
# define QB_ERROR_OUT_OF_MEMORY_FATAL_514 514
# define QB_ERROR_OUT_OF_MEMORY_FATAL_515 515
# define QB_ERROR_OUT_OF_MEMORY_FATAL_516 516
# define QB_ERROR_OUT_OF_MEMORY_FATAL_517 517
# define QB_ERROR_OUT_OF_MEMORY_FATAL_518 518

// QB64 string descriptor structure
struct qbs_field {
int32 fileno;
int64 fileid;
int64 size;
int64 offset;
};

struct qbs {
uint8 *chr; // a 32 bit pointer to the string's data
int32 len; // must be signed for comparisons against signed int32s
uint8 in_cmem; // set to 1 if in the conventional memory DBLOCK
uint16 *cmem_descriptor;
uint16 cmem_descriptor_offset;
uint32 listi; // the index in the list of strings that references it
uint8 tmp; // set to 1 if the string can be deleted immediately after being processed
uint32 tmplisti; // the index in the list of strings that references it
uint8 fixed; // fixed length string
uint8 readonly; // set to 1 if string is read only
qbs_field *field;
};
#include "error_handle.h"
#include "qbs.h"

struct img_struct {
void *lock_offset;
Expand Down Expand Up @@ -348,28 +230,6 @@ struct device_struct {
# define DEVICETYPE_KEYBOARD 2
# define DEVICETYPE_MOUSE 3

struct mem_block {
ptrszint offset;
ptrszint size;
int64 lock_id; // 64-bit key, must be present at lock's offset or memory region is invalid
ptrszint lock_offset; // pointer to lock
ptrszint type; // https://qb64phoenix.com/qb64wiki/index.php/MEM
ptrszint elementsize;
int32 image;
int32 sound;
};

struct mem_lock {
uint64 id;
int32 type; // required to know what action to take (if any) when a request is made to free the block
// 0=no security (eg. user defined block from _OFFSET)
// 1=C-malloc'ed block
// 2=image
// 3=sub/function scope block
// 4=array
// 5=sound
//---- type specific variables follow ----
void *offset; // used by malloc'ed blocks to free them
};
#include "mem.h"

#endif // INC_COMMON_CPP
Loading