added lexer and parser basics
This commit is contained in:
+38
-10
@@ -1,19 +1,47 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class IRBackend {
|
||||
private final ReadOnlyList<IRFunction> functions;
|
||||
@Builder.Default
|
||||
private final ReadOnlyList<IRFunction> functions = ReadOnlyList.empty();
|
||||
|
||||
public IRBackend() {
|
||||
this(ReadOnlyList.empty());
|
||||
/**
|
||||
* Returns a stable human-readable representation useful for debug logs and tests.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final var sb = new StringBuilder();
|
||||
sb.append("IRBackend{functions=").append(functions.size()).append('}');
|
||||
|
||||
if (functions.isEmpty()) {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
sb.append(System.lineSeparator());
|
||||
for (final var function : functions) {
|
||||
sb.append(" - fn ")
|
||||
.append(function.name())
|
||||
.append('(')
|
||||
.append(function.parameterCount())
|
||||
.append(" params)")
|
||||
.append(" returnType=")
|
||||
.append(function.hasExplicitReturnType() ? "explicit" : "inferred")
|
||||
.append(" fileId=")
|
||||
.append(function.fileId())
|
||||
.append(" span=[")
|
||||
.append(function.span().getStart())
|
||||
.append(',')
|
||||
.append(function.span().getEnd())
|
||||
.append(']')
|
||||
.append(System.lineSeparator());
|
||||
}
|
||||
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public IRBackend(final ReadOnlyList<IRFunction> functions) {
|
||||
this.functions = functions == null ? ReadOnlyList.empty() : functions;
|
||||
}
|
||||
|
||||
public ReadOnlyList<IRFunction> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user