Skip to content

Commit 6d67508

Browse files
committed
rt: Changed reportError to report since it is now shared
1 parent afd825a commit 6d67508

File tree

4 files changed

+15
-48
lines changed

4 files changed

+15
-48
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public abstract class NativeFunction implements PiccodeValue {
1313

1414
private final String name;
1515

16-
private final List<String> params;
17-
private final Map<String, PiccodeValue> defaultArgs;
18-
private final Map<String, PiccodeValue> boundArgs;
16+
public List<String> params;
17+
protected final Map<String, PiccodeValue> defaultArgs;
18+
protected final Map<String, PiccodeValue> boundArgs;
1919
public Integer frame;
2020
public int line = 0;
2121
public int column = 0;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void addNote(PiccodeInfo note) {
3434
}
3535

3636
public void reportError() {
37-
reportError(!ReplState.ACTIVE, "ERROR");
37+
report(!ReplState.ACTIVE, "ERROR");
3838
}
3939

4040
@Override
41-
public void reportError(boolean die, String kind) {
41+
public void report(boolean die, String kind) {
4242
var fp = new File("");
4343

4444
String[] lines = new String[]{};
@@ -90,7 +90,7 @@ public void reportError(boolean die, String kind) {
9090
if (!notes.isEmpty()) {
9191
System.out.println((Chalk.on(".").yellow() + "\n").repeat(2));
9292
for (var note : notes) {
93-
note.reportError(false, "INFO");
93+
note.report(false, "INFO");
9494
}
9595
}
9696

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public PiccodeSimpleNote(String message) {
1414
}
1515

1616
@Override
17-
public void reportError(boolean die, String kind) {
17+
public void report(boolean die, String kind) {
1818
System.out.println(Chalk.on("[NOTE]: ").bold().yellow() + message);
1919
}
2020
}

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

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @author hexaredecimal
1313
*/
14-
public class PiccodeException extends RuntimeException implements PiccodeInfo {
14+
public class PiccodeWarning implements PiccodeInfo {
1515

1616
public String file;
1717
public int line, col;
@@ -21,8 +21,7 @@ public class PiccodeException extends RuntimeException implements PiccodeInfo {
2121

2222
private List<PiccodeInfo> notes = new ArrayList<>();
2323

24-
public PiccodeException(String file, int line, int col, String message) {
25-
super(message);
24+
public PiccodeWarning(String file, int line, int col, String message) {
2625
this.file = file;
2726
this.line = line;
2827
this.col = col;
@@ -33,12 +32,12 @@ public void addNote(PiccodeInfo note) {
3332
this.notes.add(note);
3433
}
3534

36-
public void reportError() {
37-
reportError(!ReplState.ACTIVE, "ERROR");
35+
public void report() {
36+
report(false, "WARNING");
3837
}
3938

4039
@Override
41-
public void reportError(boolean die, String kind) {
40+
public void report(boolean die, String kind) {
4241
var fp = new File("");
4342

4443
String[] lines = new String[]{};
@@ -60,8 +59,8 @@ public void reportError(boolean die, String kind) {
6059
? "repl"
6160
: fp.getName(),
6261
line, col + 1,
63-
kind == null || kind.equals("ERROR")
64-
? Chalk.on("ERROR").red() // I hard code ERROR just in case it is null;
62+
kind == null || kind.equals("WARNING")
63+
? Chalk.on("WARNING").yellow()// I hard code ERROR just in case it is null;
6564
: Chalk.on(kind.toUpperCase()).yellow(),
6665
message
6766
);
@@ -90,41 +89,9 @@ public void reportError(boolean die, String kind) {
9089
if (!notes.isEmpty()) {
9190
System.out.println((Chalk.on(".").yellow() + "\n").repeat(2));
9291
for (var note : notes) {
93-
note.reportError(false, "INFO");
92+
note.report(false, "INFO");
9493
}
9594
}
96-
97-
var ctx = frame == null
98-
? Context.top
99-
: Context.getContextAt(frame);
100-
101-
if (frame != null) {
102-
ctx = Context.getContextAt(frame);
103-
}
104-
var stack = ctx.getCallStack();
105-
106-
var list = List.of(stack.toArray(StackFrame[]::new)).reversed();
107-
108-
if (!list.isEmpty()) {
109-
var thread = frame == null ? "" : String.format(".THREAD[%s]", frame);
110-
System.out.println("\n[STACK TRACE]" + thread);
111-
for (int i = 0; i < list.size(); i++) {
112-
var _frame = list.get(i);
113-
var callSite = _frame.caller;
114-
var _str = String.format(
115-
"[%s:%d:%d]: %s", callSite.file,
116-
callSite.line, callSite.column + 1,
117-
i == 0
118-
? Chalk.on(callSite.toString()).red()
119-
: callSite.toString());
120-
121-
System.out.println(_str);
122-
}
123-
}
124-
125-
if (die) {
126-
System.exit(1);
127-
}
12895
}
12996

13097
private static String[] toLines(File fp) {

0 commit comments

Comments
 (0)