From f73a192aa006c0b6cf1cb2657d94c473f7dc88fb Mon Sep 17 00:00:00 2001 From: otya128 Date: Wed, 8 Jul 2015 20:31:48 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B5=84=E3=81=BF=E8=BE=BC=E3=81=BF=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E8=A7=A3=E6=9E=90=E3=82=92=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=BF=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/petitcomputer.d | 79 +++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index c9decc1..511f4ea 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -24,6 +24,7 @@ class PetitComputer { this() { + new Test(); } static const string resourceDirName = "resources"; static const string resourcePath = "./resources"; @@ -227,4 +228,80 @@ class PetitComputer } } } -} \ No newline at end of file +} +import std.typecons; +import std.typetuple; +import std.traits; +import otya.smilebasic.error; +import otya.smilebasic.type; +static string func; +class Test +{ + import otya.smilebasic.type; + int a;/* + static Value abs(Value[] a) + { + return Value((a[0].castDouble < 0 ? -a[0].castDouble : a[0].castDouble)); + }*/ + static double ABS(double a) + { + return a < 0 ? -a : a; + } + wstring[] ah; + void*[] ahe; + alias void function(Value[], Value[]) BuiltinFunc; + BuiltinFunc[] builtinFunctions; + this() + { + foreach(name; __traits(derivedMembers, Test)) + { + //writeln(name); + ah ~= name; + // foreach (t; __traits(getVirtualFunctions, Test, name)) + { + static if(__traits(isStaticFunction, __traits(getMember, Test, name))) + { + ahe ~= cast(void*)&__traits(getMember, Test, name); + writeln(name); + auto m = typeid(typeof(__traits(getMember, Test, name))); + writeln(m); + writeln(AddFunc!(Test,name)); + builtinFunctions ~= mixin(AddFunc!(Test,name)); + } + } + } + } + +} +template AddFunc(T, string N) +{ + static if(is(ReturnType!(__traits(getMember, T, N)) == double)) + { + const string AddFunc = "function void(Value[] arg, Value[] ret){if(ret.length != 1){throw new IllegalFunctionCall();}ret[0] = Value(" ~ N ~ "(" ~ + AddFuncArg!(Tuple!(ParameterTypeTuple!(__traits(getMember, T, N))), 0) ~ "));}"; + } + else + { + const string AddFunc = ""; + } +} +template AddFuncArg(P, int N = 0) +{ + static if(is(typeof(P[N]) == double)) + { + const string arg = "arg[" ~ N.to!string ~ "].castDouble"; + } + else + { + const string arg = ""; + static assert(false, "Invalid type"); + } + static if(N + 1 == P.length) + { + const string AddFuncArg = arg; + } + else + { + const string AddFuncArg = arg ~ ", " ~ AddFuncArg!(P, N + 1); + } +}