Beispiel #1
0
 public DyLinker(FileLookup lookup, BuilderOptions options, DyTuple args)
 {
     this.Lookup         = lookup;
     this.BuilderOptions = options;
     this.lang           = new Lang(args)
     {
         FileName = nameof(lang), Id = 1
     };
     Units.Add(null);
 }
Beispiel #2
0
 private static DyObject Lesser(ExecutionContext ctx, DyObject left, DyObject right)
 {
     try
     {
         return(DyTuple.Lesser(ctx, ((DyClass)left).Fields, ((DyClass)right).Fields));
     }
     catch (DyCodeException e)
     {
         ctx.Error = e.Error;
         return(Nil);
     }
 }
Beispiel #3
0
    protected override DyObject LtOp(ExecutionContext ctx, DyObject left, DyObject right)
    {
        if (left.TypeId != right.TypeId)
        {
            return(ctx.OperationNotSupported(Builtins.Lt, left, right));
        }

        try
        {
            return(DyTuple.Lesser(ctx, (DyTuple)left, (DyTuple)right));
        }
        catch (DyCodeException e)
        {
            ctx.Error = e.Error;
            return(Nil);
        }
    }
Beispiel #4
0
    protected override DyObject EqOp(ExecutionContext ctx, DyObject left, DyObject right)
    {
        if (left.TypeId != right.TypeId)
        {
            return(False);
        }

        var(xs, ys) = ((DyTuple)left, (DyTuple)right);

        try
        {
            return(DyTuple.Equals(ctx, xs, ys));
        }
        catch (DyCodeException ex)
        {
            ctx.Error = ex.Error;
            return(Nil);
        }
    }
Beispiel #5
0
    private static DyObject Equatable(ExecutionContext ctx, DyObject left, DyObject right)
    {
        var self = (DyClass)left;

        if (self.TypeId == right.TypeId && right is DyClass t && t.Constructor == self.Constructor)
        {
            try
            {
                return(DyTuple.Equals(ctx, self.Fields, t.Fields));
            }
            catch (DyCodeException ex)
            {
                ctx.Error = ex.Error;
                return(Nil);
            }
        }

        return(False);
    }
Beispiel #6
0
    public static DyObject?Eval(SourceBuffer buffer, BuilderOptions options, FileLookup lookup, object?args = null)
    {
        DyTuple?tup = null;

        if (args is not null)
        {
            var arr = args.GetType().GetProperties().Select(pi =>
                                                            new DyLabel(pi.Name, TypeConverter.ConvertFrom(pi.GetValue(args)))).ToArray();
            tup = new DyTuple(arr);
        }

        var linker = new DyLinker(lookup ?? FileLookup.Default, options ?? BuilderOptions.Default(), tup);
        var result = linker.Make(buffer);

        if (!result.Success)
        {
            throw new DyBuildException(result.Messages);
        }

        var ctx     = DyMachine.CreateExecutionContext(result.Value !);
        var result2 = DyMachine.Execute(ctx);

        return(result2.Value);
    }
Beispiel #7
0
 internal DyClass(DyTypeInfo type, string ctor, DyTuple fields, DyTuple inits, Unit unit) : base(type.ReflectedTypeId) =>
     (DecType, Constructor, Fields, Inits, DeclaringUnit) = (type, ctor, fields, inits, unit);
 public DyIncrementalLinker(FileLookup lookup, BuilderOptions options, DyTuple args) : base(lookup, options, args)
 {
 }
Beispiel #9
0
 public Lang(DyTuple args)
 {
     FileName  = "lang";
     this.args = args;
 }
Beispiel #10
0
 internal static bool ContainsField(DyTuple self, string field) =>
 self.GetOrdinal(field.ToString()) is not - 1;