params function

This commit is contained in:
trochas
2025-04-25 15:05:27 +02:00
parent a86f3433be
commit c281229dbf
3 changed files with 15 additions and 10 deletions

View File

@@ -36,9 +36,9 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
public String visitPrototype(PrototypeImp proto, String indent){
String str= indent + "PROTO "+proto.type().accept(this, "")+ " "+ proto.nom() + "(";
for(int i=0; i<proto.s().size();i++){
str+=proto.s().get(i);
if((i<proto.s().size()-1)){
for(int i=0; i<proto.params().size();i++){
str+=proto.params().get(i);
if((i<proto.params().size()-1)){
str+=", ";
}
}
@@ -51,9 +51,9 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
public String visitFunction(FunctionImp fun, String indent) {
String str = indent+"FUNC " + fun.type().accept(this,"")+ " " + fun.nom() +"(";
for(int i=0; i<fun.s().size();i++){
str+=fun.s().get(i);
if((i<fun.s().size()-1)){
for(int i=0; i<fun.params().size();i++){
str+=fun.params().get(i);
if((i<fun.params().size()-1)){
str+=", ";
}
}
@@ -202,4 +202,4 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
return e.name();
}
}
}

View File

@@ -25,7 +25,7 @@ public class Program{
}
//Prototype
public static record PrototypeImp(Type type, String nom, ArrayList<String> s) implements Prototype{
public static record PrototypeImp(Type type, String nom, ArrayList<String> params) implements Prototype{
@Override
public <H, S> S accept(PrototypeVisitor<H, S> v, H h) {
return v.visitPrototype(this,h);
@@ -34,7 +34,7 @@ public class Program{
}
//Fonction
public static record FunctionImp(Type type, String nom, ArrayList<String> s,Instruction instruction)implements Function {
public static record FunctionImp(Type type, String nom, ArrayList<VarImp> params,Instruction instruction)implements Function {
//public FunctionImp(Type type, String name, Instruction instruction) {
// this(type, name, new ArrayList<>() {{ add(instruction); }}); C KOI ?
//}
@@ -62,7 +62,7 @@ public class Program{
return v.visitVar(this, h);
}
}
//Declaration
public static record DeclarationImp(Type t, ArrayList<String> s) implements Declaration{

View File

@@ -56,6 +56,11 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
@Override
public DefineLLVM visitFunction(FunctionImp fun, SymTable h) {
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
for(VarImp param: fun.params()){
paramsLLVM.add(param.accept(this, h).val);
}
instrLLVM.addAll(fun.instruction().accept(this, h));
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), new ArrayList<>(), instrLLVM);
}