Skip to content

Commit 0228146

Browse files
committed
Removed some unnecessary keywords, improved string and range performance
1 parent 91ff311 commit 0228146

23 files changed

+416
-727
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ All documentation can be found in the [wiki](https://github.com/tomdodd4598/Dodd
1616
Planned Features
1717
----------------
1818

19-
- All planned features currently implemented!
19+
All planned features currently implemented!
2020

2121
Permissions
2222
-----------

run/fibonacci.dssl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
# ------------------- #
2-
# RECURSIVE FIBONACCI #
2+
# ITERATIVE FIBONACCI #
33
# ------------------- #
44

5-
/f 0 def
6-
/n 0 def
5+
/a 1 def
6+
/b 0 def
7+
/c 0 def
78

8-
/fib {
9-
dup 1 > {
10-
dup 1 - fib
11-
exch 2 - fib +
12-
} if
13-
} macro
9+
10 {
10+
/c a =
11+
/a b +=
12+
/b c =
13+
c println
14+
} repeat
1415

15-
{
16-
/n ++
17-
n 10 > { break } if
18-
/f n fib =
19-
f println
20-
} loop
16+
'\n' print
2117

2218
# ------------------- #
23-
# ITERATIVE FIBONACCI #
19+
# RECURSIVE FIBONACCI #
2420
# ------------------- #
2521

2622
/fib {

src/dssl.sable

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,18 @@ Tokens
5353

5454
new = 'new';
5555

56-
null = 'null';
5756
deref = 'deref';
5857

58+
null = 'null';
5959
type = 'type';
6060
cast = 'cast';
6161

6262
exch = 'exch';
63+
roll = 'roll';
6364
pop = 'pop';
6465
dup = 'dup';
6566

66-
roll = 'roll';
67-
rid = 'rid';
68-
copy = 'copy';
69-
70-
index = 'index';
71-
count = 'count';
72-
countto = 'countto';
67+
stacksize = 'stacksize';
7368

7469
read = 'read';
7570
print = 'print';

src/dssl/Helpers.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import java.nio.charset.Charset;
77
import java.nio.file.*;
88
import java.util.*;
9-
import java.util.Map.Entry;
10-
import java.util.function.*;
9+
import java.util.function.Function;
1110
import java.util.stream.*;
1211

1312
import org.apache.commons.lang3.StringUtils;
@@ -198,8 +197,8 @@ public static <A, B> Set<B> map(Set<A> set, Function<? super A, B> function) {
198197
return set.stream().map(function).collect(Collectors.toSet());
199198
}
200199

201-
public static <A, B, C, D> Collector<Entry<A, B>, ?, Map<C, D>> mapCollector(Function<? super A, C> keyFunction, Function<? super B, D> valueFunction, BinaryOperator<D> mergeFunction) {
202-
return Collectors.toMap(x -> keyFunction.apply(x.getKey()), x -> valueFunction.apply(x.getValue()), mergeFunction);
200+
public static <A, B, C, D> Map<C, D> map(Map<A, B> map, Function<? super A, C> keyFunction, Function<? super B, D> valueFunction) {
201+
return map.entrySet().stream().collect(Collectors.toMap(x -> keyFunction.apply(x.getKey()), x -> valueFunction.apply(x.getValue()), (x, y) -> y));
203202
}
204203

205204
public static final Set<String> KEYWORDS = new HashSet<>();
@@ -222,23 +221,18 @@ public static <A, B> Set<B> map(Set<A> set, Function<? super A, B> function) {
222221

223222
public static final String NEW = "new";
224223

225-
public static final String NULL = "null";
226224
public static final String DEREF = "deref";
227225

226+
public static final String NULL = "null";
228227
public static final String TYPE = "type";
229228
public static final String CAST = "cast";
230229

231230
public static final String EXCH = "exch";
231+
public static final String ROLL = "roll";
232232
public static final String POP = "pop";
233233
public static final String DUP = "dup";
234234

235-
public static final String ROLL = "roll";
236-
public static final String RID = "rid";
237-
public static final String COPY = "copy";
238-
239-
public static final String INDEX = "index";
240-
public static final String COUNT = "count";
241-
public static final String COUNTTO = "countto";
235+
public static final String STACKSIZE = "stacksize";
242236

243237
public static final String READ = "read";
244238
public static final String PRINT = "print";
@@ -324,23 +318,18 @@ public static <A, B> Set<B> map(Set<A> set, Function<? super A, B> function) {
324318

325319
KEYWORDS.add(NEW);
326320

327-
KEYWORDS.add(NULL);
328321
KEYWORDS.add(DEREF);
329322

323+
KEYWORDS.add(NULL);
330324
KEYWORDS.add(TYPE);
331325
KEYWORDS.add(CAST);
332326

333327
KEYWORDS.add(EXCH);
328+
KEYWORDS.add(ROLL);
334329
KEYWORDS.add(POP);
335330
KEYWORDS.add(DUP);
336331

337-
KEYWORDS.add(ROLL);
338-
KEYWORDS.add(RID);
339-
KEYWORDS.add(COPY);
340-
341-
KEYWORDS.add(INDEX);
342-
KEYWORDS.add(COUNT);
343-
KEYWORDS.add(COUNTTO);
332+
KEYWORDS.add(STACKSIZE);
344333

345334
KEYWORDS.add(READ);
346335
KEYWORDS.add(PRINT);

src/dssl/NativeImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static Object set_nativize(@NonNull Element elem, Type type) {
373373

374374
static Object map_nativize(@NonNull Element elem, Type keyType, Type valueType) {
375375
Tracker tracker = new Tracker();
376-
Map<?, ?> obj = ((DictElement) elem).value.entrySet().stream().collect(Helpers.mapCollector(x -> tracked_nativize(x, keyType, tracker), x -> tracked_nativize(x, valueType, tracker), (x, y) -> y));
376+
Map<?, ?> obj = Helpers.map(((DictElement) elem).value, x -> tracked_nativize(x, keyType, tracker), x -> tracked_nativize(x, valueType, tracker));
377377
return tracker.flag ? null : obj;
378378
}
379379

@@ -438,7 +438,7 @@ else if (obj instanceof Set) {
438438
return new SetElement(Helpers.map((Set<?>) obj, NativeImpl::convert));
439439
}
440440
else if (obj instanceof Map) {
441-
return new DictElement(((Map<?, ?>) obj).entrySet().stream().collect(Helpers.mapCollector(NativeImpl::convert, NativeImpl::convert, (x, y) -> y)));
441+
return new DictElement(Helpers.map((Map<?, ?>) obj, NativeImpl::convert, NativeImpl::convert));
442442
}
443443
else {
444444
return new NativeElement(obj);

src/dssl/analysis/Analysis.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,15 @@ public interface Analysis extends Switch
2525
void caseTClass(TClass node);
2626
void caseTMagic(TMagic node);
2727
void caseTNew(TNew node);
28-
void caseTNull(TNull node);
2928
void caseTDeref(TDeref node);
29+
void caseTNull(TNull node);
3030
void caseTType(TType node);
3131
void caseTCast(TCast node);
3232
void caseTExch(TExch node);
33+
void caseTRoll(TRoll node);
3334
void caseTPop(TPop node);
3435
void caseTDup(TDup node);
35-
void caseTRoll(TRoll node);
36-
void caseTRid(TRid node);
37-
void caseTCopy(TCopy node);
38-
void caseTIndex(TIndex node);
39-
void caseTCount(TCount node);
40-
void caseTCountto(TCountto node);
36+
void caseTStacksize(TStacksize node);
4137
void caseTRead(TRead node);
4238
void caseTPrint(TPrint node);
4339
void caseTPrintln(TPrintln node);

src/dssl/analysis/AnalysisAdapter.java

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ public void caseTNew(TNew node)
153153
}
154154

155155
@Override
156-
public void caseTNull(TNull node)
156+
public void caseTDeref(TDeref node)
157157
{
158158
defaultCase(node);
159159
}
160160

161161
@Override
162-
public void caseTDeref(TDeref node)
162+
public void caseTNull(TNull node)
163163
{
164164
defaultCase(node);
165165
}
@@ -182,50 +182,26 @@ public void caseTExch(TExch node)
182182
defaultCase(node);
183183
}
184184

185-
@Override
186-
public void caseTPop(TPop node)
187-
{
188-
defaultCase(node);
189-
}
190-
191-
@Override
192-
public void caseTDup(TDup node)
193-
{
194-
defaultCase(node);
195-
}
196-
197185
@Override
198186
public void caseTRoll(TRoll node)
199187
{
200188
defaultCase(node);
201189
}
202190

203191
@Override
204-
public void caseTRid(TRid node)
205-
{
206-
defaultCase(node);
207-
}
208-
209-
@Override
210-
public void caseTCopy(TCopy node)
211-
{
212-
defaultCase(node);
213-
}
214-
215-
@Override
216-
public void caseTIndex(TIndex node)
192+
public void caseTPop(TPop node)
217193
{
218194
defaultCase(node);
219195
}
220196

221197
@Override
222-
public void caseTCount(TCount node)
198+
public void caseTDup(TDup node)
223199
{
224200
defaultCase(node);
225201
}
226202

227203
@Override
228-
public void caseTCountto(TCountto node)
204+
public void caseTStacksize(TStacksize node)
229205
{
230206
defaultCase(node);
231207
}

src/dssl/interpret/Interpreter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Interpreter {
1212
protected final TokenExecutor root;
1313
protected boolean halt = false;
1414

15-
protected final Deque<@NonNull Element> elemStack = new ArrayDeque<>();
15+
protected final Deque<@NonNull Element> stack = new ArrayDeque<>();
1616
protected final List<String> printList = new ArrayList<>();
1717

1818
protected final IO io;

0 commit comments

Comments
 (0)