Skip to content

Commit 51e588a

Browse files
committed
Clean and rename to out_i32
1 parent 39a5985 commit 51e588a

19 files changed

Lines changed: 325 additions & 213 deletions

File tree

.idea/workspace.xml

Lines changed: 17 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/ko/carbonel/compiler/generated/AttrTinyRustParser.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,19 +1207,7 @@ private List<TinyRustLexerToken> matchToken_Stmt_star(){
12071207
private List<TinyRustLexerToken> matchToken_Stmt(){
12081208
enter("matchToken_Stmt");
12091209
List<TinyRustLexerToken> result = null;
1210-
if (peek(TinyRustTokenType.SEMI_COLON)){
1211-
st.newEmpty();
1212-
TinyRustLexerToken v_1 = match(TinyRustTokenType.SEMI_COLON);
1213-
} else if (peek(TinyRustTokenType.WHILE)){
1214-
st.newWhile();
1215-
TinyRustLexerToken v_1 = match(TinyRustTokenType.WHILE);
1216-
TinyRustLexerToken v_2 = match(TinyRustTokenType.OPN_PAREN);
1217-
List<TinyRustLexerToken> v_3 = matchToken_ExpOr();
1218-
TinyRustLexerToken v_4 = match(TinyRustTokenType.CLS_PAREN);
1219-
st.whileBody();
1220-
List<TinyRustLexerToken> v_6 = matchToken_Stmt();
1221-
st.endWhile();
1222-
} else if (peek(TinyRustTokenType.IF)){
1210+
if (peek(TinyRustTokenType.IF)){
12231211
st.newIf();
12241212
TinyRustLexerToken v_1 = match(TinyRustTokenType.IF);
12251213
TinyRustLexerToken v_2 = match(TinyRustTokenType.OPN_PAREN);
@@ -1229,26 +1217,38 @@ private List<TinyRustLexerToken> matchToken_Stmt(){
12291217
List<TinyRustLexerToken> v_6 = matchToken_Stmt();
12301218
List<TinyRustLexerToken> v_7 = matchToken_Stmt_factored_factored_factored();
12311219
st.ifEnd();
1220+
} else if (peek(TinyRustTokenType.WHILE)){
1221+
st.newWhile();
1222+
TinyRustLexerToken v_1 = match(TinyRustTokenType.WHILE);
1223+
TinyRustLexerToken v_2 = match(TinyRustTokenType.OPN_PAREN);
1224+
List<TinyRustLexerToken> v_3 = matchToken_ExpOr();
1225+
TinyRustLexerToken v_4 = match(TinyRustTokenType.CLS_PAREN);
1226+
st.whileBody();
1227+
List<TinyRustLexerToken> v_6 = matchToken_Stmt();
1228+
st.endWhile();
1229+
} else if (peek(TinyRustTokenType.RETURN)){
1230+
st.newReturn();
1231+
TinyRustLexerToken v_1 = match(TinyRustTokenType.RETURN);
1232+
List<TinyRustLexerToken> v_2 = matchToken_Stmt_factored();
1233+
st.endReturn();
1234+
} else if (peek(TinyRustTokenType.SEMI_COLON)){
1235+
st.newEmpty();
1236+
TinyRustLexerToken v_1 = match(TinyRustTokenType.SEMI_COLON);
12321237
} else if (peek(TinyRustTokenType.OPN_BRACE)){
12331238
st.newBlock();
12341239
TinyRustLexerToken v_1 = match(TinyRustTokenType.OPN_BRACE);
12351240
List<TinyRustLexerToken> v_2 = matchToken_Method_factored();
1236-
} else if (peek(TinyRustTokenType.ATTR_ID, TinyRustTokenType.SELF)){
1237-
st.newAssign();
1238-
List<TinyRustLexerToken> v_1 = matchToken_Assign();
1239-
TinyRustLexerToken v_2 = match(TinyRustTokenType.SEMI_COLON);
12401241
} else if (peek(TinyRustTokenType.OPN_PAREN)){
12411242
st.newExpr();
12421243
TinyRustLexerToken v_1 = match(TinyRustTokenType.OPN_PAREN);
12431244
List<TinyRustLexerToken> v_2 = matchToken_ExpOr();
12441245
TinyRustLexerToken v_3 = match(TinyRustTokenType.CLS_PAREN);
12451246
TinyRustLexerToken v_4 = match(TinyRustTokenType.SEMI_COLON);
12461247
st.endExpr();
1247-
} else if (peek(TinyRustTokenType.RETURN)){
1248-
st.newReturn();
1249-
TinyRustLexerToken v_1 = match(TinyRustTokenType.RETURN);
1250-
List<TinyRustLexerToken> v_2 = matchToken_Stmt_factored();
1251-
st.endReturn();
1248+
} else if (peek(TinyRustTokenType.ATTR_ID, TinyRustTokenType.SELF)){
1249+
st.newAssign();
1250+
List<TinyRustLexerToken> v_1 = matchToken_Assign();
1251+
TinyRustLexerToken v_2 = match(TinyRustTokenType.SEMI_COLON);
12521252
} else {
12531253
handleUnexpectedToken("Stmt", Set.of(TinyRustTokenType.ATTR_ID, TinyRustTokenType.IF, TinyRustTokenType.OPN_BRACE, TinyRustTokenType.OPN_PAREN, TinyRustTokenType.RETURN, TinyRustTokenType.SELF, TinyRustTokenType.SEMI_COLON, TinyRustTokenType.WHILE));
12541254
}

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/TinyRustSymbolTable.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ko.carbonel.compiler.intermediate.tinyRust;
22

3-
import ko.carbonel.Logger;
43
import ko.carbonel.compiler.exception.semantic.MethodRedeclaredError;
54
import ko.carbonel.compiler.intermediate.SymbolTable;
65
import ko.carbonel.compiler.intermediate.tinyRust.ast.expression.*;
@@ -76,7 +75,6 @@ public void addMethod() {
7675
activeMethod.setParentScope(activeClass);
7776
activeMethod.block = (BlockStatementEntry) statementStack.pop();
7877
activeClass.addMethod(activeMethod);
79-
Logger.output("Adding method " + activeMethod.name.lexeme() + " to class " + activeClass.name.lexeme() + " with " + activeMethod.parameters.size() + " parameters and " + activeMethod.variables.size() + " variables returning " + activeMethod.returnType + " it has " + activeMethod.block.statements.size() + " statements");
8078
activeMethod = new MethodEntry(this, null);
8179
}
8280

@@ -128,23 +126,20 @@ public void checkExpressions() {
128126
public void newIf() {
129127
IfStatementEntry newIf = new IfStatementEntry();
130128
statementStack.push(newIf);
131-
Logger.output("New if");
132129
}
133130

134131
@CalledByParser
135132
public void ifBlock() {
136133
IfStatementEntry active = (IfStatementEntry) statementStack.peek();
137134
ExpressionEntry condition = expressionStack.pop();
138135
active.setIfCondition(condition);
139-
Logger.output("If condition set");
140136
}
141137

142138
@CalledByParser
143139
public void ifElse() {
144140
StatementEntry body = statementStack.pop();
145141
IfStatementEntry iF = (IfStatementEntry) statementStack.peek();
146142
iF.setIfBody(body);
147-
Logger.output("If body set");
148143
}
149144

150145
@CalledByParser
@@ -153,7 +148,6 @@ public void ifEnd() {
153148
IfStatementEntry iF = (IfStatementEntry) statementStack.peek();
154149
if (iF.body() == null) iF.setIfBody(someBody); // If there is no body yet, that means there is no else
155150
else iF.setElseBody(someBody);
156-
Logger.output("If close");
157151
}
158152

159153
@CalledByParser
@@ -207,7 +201,6 @@ public void whileBody() {
207201
@CalledByParser
208202
public void expWrapBin(List<TinyRustLexerToken> op) {
209203
if (op.size() != 1) throw new RuntimeException("Operator size is not 1");
210-
Logger.output("Operator: " + op.get(0).lexeme());
211204
BinaryExpressionEntry nw = new BinaryExpressionEntry();
212205
nw.setLeft(expressionStack.pop());
213206
nw.setOperator(op.get(0));
@@ -219,21 +212,18 @@ public void expBinComplete() {
219212
ExpressionEntry rhs = expressionStack.pop();
220213
BinaryExpressionEntry nw = (BinaryExpressionEntry) expressionStack.peek();
221214
nw.setRight(rhs);
222-
Logger.output("Binary expression: " + nw);
223215
}
224216

225217
@CalledByParser
226218
public void expLit(List<TinyRustLexerToken> lit) {
227219
if (lit.size() != 1) throw new RuntimeException("Literal size is not 1");
228-
Logger.output("Literal: " + lit.get(0).lexeme());
229220
LiteralExpressionEntry exp = new LiteralExpressionEntry();
230221
exp.setLiteral(lit.get(0));
231222
expressionStack.push(exp);
232223
}
233224

234225
@CalledByParser
235226
public void expClassRef(TinyRustLexerToken lit) {
236-
Logger.output("Class Ref: " + lit.lexeme());
237227
ClassRefEntry exp = new ClassRefEntry();
238228
exp.setName(lit);
239229
expressionStack.push(exp);
@@ -247,15 +237,13 @@ public void expField(TinyRustLexerToken lit) {
247237
@CalledByParser
248238
public void expField(List<TinyRustLexerToken> lit) {
249239
if (lit.size() != 1) throw new RuntimeException("Literal size is not 1");
250-
Logger.output("Field: " + lit.get(0).lexeme());
251240
FieldAccessEntry exp = new FieldAccessEntry();
252241
exp.setFieldName(lit.get(0));
253242
expressionStack.push(exp);
254243
}
255244

256245
@CalledByParser
257246
public void expChainWith(TinyRustLexerToken id) {
258-
Logger.output("Chain with: " + id.lexeme());
259247
ChainedExpressionEntry chain = new ChainedExpressionEntry();
260248
FieldAccessEntry lit = new FieldAccessEntry();
261249
lit.setFieldName(id);
@@ -266,7 +254,6 @@ public void expChainWith(TinyRustLexerToken id) {
266254

267255
@CalledByParser
268256
public void expReverseChain(TinyRustLexerToken id) {
269-
Logger.output("Chain with: " + id.lexeme());
270257
ChainedExpressionEntry chain = new ChainedExpressionEntry();
271258
ClassRefEntry lit = new ClassRefEntry();
272259
lit.setName(id);
@@ -277,10 +264,9 @@ public void expReverseChain(TinyRustLexerToken id) {
277264

278265
@CalledByParser
279266
public void endChainMethod() {
280-
MethodCallExpressionEntry method = (MethodCallExpressionEntry) expressionStack.pop();
267+
AttributeAccessEntry method = (MethodCallExpressionEntry) expressionStack.pop();
281268
if (expressionStack.isEmpty()) {
282269
expressionStack.push(method);
283-
Logger.output("Method call UNCHAINED: " + method);
284270
return; // was not chained
285271
}
286272
ExpressionEntry expr = expressionStack.pop();
@@ -302,22 +288,19 @@ public void expArrayAccess() {
302288
public void newBlock() {
303289
BlockStatementEntry block = new BlockStatementEntry();
304290
statementStack.push(block);
305-
Logger.output("New Block");
306291
}
307292

308293
@CalledByParser
309294
public void endBlock() {
310295
popStatementUntil(BlockStatementEntry.class, (block, statements) -> {
311296
block.setStatements(statements);
312-
Logger.output("Block: " + block);
313297
});
314298
}
315299

316300
@CalledByParser
317301
public void endExpr() {
318302
ExpressionStatementEntry exp = (ExpressionStatementEntry) statementStack.peek();
319303
exp.setExpression(expressionStack.pop());
320-
Logger.output("Expression: " + exp);
321304
}
322305

323306
@CalledByParser
@@ -327,18 +310,15 @@ public void expWrapUn(List<TinyRustLexerToken> op) {
327310
nw.setOperator(op.get(0));
328311
nw.setExpression(expressionStack.pop());
329312
expressionStack.push(nw);
330-
Logger.output("Unary expression: " + nw);
331313
}
332314

333315
@CalledByParser
334316
public void endMain() {
335-
Logger.output("Main end " + activeMethod.name);
336317
activeMethod.block = (BlockStatementEntry) statementStack.pop();
337318
}
338319

339320
@CalledByParser
340321
public void endWhile() {
341-
Logger.output("While end");
342322
StatementEntry pop = statementStack.pop();
343323
WhileStatementEntry whileStatement = (WhileStatementEntry) statementStack.peek();
344324
whileStatement.setWhileBody(pop);
@@ -348,23 +328,20 @@ public void endWhile() {
348328
public void endReturn() {
349329
ReturnStatementEntry ret = (ReturnStatementEntry) statementStack.peek();
350330
ret.setReturnExpression(expressionStack.pop());
351-
Logger.output("Return: " + ret);
352331
}
353332

354333
@CalledByParser
355334
public void expMethodCall() {
356-
ExpressionEntry pop = expressionStack.pop();
335+
ExpressionEntry base = expressionStack.pop();
357336
MethodCallExpressionEntry exp = new MethodCallExpressionEntry();
358-
if (pop instanceof FieldAccessEntry id) {
337+
if (base instanceof FieldAccessEntry id) {
359338
exp.setMethodName(id.fieldName());
360339
expressionStack.push(exp);
361-
Logger.output("Method call: " + exp);
362-
} else if (pop instanceof ChainedExpressionEntry chain) {
363-
exp.setMethodName(chain.chain.fieldName());
340+
} else if (base instanceof ChainedExpressionEntry chain) {
341+
exp.setMethodName(chain.chain.name());
364342
chain.chain = exp;
365343
expressionStack.push(chain);
366344
expressionStack.push(exp);
367-
Logger.output("Method call: " + exp);
368345
}
369346
}
370347

@@ -375,7 +352,6 @@ public void endMethodCall() {
375352
ExpressionEntry pop = expressionStack.pop();
376353
if (pop != methodCall) throw new RuntimeException("Method call not on top of stack");
377354
expressionStack.push(methodCall);
378-
Logger.output("Method call: " + methodCall);
379355
}, it -> it.arguments() != null);
380356
}
381357

@@ -394,7 +370,6 @@ public void expNewClass() {
394370
ExpressionEntry pop = expressionStack.pop();
395371
if (pop != newClass) throw new RuntimeException("New class not on top of stack");
396372
expressionStack.push(newClass);
397-
Logger.output("New class: " + newClass);
398373
}, it -> it.constructorArguments() != null);
399374
}
400375

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package ko.carbonel.compiler.intermediate.tinyRust.ast.expression;
22

3+
import ko.carbonel.compiler.stream.lexer.tinyRust.model.TinyRustLexerToken;
4+
35
public abstract class AttributeAccessEntry extends ExpressionEntry {
6+
public abstract TinyRustLexerToken name();
47
}

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ast/expression/ChainedExpressionEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class ChainedExpressionEntry extends ExpressionEntry {
1212
@SerializeClass(AST) public ExpressionEntry base;
13-
@SerializeClass(AST) public FieldAccessEntry chain;
13+
@SerializeClass(AST) public AttributeAccessEntry chain;
1414

1515
public ExpressionEntry left() {
1616
return base;
@@ -24,7 +24,7 @@ public ExpressionEntry right() {
2424
return chain;
2525
}
2626

27-
public void setChain(FieldAccessEntry chain) {
27+
public void setChain(AttributeAccessEntry chain) {
2828
this.chain = chain;
2929
}
3030

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ast/expression/ClassRefEntry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public class ClassRefEntry extends AttributeAccessEntry {
1515
@SerializeClass(AST) public TinyRustLexerToken name;
1616

17+
@Override
1718
public TinyRustLexerToken name() {
1819
return name;
1920
}

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ast/expression/FieldAccessEntry.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public FileLocation location() {
3939
public String toString() {
4040
return "FieldAccess<%s>".formatted(fieldName);
4141
}
42+
43+
@Override
44+
public TinyRustLexerToken name() {
45+
return fieldName;
46+
}
4247
}

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ast/expression/MethodCallExpressionEntry.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import java.util.List;
1212

13-
public class MethodCallExpressionEntry extends FieldAccessEntry {
13+
public class MethodCallExpressionEntry extends AttributeAccessEntry {
1414
@SerializeClass("ast")
1515
public TinyRustLexerToken methodName;
1616
@SerializeClass("ast")
@@ -54,4 +54,9 @@ public TypeEntry getType(Scope scope, boolean isImmediateChainedScope) {
5454
public FileLocation location() {
5555
return methodName.location();
5656
}
57+
58+
@Override
59+
public TinyRustLexerToken name() {
60+
return methodName;
61+
}
5762
}

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ast/statement/ExpressionStatementEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public String toString() {
3131
@Override
3232
boolean checkExpressions(Scope scope, TypeEntry expectedReturnType) {
3333
TypeEntry type = expression.getType(scope, false);
34-
if (Config.getBool(ArgumentName.W_UNUSED_RETURN)){
34+
if (Config.getBool(ArgumentName.W_UNUSED_RETURN) && !type.equals(TypeEntry.VOID)) {
3535
Logger.warn("Unused return value of type " + type + " at " + expression.location());
3636
}
3737
return false;

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ts/IOClassEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public IOClassEntry(TinyRustSymbolTable root) {
2222
// static fn in bool()->Bool: lee un booleano de la entrada est´andar.
2323
// static fn in Char()->Char: lee un caracter de la entrada est´andar.
2424
createMethod(root, "out_str", TypeEntry.VOID, "out_str", TypeEntry.STR);
25-
createMethod(root, "out_int", TypeEntry.VOID, "out_int", TypeEntry.I32);
25+
createMethod(root, "out_i32", TypeEntry.VOID, "out_i32", TypeEntry.I32);
2626
createMethod(root, "out_bool", TypeEntry.VOID, "out_bool", TypeEntry.BOOL);
2727
createMethod(root, "out_char", TypeEntry.VOID, "out_char", TypeEntry.CHAR);
2828
// createMethod(root, "out_array", TypeEntry.VOID, "out_array", TypeEntry.ARRAY);

0 commit comments

Comments
 (0)