private static void findAndCallConstructor( string name, parse_tree.parameter_list parameters, ClassTabPage ctp, int count, NClass.Core.ClassType theClass) { foreach (NClass.Core.Operation op in theClass.Operations) { if (op is NClass.Core.Constructor) { if ((op as NClass.Core.Constructor).numberArguments == count) { Procedure_Chart sc = (op as NClass.Core.Constructor).raptorTab as Procedure_Chart; if (sc != null) { Runtime.Set_Running(sc); Invoke_Tab_Procedure_Enter( parameters, sc, Runtime.getContext()); CallStack.setContext(Runtime.getContext()); return; } } } } throw new System.Exception("could not find constructor for " + name + " with " + count + " parameter(s)."); }
public static void Invoke_Method(string name, parse_tree.parameter_list parameters) { if (Component.Current_Mode != Mode.Expert) { throw new Exception("there is no function named " + name); } Procedure_Chart sc = Runtime.Find_Method_Set_Running(name, parse_tree_pkg.count_parameters(parameters)); if (state == State_Enum.Entering) { Runtime.Variable this_value = Runtime.getContext(); Runtime.setContext(null); // we stored the "this" parameter in the context // but need to set it to null before entering the // method Invoke_Tab_Procedure_Enter(parameters, sc, this_value); // this used to be a call to getContext, but I'm not // at all sure why. CallStack.setContext(this_value); } else { Invoke_Tab_Procedure_Exit(parameters, sc); } }
public object createMethod(object theClass, string name, NClass.Core.Method method) { form.Clear_Undo(); Procedure_Chart sbchrt = new Procedure_Chart(form, name, 0); sbchrt.method = method; (theClass as ClassTabPage).tabControl1.TabPages.Add(sbchrt); form.modified = true; return(sbchrt); }
public override void compile_pass1(generate_interface.typ gen) { if (this.kind == Kind_Of.Call && ((parse_tree.procedure_call) this.parse_tree).is_tab_call()) { string call_name = interpreter_pkg.get_name_call(this.parse_tree as parse_tree.procedure_call, this.Text); Subchart sub = Find_Start(call_name); if (!(sub is Procedure_Chart)) { if (sub.am_compiling) { throw new System.Exception("The RAPTOR compiler does not support recursive programs.\n" + "Recursion found at call to: " + this.Text + "\n" + "Cycle of calls includes: " + Recursion_Involves()); } sub.am_compiling = true; sub.Start.compile_pass1(gen); sub.am_compiling = false; } else { Procedure_Chart pc = sub as Procedure_Chart; parse_tree.parameter_list walk = ((parse_tree.procedure_call) this.parse_tree).param_list; for (int i = 0; i < pc.num_params; i++) { // it seems like we would want to call pass1 on our parameters // but this may give us the mistaken impression that an array is a variable // if it is passed // walk.parameter.compile_pass1(gen); walk = walk.next; } } } else if (this.parse_tree != null) { interpreter_pkg.compile_pass1(this.parse_tree, this.Text, gen); } if (this.Successor != null) { this.Successor.compile_pass1(gen); } }
public static bool Invoke_Constructor(string name, parse_tree.parameter_list parameters) { int count = parse_tree_pkg.count_parameters(parameters); NClass.Core.ClassType theClass = Runtime.parent.projectCore.findClass(name); while (theClass != null) { foreach (NClass.Core.Operation op in theClass.Operations) { if (op is NClass.Core.Constructor) { if ((op as NClass.Core.Constructor).numberArguments == count) { Procedure_Chart sc = (op as NClass.Core.Constructor).raptorTab as Procedure_Chart; if (sc != null) { Runtime.Set_Running(sc); Runtime.Variable this_value = Runtime.getContext(); Runtime.setContext(null); // we stored the "this" parameter in the context // but need to set it to null before entering the // method Invoke_Tab_Procedure_Enter(parameters, sc, this_value); CallStack.setContext(Runtime.getContext()); return(true); } } } } theClass = theClass.BaseClass; } if (count == 0) { return(false); } else { throw new System.Exception("could not find constructor for " + name + " with " + count + " parameter(s)."); } }
public override void Emit_Code(generate_interface.typ gen) { if (this.kind == Kind_Of.Call && ((parse_tree.procedure_call) this.parse_tree).is_tab_call()) { string call_name = interpreter_pkg.get_name_call(this.parse_tree as parse_tree.procedure_call, this.Text); Subchart called_chart = Find_Start(call_name); if (!(called_chart is Procedure_Chart)) { called_chart.Start.Emit_Code(gen); } else { Procedure_Chart pc = called_chart as Procedure_Chart; parse_tree.parameter_list walk = ((parse_tree.procedure_call) this.parse_tree).param_list; object o = gen.Emit_Call_Subchart(pc.Text); for (int i = 0; i < pc.num_params; i++) { parse_tree_pkg.emit_parameter_number(walk.parameter, gen, 0); walk = walk.next; if (walk != null) { gen.Emit_Next_Parameter(o); } } gen.Emit_Last_Parameter(o); } } else if (this.parse_tree != null) { interpreter_pkg.emit_code(this.parse_tree, this.Text, gen); } if (this.Successor != null) { this.Successor.Emit_Code(gen); } }
private static void Invoke_Tab_Procedure_Enter( parse_tree.parameter_list parameters, Procedure_Chart chart, Runtime.Variable this_value) { parse_tree.parameter_list walk; int num_parameters = chart.num_params; numbers.value[] the_values = new numbers.value[num_parameters]; //string[] param_strings = new string[num_parameters]; bool[] is_array = new bool[num_parameters]; bool[] is_2d_array = new bool[num_parameters]; object[] array_values = new object[num_parameters]; int call_site_param_count = 0; // count the parameters walk = parameters; while (walk != null) { call_site_param_count++; walk = walk.next; } // start walk at beginning again walk = parameters; if (call_site_param_count != num_parameters) { string paramstr, verb; if (num_parameters != 1) { paramstr = "parameters"; } else { paramstr = "parameter"; } if (call_site_param_count != 1) { verb = "were"; } else { verb = "was"; } throw new System.Exception(chart.Text + " requires " + num_parameters + " " + paramstr + " but " + call_site_param_count + " " + verb + " provided."); } for (int i = 0; i < num_parameters; i++) { if (chart.is_input_parameter(i)) { try { raptor.Runtime.processing_parameter_list = true; the_values[i] = ((parse_tree.expr_output) walk.parameter).expr.execute(); } catch { raptor.Runtime.processing_parameter_list = false; throw; } raptor.Runtime.processing_parameter_list = false; if (numbers_pkg.is_ref_1d(the_values[i])) { is_array[i] = true; is_2d_array[i] = false; array_values[i] = Runtime.getValueArray( numbers_pkg.object_of(the_values[i]) as Runtime.Variable); } else if (numbers_pkg.is_ref_2d(the_values[i])) { is_array[i] = false; is_2d_array[i] = true; array_values[i] = Runtime.get2DValueArray( numbers_pkg.object_of(the_values[i]) as Runtime.Variable); } else { is_array[i] = false; is_2d_array[i] = false; } } walk = walk.next; } Runtime.Increase_Scope(chart.Text); if (this_value != null) { if (chart.method.IsStatic) { if (this_value.Kind != Runtime.Variable_Kind.Class_Value) { throw new System.Exception("can't call static method " + chart.Text + " with object"); } } else if (this_value.Kind == Runtime.Variable_Kind.Heap_Object) { Runtime.setVariable("this", this_value.Variable_Value); } else { throw new System.Exception("can't call dispatching method " + chart.Text + " without object"); } } for (int i = 0; i < num_parameters; i++) { if (chart.is_input_parameter(i)) { if (is_array[i]) { numbers.value[] values = array_values[i] as numbers.value[]; for (int ind1 = values.Length - 1; ind1 >= 0; ind1--) { Runtime.setArrayElement(chart.parameter_name(i), ind1 + 1, values[ind1]); } } else if (is_2d_array[i]) { numbers.value[][] values = array_values[i] as numbers.value[][]; for (int ind1 = values.Length - 1; ind1 >= 0; ind1--) { for (int ind2 = values[0].Length - 1; ind2 >= 0; ind2--) { Runtime.set2DArrayElement(chart.parameter_name(i), ind1 + 1, ind2 + 1, values[ind1][ind2]); } } } else { Runtime.setVariable(chart.parameter_name(i), the_values[i]); } } } }
private static void Invoke_Tab_Procedure_Exit( parse_tree.parameter_list parameters, Procedure_Chart chart) { end_oval.running = true; call_rect.running = false; Runtime.parent.currentObj = end_oval; parse_tree.parameter_list walk; int num_parameters = chart.num_params; walk = parameters; numbers.value[] the_values = new numbers.value[num_parameters]; string[] param_strings = new string[num_parameters]; bool[] is_array = new bool[num_parameters]; bool[] is_2d_array = new bool[num_parameters]; object[] old_values = new object[num_parameters]; for (int i = 0; i < num_parameters; i++) { if (chart.is_output_parameter(i)) { try { param_strings[i] = ((parse_tree.expr_output) walk.parameter).get_string(); } catch { param_strings[i] = ""; } if (Runtime.isArray(chart.parameter_name(i))) { is_array[i] = true; is_2d_array[i] = false; old_values[i] = Runtime.getValueArray(chart.parameter_name(i)); } else if (Runtime.is_2D_Array(chart.parameter_name(i))) { is_array[i] = false; is_2d_array[i] = true; old_values[i] = Runtime.get2DValueArray(chart.parameter_name(i)); } else { is_array[i] = false; is_2d_array[i] = false; old_values[i] = Runtime.getVariable(chart.parameter_name(i)); } } walk = walk.next; } Runtime.Decrease_Scope(); end_oval.running = false; call_rect.running = true; Runtime.parent.currentObj = call_rect; Runtime.parent.Possible_Tab_Update(next_chart); walk = parameters; for (int i = 0; i < num_parameters; i++) { if (chart.is_output_parameter(i)) { if (is_array[i]) { numbers.value[] values = (numbers.value [])old_values[i]; for (int ind1 = values.Length - 1; ind1 >= 0; ind1--) { Runtime.setArrayElement(param_strings[i], ind1 + 1, values[ind1]); } } else if (is_2d_array[i]) { numbers.value[][] values = old_values[i] as numbers.value[][]; for (int ind1 = values.Length - 1; ind1 >= 0; ind1--) { for (int ind2 = values[0].Length - 1; ind2 >= 0; ind2--) { Runtime.set2DArrayElement(param_strings[i], ind1 + 1, ind2 + 1, values[ind1][ind2]); } } } else { numbers.value t = (numbers.value)old_values[i]; parse_tree_pkg.ms_assign_to(walk.parameter, t, "Parameter " + (i + 1) + ":"); //Runtime.setVariable(param_strings[i], // t); } } walk = walk.next; } call_rect.running = false; }