static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, params Expression[] pp) { // all var names are unique. CodeBlock cb = cbe.Block; List <Statement> assigns = new List <Statement>(); int i = 0; cb.Inlined = true; var parentvars = new List <Variable>(parent.Variables); foreach (Variable p in cb.Parameters) { SymbolId origname = p.Name; p.Name = (SymbolId)Builtins.GenSym(p.Name); p.Block = parent; p.Kind = Variable.VariableKind.Local; parent.AddVariable(p); assigns.Add(Ast.Write(p, pp[i])); if (p.Lift) { parent.HasEnvironment = true; } i++; } foreach (Variable l in cb.Variables) { if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global) { l.Name = (SymbolId)Builtins.GenSym(l.Name); } l.Block = parent; parent.AddVariable(l); if (l.Lift) { parent.HasEnvironment = true; } } assigns.Add(cb.Body); return(Ast.Void(Ast.Block(assigns))); }
protected internal static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, bool istailpostion, params Expression[] pp) { // all var names are unique. CodeBlock cb = cbe.Block; if (parent.IsGlobal) { return CallNormal(cbe, pp); } List<Statement> assigns = new List<Statement>(); int i = 0; cb.Inlined = true; if (parent.Filename == null && cb.Filename != null) { parent.Filename = cb.Filename; } var parentvars = new List<Variable>(parent.Variables); foreach (Variable p in cb.Parameters) { SymbolId origname = p.Name; p.Name = (SymbolId)Builtins.GenSym(p.Name); p.Block = parent; p.Kind = Variable.VariableKind.Local; parent.AddVariable(p); Expression val = Unwrap(pp[i]); if (val.Type != typeof(SymbolId) && !Generator.assigns.ContainsKey(origname)) { if (p.Type == typeof(object)) { p.Type = val.Type; assigns.Add(Ast.Write(p, val)); } else { assigns.Add(Ast.Write(p, Ast.ConvertHelper(val, p.Type))); } } else { if (p.Type == typeof(object)) { assigns.Add(Ast.Write(p, pp[i])); } else { assigns.Add(Ast.Write(p, Ast.ConvertHelper(pp[i], p.Type))); } } if (p.Lift) { parent.HasEnvironment = true; } i++; } foreach (Variable l in cb.Variables) { if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global) { l.Name = (SymbolId)Builtins.GenSym(l.Name); } l.Block = parent; parent.AddVariable(l); if (l.Lift) { parent.HasEnvironment = true; } } Expression body = RewriteReturn(cb.Body); if (assigns.Count > 0) { return Ast.Comma(Ast.Void(Ast.Block(assigns)), body); } else { return body; } }
protected internal static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, bool istailpostion, params Expression[] pp) { // all var names are unique. CodeBlock cb = cbe.Block; if (parent.IsGlobal) { return(CallNormal(cbe, pp)); } List <Statement> assigns = new List <Statement>(); int i = 0; cb.Inlined = true; if (parent.Filename == null && cb.Filename != null) { parent.Filename = cb.Filename; } var parentvars = new List <Variable>(parent.Variables); foreach (Variable p in cb.Parameters) { SymbolId origname = p.Name; p.Name = (SymbolId)Builtins.GenSym(p.Name); p.Block = parent; p.Kind = Variable.VariableKind.Local; parent.AddVariable(p); Expression val = Unwrap(pp[i]); if (val.Type != typeof(SymbolId) && !Generator.assigns.ContainsKey(origname)) { if (p.Type == typeof(object)) { p.Type = val.Type; assigns.Add(Ast.Write(p, val)); } else { assigns.Add(Ast.Write(p, Ast.ConvertHelper(val, p.Type))); } } else { if (p.Type == typeof(object)) { assigns.Add(Ast.Write(p, pp[i])); } else { assigns.Add(Ast.Write(p, Ast.ConvertHelper(pp[i], p.Type))); } } if (p.Lift) { parent.HasEnvironment = true; } i++; } foreach (Variable l in cb.Variables) { if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global) { l.Name = (SymbolId)Builtins.GenSym(l.Name); } l.Block = parent; parent.AddVariable(l); if (l.Lift) { parent.HasEnvironment = true; } } Expression body = RewriteReturn(cb.Body); if (assigns.Count > 0) { return(Ast.Comma(Ast.Void(Ast.Block(assigns)), body)); } else { return(body); } }
static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, params Expression[] pp) { // all var names are unique. CodeBlock cb = cbe.Block; List<Statement> assigns = new List<Statement>(); int i = 0; cb.Inlined = true; var parentvars = new List<Variable>(parent.Variables); foreach (Variable p in cb.Parameters) { SymbolId origname = p.Name; p.Name = (SymbolId)Builtins.GenSym(p.Name); p.Block = parent; p.Kind = Variable.VariableKind.Local; parent.AddVariable(p); assigns.Add(Ast.Write(p, pp[i])); if (p.Lift) { parent.HasEnvironment = true; } i++; } foreach (Variable l in cb.Variables) { if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global) { l.Name = (SymbolId)Builtins.GenSym(l.Name); } l.Block = parent; parent.AddVariable(l); if (l.Lift) { parent.HasEnvironment = true; } } assigns.Add(cb.Body); return Ast.Void(Ast.Block(assigns)); }