Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions native-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

BUILD_NATIVE_DIR="build-native"
CLASSPATH="../lib/antlr-4.7-complete.jar:.:../build-tile" # use forward slashes on Linux

mkdir -p "$BUILD_NATIVE_DIR"
cd "$BUILD_NATIVE_DIR"

NATIVE_IMAGE="/home/yasinxdxd/.sdkman/candidates/java/current/bin/native-image"

# Optional: print what you're doing
echo "Using native-image from: $NATIVE_IMAGE"
echo "Using classpath: $CLASSPATH"

# Run native-image
"$NATIVE_IMAGE" \
-H:+UnlockExperimentalVMOptions \
-H:-CheckToolchain \
-cp "$CLASSPATH" \
tile.app.Tile \
-o "tile"
85 changes: 62 additions & 23 deletions src/tile/AntlrToExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,16 @@ public Expression visitObjectLiteralExpression(ObjectLiteralExpressionContext ct

@Override
public Expression visitObjectAccessor(ObjectAccessorContext ctx) {
String identifier = ctx.IDENTIFIER(0).getText();
String identifier;
StringBuilder varType = new StringBuilder();
int tasmIdx = -1;
AtomicBoolean isGlobal = new AtomicBoolean(false);
if (ctx.arrayIndexAccessor() != null) {
identifier = ctx.arrayIndexAccessor().IDENTIFIER().getText();
} else {
identifier = ctx.IDENTIFIER(0).getText();
}

try {
tasmIdx = TasmSymbolGenerator.identifierScopeFind(identifier, varType, isGlobal);
// TODO: use isGlobal!!!
Expand All @@ -660,34 +666,67 @@ public Expression visitObjectAccessor(ObjectAccessorContext ctx) {
TypeDefinition td = TypeResolver.userTypeDefs.get(type);


if (ctx.objectAccessor() == null) {
String fieldId = ctx.IDENTIFIER(1).getText();
if (td != null) {
td.getFields().get(fieldId);
if (td.getFields().get(fieldId) == null) {
int line = ctx.IDENTIFIER(1).getSymbol().getLine();
int col = ctx.IDENTIFIER(1).getSymbol().getCharPositionInLine();
Log.error(line + ":" + col + ": '" + identifier + ": " + type + "'' doesn't have a field " + fieldId + "!");
if (ctx.arrayIndexAccessor() != null) {
if (ctx.objectAccessor() == null) {
String fieldId = ctx.IDENTIFIER(0).getText();
if (td != null) {
td.getFields().get(fieldId);
if (td.getFields().get(fieldId) == null) {
int line = ctx.IDENTIFIER(0).getSymbol().getLine();
int col = ctx.IDENTIFIER(0).getSymbol().getCharPositionInLine();
Log.error(line + ":" + col + ": '" + identifier + ": " + type + "'' doesn't have a field " + fieldId + "!");
}
} else {
Log.error("NOT IMPLEMENTED!");
}
}

ObjectAccessor oa = new ObjectAccessor(fieldId, td, tasmIdx, null);
if (isGlobal.get() == true) {
oa.setAsGlobal();
}
ObjectAccessor oa = new ObjectAccessor(fieldId, td, tasmIdx, null);
if (isGlobal.get() == true) {
oa.setAsGlobal();
}

return oa;
} else {

ObjectAccessor accessor = (ObjectAccessor)visit(ctx.objectAccessor());
return oa;
} else {
ObjectAccessor accessor = (ObjectAccessor)visit(ctx.objectAccessor());

ObjectAccessor oa = new ObjectAccessor(null, td, tasmIdx, accessor);
if (isGlobal.get() == true) {
oa.setAsGlobal();
}

ObjectAccessor oa = new ObjectAccessor(null, td, tasmIdx, accessor);
if (isGlobal.get() == true) {
oa.setAsGlobal();
return oa;
}
} else {
if (ctx.objectAccessor() == null) {
String fieldId = ctx.IDENTIFIER(1).getText();
if (td != null) {
td.getFields().get(fieldId);
if (td.getFields().get(fieldId) == null) {
int line = ctx.IDENTIFIER(1).getSymbol().getLine();
int col = ctx.IDENTIFIER(1).getSymbol().getCharPositionInLine();
Log.error(line + ":" + col + ": '" + identifier + ": " + type + "'' doesn't have a field " + fieldId + "!");
}
}

ObjectAccessor oa = new ObjectAccessor(fieldId, td, tasmIdx, null);
if (isGlobal.get() == true) {
oa.setAsGlobal();
}

return oa;
} else {

ObjectAccessor accessor = (ObjectAccessor)visit(ctx.objectAccessor());

return oa;
}
ObjectAccessor oa = new ObjectAccessor(null, td, tasmIdx, accessor);
if (isGlobal.get() == true) {
oa.setAsGlobal();
}

return oa;
}
}

}

}
4 changes: 2 additions & 2 deletions src/tile/AntlrToStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ public Statement visitTypeDefinition(TypeDefinitionContext ctx) {
String typeName = ctx.IDENTIFIER().getText();
HashMap<String, TypeDefinition.Field> fields = null;
TypeDefinition.Kind kind = null;
int offset = 0;
if (ctx.structDefinition() != null) {
fields = new HashMap<>();
kind = TypeDefinition.Kind.STRUCT;
int offset = 0;
for (int i = 0; i < ctx.structDefinition().fieldDefinition().size(); i++) {
String id = ctx.structDefinition().fieldDefinition(i).IDENTIFIER().getText();
String type = ctx.structDefinition().fieldDefinition(i).typeName().getText();
Expand All @@ -330,7 +330,7 @@ public Statement visitTypeDefinition(TypeDefinitionContext ctx) {
}
}

TypeDefinition td = new TypeDefinition(typeName, kind, fields);
TypeDefinition td = new TypeDefinition(typeName, kind, fields, offset);
TypeResolver.userTypeDefs.put(typeName, td);
return td;
}
Expand Down
4 changes: 3 additions & 1 deletion src/tile/ast/stmt/TypeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum Kind {

public String typeName;
public Kind kind;
public int size;

public static class Field {
public String id;
Expand All @@ -31,10 +32,11 @@ public Field(String id, String type, int type_size, int offset) {
private HashMap<String, Field> fields; // for struct
private List<String> variants; // for union

public TypeDefinition(String typeName, Kind kind, HashMap<String, Field> fields) {
public TypeDefinition(String typeName, Kind kind, HashMap<String, Field> fields, int size) {
this.typeName = typeName;
this.kind = kind;
this.fields = fields;
this.size = size;
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/tile/ast/types/TypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ private static int resolveArrayTypeSize(String type) {
}

// composite type
// FIXME:
if (isUserDefinedType(type)) {
return userTypeDefs.get(type).size;
}
return -1;
}

Expand All @@ -182,7 +184,9 @@ public static int resolveFieldTypeSize(String type) {
}

// composite type
// FIXME:
if (isUserDefinedType(type)) {
return userTypeDefs.get(type).size;
}
return -1;
}

Expand Down
6 changes: 4 additions & 2 deletions tileParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ objectLiteralFieldAssignment
objectAccessor
: IDENTIFIER '.' IDENTIFIER
| IDENTIFIER '.' objectAccessor
| arrayIndexAccessor '.' IDENTIFIER
| arrayIndexAccessor '.' objectAccessor
;

unaryExpression
Expand Down Expand Up @@ -122,7 +124,7 @@ arrayValuedInitializerElements
;

arraySizedInitializer
: primaryTypeName arraySizeSpecifier+
: arraySizeSpecifier+ primaryTypeName
;

arraySizeSpecifier
Expand Down Expand Up @@ -306,7 +308,7 @@ tasmBlock
;

tasmInstructions
: (tasmLine)? (PUNC_COMMA tasmLine)*
: (tasmLine)? PUNC_COMMA? (PUNC_COMMA tasmLine)* PUNC_COMMA?
;

tasmLine
Expand Down
Loading