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

@ -4,6 +4,9 @@ AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
SRC_C = $(wildcard src/*.c) SRC_C = $(wildcard src/*.c)
SRC_CXX = $(wildcard src/*.cpp) SRC_CXX = $(wildcard src/*.cpp)
TEST_SRC_C = $(wildcard src/test/*.c)
TEST_SRC_CXX = $(wildcard src/test/*.cpp)
INCLUDE=include INCLUDE=include
COMMON_FLAGS= -W -Wall -pedantic -fno-strict-aliasing $(addprefix -I,$(INCLUDE)) COMMON_FLAGS= -W -Wall -pedantic -fno-strict-aliasing $(addprefix -I,$(INCLUDE))
@ -34,18 +37,25 @@ OBJ_C = $(addprefix obj/c/,$(SRC_C:.c=.o))
OBJ_CXX = $(addprefix obj/cxx/,$(SRC_CXX:.cpp=.o)) OBJ_CXX = $(addprefix obj/cxx/,$(SRC_CXX:.cpp=.o))
OBJ = $(OBJ_C) $(OBJ_CXX) OBJ = $(OBJ_C) $(OBJ_CXX)
TEST_OBJ_C = $(addprefix obj/c/,$(TEST_SRC_C:.c=.o))
TEST_OBJ_CXX = $(addprefix obj/cxx/,$(TEST_SRC_CXX:.cpp=.o))
TEST_OBJ = $(TEST_OBJ_C) $(TEST_OBJ_CXX)
# Phonies # Phonies
.PHONY: release .PHONY: release
release: | dirs $(PROJECT).so $(PROJECT).a release: | dirs lib$(PROJECT).so lib$(PROJECT).a
.PHONY: debug .PHONY: debug
debug: | dirs $(PROJECT)-debug.so $(PROJECT)-debug.a debug: | dirs lib$(PROJECT)-debug.so lib$(PROJECT)-debug.a
.PHONY: test
test: | dirs $(PROJECT)-test
# Targets # Targets
dirs: dirs:
@mkdir -p obj/c{,xx}/src @mkdir -p obj/c{,xx}/src{,/test}
obj/c/%.o: %.c obj/c/%.o: %.c
$(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS) $(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS)
@ -53,34 +63,42 @@ obj/c/%.o: %.c
obj/cxx/%.o: %.cpp obj/cxx/%.o: %.cpp
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS) $(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
$(PROJECT).a: CFLAGS+= $(RELEASE_CFLAGS) lib$(PROJECT).a: CFLAGS+= $(RELEASE_CFLAGS)
$(PROJECT).a: CXXFLAGS += $(RELEASE_CXXFLAGS) lib$(PROJECT).a: CXXFLAGS += $(RELEASE_CXXFLAGS)
$(PROJECT).a: $(OBJ) lib$(PROJECT).a: $(OBJ)
ar -rcs $@ $^ ar -rcs $@ $^
$(STRIP) $@ ranlib $@
lib$(PROJECT).so: CFLAGS+= -fPIC $(RELEASE_CFLAGS)
$(PROJECT).so: CFLAGS+= -fPIC $(RELEASE_CFLAGS) lib$(PROJECT).so: CXXFLAGS += -fPIC $(RELEASE_CXXFLAGS)
$(PROJECT).so: CXXFLAGS += -fPIC $(RELEASE_CXXFLAGS) lib$(PROJECT).so: LDFLAGS += $(RELEASE_LDFLAGS)
$(PROJECT).so: LDFLAGS += $(RELEASE_LDFLAGS) lib$(PROJECT).so: $(OBJ)
$(PROJECT).so: $(OBJ)
gcc -shared $^ -o $@ gcc -shared $^ -o $@
$(STRIP) $@ $(STRIP) $@
$(PROJECT)-debug.a: CFLAGS+= $(DEBUG_CFLAGS) lib$(PROJECT)-debug.a: CFLAGS+= $(DEBUG_CFLAGS)
$(PROJECT)-debug.a: CXXFLAGS += $(DEBUG_CXXFLAGS) lib$(PROJECT)-debug.a: CXXFLAGS += $(DEBUG_CXXFLAGS)
$(PROJECT)-debug.a: $(OBJ) lib$(PROJECT)-debug.a: $(OBJ)
ar -rcs $@ $^ ar -rcs $@ $^
ranlib $@
$(PROJECT)-debug.so: CFLAGS+= -fPIC $(DEBUG_CFLAGS) lib$(PROJECT)-debug.so: CFLAGS+= -fPIC $(DEBUG_CFLAGS)
$(PROJECT)-debug.so: CXXFLAGS += -fPIC $(DEBUG_CXXFLAGS) lib$(PROJECT)-debug.so: CXXFLAGS += -fPIC $(DEBUG_CXXFLAGS)
$(PROJECT)-debug.so: LDFLAGS += $(DEBUG_LDFLAGS) lib$(PROJECT)-debug.so: LDFLAGS += $(DEBUG_LDFLAGS)
$(PROJECT)-debug.so: $(OBJ) lib$(PROJECT)-debug.so: $(OBJ)
gcc -shared $^ -o $@ gcc -shared $^ -o $@
$(PROJECT)-test-static: $(TEST_OBJ)
gcc $^ -o $@ -L. -l:lib$(PROJECT).a
$(PROJECT)-test: lib$(PROJECT).a
$(MAKE) $(PROJECT)-test-static
mv $(PROJECT)-test-static $@
./$@
clean-rebuild: clean-rebuild:
rm -rf obj rm -rf obj
clean: clean-rebuild clean: clean-rebuild
rm -f $(PROJECT){-debug,}.{so,a} rm -f lib$(PROJECT){-debug,}.{so,a}
rm -f $(PROJECT)-test

@ -1,11 +1,70 @@
#include <state.h>
#include <gen.h> #include <gen.h>
SM_GENERATOR(read_number) #include <cstdio>
struct _test {
int a, b;
};
SM_GENERATOR(sm_test_2)
{
int* a = SM_VAR(-10);
SM_BEGIN;
while( (*a) < 0 ) {
printf("(2) a = %d\n", *a);
SM_YIELD_VALUE(*a);
(*a)+=1;
}
printf("Done!\n");
SM_END;
}
SM_GENERATOR(sm_test)
{ {
int* a = SM_VAR(10);
auto c = SM_SLOT(_test);
float* d = SM_SLOT(float);
*c = { 200, 300 };
*d = 10.f;
SM_BEGIN;
*a = 5;
SM_YIELD_VALUE(*a);
printf("IN a = %d\n", *a);
*a = 1;
SM_YIELD_VALUE(*a);
printf("IN a = %d\n", *a);
//printf("Starting function 2\n");
SM_YIELD(sm_test_2);
//printf("2 done\n");
SM_END;
} }
int main() int main()
{ {
auto state = sm_new_state();
auto gen = sm_generate(&sm_test);
sm_state_setopt(state, INTERMEDIATE_RETURNS, false);
sm_output output;
int out_int=0;
while(sm_next(&gen, state, &output)) {
if(!sm_output_value(output, &out_int))
continue;
printf("OUT \t\ta = %d\n", out_int); // prints the last one, is this a good or bad thing?
}
printf("\n\nFinal output: %d\n", out_int);
sm_free_output(&output);
sm_free_generator(gen);
sm_free_state(state);
return 0; return 0;
} }

@ -1,70 +0,0 @@
#include <state.h>
#include <gen.h>
#include <cstdio>
struct _test {
int a, b;
};
SM_GENERATOR(sm_test_2)
{
int* a = SM_VAR(-10);
SM_BEGIN;
while( (*a) < 0 ) {
printf("(2) a = %d\n", *a);
SM_YIELD_VALUE(*a);
(*a)+=1;
}
printf("Done!\n");
SM_END;
}
SM_GENERATOR(sm_test)
{
int* a = SM_VAR(10);
auto c = SM_SLOT(_test);
float* d = SM_SLOT(float);
*c = { 200, 300 };
*d = 10.f;
SM_BEGIN;
*a = 5;
SM_YIELD_VALUE(*a);
printf("IN a = %d\n", *a);
*a = 1;
SM_YIELD_VALUE(*a);
printf("IN a = %d\n", *a);
//printf("Starting function 2\n");
SM_YIELD(sm_test_2);
//printf("2 done\n");
SM_END;
}
int main()
{
auto state = sm_new_state();
auto gen = sm_generate(&sm_test);
sm_state_setopt(state, INTERMEDIATE_RETURNS, false);
sm_output output;
int out_int=0;
while(sm_next(&gen, state, &output)) {
if(!sm_output_value(output, &out_int))
continue;
printf("OUT \t\ta = %d\n", out_int); // prints the last one, is this a good or bad thing?
}
printf("\n\nFinal output: %d\n", out_int);
sm_free_output(&output);
sm_free_generator(gen);
sm_free_state(state);
return 0;
}
Loading…
Cancel
Save