Skip to content

Commit 4ecf0ac

Browse files
committed
Core functionality
1 parent 138fc73 commit 4ecf0ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1006
-900
lines changed

ecr/command.h

Lines changed: 242 additions & 168 deletions
Large diffs are not rendered by default.

ecr/definitions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ enum domains {
77
enum valueTypes {
88
TEXT_VALUE,
99
INT_VALUE,
10-
BOOL_VALUE
10+
BOOL_VALUE,
11+
CAT_VALUE
1112
};

ecr/domain/core/add.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
int core_add(Runtime* runtime) {
2-
print("add handler\n");
2+
runtime->notImplemented("add");
33
return 0;
44
};
55

ecr/domain/core/append.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
int core_append(Runtime* runtime) {
2-
print("append handler\n");
2+
runtime->notImplemented("append");
33
return 0;
44
};
55

ecr/domain/core/array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_array(Runtime* runtime) {
2-
print("array handler\n");
2+
runtime->notImplemented("array");
33
return 0;
44
};

ecr/domain/core/begin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_begin(Runtime* runtime) {
2-
print("begin handler\n");
2+
runtime->notImplemented("abegindd");
33
return 0;
44
};

ecr/domain/core/cat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RuntimeValue* core_cat(Functions* functions) {
2+
functions->notImplemented("cat");
3+
return nullptr;
4+
};

ecr/domain/core/clear.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_clear(Runtime* runtime) {
2-
print("clear handler\n");
2+
runtime->notImplemented("clear");
33
return 0;
44
};

ecr/domain/core/close.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_close(Runtime* runtime) {
2-
print("close handler\n");
2+
runtime->notImplemented("close");
33
return 0;
44
};

ecr/domain/core/core-keywords.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,30 @@ class CoreKeywords {
9595
WRITE
9696
};
9797

98+
int index = 0;
99+
int* map;
100+
TextArray* keyArray;
98101
KeywordArray* keywords;
99102
Text* domain = new Text("core");
100103

104+
///////////////////////////////////////////////////////////////////////
105+
// Add a keyword. Only add keywords that are found in the key array.
106+
// The map contains the index of the variable (and thus its handler)
107+
// against the index of its name in the key array.
101108
void add(const char* name) {
102-
Keyword* keyword = new Keyword();
103-
keyword->setName(new Text(name));
104-
keyword->setDomain(domain);
105-
keywords->add(keyword);
109+
int size = keyArray->getSize();
110+
for (int n = 0; n < size; n++) {
111+
if (keyArray->get(n)->is(name)) {
112+
Keyword* keyword = new Keyword();
113+
keyword->setName(new Text(name));
114+
keyword->setDomain(domain);
115+
keyword->setIndex(n);
116+
map[n] = index;
117+
keywords->add(keyword);
118+
break;
119+
}
120+
}
121+
index++;
106122
}
107123

108124
public:
@@ -124,7 +140,8 @@ class CoreKeywords {
124140

125141
///////////////////////////////////////////////////////////////////////
126142
// Run a command. All the information needed is in 'runtime'
127-
int run(Runtime* runtime, int index) {
143+
int run(Runtime* runtime, int code) {
144+
int index = map[code];
128145
switch (index)
129146
{
130147
case ADD:
@@ -222,7 +239,9 @@ class CoreKeywords {
222239

223240
///////////////////////////////////////////////////////////////////////
224241
// Constructor
225-
CoreKeywords() {
242+
CoreKeywords(TextArray* array) {
243+
keyArray = array;
244+
map = new int[array->getSize()];
226245
keywords = new KeywordArray();
227246
add("add");
228247
add("append");
@@ -274,6 +293,7 @@ class CoreKeywords {
274293
///////////////////////////////////////////////////////////////////////
275294
// Destructor
276295
~CoreKeywords() {
296+
delete[] map;
277297
print("CoreKeywords: Destructor executed\n");
278298
}
279299
};

ecr/domain/core/core-values.h

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,87 @@
1-
#include "../../debug.h"
1+
#include "symbol.h"
2+
#include "cat.h"
23

34
// Values for the 'core' domain
45
class CoreValues {
56

67
private:
78

8-
ValueArray* values;
9-
Text* domain = new Text("core", "domain");
10-
TextArray* choices;
9+
enum coreIndices {
10+
SYMBOL,
11+
CAT
12+
};
1113

12-
void add(Text* name, int code) {
13-
values->add(new Value(name, domain, code));
14-
}
14+
int index = 0;
15+
int* map;
16+
TextArray* keyArray;
17+
KeywordArray* keywords;
18+
Text* domain = new Text("core");
1519

16-
void add(const char* name, int code) {
17-
add(new Text(name), code);
20+
///////////////////////////////////////////////////////////////////////
21+
// Add a keyword. Only add keywords that are found in the key array.
22+
// The map contains the index of the variable (and thus its handler)
23+
// against the index of its name in the key array.
24+
void add(const char* name) {
25+
int size = keyArray->getSize();
26+
for (int n = 0; n < size; n++) {
27+
if (keyArray->get(n)->is(name)) {
28+
printf("Adding %s at position %d pointing to %d\n", name, n, index);
29+
Keyword* keyword = new Keyword();
30+
keyword->setName(new Text(name));
31+
keyword->setDomain(domain);
32+
keyword->setIndex(n);
33+
map[n] = index;
34+
keywords->add(keyword);
35+
}
36+
}
37+
index++;
1838
}
1939

2040
public:
2141

22-
void dump() {
23-
print("This is the list of value keywords defined for the 'core' package\n");
24-
for (int n = 0; n < values->getSize(); n++) {
25-
Value* v = values->get(n);
26-
print("%s\n", v->getName()->getText());
42+
void info() {
43+
print("This is the list of keywords defined for the 'core' package\n");
44+
for (int n = 0; n < keywords->getSize(); n++) {
45+
Keyword* k = (Keyword*)keywords->get(n);
46+
print("%s\n", k->getName()->getText());
2747
}
2848
print("-----------------\n");
2949
};
3050

3151
///////////////////////////////////////////////////////////////////////
32-
// Get the value choices
33-
TextArray* getChoices() {
34-
return choices;
52+
// Get the keyword array
53+
KeywordArray* getKeywords() {
54+
return keywords;
3555
}
3656

37-
void init(ValueArray* values) {
38-
this->values = values;
39-
add("text", TEXT_VALUE);
40-
add("int", INT_VALUE);
41-
add("bool", BOOL_VALUE);
42-
};
57+
///////////////////////////////////////////////////////////////////////
58+
// Run a command. All necessary information is passed in
59+
RuntimeValue* run(int code, ElementArray* value, SymbolArray* symbols, Functions* functions) {
60+
// functions->showSymbolValues();
61+
int index = map[code];
62+
switch (index)
63+
{
64+
case SYMBOL:
65+
return core_symbol(functions);
66+
case CAT:
67+
return core_cat(functions);
68+
default:
69+
print("Unknown keyword code %d in CoreValues\n", index);
70+
exit(1);
71+
}
72+
return nullptr;
73+
}
4374

4475
///////////////////////////////////////////////////////////////////////
4576
// Constructor
46-
CoreValues() {}
77+
CoreValues(TextArray* array) {
78+
keyArray = array;
79+
map = new int[array->getSize()];
80+
keywords = new KeywordArray();
81+
add("symbol");
82+
add("cat");
83+
keywords->flatten();
84+
}
4785

4886
///////////////////////////////////////////////////////////////////////
4987
// Destructor

ecr/domain/core/decrement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_decrement(Runtime* runtime) {
2-
print("decrement handler\n");
2+
runtime->notImplemented("decrement");
33
return 0;
44
};

ecr/domain/core/delete.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_delete(Runtime* runtime) {
2-
print("delete handler\n");
2+
runtime->notImplemented("delete");
33
return 0;
44
};

ecr/domain/core/divide.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_divide(Runtime* runtime) {
2-
print("divide handler\n");
2+
runtime->notImplemented("divide");
33
return 0;
44
};

ecr/domain/core/dummy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_dummy(Runtime* runtime) {
2-
print("dummy handler\n");
2+
runtime->notImplemented("dummy");
33
return 0;
44
};

ecr/domain/core/end.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_end(Runtime* runtime) {
2-
print("end handler\n");
2+
runtime->notImplemented("end");
33
return 0;
44
};

ecr/domain/core/exit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
int core_exit(Runtime* runtime) {
22
#if KEYWORDS
3-
printf("Line %s: exit\n", runtime->getCommand()->get(0)->getText());
3+
printf("Line %s\n", runtime->getLineNumber());
44
#endif
55

66
return -1;

ecr/domain/core/file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_file(Runtime* runtime) {
2-
print("file handler\n");
2+
runtime->notImplemented("file");
33
return 0;
44
};

ecr/domain/core/fork.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#ifndef CORE_FORK
2-
#define CORE_FORK
3-
41
int core_fork(Runtime* runtime) {
5-
print("fork handler\n");
2+
runtime->notImplemented("fork");
63
return 0;
74
};
8-
9-
#endif

ecr/domain/core/get.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_get(Runtime* runtime) {
2-
print("get handler\n");
2+
runtime->notImplemented("get");
33
return 0;
44
};

ecr/domain/core/gosub.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
21
int core_gosub(Runtime* runtime) {
3-
print("gosub handler\n");
2+
runtime->notImplemented("gosub");
43
return 0;
54
};

ecr/domain/core/goto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_goto(Runtime* runtime) {
2-
print("goto handler\n");
2+
runtime->notImplemented("goto");
33
return 0;
44
};

ecr/domain/core/gotopc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_gotoPC(Runtime* runtime) {
2-
print("gotoPC handler\n");
2+
runtime->notImplemented("gotoPC");
33
return 0;
44
};

ecr/domain/core/if.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#ifndef CORE_IF
2-
#define CORE_IF
3-
41
int core_if(Runtime* runtime) {
5-
print("if handler\n");
2+
runtime->notImplemented("if");
63
return 0;
74
};
8-
9-
#endif

ecr/domain/core/increment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_increment(Runtime* runtime) {
2-
print("increment handler\n");
2+
runtime->notImplemented("incrment");
33
return 0;
44
};

ecr/domain/core/index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_index(Runtime* runtime) {
2-
print("index handler\n");
2+
runtime->notImplemented("index");
33
return 0;
44
};

ecr/domain/core/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_init(Runtime* runtime) {
2-
print("init handler\n");
2+
runtime->notImplemented("init");
33
return 0;
44
};

ecr/domain/core/multiply.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_multiply(Runtime* runtime) {
2-
print("multiply handler\n");
2+
runtime->notImplemented("multiply");
33
return 0;
44
};

ecr/domain/core/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_object(Runtime* runtime) {
2-
print("object handler\n");
2+
runtime->notImplemented("object");
33
return 0;
44
};

ecr/domain/core/open.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_open(Runtime* runtime) {
2-
print("open handler\n");
2+
runtime->notImplemented("open");
33
return 0;
44
};

ecr/domain/core/pop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_pop(Runtime* runtime) {
2-
print("pop handler\n");
2+
runtime->notImplemented("pop");
33
return 0;
44
};

ecr/domain/core/post.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_post(Runtime* runtime) {
2-
print("post handler\n");
2+
runtime->notImplemented("post");
33
return 0;
44
};

ecr/domain/core/print.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
int core_print(Runtime* runtime) {
22
#if KEYWORDS
3-
printf("Line %s: print\n", runtime->getCommand()->get(0)->getText());
3+
printf("Line %s ", runtime->getLineNumber());
44
#endif
55

66
const char* buf = runtime->getTextValue("value");
7+
if (buf == nullptr) {
8+
print("No value at line %s\n", runtime->getLineNumber());
9+
exit(1);
10+
}
711
printf("->%s\n", buf);
8-
delete buf;
12+
delete[] buf;
913

1014
return runtime->getPC() + 1;
1115
};

ecr/domain/core/push.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int core_push(Runtime* runtime) {
2-
print("push handler\n");
2+
runtime->notImplemented("push");
33
return 0;
44
};

0 commit comments

Comments
 (0)