Skip to content

Commit 8ff196e

Browse files
author
Matthew Stern
committed
O2 flag
2 parents d7e3a8a + f2ce8e9 commit 8ff196e

28 files changed

+208
-529
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*.json linguist-language=json
44
*.y linguist-language=Yacc
55
*.lex linguist-language=Lex
6-
*.i linguist-language=SWIG
6+
*.i linguist-language=SWIG
7+
*.rs linguist-language=Rust

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ testing/self_edge
1717
testing/*.o
1818
parse/topologic_parser.tab.c
1919
parse/topologic_parser.yy.c
20+
parse/topologic_parser_cpp.tab.cpp
21+
parse/topologic_parser_cpp.tab.hpp
22+
parse/topologic_parser_cpp.yy.cpp
2023
src/*.o
2124
state_*.json
2225
parse/*.c
@@ -31,3 +34,19 @@ topylogic/__pycache__/*
3134
topylogic/topylogic.py
3235
topylogic/_topylogic.so
3336
topylogic/topylogic_wrap.c
37+
*.exe
38+
#rustopologic/RustTopologic/Cargo.toml
39+
rustopologic/RustTopologic/Cargo.lock
40+
rustopologic/RustTopologic/target/*
41+
rustopologic/RustTopologic/src/*.c
42+
rustopologic/RustTopologic/src/bindings.rs
43+
rustopologic/RustTopologic/include/*
44+
rustopologic/RustTopologic/*.a
45+
rustopologic/RustTopologic/rustTests/bindings.rs
46+
47+
topologicsharp/*.cs
48+
topologicsharp/*.c
49+
topologicsharp/_topologicsharp.so
50+
*.dll
51+
52+

Makefile

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
CC=gcc
55
CXX=g++
6+
MCS=$(MCS)
67

78
LDFLAGS= -lm -lpthread -L. -ltopologic -pthread -lfl
89
CFLAGS=-Wall -Werror -g -fPIC -O2
@@ -35,6 +36,12 @@ TOPYLOGIC_SO=topylogic/_topylogic.so
3536
TOPYLOGIC_PY=topylogic/topylogic.py
3637
TOPYLOGIC_O=$(wildcard topylogic/*.o)
3738

39+
CSHARP_I=topologicsharp/topologicsharp.i
40+
CSHARP_WRAP=topologicsharp/topologicsharp_wrap.c
41+
CSHARP_SO=topologicsharp/_topologicsharp.so
42+
CSHARP_CS=topologicsharp/topologicsharp.cs
43+
CSHARP_O=$(wildcard topologicsharp/*.o)
44+
3845
TESTS=$(TEST_SRC:.c=)#ADD MORE AS THEY GO
3946
TEST_SRC=$(wildcard testing/*.c) #ADD MORE IF NEED BE
4047
TEST_OBJ=$(TEST_SRC:.c=.o)
@@ -56,19 +63,28 @@ $(BIN): $(OBJ) $(INCLUDES) $(BISON_OBJ) $(FLEX_OBJ)
5663
$(TESTS): $(BIN) $(OBJ) $(TEST_OBJ)
5764
$(CC) $(CFLAGS) -o $@ libtopologic.a $(TEST_DIR)/$(@F).o $(LDFLAGS)
5865

59-
python: $(OBJ) $(INCLUDES)
60-
swig -python $(TOPYLOGIC_I)
61-
$(CC) -c -fPIC topylogic/topylogic_wrap.c -o topylogic/topylogic_wrap.o -I/usr/include/python3.6m
62-
$(CC) -shared topylogic/topylogic_wrap.o $(OBJ) -o $(TOPYLOGIC_SO)
66+
#python: $(OBJ) $(INCLUDES)
67+
# swig -python $(TOPYLOGIC_I)
68+
# $(CC) -c -fPIC topylogic/topylogic_wrap.c -o topylogic/topylogic_wrap.o -I/usr/include/python3.6m
69+
# $(CC) -shared topylogic/topylogic_wrap.o $(OBJ) -o $(TOPYLOGIC_SO)
70+
71+
#python2: $(OBJ) $(INCLUDES)
72+
# swig -python $(TOPYLOGIC_I)
73+
# $(CC) -c -fPIC topylogic/topylogic_wrap.c -o topylogic/topylogic_wrap.o -I/usr/include/python2.7
74+
# $(CC) -shared topylogic/topylogic_wrap.o $(OBJ) -o $(TOPYLOGIC_SO)
6375

64-
python2: $(OBJ) $(INCLUDES)
65-
swig -python $(TOPYLOGIC_I)
66-
$(CC) -c -fPIC topylogic/topylogic_wrap.c -o topylogic/topylogic_wrap.o -I/usr/include/python2.7
67-
$(CC) -shared topylogic/topylogic_wrap.o $(OBJ) -o $(TOPYLOGIC_SO)
76+
#csharp: $(OBJ) $(INCLUDES)
77+
# swig -outfile topologicsharp.cs -csharp $(CSHARP_I)
78+
# $(CC) -c -fPIC $(CSHARP_WRAP) -o topologicsharp/topologicsharp.o
79+
# @bash topologicsharp/make_dll.sh
80+
6881

6982
cpp: $(BISON_CPP) $(BISON_OBJ_PP) $(BISON_HPP) $(FLEX_CPP) $(FLEX_OBJ_PP) $(OBJ) $(INCLUDES)
7083
$(AR) rcs libtopologic.a $(OBJ) $(BISON_OBJ_PP) $(FLEX_OBJ_PP)
7184

85+
rust:
86+
@bash rustopologic/rustCreation.sh
87+
7288
$(FLEX_CPP):
7389
flex $(FLEXPP)
7490
mv lex.yy.cc $(FLEX_CPP)
@@ -78,7 +94,7 @@ $(BISON_CPP): $(BISONPP)
7894
$(CXX) -fPIC -g -c $(BISON_CPP) -o $(BISON_OBJ_PP)
7995

8096
all:$(BIN)
81-
.PHONY : clean cpp python python2
97+
.PHONY : clean cpp python python2 rust csharp
8298

8399
clean:
84100
rm -f libtopologic.a
@@ -88,8 +104,17 @@ clean:
88104
rm -f $(BISON_CPP) $(BISON_OBJ_PP) $(BISON_HPP)
89105
rm -f $(OBJ) $(BIN)
90106
rm -f $(TOPYLOGIC_WRAP) $(TOPYLOGIC_PY) $(TOPYLOGIC_SO) $(TOPYLOGIC_O)
107+
rm -f $(CSHARP_WRAP) $(CSHARP_CS) $(CSHARP_SO) $(CSHARP_O)
108+
rm -f topologicsharp/*.cs
91109
rm -rf topylogic/__pycache__
92110
rm -rf topylogic/build
93-
#rm -r topylogic/*.pyc
94111
-rm -f state_*
112+
-rm -f topylogic/state_*
113+
rm -f topologicsharp/*.dll
95114
rm -f $(TESTS) $(TEST_OBJ)
115+
-rm -f testing/*.exe
116+
rm -f rustopologic/RustTopologic/src/bindings.rs
117+
rm -f rustopologic/RustTopologic/src/*.c
118+
rm -f rustopologic/RustTopologic/Cargo.lock
119+
rm -f rustopologic/RustTopologic/rustTests/bindings.rs
120+
#cd rustopologic/RustTopologic/ && cargo clean && rm -rf include/ && rm -f libtopologic.a

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
11
# Topologic
2-
A library to simulate DFAs and Probabilistic DFAs using context switching.
2+
A library to simulate DFAs and Probabilistic DFAs using context switching. This library provides a way to build and define the behavior of a graph. The client is able to define the function each vertex and edge of the graph make and how the graph transitions from one (the first valid edge) or to many states, as well as which states the graph starts in.
3+
4+
The library provides a way for the client to define what information is saved localy to each vertex and edge, as well as which information the vertex and edges originating at that edge share. In addition the client can pass information to each initial state that will be passed and modifyable by vertices at each state transition.
5+
6+
This library can be used to create AI, ML, and simulations (such as of stock options, electron-electron interaction, etc.).
7+
8+
## Installation
9+
Build C Library
10+
>make
11+
12+
-creates libtopologic.a
13+
14+
Build C++ Library
15+
>make cpp
16+
17+
-creates libtopologic.a
18+
19+
Build Python 3 Library
20+
>make python
21+
22+
-creates topylogic/topylogic.so
23+
24+
Build Python 2 Library
25+
>make python2
26+
27+
-creates topylogic/topylogic.so
28+
29+
Clean
30+
>make clean
31+
32+
## TODO
33+
-C# Wrap
34+
35+
-Rust Wrap
36+
37+
-Python (2/3) Wrap

Topologic_Design_Document.pdf

175 KB
Binary file not shown.

docs/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Topologic
2+
A library to simulate DFAs and Probabilistic DFAs using context switching. This library provides a way to build and define the behavior of a graph. The client is able to define the function each vertex and edge of the graph make and how the graph transitions from one (the first valid edge) or to many states, as well as which states the graph starts in.
3+
4+
The library provides a way for the client to define what information is saved localy to each vertex and edge, as well as which information the vertex and edges originating at that edge share. In addition the client can pass information to each initial state that will be passed and modifyable by vertices at each state transition.
5+
6+
This library can be used to create AI, ML, and simulations (such as of stock options, electron-electron interaction, etc.).
7+
8+
## Download v1.0.0
9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
10+
<button class="btn"><i class="fa fa-download"></i><a href="https://github.com/mstern98/Topologic/archive/v1.0.0.zip">Download Zip</a></button>
11+
12+
<button class="btn"><i class="fa fa-download"></i><a href="https://github.com/mstern98/Topologic/archive/v1.0.0.tar.gz">Download tar</a></button>
13+
14+
<button class="btn"><i class="fa fa-download"></i><a href="https://github.com/mstern98/Topologic/releases/download/v1.0.0/libtopologic.a">Download UNIX C</a></button>
15+
16+
<button class="btn"><i class="fa fa-download"></i><a href="https://github.com/mstern98/Topologic/releases/download/v1.0.0/libtopologic_windows.a">Download Windows C</a></button>
17+
18+
<button class="btn"><i class="fa fa-download"></i><a href="https://github.com/mstern98/Topologic/releases/download/v1.0.0/libtopologicpp.a">Download UNIX C++</a></button>
19+
20+
<button class="btn"><i class="fa fa-download"></i><a href="https://github.com/mstern98/Topologic/releases/download/v1.0.0/libtopologicpp_windows.a">Download Windows C++</a></button>
21+
22+
## Installation
23+
Build C Library
24+
>make
25+
26+
-creates libtopologic.a
27+
28+
Build C++ Library
29+
>make cpp
30+
31+
-creates libtopologic.a
32+
33+
Build Python 3 Library
34+
>make python
35+
36+
-creates topylogic/topylogic.so
37+
38+
Build Python 2 Library
39+
>make python2
40+
41+
-creates topylogic/topylogic.so
42+
43+
Clean
44+
>make clean
45+
46+
## TODO
47+
-C# Wrap
48+
49+
-Rust Wrap
50+
51+
-Python (2/3) Wrap

docs/_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-slate

include/edge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct edge
2525
//will compare with other Edges in graph
2626
//Also unique, a la vertex
2727
//Perhaps @nanosecond level
28-
int (*f)(void *);
28+
int (*f)(void *, void *, const void *const);
2929
void *glbl;
3030
const void *const *a_vars; //To be shared among vertex a and shared edge
3131
struct vertex *a;
@@ -39,7 +39,7 @@ struct edge_request
3939
{
4040
struct vertex *a;
4141
struct vertex *b;
42-
int (*f)(void *);
42+
int (*f)(void *, void *, const void *const);
4343
void *glbl;
4444
};
4545

include/topologic.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ NOTE: NULL glbl will mean no global variables.
7777
f cannot be NULL.
7878
**/
7979
struct vertex *create_vertex(struct graph *graph,
80-
void (*f)(struct graph *, struct vertex_result *),
80+
void (*f)(struct graph *, struct vertex_result *, void *, void *),
8181
int id,
8282
void *glbl);
8383
#define CREATE_VERTEX(graph, f, id) create_vertex(graph, f, id, NULL)
@@ -94,7 +94,7 @@ NOTE: NULL glbl will mean no global variables. f cannot be NULL.
9494
**/
9595
struct edge *create_edge(struct vertex *a,
9696
struct vertex *b,
97-
int (*f)(void *),
97+
int (*f)(void *, void *, const void *const),
9898
void *glbl);
9999
#define CREATE_EDGE(a, b, f) create_edge(a, b, f, NULL)
100100

@@ -109,7 +109,7 @@ If edge_a_to_b or edge_b_to_a is NULL it will not.
109109
**/
110110
int create_bi_edge(struct vertex *a,
111111
struct vertex *b,
112-
int (*f)(void *),
112+
int (*f)(void *, void *, const void *const),
113113
void *glbl,
114114
struct edge **edge_a_to_b,
115115
struct edge **edge_b_to_a);
@@ -177,7 +177,7 @@ NOTE: NULL f, or glbl will mean no change.
177177
Modifies the vertices function
178178
**/
179179
int modify_vertex(struct vertex *vertex,
180-
void (*f)(struct graph *, struct vertex_result *),
180+
void (*f)(struct graph *, struct vertex_result *, void *, void *),
181181
void *glbl);
182182
#define MODIFY_VERTEX(vertex, f) modify_vertex(vertex, f, NULL)
183183
#define MODIFY_VERTEX_GLOBALS(vertex, glbl) modify_vertex(vertex, NULL, glbl)
@@ -204,7 +204,7 @@ NOTE: NULL f, or glbl will mean no change.
204204
**/
205205
int modify_edge(struct vertex *a,
206206
struct vertex *b,
207-
int (*f)(void *),
207+
int (*f)(void *, void *, const void *const),
208208
void *glbl);
209209

210210
#define MODIFY_EDGE(a, b, f) modify_edge(a, b, f, NULL)
@@ -225,7 +225,7 @@ NOTE: NULL f, or glbl will mean no change.
225225
**/
226226
int modify_bi_edge(struct vertex *a,
227227
struct vertex *b,
228-
int (*f)(void *),
228+
int (*f)(void *, void *, const void *const),
229229
void *glbl);
230230
#define MODIFY_BI_EDGE(a, b, f) modify_bi_edge(a, b, f, NULL)
231231
#define MODIFY_BI_EDGE_GLOBALS(a, b, glbl) modify_bi_edge(a, b, NULL, glbl)

include/vertex.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct vertex
3636
//will compare with other vertices in graph
3737
//Must be unique. If non-unique ID, error
3838
int is_active;
39-
void (*f)(struct graph *, struct vertex_result *);
39+
void (*f)(struct graph *, struct vertex_result *, void *, void *);
4040
void *glbl;
4141
union shared_edge *shared;
4242
pthread_mutex_t lock;
@@ -51,14 +51,14 @@ struct vertex_request
5151
int id; //Hash for number passed in,
5252
//will compare with other vertices in graph
5353
//Must be unique. If non-unique ID, error
54-
void (*f)(struct graph *, struct vertex_result *);
54+
void (*f)(struct graph *, struct vertex_result *, void *, void *);
5555
void *glbl;
5656
};
5757

5858
struct mod_vertex_request
5959
{
6060
struct vertex *vertex;
61-
void (*f)(struct graph *, struct vertex_result *);
61+
void (*f)(struct graph *, struct vertex_result *, void *, void *);
6262
void *glbl;
6363
};
6464

include/windows_wrap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#define __TOPILOGIC_WINDOWS__
77

88
#include <windows.h>
9+
#include <process.h>
10+
#include <stdbool.h>
11+
912

1013
#ifdef __cplusplus
1114
extern "C" {
@@ -36,4 +39,4 @@ int pthread_cond_signal(pthread_cond_t *cond);
3639
}
3740
#endif
3841

39-
#endif
42+
#endif

parse/topologic_parser.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ blanks [ \t\n]+
2222
"max_state" return(MAX_STATE);
2323
"lvl_verbose" return(LVL_VERBOSE);
2424
"mem_option" return(MEM_OPT);
25-
"context" return(CONTEXT);
25+
"context" return(LEX_CONTEXT);
2626
"max_loop" return(MAX_LOOP);
2727
[0-9]+ {yylval.val = atoi(yytext); return(VALUE);}
2828
%%

parse/topologic_parser.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
%{
55
#include "../include/topologic.h"
6-
void f(struct graph *graph, struct vertex_result *args) {}
7-
int edge_f(void *args) {return 0;}
6+
void f(struct graph *graph, struct vertex_result *args, void *glbl, void *edge_vars) {}
7+
int edge_f(void *args, void *glbl, const void *const edge_vars) {return 0;}
88
int yylex();
99
void yyerror(struct graph** graph, const char *s);
1010
extern FILE *yyin;
@@ -29,7 +29,7 @@ extern int yylex(void);
2929
%token COMMA
3030
%token MAX_STATE
3131
%token LVL_VERBOSE
32-
%token CONTEXT
32+
%token LEX_CONTEXT
3333
%token MEM_OPT
3434
%token MAX_LOOP
3535
%token <val> VALUE
@@ -61,7 +61,7 @@ state: MAX_STATE COLON VALUE {(*graph)->max_state_changes = $3;}
6161
;
6262
verb: LVL_VERBOSE COLON VALUE {(*graph)->lvl_verbose = $3;}
6363
;
64-
context: CONTEXT COLON VALUE {(*graph)->context = $3;}
64+
context: LEX_CONTEXT COLON VALUE {(*graph)->context = $3;}
6565
;
6666
mem_opt: MEM_OPT COLON VALUE {(*graph)->mem_option = $3;}
6767
;

parse/topologic_parser_cpp.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ blanks [ \t\n]+
2424
"max_state" return(MAX_STATE);
2525
"lvl_verbose" return(LVL_VERBOSE);
2626
"mem_option" return(MEM_OPT);
27-
"context" return(CONTEXT);
27+
"context" return(LEX_CONTEXT);
2828
"max_loop" return(MAX_LOOP);
2929
[0-9]+ {yylval.val = atoi(yytext); return(VALUE);}
3030
%%

0 commit comments

Comments
 (0)