Skip to content
Snippets Groups Projects
Commit 0cb5a82f authored by lucien.noel's avatar lucien.noel
Browse files

test 2 passe

parent bdf3e61d
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,14 @@ public class ByteCodeGenerator implements ASTVisitor {
public Object visit(Affectation node) {
node.getDestination().accept(this);
node.getSource().accept(this);
String varName = ((Idf)node.getDestination()).getNom();
int value = 0;
if(isExpressionBooleen(node.getSource())){
value = (getBoolInExpression(node.getSource()))?1:0;
}else if(isExpressionNumber(node.getSource())){
value = getIntInExpression(node.getSource());
}
varValues.put(varName, value);
return null;
}
......@@ -52,11 +60,11 @@ public class ByteCodeGenerator implements ASTVisitor {
public Object visit(DeclarationProgramme node) {
bytecode += ".class public Program\n";
node.getIdentifier().accept(this);
node.getDeclaration().accept(this);
int nbDeclarations = TDS.getInstance().map.size()+1;
bytecode += ".super java/lang/Object\n.method public static main([Ljava/lang/String;)V\n.limit stack 20000\n.limit locals "+nbDeclarations+"\n";
node.getDeclaration().accept(this);
node.getInstructions().accept(this);
bytecode += "return\n.end method";
return null;
......@@ -65,7 +73,8 @@ public class ByteCodeGenerator implements ASTVisitor {
public Object visit(DeclarationVariable node) {
for (int i = 0; i < node.listeId.size(); i++) {
node.getIdentifier(i).accept(this);
varValues.put(node.getIdentifier(i).getNom(), null);
bytecode+=".var "+(varValues.size()-1)+" is "+node.getIdentifier(i).getNom()+" "+((node.id.type instanceof Booleen)?"Z":"I")+"\n";
}
return null;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment