Skip to content

Commit

Permalink
Fix a bug and removed test directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalium committed Jun 10, 2017
1 parent 779924d commit cc0de12
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 182 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ SRCS= main.c \
nv_variable.c nv_term.c nv_signal.c \
nv_integer.c nv_string.c nv_relation.c \
fnv1.c \
lang/02/parse.c lang/02/eval.c \
nv_anchor.c
lang/02/parse.c lang/02/eval.c
HEADERS=nv.h nv_node.h nv_func.h nv_static.h
CFLAGS=-Wall -Wextra -lncurses -Wunused-function
CFLAGS += -DGIT_COMMIT_ID="\"$(GIT_COMMIT_ID)\"" \
Expand Down
4 changes: 2 additions & 2 deletions fnv1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const uint64_t FNV_PRIME_64 = 1099511628211LLU;
/*
* FNV Hash Algorithm
*/
uint32_t fnv_1_hash_32(uint8_t *bytes, size_t length)
uint32_t fnv_1_hash_32(const uint8_t *bytes, size_t length)
{
uint32_t hash;
size_t i;
Expand All @@ -28,7 +28,7 @@ uint32_t fnv_1_hash_32(uint8_t *bytes, size_t length)

return hash;
}
uint64_t fnv_1_hash_64(uint8_t *bytes, size_t length)
uint64_t fnv_1_hash_64(const uint8_t *bytes, size_t length)
{
uint64_t hash;
size_t i;
Expand Down
2 changes: 1 addition & 1 deletion lang/02/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ NV_ID NV_parseToCodeGraph(const NV_ID *baseTokenList, const NV_ID *opDict)
printf("parsing tokens: ");
NV_Array_print(&tokenList); putchar('\n');
*/
printf("tokenList hash = %08X\n", NV_Term_calcHash(baseTokenList));
//printf("tokenList hash = %08X\n", NV_Term_calcHash(baseTokenList));
NV_ID codeGraphRoot = NV_Node_createWithString("eval");
NV_ID lastNode = codeGraphRoot;
NV_OpPointer p;
Expand Down
75 changes: 57 additions & 18 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,67 @@ int main(int argc, char *argv[])
*/
// TEST CODE BEGIN vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
/*
NV_ID rootAnchor = NV_Anchor_createWithName("root");
NV_ID nodeA = NV_Node_createWithString("A");
NV_ID nodeB = NV_Node_createWithString("B");
NV_ID nodeC = NV_Node_createWithString("C");
NV_ID nodeD = NV_Node_createWithString("D");
NV_ID nodeE = NV_Node_createWithString("E");
NV_NodeID_createRelation(&nodeA, &nodeB, &nodeC);
NV_ID list1 = NV_Array_create();
NV_ID e;
e = NV_Node_createWithString("test1");
NV_Array_push(&list1, &e);
e = NV_Node_createWithString("hello");
NV_Array_push(&list1, &e);
NV_Array_print(&list1); putchar('\n');
NV_Dict_printWithDepth(&list1, 6, 0);
printf("Hash: %08X\n", NV_Term_calcHash(&list1));
printf("Hash: %08X\n", NV_Term_calcHash(&opDict));
{
NV_ID r = NV_NodeID_getRelatedNodeFrom(&nodeA, &nodeB);
NV_NodeID_printForDebug(&r);
if(NV_NodeID_isEqual(&nodeC, &r)){
printf("OK");
} else{
printf("BAD");
}
}
FILE *fp = fopen("dump.txt", "w");
if(fp){
NV_Node_dumpAllToFile(fp);
fclose(fp);
NV_Dict_addUniqueIDKey(&nodeA, &nodeB, &nodeD);
{
NV_ID r = NV_NodeID_getRelatedNodeFrom(&nodeA, &nodeB);
NV_NodeID_printForDebug(&r);
if(NV_NodeID_isEqual(&nodeD, &r)){
printf("OK");
} else{
printf("BAD");
}
}
return 0;
*/
NV_Dict_addUniqueIDKey(&nodeA, &nodeB, &nodeE);
{
NV_ID r = NV_NodeID_getRelatedNodeFrom(&nodeA, &nodeB);
NV_NodeID_printForDebug(&r);
if(NV_NodeID_isEqual(&nodeE, &r)){
printf("OK");
} else{
printf("BAD");
}
}
*/
/*
{
NV_ID ary = NV_Array_create();
NV_ID nodeA = NV_Node_createWithString("A");
NV_ID nodeB = NV_Node_createWithString("B");
NV_Array_push(&ary, &nodeA);
NV_Array_push(&ary, &nodeB);
{
NV_ID r0 = NV_Array_getByIndex(&ary, 0);
NV_ID r1 = NV_Array_getByIndex(&ary, 1);
NV_NodeID_printForDebug(&r0);
NV_NodeID_printForDebug(&r1);
if(NV_NodeID_isEqual(&nodeA, &r0) && NV_NodeID_isEqual(&nodeB, &r1)){
printf("OK");
} else{
printf("BAD");
}
}
NV_Array_print(&ary);
}
*/
// return 0;
// TEST CODE END ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

char line[MAX_INPUT_LEN];
Expand Down
28 changes: 1 addition & 27 deletions nv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,7 @@
// main
//
volatile sig_atomic_t NV_globalExecFlag;
/*
// int NV_interactiveInput(const NV_ID *cTypeList, const NV_ID *ctx)
{
char line[MAX_INPUT_LEN];
//
if(NV_gets(line, sizeof(line)) != NULL){
NV_evalLine(cTypeList, ctx, line);
return 0;
}
return 1;
}
*/
/*
// int NV_evalLine(const NV_ID *cTypeList, const NV_ID *ctx, const char *line)
{
NV_ID tokenList;
tokenList = NV_tokenize(cTypeList, line);
if(IS_DEBUG_MODE()){
NV_Term_print(&tokenList); putchar('\n');
}
NV_Context_pushToEvalStack(ctx, &tokenList, &NODEID_NULL);
if(IS_DEBUG_MODE()){
NV_Term_print(&tokenList); putchar('\n');
}
return 0;
}
*/

NV_ID NV_tokenize(const NV_ID *cTypeList, const char *input)
{
// retv: tokenized str array
Expand Down
20 changes: 9 additions & 11 deletions nv_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ NV_Node *NV_Node_getNextNode(const NV_Node *n);
int NV_Node_getNodeCount();
NV_ID NV_NodeID_create(const NV_ID *id);
NV_ID NV_Node_create();
NV_ID NV_Node_createWithTypeAndData(NV_NodeType type, void *data, int32_t size);
NV_ID NV_Node_createWithTypeAndData
(NV_NodeType type, const void *data, int32_t size);
NV_ID NV_Node_createWith_ID_Type_Data_Size
(const NV_ID *id, NV_NodeType type, const void *data, int32_t size);
int NV_NodeID_isEqual(const NV_ID *a, const NV_ID *b);
int NV_NodeID_isEqualInValue(const NV_ID *a, const NV_ID *b);
int NV_NodeID_exists(const NV_ID *id);
Expand All @@ -93,8 +96,8 @@ const NV_Node *NV_Node_getRelCache(const NV_Node *n);
void NV_Node_setRelCache(NV_Node *n, const NV_Node *rel);
int32_t NV_Node_calcHash(const NV_Node *n);
int32_t NV_NodeID_calcHash(const NV_ID *id);
void *NV_Node_getDataAsType(const NV_Node *n, NV_NodeType type);
void *NV_NodeID_getDataAsType(const NV_ID *id, NV_NodeType type);
const void *NV_Node_getDataAsType(const NV_Node *n, NV_NodeType type);
const void *NV_NodeID_getDataAsType(const NV_ID *id, NV_NodeType type);
NV_ID NV_Node_getID(const NV_Node *n);
void NV_Node_dumpAll();
void NV_Node_dumpAllToFile(FILE *fp);
Expand Down Expand Up @@ -182,8 +185,8 @@ int32_t NV_NodeID_getInt32(const NV_ID *id);
// @nv_string.c
int NV_NodeID_isString(const NV_ID *id);
NV_ID NV_Node_createWithString(const char *s);
NV_ID NV_Node_createWith_ID_String(const NV_ID *id, const char *s);
NV_ID NV_Node_createWithStringFormat(const char *fmt, ...);
void NV_NodeID_createAndString(const NV_ID *id, const char *s);
const char *NV_NodeID_getCStr(const NV_ID *id);
int NV_Node_String_compare(const NV_ID *ida, const NV_ID *idb);
int NV_Node_String_compareWithCStr(const NV_ID *ida, const char *s);
Expand Down Expand Up @@ -217,8 +220,8 @@ NV_ID NV_NodeID_getEqRelatedNodeFrom(const NV_ID *from, const NV_ID *rel);


// @fnv1.c
uint32_t fnv_1_hash_32(uint8_t *bytes, size_t length);
uint64_t fnv_1_hash_64(uint8_t *bytes, size_t length);
uint32_t fnv_1_hash_32(const uint8_t *bytes, size_t length);
uint64_t fnv_1_hash_64(const uint8_t *bytes, size_t length);


// @lang/02/parse.c
Expand Down Expand Up @@ -256,8 +259,3 @@ NV_ID NV_Lang02_OpFunc_parentheses
(NV_ID * const p, NV_ID * const lastEvalVal, const NV_ID *scope);
NV_ID NV_evalGraph(const NV_ID *codeGraphRoot, const NV_ID *scope);


// @nv_anchor.c
int NV_Anchor_isAnchor(const NV_ID *id);
NV_ID NV_Anchor_createWithName(const char *s);

59 changes: 28 additions & 31 deletions nv_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void NV_Node_Internal_resetData(NV_Node *n)
}
*/
NV_DbgInfo("Free Data type: %s", NV_NodeTypeList[n->type]);
NV_free(n->data);
NV_free((void *)n->data);
n->data = NULL;
n->size = 0;
}
Expand Down Expand Up @@ -69,6 +69,15 @@ int NV_Node_Internal_isEqualInValue(const NV_Node *na, const NV_Node *nb)
return 0;
}

void NV_Node_Internal_set_Type_Data_Size(const NV_ID *id, NV_NodeType type, const void *data, int32_t size)
{
NV_Node *n;
n = NV_NodeID_getNode(id);
n->type = type;
n->size = size;
n->data = data;
}

//
// Node
//
Expand Down Expand Up @@ -120,31 +129,22 @@ NV_ID NV_Node_create()
return NV_NodeID_createNew(&id);
}

NV_ID NV_Node_createWithTypeAndData(NV_NodeType type, void *data, int32_t size)
NV_ID NV_Node_createWithTypeAndData
(NV_NodeType type, const void *data, int32_t size)
{
NV_ID id;
NV_Node *n;
id = NV_Node_create();
n = NV_NodeID_getNode(&id);
n->type = type;
n->size = size;
n->data = data;
NV_ID id = NV_Node_create();
NV_Node_Internal_set_Type_Data_Size(&id, type, data, size);
return id;
}
/*
//NV_ID NV_Node_createWith_ID_Type_Data
//(NV_ID *id, NV_NodeType type, void *data, int32_t size)

NV_ID NV_Node_createWith_ID_Type_Data_Size
(const NV_ID *id, NV_NodeType type, const void *data, int32_t size)
{
NV_ID id;
NV_Node *n;
id = NV_Node_create();
n = NV_NodeID_getNode(&id);
n->type = type;
n->size = size;
n->data = data;
return id;
NV_NodeID_create(id);
NV_Node_Internal_set_Type_Data_Size(id, type, data, size);
return *id;
}
*/

int NV_NodeID_isEqual(const NV_ID *a, const NV_ID *b)
{
int i;
Expand Down Expand Up @@ -241,13 +241,13 @@ int32_t NV_NodeID_calcHash(const NV_ID *id)
n->data = data;
}
*/
void *NV_Node_getDataAsType(const NV_Node *n, NV_NodeType type)
const void *NV_Node_getDataAsType(const NV_Node *n, NV_NodeType type)
{
if(!n || n->type != type) return NULL;
return n->data;
}

void *NV_NodeID_getDataAsType(const NV_ID *id, NV_NodeType type)
const void *NV_NodeID_getDataAsType(const NV_ID *id, NV_NodeType type)
{
NV_Node *n;
n = NV_NodeID_getNode(id);
Expand Down Expand Up @@ -296,17 +296,14 @@ void NV_NodeID_remove(const NV_ID *baseID)

NV_ID NV_NodeID_clone(const NV_ID *baseID)
{
NV_Node *base, *new;
NV_ID newID = NV_Node_create();
new = NV_NodeID_getNode(&newID);
NV_Node *base;
base = NV_NodeID_getNode(baseID);
new->type = base->type;
void *data = NULL;
if(base->data){
new->data = NV_malloc(base->size);
new->size = base->size;
memcpy(new->data, base->data, new->size);
data = NV_malloc(base->size);
memcpy(data, base->data, base->size);
}
return newID;
return NV_Node_createWithTypeAndData(base->type, data, base->size);
}


Expand Down
2 changes: 1 addition & 1 deletion nv_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

struct NV_NODE {
NV_ID id;
void *data;
const void *data;
NV_Node *prev;
NV_Node *next;
NV_NodeType type;
Expand Down
16 changes: 12 additions & 4 deletions nv_relation.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ NV_ID NV_NodeID_createRelation
reld->rel = *rel;
reld->to = *to;

if(IS_DEBUG_MODE()){
printf("Rel created: ");
NV_NodeID_printForDebug(from);
NV_NodeID_printForDebug(rel);
NV_NodeID_printForDebug(to);
printf("\n");
}

return NV_Node_createWithTypeAndData(kRelation, reld, size);
}

Expand Down Expand Up @@ -88,7 +96,7 @@ NV_ID NV_NodeID_createUniqueEqRelation
*/
NV_Node *NV_NodeID_Relation_getLinkFrom(const NV_ID *relnid)
{
NV_Relation *reld;
const NV_Relation *reld;
//
reld = NV_NodeID_getDataAsType(relnid, kRelation);
if(!reld) return NULL;
Expand All @@ -97,7 +105,7 @@ NV_Node *NV_NodeID_Relation_getLinkFrom(const NV_ID *relnid)

NV_ID NV_NodeID_Relation_getIDLinkTo(const NV_ID *relnid)
{
NV_Relation *reld;
const NV_Relation *reld;
//
reld = NV_NodeID_getDataAsType(relnid, kRelation);
if(!reld) return NODEID_NOT_FOUND;
Expand All @@ -113,7 +121,7 @@ NV_Node *NV_NodeID_Relation_getLinkTo(const NV_ID *relnid)

NV_ID NV_NodeID_Relation_getIDLinkRel(const NV_ID *relnid)
{
NV_Relation *reld;
const NV_Relation *reld;
//
reld = NV_NodeID_getDataAsType(relnid, kRelation);
return reld->rel;
Expand All @@ -132,7 +140,7 @@ NV_ID NV_NodeID_updateRelationTo(const NV_ID *relnid, const NV_ID *to)
// 既存のものを削除して、新しいノードを生成し、以前と同一の関係性を持たせる。
NV_ID from, rel;
NV_Node *n;
NV_Relation *reld;
const NV_Relation *reld;
//
n = NV_NodeID_getNode(relnid);
reld = NV_Node_getDataAsType(n, kRelation);
Expand Down
4 changes: 2 additions & 2 deletions nv_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ void NV_Graph_addStaticNode(const NV_ID *id, const char *s)
{
int f = NV_NodeID_exists(id);
//
NV_NodeID_createAndString(id, s);
NV_Node_createWith_ID_String(id, s);
if(!f){
NV_NodeID_createRelation(&NODEID_NV_STATIC_ROOT, &NODEID_NULL, id);
}
}

void NV_Graph_initStaticNodes()
{
NV_NodeID_createAndString(&NODEID_NV_STATIC_ROOT, "NV_StaticRoot");
NV_Node_createWith_ID_String(&NODEID_NV_STATIC_ROOT, "NV_StaticRoot");
//
NV_StaticNodeNameTag *t;
int i;
Expand Down
Loading

0 comments on commit cc0de12

Please sign in to comment.