summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java18
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/java/JavaGeneratorConfig.java1
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeRef.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java3
4 files changed, 17 insertions, 7 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java
index 082a3b6..30eaf13 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java
@@ -5,26 +5,30 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode imports
// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode imports
-public record UntypedSumVariantDefinitionNode(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, org.zwobble.hobgoblin.compiler.sources.Source source) {
+public record UntypedSumVariantDefinitionNode(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, boolean isBox, org.zwobble.hobgoblin.compiler.sources.Source source) {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), false, org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
- public record Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, org.zwobble.hobgoblin.compiler.sources.Source source) {
+ public record Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, boolean isBox, org.zwobble.hobgoblin.compiler.sources.Source source) {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode build() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode(type, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode(type, isBox, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder withType(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type, isBox, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder withType(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode.Builder type) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type.build(), source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type.build(), isBox, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder withIsBox(boolean isBox) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type, isBox, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(type, isBox, source);
}
// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder body
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/java/JavaGeneratorConfig.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/java/JavaGeneratorConfig.java
index f22e8ff..37262fe 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/java/JavaGeneratorConfig.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/java/JavaGeneratorConfig.java
@@ -78,6 +78,7 @@ public record JavaGeneratorConfig(
}
private static final Map<SimpleNativeType, JavaNativeTypeConfig> DEFAULT_NATIVE_TYPE_CONFIGS = Map.ofEntries(
+ Map.entry(NativeTypes.BOOL, JavaNativeTypeConfig.primitive(JavaTypeRef.BOOLEAN, JavaTypeRef.BOOLEAN_BOXED, new JavaBooleanLiteral(false))),
Map.entry(NativeTypes.INT_32, JavaNativeTypeConfig.primitive(JavaTypeRef.INT, JavaTypeRef.INT_BOXED, new JavaIntegerLiteral(0))),
Map.entry(NativeTypes.INT_64, JavaNativeTypeConfig.primitive(JavaTypeRef.LONG, JavaTypeRef.LONG_BOXED, new JavaIntegerLiteral(0))),
Map.entry(NativeTypes.STRING, JavaNativeTypeConfig.of(JavaTypeRef.STRING, new JavaStringLiteral(""))),
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeRef.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeRef.java
index 6db0c5c..099518c 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeRef.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTypeRef.java
@@ -38,6 +38,8 @@ public record JavaTypeRef(JavaPackageName packageName, List<JavaIdentifier> type
private static final JavaPackageName JAVA_UTIL_STREAM = JavaPackageName.of("java", "util", "stream");
}
+ public static final JavaTypeRef BOOLEAN = primitive("boolean");
+ public static final JavaTypeRef BOOLEAN_BOXED = topLevel(JavaPackages.JAVA_LANG, JavaIdentifier.of("Boolean"));
public static final JavaTypeRef INT = primitive("int");
public static final JavaTypeRef INT_BOXED = topLevel(JavaPackages.JAVA_LANG, JavaIdentifier.of("Integer"));
public static final JavaTypeRef LONG = primitive("long");
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
index a9e5947..47a8095 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
@@ -150,6 +150,7 @@ public class Parser {
tokens.skip(TokenType.KEYWORD_VARIANT);
var name = parseIdentifier(tokens);
+
tokens.skip(TokenType.SYMBOL_SEMICOLON);
var end = tokens.endPosition();
@@ -292,6 +293,7 @@ public class Parser {
tokens.skip(TokenType.KEYWORD_VARIANT);
var type = parseTypeLevelExpression(tokens);
+ var isBox = tokens.trySkip(TokenType.KEYWORD_BOX);
tokens.skip(TokenType.SYMBOL_SEMICOLON);
var end = tokens.endPosition();
@@ -299,6 +301,7 @@ public class Parser {
return new UntypedSumVariantDefinitionNode(
type,
+ isBox,
source
);
}