public void parsesMethod1Parameter1Statement() { String statement = "method printName ( Person p ) { print ( value = \"person\" + p.name); }"; OTestParser parser = new OTestParser(statement); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); Assert.IsTrue(ad.getParameters().Contains(new CategoryParameter(new CategoryType("Person"), "p"))); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print(value = \"person\" + p.name)", generate(ad.getStatements()[0])); }
public override void ToDialect(CodeWriter writer) { try { ConcreteMethodDeclaration method = (ConcreteMethodDeclaration)(object)declaration; writer.getContext().registerDeclaration(method); } catch (SyntaxError /*e*/) { // ok } declaration.ToDialect(writer); }
public void testMethod1Parameter1Statement() { String statement = "define printName as method receiving Person p doing:\r\n" + "\tprint with \"person\" + p.name as value"; ETestParser parser = new ETestParser(statement, false); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); Assert.IsTrue(ad.getParameters().Contains(new CategoryParameter(new CategoryType("Person"), "p"))); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print with \"person\" + p.name as value", generate(ad.getStatements()[0])); }
public override IType check(Context context) { if (declaration is ConcreteMethodDeclaration) { ConcreteMethodDeclaration method = (ConcreteMethodDeclaration)(object)declaration; method.checkChild(context); context.registerDeclaration(method); } else { throw new SyntaxError("Unsupported:" + declaration.GetType().Name); } return(VoidType.Instance); }
public void parsesMethod1Array1Statement() { String statement = "method printName ( Option[] options ) { print ( value = \"array\" + options ); }"; OTestParser parser = new OTestParser(statement); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new CategoryParameter(new ListType(new CategoryType("Option")), "options"); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print(value = \"array\" + options)", generate(ad.getStatements()[0])); }
public void parsesMethod1Extended1Statement() { String statement = "method printName ( Object(name) o ) { print ( value = \"object\" + o.name ); }"; OTestParser parser = new OTestParser(statement); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new ExtendedParameter(new CategoryType("Object"), "o", new IdentifierList("name")); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print(value = \"object\" + o.name)", generate(ad.getStatements()[0])); }
public void testMethod1Array1Statement() { String statement = "define printName as method receiving Option[] options doing:\r\n" + "\tprint with \"array\" + args as value"; ETestParser parser = new ETestParser(statement, false); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new CategoryParameter(new ListType(new CategoryType("Option")), "options"); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print with \"array\" + args as value", generate(ad.getStatements()[0])); }
public void testMethod1Extended1Statement() { String statement = "define printName as method receiving Object o with attribute name doing:\r\n" + "\tprint with \"object\" + o.name as value"; ETestParser parser = new ETestParser(statement, false); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new ExtendedParameter(new CategoryType("Object"), "o", new IdentifierList("name")); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print with \"object\" + o.name as value", generate(ad.getStatements()[0])); }
public override IValue interpret(Context context) { if (declaration is ConcreteMethodDeclaration) { ConcreteMethodDeclaration method = (ConcreteMethodDeclaration)(object)declaration; context.registerDeclaration(method); MethodType type = new MethodType(method); context.registerValue(new Variable(method.GetName(), type)); context.setValue(method.GetName(), new ClosureValue(context, type)); return(null); } else { throw new SyntaxError("Unsupported:" + declaration.GetType().Name); } }
private IType fullCheck(ConcreteMethodDeclaration declaration, Context parent, Context local) { try { ArgumentList arguments = makeArguments(parent, declaration); declaration.registerParameters(local); foreach (Argument argument in arguments) { IExpression expression = argument.resolve(local, declaration, true); IValue value = argument.Parameter.checkValue(parent, expression); local.setValue(argument.GetName(), value); } return(declaration.check(local)); } catch (PromptoError e) { throw new SyntaxError(e.Message); } }
public ConcreteInstance loadSingleton(CategoryType type) { if (this == globals) { IValue value = null; values.TryGetValue(type.GetTypeName(), out value); if (value == null) { IDeclaration decl = declarations[type.GetTypeName()]; if (!(decl is ConcreteCategoryDeclaration)) { throw new InternalError("No such singleton:" + type.GetTypeName()); } value = new ConcreteInstance(this, (ConcreteCategoryDeclaration)decl); ((IInstance)value).setMutable(true); // a singleton is protected by "with x do", so always mutable in that context ConcreteMethodDeclaration method = ((SingletonCategoryDeclaration)decl).getInitializeMethod(this); if (method != null) { Context instance = newInstanceContext((IInstance)value, false); Context child = instance.newChildContext(); method.interpret(child); } values[type.GetTypeName()] = value; } if (value is ConcreteInstance) { return((ConcreteInstance)value); } else { throw new InternalError("Not a concrete instance:" + value.GetType().Name); } } else { return(this.globals.loadSingleton(type)); } }
public void testBreakpoint() { debugResource("debug/stack.pec"); thread.Start(); waitBlocked(); Assert.AreEqual(Status.SUSPENDED, debugger.getStatus()); Assert.AreEqual(MAIN_LINE, debugger.getLine()); MethodDeclarationMap mdm = context.getRegisteredDeclaration <MethodDeclarationMap>("printLevel2"); IEnumerator <IMethodDeclaration> emd = mdm.Values.GetEnumerator(); emd.MoveNext(); ConcreteMethodDeclaration cmd = (ConcreteMethodDeclaration)emd.Current; ISection section = cmd.getStatements()[0]; Assert.AreEqual(LEVEL_2_LINE + 1, section.Start.Line); section.Breakpoint = true; debugger.resume(); waitBlocked(); Assert.AreEqual(Status.SUSPENDED, debugger.getStatus()); Assert.AreEqual(LEVEL_2_LINE + 1, debugger.getLine()); debugger.resume(); thread.Join(); Assert.AreEqual("test123-ok", Out.read()); }