Esempio n. 1
0
        IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(FuncRefExpr expr)
        {
            IBoundDecl paramType = null;
            if (expr.ParamType != null)
            {
                paramType = TypeBinder.Bind(mContext, expr.ParamType);
            }

            var callable = mContext.Compiler.Functions.Find(mContext, 
                expr.Name.Name, expr.Name.TypeArgs, paramType);

            var function = callable as Function;

            //### bob: to support intrinsics, we'll need to basically create wrapper functions
            // that have the same type signature as the intrinsic and that do nothing but
            // call the intrinsic and return. then, we can get a reference to that wrapper.
            // 
            // to support foreign functions, we can either do the same thing, or change the
            // way function references work. if a function reference can be distinguished
            // between being a regular function, a foreign one (or later a closure), then
            // we can get rid of ForeignFuncCallExpr and just use CallExpr for foreign calls
            // too.
            if (function == null) throw new NotImplementedException("Can only get references to user-defined functions. Intrinsics, auto-generated, and foreign function references aren't supported yet.");

            return new BoundFuncRefExpr(function);
        }
Esempio n. 2
0
        IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(LocalFuncExpr expr)
        {
            // create a unique name for the local function
            string name = mContext.NameGenerator.Generate();

            // create a reference to it
            var reference = new FuncRefExpr(expr.Position,
                new NameExpr(expr.Position, name),
                expr.Type.Parameter.Unbound);

            // lift the local function into a new top-level function
            var function = new Function(expr.Position, name,
                expr.Type, expr.ParamNames, expr.Body);

            function.BindSearchSpace(mContext.SearchSpace);

            // bind it
            mContext.Compiler.Functions.AddAndBind(mContext.Compiler, function);

            // return the reference to it
            return reference.Accept(this);

            //### bob: eventually, will need to handle closures
        }
 public virtual IUnboundExpr Transform(FuncRefExpr expr)
 {
     return(expr);
 }
Esempio n. 4
0
 IUnboundExpr IUnboundExprVisitor <IUnboundExpr> .Visit(FuncRefExpr expr)
 {
     throw new NotImplementedException();
 }