Skip to content

Commit

Permalink
Update docs of sum types and box. Update Makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
tylov committed Jan 10, 2025
1 parent 8b4ac26 commit 6fecb35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
CFLAGS ?= -std=c11 -Iinclude -MMD -O3 -Wpedantic -Wall -Wextra -Werror -Wno-missing-field-initializers
CXXFLAGS ?= -std=c++20 -Iinclude -O3 -MMD -Wall
LDFLAGS ?=
ifeq ($(CC:.exe=),tcc)
ifeq ($(CC),tcc)
AR_RCS ?= tcc -ar rcs
else
AR_RCS ?= ar rcs
Expand All @@ -24,11 +24,14 @@ RM_F ?= rm -f

ifeq ($(OS),Windows_NT)
DOTEXE := .exe
BUILDDIR := bld_Windows/$(CC:.exe=)
BUILDDIR := bld_Windows/$(CC)
else
# CC_VER := $(shell $(CC) -dumpversion | cut -f1 -d.)
BUILDDIR := bld_$(shell uname)/$(CC)
LDFLAGS += -lm
CFLAGS += -Wno-clobbered
ifneq ($(CC),clang)
CFLAGS += -Wno-clobbered
endif
endif

OBJ_DIR := $(BUILDDIR)
Expand All @@ -50,10 +53,15 @@ TEST_OBJS := $(TEST_SRCS:%.c=$(OBJ_DIR)/%.o)
TEST_DEPS := $(TEST_SRCS:%.c=$(OBJ_DIR)/%.d)
TEST_EXE := $(OBJ_DIR)/tests/test_all$(DOTEXE)

PROGRAMS := $(EX_EXES) $(TEST_EXE)

fast:
@$(MAKE) -j --no-print-directory all

all: $(LIB_PATH) $(EX_EXES) $(TEST_EXE)
all: $(PROGRAMS)
@echo

$(PROGRAMS): $(LIB_PATH)

clean:
@$(RM_F) $(LIB_OBJS) $(TEST_OBJS) $(EX_OBJS) $(LIB_DEPS) $(EX_DEPS) $(LIB_PATH) $(EX_EXES) $(TEST_EXE)
Expand Down Expand Up @@ -85,6 +93,7 @@ $(OBJ_DIR)/%$(DOTEXE): %.c $(LIB_PATH)

$(TEST_EXE): $(TEST_OBJS)
@printf "\r\e[2K%s" "$(CC) -o $@"
@echo
@$(CC) -o $@ $(TEST_OBJS) -s $(LDFLAGS) -L$(BUILDDIR) -l$(LIB_NAME)


Expand Down
8 changes: 6 additions & 2 deletions docs/algorithm_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,12 @@ The **c_when** statement is exhaustive. The compiler will give a warning if not
covered by **c_is** (requires `-Wall` or `-Wswitch` gcc/clang compiler flag). The first enum value
is deliberately set to 1 in order to easier detect non/zero-initialized variants.

* Note 1: The `x` variables in the synopsis are "auto" type declared/defined - see examples.
* Note 2: Sum types will not work in coroutines (i.e. if `cco_yield..` or `cco_await..` are used within `c_when` / `c_if_is` blocks).
* Note: The `x` variables in the synopsis are "auto" type declared/defined - see examples.
* Caveat 1: The use of `continue` inside a `c_when` (or `c_if_is`) block, when `c_when` is inside a loop will
not work as expected. It will only break out of the `c_when`-block. Instead, use `goto` to jump to the
end of the loop. `break` will break out of `c_when`, i.e. it behaves like `switch`.
* Caveat 2: Sum types will generally not work in coroutines because the `x` variable is local and therefore
will not be preserved across `cco_yield..` / `cco_await..`.

### Example 1

Expand Down
6 changes: 2 additions & 4 deletions docs/box_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ and `i_keydrop` macros specified. Use *box_X_clone(p)* to make a deep copy, whic
`i_keyclone` macro if defined. Note that a box set to NULL is consider uninitialized, and
cannot be e.g. cloned or dropped.

When declaring a container of **box** values, define `i_keypro` with the
box type instead of defining `i_key`. This will auto-set `i_keydrop`, `i_keyclone`, and `i_cmp` using
When declaring a container of **box** elements, define `i_keypro` with the
box type instead of defining `i_key`. This will auto-define `i_keydrop`, `i_keyclone`, and `i_cmp` using
functions defined by the specified **box**.

See similar c++ class [std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr) for a functional reference, or Rust [std::boxed::Box](https://doc.rust-lang.org/std/boxed/struct.Box.html)
Expand Down Expand Up @@ -37,8 +37,6 @@ See similar c++ class [std::unique_ptr](https://en.cppreference.com/w/cpp/memory
#define i_keyfrom <fn> // from-raw func.
#include "stc/box.h"
```
When defining a container with **box** elements, specify `#define i_keypro <box-type>` instead of `i_key`.
In the following, `X` is the value of `i_key` unless `i_type` is defined.
Unless `c_use_cmp` is defined, comparison between i_key's is not needed/available. Will then
compare the pointer addresses when used. Additionally, `c_no_clone` or `i_is_fwd` may be defined.
Expand Down

0 comments on commit 6fecb35

Please sign in to comment.