builds as library

lib
Avril 4 years ago
parent b49d25b4dd
commit 366ec7f235
Signed by: flanchan
GPG Key ID: 284488987C31F630

3
.gitignore vendored

@ -2,3 +2,6 @@
sm-*
old-examples/
obj/
*.so
*.a

@ -37,10 +37,10 @@ OBJ = $(OBJ_C) $(OBJ_CXX)
# Phonies
.PHONY: release
release: | dirs $(PROJECT)-release
release: | dirs $(PROJECT).so $(PROJECT).a
.PHONY: debug
debug: | dirs $(PROJECT)-debug
debug: | dirs $(PROJECT)-debug.so $(PROJECT)-debug.a
# Targets
@ -53,22 +53,34 @@ obj/c/%.o: %.c
obj/cxx/%.o: %.cpp
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
$(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS)
$(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS)
$(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS)
$(PROJECT)-release: $(OBJ)
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
$(PROJECT).a: CFLAGS+= $(RELEASE_CFLAGS)
$(PROJECT).a: CXXFLAGS += $(RELEASE_CXXFLAGS)
$(PROJECT).a: $(OBJ)
ar -rcs $@ $^
$(STRIP) $@
$(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS)
$(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS)
$(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS)
$(PROJECT)-debug: $(OBJ)
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
$(PROJECT).so: CFLAGS+= -fPIC $(RELEASE_CFLAGS)
$(PROJECT).so: CXXFLAGS += -fPIC $(RELEASE_CXXFLAGS)
$(PROJECT).so: LDFLAGS += $(RELEASE_LDFLAGS)
$(PROJECT).so: $(OBJ)
gcc -shared $^ -o $@
$(STRIP) $@
$(PROJECT)-debug.a: CFLAGS+= $(DEBUG_CFLAGS)
$(PROJECT)-debug.a: CXXFLAGS += $(DEBUG_CXXFLAGS)
$(PROJECT)-debug.a: $(OBJ)
ar -rcs $@ $^
$(PROJECT)-debug.so: CFLAGS+= -fPIC $(DEBUG_CFLAGS)
$(PROJECT)-debug.so: CXXFLAGS += -fPIC $(DEBUG_CXXFLAGS)
$(PROJECT)-debug.so: LDFLAGS += $(DEBUG_LDFLAGS)
$(PROJECT)-debug.so: $(OBJ)
gcc -shared $^ -o $@
clean-rebuild:
rm -rf obj
clean: clean-rebuild
rm -f $(PROJECT)-{release,debug,pgo}
rm -f $(PROJECT){-debug,}.{so,a}

@ -35,6 +35,7 @@ inline T sm_output_assume_value(const sm_output& data)
// A generator method
struct sm_generator;
extern "C" {
/// Create a generator method with this function.
sm_generator* sm_generate(sm_gen_fun function);
/// Free a generator method
@ -43,3 +44,4 @@ void sm_free_generator(sm_generator* generator);
/// Returns false if the generator ends.
/// Any output value yielded from the generator is returned in the output pointer, unless the pointer is NULL, in which case the output is discarded.
bool sm_next(sm_generator** gen, sm_state* state, sm_output* output);
}

@ -1,12 +1,14 @@
#include <gen.h>
#define EX_C extern "C"
struct sm_generator
{
sm_generator* prev;
sm_gen_fun current;
};
sm_generator* sm_generate(sm_gen_fun function)
EX_C sm_generator* sm_generate(sm_gen_fun function)
{
auto gen = box<sm_generator>();
gen->prev = nullptr;
@ -14,7 +16,7 @@ sm_generator* sm_generate(sm_gen_fun function)
return gen;
}
void sm_free_generator(sm_generator* gen)
EX_C void sm_free_generator(sm_generator* gen)
{
auto g = unbox(gen);
if(g.prev)
@ -22,7 +24,7 @@ void sm_free_generator(sm_generator* gen)
}
// Returns false if the generator ends.
bool sm_next(sm_generator** gen, sm_state* state, _sm_user* output)
EX_C bool sm_next(sm_generator** gen, sm_state* state, _sm_user* output)
{
if( !(*gen)->current) return false;

Loading…
Cancel
Save