Пример #1
0
 @Override
 public void genTopLevel(TopLevelContext tlc) {
   for (TypedAST ast : exps) {
     ast.genTopLevel(tlc);
     if (ast instanceof Declaration) {
       ((Declaration) ast).addModuleDecl(tlc);
     }
   }
 }
Пример #2
0
 @Override
 public Type typecheck(Environment env, Optional<Type> expected) {
   Type lastType = new Unit();
   for (TypedAST t : exps) {
     if (t == null) continue;
     lastType = t.typecheck(env, (exps.getLast() == t) ? expected : Optional.empty());
     if (t instanceof EnvironmentExtender) env = ((EnvironmentExtender) t).extend(env, env);
   }
   retType = lastType;
   return lastType;
 }
Пример #3
0
 @Override
 public Value evaluate(EvaluationEnvironment env) {
   EvaluationEnvironment iEnv = env;
   Value lastVal = UnitVal.getInstance(this.getLocation());
   for (TypedAST exp : this) {
     if (exp == null) continue;
     if (exp instanceof EnvironmentExtender) {
       iEnv = ((EnvironmentExtender) exp).evalDecl(iEnv);
     } else {
       lastVal = exp.evaluate(iEnv);
     }
   }
   return lastVal;
 }
Пример #4
0
 @Override
 public void codegenToIL(GenerationEnvironment environment, ILWriter writer) {
   for (TypedAST ast : exps) {
     if (ast instanceof ValDeclaration) {
       environment.register(((ValDeclaration) ast).getName(), ast.getType().generateILType());
       writer.wrap(
           e ->
               new Let(
                   ((ValDeclaration) ast).getName(),
                   ExpressionWriter.generate(
                       iw -> ((ValDeclaration) ast).getDefinition().codegenToIL(environment, iw)),
                   (Expression) e));
     } else if (ast instanceof Declaration) {
       String genName = GenerationEnvironment.generateVariableName();
       List<wyvern.target.corewyvernIL.decl.Declaration> generated =
           DeclarationWriter.generate(
               writer, iw -> ast.codegenToIL(new GenerationEnvironment(environment, genName), iw));
       writer.wrap(e -> new Let(genName, new New(generated, "this", null), (Expression) e));
     } else {
       ast.codegenToIL(environment, writer);
     }
   }
 }