private static KecaknoahFunctionResult CreateArray(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
 {
     if (args.Length == 0) throw new ArgumentException("次元数が不正です");
     if (args.Length >= 5) throw new ArgumentException("次元数が多すぎます");
     var dq = args.Select(p => (int)p.ToInt64()).ToArray();
     var result = new KecaknoahArray(dq);
     return result.NoResume();
 }
        private static KecaknoahFunctionResult WriteLine(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine(args[0].ToString());
            }

            return KecaknoahNil.Instance.NoResume();
        }
 /// <summary>
 /// 新しいインスタンスを初期化します。
 /// </summary>
 /// <param name="ctx">実行している<see cref="KecaknoahContext"/></param>
 /// <param name="il">実行する<see cref="KecaknoahIL"/></param>
 public KecaknoahStackFrame(KecaknoahContext ctx, KecaknoahIL il)
 {
     Codes = il.Codes;
     ProgramCounter = 0;
     RunningContext = ctx;
 }
 private static KecaknoahFunctionResult Exit(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
 {
     Environment.Exit(args.Length > 0 ? (int)args[0].ToInt64() : 0);
     return KecaknoahNil.Instance.NoResume();
 }
 private static KecaknoahFunctionResult Write(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
 {
     Console.Write(args[0]);
     return KecaknoahNil.Instance.NoResume();
 }
 private static KecaknoahFunctionResult Format(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
 {
     var b = args[0].ToString();
     var ar = args.Skip(1).Select(p => p.ToString()).ToArray();
     return string.Format(b, ar).AsKecaknoahString().NoResume();
 }
 private static KecaknoahFunctionResult ReadLine(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args) => Console.ReadLine().AsKecaknoahString().NoResume();
示例#8
0
        private static KecaknoahFunctionResult Throw(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
        {
            var d = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Red;
            switch (args[0].ExtraType)
            {
                case "String":
                    Console.WriteLine($"Kecaknoahで例外がスローされました : {args[0].ToString()}");
                    break;
                default:
                    var ex = args[0] as KecaknoahInstance;
                    if (ex == null) throw new ArgumentException("Kecaknoah上で生成したインスタンス以外渡せません");
                    var mes = ex["message"].ToString();
                    Console.WriteLine($"{ex.Class.Name}: {mes}");
                    break;

            }
            Console.Write("Enterで終了します...");
            Console.ReadLine();
            Environment.Exit(-1);
            return KecaknoahNil.Instance.NoResume();
        }
 public KecaknoahScriptCoroutineFrame(KecaknoahContext ctx, KecaknoahScriptFunction func, KecaknoahObject[] args)
 {
     StackFrame = new KecaknoahStackFrame(ctx, func.BaseMethod.Codes);
     Args = args;
     StackFrame.Arguments = Args;
 }
示例#10
0
 private static KecaknoahFunctionResult ClassNew(KecaknoahContext ctx, KecaknoahObject self,KecaknoahObject[] args)
 {
     Console.WriteLine("External Sample Class Constructor");
     return KecaknoahNil.Instance.NoResume();
 }
 public KecaknoahInteropCoroutineFrame(KecaknoahContext ctx, KecaknoahInteropFunction func, KecaknoahObject[] args)
 {
     Function = func;
     Context = ctx;
 }
示例#12
0
 private KecaknoahFunctionResult Eval(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args) => new KecaknoahContext(this).ExecuteExpressionIL(new KecaknoahPrecompiler().PrecompileExpression(new KecaknoahParser().ParseAsExpression(new KecaknoahLexer().AnalyzeFromSource(args[0].ToString())))).NoResume();
示例#13
0
 internal KecaknoahContext(KecaknoahContext parent)
 {
     Module = parent.Module;
 }
示例#14
0
 private KecaknoahFunctionResult Write(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
 {
     Console.Write(args[0]);
     return(KecaknoahNil.Instance.NoResume());
 }
示例#15
0
 private KecaknoahFunctionResult Eval(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args) => new KecaknoahContext(this).ExecuteExpressionIL(new KecaknoahPrecompiler().PrecompileExpression(new KecaknoahParser().ParseAsExpression(new KecaknoahLexer().AnalyzeFromSource(args[0].ToString())))).NoResume();