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-* sm-*
old-examples/ old-examples/
obj/ obj/
*.so
*.a

@ -37,10 +37,10 @@ OBJ = $(OBJ_C) $(OBJ_CXX)
# Phonies # Phonies
.PHONY: release .PHONY: release
release: | dirs $(PROJECT)-release release: | dirs $(PROJECT).so $(PROJECT).a
.PHONY: debug .PHONY: debug
debug: | dirs $(PROJECT)-debug debug: | dirs $(PROJECT)-debug.so $(PROJECT)-debug.a
# Targets # Targets
@ -53,22 +53,34 @@ obj/c/%.o: %.c
obj/cxx/%.o: %.cpp obj/cxx/%.o: %.cpp
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS) $(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
$(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS) $(PROJECT).a: CFLAGS+= $(RELEASE_CFLAGS)
$(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS) $(PROJECT).a: CXXFLAGS += $(RELEASE_CXXFLAGS)
$(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS) $(PROJECT).a: $(OBJ)
$(PROJECT)-release: $(OBJ) ar -rcs $@ $^
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
$(STRIP) $@ $(STRIP) $@
$(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS)
$(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS) $(PROJECT).so: CFLAGS+= -fPIC $(RELEASE_CFLAGS)
$(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS) $(PROJECT).so: CXXFLAGS += -fPIC $(RELEASE_CXXFLAGS)
$(PROJECT)-debug: $(OBJ) $(PROJECT).so: LDFLAGS += $(RELEASE_LDFLAGS)
$(CXX) $^ $(CXXFLAGS) -o $@ $(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: clean-rebuild:
rm -rf obj rm -rf obj
clean: clean-rebuild 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 // A generator method
struct sm_generator; struct sm_generator;
extern "C" {
/// Create a generator method with this function. /// Create a generator method with this function.
sm_generator* sm_generate(sm_gen_fun function); sm_generator* sm_generate(sm_gen_fun function);
/// Free a generator method /// Free a generator method
@ -43,3 +44,4 @@ void sm_free_generator(sm_generator* generator);
/// Returns false if the generator ends. /// 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. /// 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); bool sm_next(sm_generator** gen, sm_state* state, sm_output* output);
}

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

Loading…
Cancel
Save