Skip to content

Commit d88aa50

Browse files
committed
PiccodeValue: Add helper methods for creating error and success values
1 parent cbd0332 commit d88aa50

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/org/piccode/rt/PiccodeValue.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.piccode.rt;
22

33
import com.github.tomaslanger.chalk.Chalk;
4+
import java.util.ArrayList;
5+
import java.util.List;
46
import org.piccode.ast.Ast;
57

68
/**
@@ -24,6 +26,27 @@ public static void verifyType(Ast caller, PiccodeValue value, Type type) {
2426
}
2527
}
2628

29+
public static PiccodeValue error(PiccodeValue value) {
30+
var nodes = new ArrayList<PiccodeValue>();
31+
nodes.addFirst(new PiccodeUnit());
32+
nodes.addLast(value);
33+
return new PiccodeTuple(nodes);
34+
}
35+
36+
public static PiccodeValue success(PiccodeValue value) {
37+
var nodes = new ArrayList<PiccodeValue>();
38+
nodes.addFirst(value);
39+
nodes.addLast(new PiccodeUnit());
40+
return new PiccodeTuple(nodes);
41+
}
42+
43+
public static PiccodeValue error(String message) {
44+
var nodes = new ArrayList<PiccodeValue>();
45+
nodes.addFirst(new PiccodeUnit());
46+
nodes.addLast(new PiccodeString(message));
47+
return new PiccodeTuple(nodes);
48+
}
49+
2750
public static enum Type {
2851
NUMBER,
2952
STRING,

0 commit comments

Comments
 (0)