Exemple #1
0
        // call using serialised native arguments, return serialised native result
        internal bool NativeCall(string name, byte[] arguments, out byte[] result)
        {
            var kind = _catvars.GetKind(name);

            if (kind != EntryKinds.Code)
            {
                return(NativeFail("unknown or invalid name: " + name, out result));
            }
            var expr = (_catvars.GetValue(name) as CodeValue).Value;

            TypedValue[] argvalues = new TypedValue[expr.NumArgs];
            using (var pr = PersistReader.Create(arguments)) {
                for (var i = 0; i < expr.NumArgs; ++i)
                {
                    try {
                        argvalues[i] = pr.Read(expr.Lookup.Columns[i].DataType); // BUG: needs heading
                    } catch {
                        return(NativeFail("argument conversion error", out result));
                    }
                }
            }
            var        argvalue = DataRow.CreateNonTuple(expr.Lookup, argvalues);
            TypedValue retvalue;

            try {
                retvalue = _evaluator.Exec(expr.Code, argvalue);
            } catch (ProgramException ex) {
                return(NativeFail(ex.ToString(), out result));
            }
            using (var pw = PersistWriter.Create()) {
                pw.Write(retvalue);
                result = pw.ToArray();
            }
            return(true);
        }
Exemple #2
0
 void Decode(ByteCode code)
 {
     if (code.Length > 0)
     {
         _indent++;
         Decode(PersistReader.Create(code.bytes));
         _indent--;
     }
 }
Exemple #3
0
        static public Decoder Create(ByteCode code)
        {
            var dc = new Decoder {
                Code     = code,
                _mstream = new MemoryStream(code.bytes)
            };

            dc._preader = PersistReader.Create(new BinaryReader(dc._mstream));
            return(dc);
        }