AST struct call
This commit is contained in:
@@ -50,6 +50,7 @@ pub enum TopLevel {
|
|||||||
pub enum Postfix {
|
pub enum Postfix {
|
||||||
FieldAccess(String),
|
FieldAccess(String),
|
||||||
Call(Vec<Expression>),
|
Call(Vec<Expression>),
|
||||||
|
StructCall(HashMap<String, Expression>),
|
||||||
Index(Expression),
|
Index(Expression),
|
||||||
Binary(BinaryOp, Expression),
|
Binary(BinaryOp, Expression),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,6 +271,14 @@ impl GoCodegen {
|
|||||||
.join(", ");
|
.join(", ");
|
||||||
format!("{}({})", result, args_str)
|
format!("{}({})", result, args_str)
|
||||||
}
|
}
|
||||||
|
Postfix::StructCall(fields) => {
|
||||||
|
let args_str = fields
|
||||||
|
.iter()
|
||||||
|
.map(|(a, b)| format!("{a}: {}", self.generate_expression(b)))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
format!("{}{{{}}}", result, args_str)
|
||||||
|
}
|
||||||
Postfix::Index(idx) => format!("{}[{}]", result, self.generate_expression(idx)),
|
Postfix::Index(idx) => format!("{}[{}]", result, self.generate_expression(idx)),
|
||||||
Postfix::Binary(op, rhs) => {
|
Postfix::Binary(op, rhs) => {
|
||||||
let op_str = match op {
|
let op_str = match op {
|
||||||
|
|||||||
+1
-1
@@ -6,6 +6,6 @@ public struct Idk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int test(int a, int b) {
|
int test(int a, int b) {
|
||||||
Idk bro = 10;
|
Idk bro = Idk { a: 10, b: 10 };
|
||||||
return a + b + bro.a;
|
return a + b + bro.a;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user