예제 #1
0
        public static char ToDotnetChar(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_CHAR);
            var clazz = obj->decodeClass();

            return((char)(int)(int *)obj->vtable[clazz.Field["!!value"].vtable_offset]);
        }
예제 #2
0
        public static float ToDotnetFloat(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_R4);
            var clazz = obj->decodeClass();

            return(BitConverter.Int32BitsToSingle((int)(int *)obj->vtable[clazz.Field["!!value"].vtable_offset]));
        }
예제 #3
0
        public static ulong ToDotnetUInt64(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_U8);
            var clazz = obj->decodeClass();

            return((ulong)(ulong *)obj->vtable[clazz.Field["!!value"].vtable_offset]);
        }
예제 #4
0
        public static bool ToDotnetBoolean(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_BOOLEAN);
            var clazz = obj->decodeClass();

            return((int)(int *)obj->vtable[clazz.Field["!!value"].vtable_offset] == 1);
        }
예제 #5
0
        public static short ToDotnetInt16(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_I2);
            var clazz = obj->decodeClass();

            return((short)(short *)obj->vtable[clazz.Field["!!value"].vtable_offset]);
        }
예제 #6
0
        public static byte ToDotnetUInt8(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_U1);
            var clazz = obj->decodeClass();

            return((byte)(byte *)obj->vtable[clazz.Field["!!value"].vtable_offset]);
        }
예제 #7
0
파일: B_String.cs 프로젝트: 0xF6/mana_lang
        public static IshtarObject *Fmt(CallFrame frame, IshtarObject **args)
        {
            var template_obj = args[0];
            var array_obj    = args[1];

            FFI.StaticValidate(frame, &template_obj);
            FFI.StaticValidate(frame, &array_obj);

            FFI.StaticTypeOf(frame, &template_obj, TYPE_STRING);
            FFI.StaticTypeOf(frame, &array_obj, TYPE_ARRAY);


            var arr = (IshtarArray *)array_obj;

            var dotnet_arr = new string[arr->length];

            for (var i = 0ul; i != arr->length; i++)
            {
                dotnet_arr[i] = IshtarMarshal.ToDotnetString(arr->Get((uint)i, frame), frame);
            }

            var template = IshtarMarshal.ToDotnetString(template_obj, frame);

            var result = string.Format(template, dotnet_arr);

            return(IshtarMarshal.ToIshtarObject(result, frame));
        }
예제 #8
0
        public static string ToDotnetString(IshtarObject *obj, CallFrame frame)
        {
            FFI.StaticTypeOf(frame, &obj, TYPE_STRING);
            var clazz = obj->decodeClass();
            var p     = (StrRef *)obj->vtable[clazz.Field["!!value"].vtable_offset];

            return(StringStorage.GetString(p, frame));
        }
예제 #9
0
파일: B_App.cs 프로젝트: 0xF6/mana_lang
        public static IshtarObject *Exit(CallFrame current, IshtarObject **args)
        {
            var exitCode = args[0];

            FFI.StaticValidate(current, &exitCode);
            FFI.StaticTypeOf(current, &exitCode, TYPE_I4);
            FFI.StaticValidateField(current, &exitCode, "!!value");

            VM.halt(IshtarMarshal.ToDotnetInt32(exitCode, current));

            return(null);
        }
예제 #10
0
파일: B_String.cs 프로젝트: 0xF6/mana_lang
        public static IshtarObject *TemplateFunctionApply(CallFrame frame, IshtarObject **args, Func <string, string> apply)
        {
            var str1 = args[0];

            FFI.StaticValidate(frame, &str1);
            FFI.StaticTypeOf(frame, &str1, TYPE_STRING);

            var clr_str = IshtarMarshal.ToDotnetString(str1, frame);

            var result = apply(clr_str);

            return(IshtarMarshal.ToIshtarObject(result, frame));
        }
예제 #11
0
파일: B_String.cs 프로젝트: 0xF6/mana_lang
        public static IshtarObject *StrEqual(CallFrame frame, IshtarObject **args)
        {
            var i_str1 = args[0];
            var i_str2 = args[1];

            FFI.StaticValidate(frame, &i_str1);
            FFI.StaticValidate(frame, &i_str2);
            FFI.StaticTypeOf(frame, &i_str1, TYPE_STRING);
            FFI.StaticTypeOf(frame, &i_str2, TYPE_STRING);

            var str1 = IshtarMarshal.ToDotnetString(i_str1, frame);
            var str2 = IshtarMarshal.ToDotnetString(i_str2, frame);

            var result = str1.Equals(str2);

            return(IshtarMarshal.ToIshtarObject(result, frame));
        }
예제 #12
0
        public static unsafe void LinkFFIMethods(IEnumerable <RuntimeIshtarMethod> methods)
        {
            foreach (var method in methods.Where(x => x.IsExtern))
            {
                var aspect = method.Aspects.FirstOrDefault(x => x.IsNative());
                var name   = method.Name;
                if (aspect is not null)
                {
                    if (aspect.Arguments.Count != 1)
                    {
                        VM.FastFail(WNE.TYPE_LOAD, $"(0x1) Native aspect incorrect arguments. [{method.Name}]", sys_frame);
                        VM.ValidateLastError();
                        return;
                    }

                    if (aspect.Arguments[0].Value is not string s)
                    {
                        VM.FastFail(WNE.TYPE_LOAD, $"(0x2) Native aspect incorrect arguments. [{method.Name}]", sys_frame);
                        VM.ValidateLastError();
                        return;
                    }

                    name = VeinMethodBase.GetFullName(s, method.Arguments);
                }

                var m = FFI.GetMethod(name);

                if (m is null)
                {
                    if (method.Name != name)
                    {
                        VM.FastFail(WNE.TYPE_LOAD, $"Extern '{method.Name} -> {name}' method not found in native mapping.", sys_frame);
                    }
                    else
                    {
                        VM.FastFail(WNE.TYPE_LOAD, $"Extern '{method.Name}' method not found in native mapping.", sys_frame);
                    }

                    Commands.DisplayDefinedMapping();
                    VM.ValidateLastError();
                    return;
                }

                method.PIInfo = m.PIInfo;
            }
        }
예제 #13
0
파일: B_App.cs 프로젝트: 0xF6/mana_lang
        public static IshtarObject *SwitchFlag(CallFrame current, IshtarObject **args)
        {
            var key   = args[0];
            var value = args[1];

            FFI.StaticValidate(current, &key);
            FFI.StaticTypeOf(current, &key, TYPE_STRING);
            FFI.StaticValidate(current, &value);
            FFI.StaticTypeOf(current, &value, TYPE_BOOLEAN);

            FFI.StaticValidateField(current, &key, "!!value");
            FFI.StaticValidateField(current, &value, "!!value");

            var clr_key   = IshtarMarshal.ToDotnetString(key, current);
            var clr_value = IshtarMarshal.ToDotnetBoolean(value, current);

            VM.Config.Set(clr_key, clr_value);

            return(null);
        }
예제 #14
0
        public static IshtarObject *FPrintLn(CallFrame current, IshtarObject **args)
        {
            var arg1 = args[0];

            if (arg1 == null)
            {
                current.ThrowException(KnowTypes.NullPointerException(current));
                return(null);
            }

            FFI.StaticValidate(current, &arg1);
            FFI.StaticTypeOf(current, &arg1, TYPE_STRING);
            var @class = arg1->decodeClass();

            var str = IshtarMarshal.ToDotnetString(arg1, current);

            Out.WriteLine();
            Out.WriteLine($"\t{str}");
            Out.WriteLine();

            return(null);
        }
예제 #15
0
 public static nint ToDotnetPointer(IshtarObject *obj, CallFrame frame)
 {
     FFI.StaticTypeOf(frame, &obj, TYPE_RAW);
     return((nint)obj->vtable);
 }