Exemplo n.º 1
0
    public ClassSymbolNative BindBar(Types ts)
    {
        var cl = new ClassSymbolNative("Bar", null,
                                       delegate(VM.Frame frm, ref Val v, IType type)
        {
            v.SetObj(new Bar(), type);
        }
                                       );

        ts.globs.Define(cl);
        cl.Define(new FieldSymbol("Int", Types.Int,
                                  delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
        {
            var c = (Bar)ctx.obj;
            v.SetNum(c.Int);
        },
                                  delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
        {
            var c = (Bar)ctx.obj;
            c.Int = (int)v.num;
            ctx.SetObj(c, ctx.type);
        }
                                  ));
        cl.Define(new FieldSymbol("Flt", ts.Type("float"),
                                  delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
        {
            var c = (Bar)ctx.obj;
            v.SetFlt(c.Flt);
        },
                                  delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
        {
            var c = (Bar)ctx.obj;
            c.Flt = (float)v.num;
            ctx.SetObj(c, ctx.type);
        }
                                  ));
        cl.Define(new FieldSymbol("Str", ts.Type("string"),
                                  delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
        {
            var c = (Bar)ctx.obj;
            v.SetStr(c.Str);
        },
                                  delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
        {
            var c = (Bar)ctx.obj;
            c.Str = (string)v.obj;
            ctx.SetObj(c, ctx.type);
        }
                                  ));

        return(cl);
    }
Exemplo n.º 2
0
    public void BindColorAlpha(Types ts)
    {
        BindColor(ts);

        {
            var cl = new ClassSymbolNative("ColorAlpha", (ClassSymbol)ts.Type("Color").Get(),
                                           delegate(VM.Frame frm, ref Val v, IType type)
            {
                v.SetObj(new ColorAlpha(), type);
            }
                                           );

            ts.globs.Define(cl);

            cl.Define(new FieldSymbol("a", ts.Type("float"),
                                      delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
            {
                var c = (ColorAlpha)ctx.obj;
                v.num = c.a;
            },
                                      delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
            {
                var c = (ColorAlpha)ctx.obj;
                c.a   = (float)v.num;
                ctx.SetObj(c, ctx.type);
            }
                                      ));

            {
                var m = new FuncSymbolNative("mult_summ_alpha", ts.Type("float"),
                                             delegate(VM.Frame frm, FuncArgsInfo args_info, ref BHS status)
                {
                    var c = (ColorAlpha)frm.stack.PopRelease().obj;

                    frm.stack.Push(Val.NewFlt(frm.vm, (c.r * c.a) + (c.g * c.a)));

                    return(null);
                }
                                             );

                cl.Define(m);
            }
        }
    }
Exemplo n.º 3
0
        static Types()
        {
            {
                ClassType = new ClassSymbolNative("Type", null,
                                                  delegate(VM.Frame frm, ref Val v, IType type)
                {
                    v.SetObj(null, type);
                }
                                                  );

                {
                    var fld = new FieldSymbol("Name", String,
                                              delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol _)
                    {
                        var t = (IType)ctx.obj;
                        v.SetStr(t.GetName());
                    },
                                              null
                                              );
                    ClassType.Define(fld);
                }
            }
        }
Exemplo n.º 4
0
    public void BindFoo(Types ts)
    {
        {
            var cl = new ClassSymbolNative("Foo", null,
                                           delegate(VM.Frame frm, ref Val v, IType type)
            {
                v.SetObj(new Foo(), type);
            }
                                           );
            ts.globs.Define(cl);

            cl.Define(new FieldSymbol("hey", Types.Int,
                                      delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
            {
                var f = (Foo)ctx.obj;
                v.SetNum(f.hey);
            },
                                      delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
            {
                var f = (Foo)ctx.obj;
                f.hey = (int)v.num;
                ctx.SetObj(f, ctx.type);
            }
                                      ));
            cl.Define(new FieldSymbol("colors", ts.Type("ArrayT_Color"),
                                      delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
            {
                var f = (Foo)ctx.obj;
                v.SetObj(f.colors, fld.Type);
            },
                                      delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
            {
                var f    = (Foo)ctx.obj;
                f.colors = (List <Color>)v.obj;
            }
                                      ));
            cl.Define(new FieldSymbol("sub_color", ts.Type("Color"),
                                      delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
            {
                var f = (Foo)ctx.obj;
                v.SetObj(f.sub_color, fld.Type);
            },
                                      delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
            {
                var f       = (Foo)ctx.obj;
                f.sub_color = (Color)v.obj;
                ctx.SetObj(f, ctx.type);
            }
                                      ));
        }

        {
            var fn = new FuncSymbolNative("PassthruFoo", ts.Type("Foo"),
                                          delegate(VM.Frame frm, FuncArgsInfo args_info, ref BHS status) {
                frm.stack.Push(frm.stack.Pop());
                return(null);
            },
                                          new FuncArgSymbol("foo", ts.Type("Foo"))
                                          );

            ts.globs.Define(fn);
        }
    }
Exemplo n.º 5
0
    public ClassSymbolNative BindColor(Types ts)
    {
        var cl = new ClassSymbolNative("Color", null,
                                       delegate(VM.Frame frm, ref Val v, IType type)
        {
            v.SetObj(new Color(), type);
        }
                                       );

        ts.globs.Define(cl);
        cl.Define(new FieldSymbol("r", ts.Type("float"),
                                  delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
        {
            var c = (Color)ctx.obj;
            v.SetFlt(c.r);
        },
                                  delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
        {
            var c = (Color)ctx.obj;
            c.r   = (float)v.num;
            ctx.SetObj(c, ctx.type);
        }
                                  ));
        cl.Define(new FieldSymbol("g", ts.Type("float"),
                                  delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld)
        {
            var c = (Color)ctx.obj;
            v.SetFlt(c.g);
        },
                                  delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld)
        {
            var c = (Color)ctx.obj;
            c.g   = (float)v.num;
            ctx.SetObj(c, ctx.type);
        }
                                  ));

        {
            var m = new FuncSymbolNative("Add", ts.Type("Color"),
                                         delegate(VM.Frame frm, FuncArgsInfo args_info, ref BHS status)
            {
                var k = (float)frm.stack.PopRelease().num;
                var c = (Color)frm.stack.PopRelease().obj;

                var newc = new Color();
                newc.r   = c.r + k;
                newc.g   = c.g + k;

                var v = Val.NewObj(frm.vm, newc, ts.Type("Color").Get());
                frm.stack.Push(v);

                return(null);
            },
                                         new FuncArgSymbol("k", ts.Type("float"))
                                         );

            cl.Define(m);
        }

        {
            var m = new FuncSymbolNative("mult_summ", ts.Type("float"),
                                         delegate(VM.Frame frm, FuncArgsInfo args_info, ref BHS status)
            {
                var k = frm.stack.PopRelease().num;
                var c = (Color)frm.stack.PopRelease().obj;
                frm.stack.Push(Val.NewFlt(frm.vm, (c.r * k) + (c.g * k)));
                return(null);
            },
                                         new FuncArgSymbol("k", ts.Type("float"))
                                         );

            cl.Define(m);
        }

        {
            var fn = new FuncSymbolNative("mkcolor", ts.Type("Color"),
                                          delegate(VM.Frame frm, FuncArgsInfo args_info, ref BHS status) {
                var r = frm.stack.PopRelease().num;
                var c = new Color();
                c.r   = (float)r;
                var v = Val.NewObj(frm.vm, c, ts.Type("Color").Get());
                frm.stack.Push(v);
                return(null);
            },
                                          new FuncArgSymbol("r", ts.Type("float"))
                                          );

            ts.globs.Define(fn);
        }

        {
            var fn = new FuncSymbolNative("mkcolor_null", ts.Type("Color"),
                                          delegate(VM.Frame frm, FuncArgsInfo args_info, ref BHS status) {
                frm.stack.Push(frm.vm.Null);
                return(null);
            }
                                          );

            ts.globs.Define(fn);
        }

        ts.globs.Define(new ArrayTypeSymbolT <Color>(ts, "ArrayT_Color", ts.Type("Color"), delegate() { return(new List <Color>()); }));

        return(cl);
    }