Skip to content

Commit eeb1cb9

Browse files
committed
Print and Put
1 parent 7d174a1 commit eeb1cb9

File tree

18 files changed

+591
-203
lines changed

18 files changed

+591
-203
lines changed

ecr/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
#define print(...) printf(__VA_ARGS__)
55
#else
66
#define print(...)
7-
#endif
7+
#endif

ecr/domain/core/core-values.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class CoreValues {
3636

3737
void init(ValueArray* values) {
3838
this->values = values;
39-
add("text", _CORE_TEXT_);
40-
add("int", _CORE_INT_);
41-
add("bool", _CORE_BOOL_);
39+
add("text", TEXT_VALUE);
40+
add("int", INT_VALUE);
41+
add("bool", BOOL_VALUE);
4242
};
4343

4444
///////////////////////////////////////////////////////////////////////

ecr/domain/core/exit.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
int core_exit(Runtime* runtime) {
2-
print("exit handler\n");
2+
#if KEYWORDS
3+
printf("Line %s: exit\n", runtime->getCommand()->get(0)->getText());
4+
#endif
5+
36
return -1;
47
};

ecr/domain/core/print.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
int core_print(Runtime* runtime) {
2-
print("print handler\n");
3-
RuntimeValue* value = runtime->getRuntimeValue("value");
4-
switch (value->getType()) {
5-
case TEXT_VALUE:
6-
printf("->%s\n", value->getTextValue());
7-
break;
8-
case INT_VALUE:
9-
printf("->%d\n", value->getIntValue());
10-
break;
11-
case BOOL_VALUE:
12-
printf("->%s\n", value->getBoolValue() ? "true" : "false");
13-
break;
14-
};
2+
#if KEYWORDS
3+
printf("Line %s: print\n", runtime->getCommand()->get(0)->getText());
4+
#endif
5+
6+
const char* buf = runtime->getTextValue("value");
7+
printf("->%s\n", buf);
8+
delete buf;
159

1610
return runtime->getPC() + 1;
1711
};

ecr/domain/core/put.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
int core_put(Runtime* runtime) {
2-
print("put handler\n");
3-
return 0;
2+
#if KEYWORDS
3+
printf("Line %s: put\n", runtime->getCommand()->get(0)->getText());
4+
#endif
5+
6+
RuntimeValue* runtimeValue = runtime->getRuntimeValue("value");
7+
runtime->setSymbolValue("target", runtimeValue->copy());
8+
9+
return runtime->getPC() + 1;
410
};

ecr/domain/core/variable.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
int core_variable(Runtime* runtime) {
2-
print("variable handler\n");
2+
#if KEYWORDS
3+
printf("Line %s: variable\n", runtime->getCommand()->get(0)->getText());
4+
#endif
5+
6+
int pc = runtime->getPC();
7+
Symbol* symbol = new Symbol(runtime->getCommandProperty(0, "name"));
8+
runtime->getSymbols()->add(symbol);
39

410
return runtime->getPC() + 1;
511
};

ecr/ecr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#define DEBUG 1 // set to 1 to debug, 0 for no debugging
1+
#define DEBUG 0 // set to 1 to debug, 0 for no debugging
22
#define DESTROY 0 // set to 1 to show destructors
3+
#define KEYWORDS 0 // set to 1 to show keywords as they execute
34

45
#include <stdio.h>
56
#include <stdlib.h>
@@ -8,11 +9,11 @@
89
#include "debug.h"
910
#include "definitions.h"
1011
#include "linkedlist.h"
12+
#include "runtimevalue.h"
1113
#include "text.h"
1214
#include "keyword.h"
1315
#include "value.h"
14-
#include "valuecodes.h"
15-
#include "runtimevalue.h"
16+
#include "symbol.h"
1617
#include "runtime.h"
1718
#include "domain/core/core-keywords.h"
1819
#include "domain/core/core-values.h"
@@ -76,6 +77,7 @@ int main(int argc, char* argv[])
7677
script[n] = '\0';
7778
Text* keys = new Text(keyStart, "keys");
7879
delete script;
80+
script = nullptr;
7981

8082
// print("codes: %s", codes->getText());
8183
// print("keys: %s", keys->getText());

ecr/keyword.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class KeywordArray {
5252
int size = 0; // the number of keywords
5353
Keyword** array = nullptr; // the array of keywords
5454
LinkedList* list = new LinkedList(); // A list to hold new keywords as they are added
55-
TextArray* choices;
5655

5756
public:
5857

@@ -168,8 +167,10 @@ class KeywordArray {
168167
// Destructor
169168
~KeywordArray() {
170169
delete array;
170+
array = nullptr;
171171
delete list;
172-
delete choices;
172+
list = nullptr;
173+
173174
#if DESTROY
174175
print("KeywordArray: Delete %s\n", name);
175176
#endif

ecr/run.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Run {
99
CoreKeywords* coreKeywords;
1010
CoreValues* coreValues;
1111
int* scriptKeywordCodes;
12+
SymbolArray* symbols;
1213

1314
///////////////////////////////////////////////////////////////////////
1415
// Set up the runtime
@@ -17,6 +18,7 @@ class Run {
1718
runtime->setCodeArray(codeArray);
1819
runtime->setKeyArray(keyArray);
1920
runtime->setCommands(commands);
21+
runtime->setSymbols(symbols);
2022
}
2123

2224
public:
@@ -25,7 +27,7 @@ class Run {
2527
// Run a sequence of commands from the current program counter
2628
int runFrom(Runtime* runtime, int pc) {
2729
do {
28-
print("Run command %d\n", pc);
30+
// print("Command %d\n", pc);
2931
TextArray* command = commands[pc];
3032
runtime->setCommand(command);
3133
runtime->setPC(pc);
@@ -110,7 +112,8 @@ class Run {
110112
print("No handler found for keyword '%s'\n", tt->getText());
111113
return;
112114
}
113-
115+
// Create an array of symbols
116+
symbols = new SymbolArray();
114117
}
115118
setupRuntime();
116119
if (runFrom(runtime, 0) < 0) {

0 commit comments

Comments
 (0)