Repository navigation
Expand file tree
/
Copy pathCall.cs
More file actions
63 lines (56 loc) · 1.81 KB
/
Copy pathCall.cs
File metadata and controls
63 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
namespace QsScript {
[Serializable]
public class Call : Expression
{
public override bool IsCalculable => true;
public MethodPath Method;
public Expression[] Params;
public Call()
{
}
public Call(Expression @this, string name, params Expression[] @params)
{
Method = new MethodPath(@this, name);
Params = @params;
}
public Call(MethodPath path, Expression[] @params)
{
Method = path;
Params = @params;
}
protected override BasicObject calc() {
if(Method == null)
return Void.Value;
var thisScop = Method.This?.Calc() ?? VM.CurrentScop;
return call(thisScop.GetFunction(Method.Name), VM.GetCleanScop(thisScop), Params);
}
/// <param name="thisScop">Remarque : thisScop must be executed befor passing to function</param>
public static BasicObject call(BasicObject thisScop, string fName, Expression[] Params) {
thisScop = thisScop ?? VM.CurrentScop;
return call((thisScop).GetFunction(fName), VM.GetCleanScop(thisScop), Params);
}
/// <param name="thisScop">Remarque : thisScop must be executed befor passing to function</param>
public static BasicObject call(Function fn, BasicObject ns, Expression[] Params)
{
if (fn == null) return ns;
int i = 0;
foreach (var p in fn.@params)
{
if (i < Params.Length)
{
var pp = Params[i++];
ns[p] = pp.Calc();
Dot h;
}
else break;
}
VM.OpenScop(ns);
var r = fn.body.Calc();
if (IsReturn)
r = VM.StopReturn();
VM.CloseScop();
return r;
}
}
}