Skip to content

Commit fae97a3

Browse files
author
MichaelSDavid
committed
Finalizing tests
1 parent 3559d16 commit fae97a3

File tree

4 files changed

+65
-115
lines changed

4 files changed

+65
-115
lines changed

src/scanner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static TokenType identifierType() {
124124
switch (scanner.start[1]) {
125125
case 'a': return checkKeyword(2, 3, "lse", TOKEN_FALSE);
126126
case 'o': return checkKeyword(2, 1, "r", TOKEN_FOR);
127-
case 'u': return checkKeyword(2, 1, "n", TOKEN_FUN);
127+
case 'n': return checkKeyword(2, 1, "c", TOKEN_FUN);
128128
}
129129
}
130130
break;

src/value.c

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -68,56 +68,4 @@ bool valuesEqual(Value a, Value b) {
6868
return false; // Unreachable
6969
}
7070
#endif
71-
}
72-
//< Types of Values values-equal
73-
74-
// #include <stdio.h>
75-
// #include <string.h>
76-
77-
// #include "object.h"
78-
// #include "memory.h"
79-
// #include "value.h"
80-
81-
// void initValueArray(ValueArray* array) {
82-
// array->values = NULL;
83-
// array->capacity = 0;
84-
// array->count = 0;
85-
// }
86-
87-
// void writeValueArray(ValueArray* array, Value value) {
88-
// if (array->capacity < array->count + 1) {
89-
// int oldCapacity = array->capacity;
90-
// array->capacity = GROW_CAPACITY(oldCapacity);
91-
// array->values = GROW_ARRAY(Value, array->values, oldCapacity, array->capacity);
92-
// }
93-
94-
// array->values[array->count] = value;
95-
// array->count++;
96-
// }
97-
98-
// void freeValueArray(ValueArray* array) {
99-
// FREE_ARRAY(Value, array->values, array->capacity);
100-
// initValueArray(array);
101-
// }
102-
103-
// void printValue(Value value) {
104-
// switch (value.type) {
105-
// case VAL_BOOL: printf(AS_BOOL(value) ? "true" : "false"); break;
106-
// case VAL_NULL: printf("null"); break;
107-
// case VAL_NUMBER: printf("%g", AS_NUMBER(value)); break;
108-
// case VAL_OBJ: printObject(value); break;
109-
// }
110-
// }
111-
112-
// bool valuesEqual(Value a, Value b) {
113-
// if (a.type != b.type) return false;
114-
115-
// switch (a.type) {
116-
// case VAL_BOOL: return AS_BOOL(a) == AS_BOOL(b);
117-
// case VAL_NULL: return true;
118-
// case VAL_NUMBER: return AS_NUMBER(a) == AS_NUMBER(b);
119-
// case VAL_OBJ: return AS_OBJ(a) == AS_OBJ(b);
120-
// default:
121-
// return false; // Unreachable
122-
// }
123-
// }
71+
}

src/value.h

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -96,57 +96,4 @@ void freeValueArray(ValueArray* array);
9696

9797
void printValue(Value value);
9898

99-
#endif
100-
101-
// #ifndef conure_value_h
102-
// #define conure_value_h
103-
104-
// #include "common.h"
105-
106-
// typedef struct sObj Obj;
107-
// typedef struct sObjString ObjString;
108-
109-
// typedef enum {
110-
// VAL_BOOL,
111-
// VAL_NULL,
112-
// VAL_NUMBER,
113-
// VAL_OBJ
114-
// } ValueType;
115-
116-
// typedef struct {
117-
// ValueType type;
118-
// union {
119-
// bool boolean;
120-
// double number;
121-
// Obj* obj;
122-
// } as;
123-
// } Value;
124-
125-
// #define IS_BOOL(value) ((value).type == VAL_BOOL)
126-
// #define IS_NULL(value) ((value).type == VAL_NULL)
127-
// #define IS_NUMBER(value) ((value).type == VAL_NUMBER)
128-
// #define IS_OBJ(value) ((value).type == VAL_OBJ)
129-
130-
// #define AS_OBJ(value) ((value).as.obj)
131-
// #define AS_BOOL(value) ((value).as.boolean)
132-
// #define AS_NUMBER(value) ((value).as.number)
133-
134-
// #define BOOL_VAL(value) ((Value){ VAL_BOOL, { .boolean = value } })
135-
// #define NULL_VAL ((Value){ VAL_NULL, { .number = 0 } })
136-
// #define NUMBER_VAL(value) ((Value){ VAL_NUMBER, { .number = value } })
137-
// #define OBJ_VAL(object) ((Value){ VAL_OBJ, { .obj = (Obj*)object } })
138-
139-
// typedef struct {
140-
// int capacity;
141-
// int count;
142-
// Value* values;
143-
// } ValueArray;
144-
145-
// bool valuesEqual(Value a, Value b);
146-
147-
// void initValueArray(ValueArray* array);
148-
// void writeValueArray(ValueArray* array, Value value);
149-
// void freeValueArray(ValueArray* array);
150-
// void printValue(Value value);
151-
152-
// #endif
99+
#endif

tests/conure_tests.cn

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
// Once debug logs are out of the way this will be much smoother
2-
// Also 'write' may turn to only a function later on
2+
// Also 'write' may turn to only a function later on (brackets for working highlighting)
33
// TODO: Add multi-line comments
44
// TODO: Add interactive history in the REPL
55

66
// 1 (Arithmetic)
77
write("|TEST 1: Arithmetic|");
88

99
write(1 + 2 + 3 + 4 + 5);
10+
write(""); // Separation (TODO: Add escape characters)
1011

1112
// 2 (Boolean logic)
1213
write("|TEST 2: Boolean Logic|");
1314

1415
write(!(5 - 4 > 3 * 2 == !none));
16+
write(""); // Separation
1517

1618
// 3 (String operations)
1719
write("|TEST 3: String Operations|");
1820

1921
write("st" + "ri" + "ng");
22+
write(""); // Separation
2023

2124
// 4 (Global variable operations)
2225
write("|TEST 4: Variable Operations|");
@@ -25,6 +28,7 @@ let breakfast = "beignets";
2528
let beverage = "cafe au lait";
2629
breakfast = "beignets with " + beverage;
2730
write(breakfast);
31+
write(""); // Separation
2832

2933
// 5 (Blocks and local variable operations)
3034
write("|TEST 5: Blocks and Locals|");
@@ -36,6 +40,8 @@ write("|TEST 5: Blocks and Locals|");
3640
}
3741
}
3842

43+
write("--no output--\n"); // Separation
44+
3945
// ERROR CASES (for testing error handling)
4046
//{
4147
// let a = "first";
@@ -72,10 +78,12 @@ for (let i = 1; i < 10; i = i + 1) {
7278
write(i);
7379
}
7480

81+
write(""); // Separation
82+
7583
// 7 (Functions and closures)
7684
write("|TEST 7: Functional Operations|");
7785

78-
fun fib(n) {
86+
fnc fib(n) {
7987
if (n < 2) return n;
8088
return fib(n - 2) + fib(n - 1);
8189
}
@@ -87,15 +95,17 @@ write(fib(10));
8795
// (3 seconds without debug info, like Python) (TODO: optimize recursion)
8896
write(time() - start);
8997

98+
write(""); // Separation
99+
90100
// 8 (Advanced embedded closures)
91101
write("|TEST 8: Advanced Closures|");
92102

93103
let globalOne;
94104
let globalTwo;
95105

96-
fun main() {
106+
fnc main() {
97107
for (let a = 1; a <= 2; a = a + 1) {
98-
fun closure() {
108+
fnc closure() {
99109
write(a);
100110
}
101111
if (globalOne == none) {
@@ -110,20 +120,24 @@ main();
110120
globalOne();
111121
globalTwo();
112122

123+
write(""); // Separation
124+
113125
// 8 (Garbage collection)
114126
write("|TEST 8: Garbage Collection|");
115127

116-
fun makeClosure() {
128+
fnc makeClosure() {
117129
let a = "data";
118130

119-
fun f() { write(a); }
131+
fnc f() { write(a); }
120132
return f;
121133
}
122134

123135
let closure = makeClosure();
124136
// Garbage collection here
125137
closure();
126138

139+
write(""); // Separation
140+
127141
// 9 (Classes and instances)
128142
write("|TEST 9: Classes and Instances|");
129143

@@ -134,6 +148,8 @@ pair.first = 1;
134148
pair.second = 2;
135149
write(pair.first + pair.second); // 3
136150

151+
write(""); // Separation
152+
137153
// 10 (Methods and constructors)
138154
write("|TEST 10: Methods and Initializers|");
139155

@@ -152,6 +168,8 @@ class CoffeeMaker {
152168
let maker = CoffeeMaker("coffee and chicory");
153169
maker.brew();
154170

171+
write(""); // Separation
172+
155173
// 11 (Advanced OOP and inheritance)
156174
write("|TEST 11: Superclasses and Inheritance|");
157175

@@ -171,4 +189,41 @@ class BostonCream < Donut {//EXR3
171189
}
172190
}
173191

174-
BostonCream().cook();
192+
BostonCream().cook();
193+
194+
write(""); // Separation
195+
196+
// 12 (Large-scale optimization)
197+
write("|TEST 11: Large-Scale Optimization|"); // Speed benchmark
198+
199+
class Zoo {
200+
init() {
201+
this.aardvark = 1;
202+
this.baboon = 1;
203+
this.cat = 1;
204+
this.donkey = 1;
205+
this.elephant = 1;
206+
this.fox = 1;
207+
}
208+
ant() { return this.aardvark; }
209+
banana() { return this.baboon; }
210+
tuna() { return this.cat; }
211+
hay() { return this.donkey; }
212+
grass() { return this.elephant; }
213+
mouse() { return this.fox; }
214+
}
215+
216+
let zoo = Zoo();
217+
let sum = 0;
218+
let start = time();
219+
while (sum < 100000000) {
220+
sum = sum + zoo.ant()
221+
+ zoo.banana()
222+
+ zoo.tuna()
223+
+ zoo.hay()
224+
+ zoo.grass()
225+
+ zoo.mouse();
226+
}
227+
228+
write(time() - start);
229+
write(sum);

0 commit comments

Comments
 (0)