예제 #1
0
파일: RppMatch.cs 프로젝트: dubik/csharprpp
        public override IRppNode Analyze(SymbolTable scope, Diagnostic diagnostic)
        {
            Value = (IRppExpr) Value.Analyze(scope, diagnostic);
            RppVar declIn = new RppVar(MutabilityFlag.MfVal, "<in>", Value.Type, Value);
            declIn.Analyze(scope, diagnostic);

            CaseClauses = NodeUtils.Analyze(scope, CaseClauses, diagnostic);

            Type = CheckCommonType(CaseClauses, Token).AsResolvable();
            RppVar declOut = new RppVar(MutabilityFlag.MfVar, "<out>", Type, new RppDefaultExpr(Type));

            RppId declInId = new RppId("<in>", declIn);
            declInId.Analyze(scope, diagnostic);
            RppId declOutId = new RppId("<out>", declOut);

            RppMatchingContext ctx = new RppMatchingContext();
            var ifC = Create(declInId, declOutId, CaseClauses, ctx);
            var expr = new RppBlockExpr(List<IRppNode>(declIn, ifC)) {Exitable = true};

            SymbolTable matchScope = new SymbolTable(scope);
            RppBlockExpr matchBlock = new RppBlockExpr(List<IRppNode>(declOut, expr, declOutId));
            return matchBlock.Analyze(matchScope, diagnostic);
        }
예제 #2
0
 public override void Visit(RppId node)
 {
     if (node.IsField)
     {
         LoadField(node.Field);
     }
     else if (node.IsVar)
     {
         ClrVarCodegen.Load((RppVar) node.Ref, _body, ClosureContext?.CapturedVars);
     }
     else if (node.IsParam)
     {
         ((RppParam) node.Ref).Accept(this);
     }
     else if (node.IsObject)
     {
         if (_typeBuilder == node.Type.Value.NativeType)
         {
             _body.Emit(OpCodes.Ldarg_0); // we are in one of the methods of object, so first parameter is it's instance
         }
         else
         {
             FieldInfo cilField = node.Type.Value.Fields.First(f => f.Name == "_instance").Native;
             _body.Emit(OpCodes.Ldsfld, cilField);
         }
     }
     else
     {
         throw new NotImplementedException("don't know what to do here");
     }
 }
예제 #3
0
파일: RppClass.cs 프로젝트: dubik/csharprpp
        private RppFunc CreatePrimaryConstructor(IEnumerable<IRppExpr> exprs)
        {
            var p = _classParams.Select(rppVar => new RppParam(MakeConstructorArgName(rppVar.Name), rppVar.Type)).ToList();
            List<IRppNode> assignExprs = new List<IRppNode>();

            foreach (var classParam in _fields)
            {
                IRppExpr initExpr;
                if (classParam.IsClassParam)
                {
                    string argName = MakeConstructorArgName(classParam.Name);
                    initExpr = new RppId(argName);
                }
                else
                {
                    RppField field = classParam;
                    initExpr = field.InitExpr;
                }

                RppAssignOp assign = new RppAssignOp(new RppId(classParam.MangledName), initExpr);
                assignExprs.Add(assign);
            }

            assignExprs.AddRange(exprs);
            assignExprs.Add(CreateParentConstructorCall());

            return new RppFunc("this", p, ResolvableType.UnitTy, new RppBlockExpr(assignExprs));
        }
예제 #4
0
        private static ResolveResults SearchInClosures(string name, IEnumerable<IRppExpr> args, SymbolTable scope)
        {
            RppId closure = new RppId(name);
            Diagnostic diagnostic = new Diagnostic();
            try
            {
                RppMember member = (RppMember) closure.Analyze(scope, diagnostic);
                RType closureType = member.Type.Value;
                if(closureType.IsObject)
                    return null;

                List<RppMethodInfo> applyMethods = closureType.Methods.Where(m => m.Name == "apply").ToList();

                List<RType> argTypes = args.Select(a => a.Type.Value).ToList();
                IEnumerable<RppMethodInfo> candidates = OverloadQuery.Find(argTypes, applyMethods).ToList();

                if (candidates.Count() > 1)
                {
                    throw new Exception("Can't figure out which overload to use");
                }

                if (!candidates.Any())
                {
                    return null;
                }
                return new ClosureResolveResults(member, candidates.First());
            }
            catch (Exception)
            {
                return null;
            }
        }
예제 #5
0
 public virtual void Visit(RppId node)
 {
 }