Search in sources :

Example 1 with IImpBuilder

use of org.whole.examples.lang.imp.builders.IImpBuilder in project whole by wholeplatform.

the class ImpLanguageDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    platform.addLanguageKit(new ImpLanguageKit());
    platform.addOperationFactory(ImpLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new ImpGenericBuilderAdapter((IImpBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new ImpSpecificBuilderAdapter(strategy, entityContext);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, PrettyPrinterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new ImpPrettyPrinterVisitor((PrettyPrinterOperation) operation);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new ImpInterpreterVisitor((InterpreterOperation) operation);
            else
                return null;
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, ValidatorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return ImpTraversalFactory.instance.topDown(ImpTraversalFactory.instance.sequence(new ImpResolverValidatorVisitor((ValidatorOperation) operation), new ImpDefUseValidatorVisitor((ValidatorOperation) operation)), false);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, BytecodeGeneratorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new ImpBytecodeGeneratorVisitor((BytecodeGeneratorOperation) operation);
        }
    });
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) PrettyPrinterOperation(org.whole.lang.operations.PrettyPrinterOperation) IVisitor(org.whole.lang.visitors.IVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) ValidatorOperation(org.whole.lang.operations.ValidatorOperation) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ImpResolverValidatorVisitor(org.whole.examples.lang.imp.visitors.ImpResolverValidatorVisitor) ImpGenericBuilderAdapter(org.whole.examples.lang.imp.builders.ImpGenericBuilderAdapter) ImpSpecificBuilderAdapter(org.whole.examples.lang.imp.builders.ImpSpecificBuilderAdapter) BytecodeGeneratorOperation(org.whole.examples.lang.imp.visitors.BytecodeGeneratorOperation) ImpBytecodeGeneratorVisitor(org.whole.examples.lang.imp.visitors.ImpBytecodeGeneratorVisitor) IImpBuilder(org.whole.examples.lang.imp.builders.IImpBuilder) ImpDefUseValidatorVisitor(org.whole.examples.lang.imp.visitors.ImpDefUseValidatorVisitor) ImpInterpreterVisitor(org.whole.examples.lang.imp.visitors.ImpInterpreterVisitor) ImpPrettyPrinterVisitor(org.whole.examples.lang.imp.visitors.ImpPrettyPrinterVisitor)

Example 2 with IImpBuilder

use of org.whole.examples.lang.imp.builders.IImpBuilder in project whole by wholeplatform.

the class Factorial method apply.

public void apply(IBuilderOperation op) {
    IImpBuilder b0 = (IImpBuilder) op.wGetBuilder(ImpLanguageKit.URI);
    ICommonsBuilder cb = (ICommonsBuilder) op.wGetBuilder(CommonsLanguageKit.URI);
    b0.FunctionDeclaration_();
    b0.PrimitiveType("void");
    b0.Name("testFactorial");
    cb.Resolver();
    b0.BlockStatement_(4);
    b0.FunctionDeclaration_();
    b0.PrimitiveType("int");
    b0.Name("ifact");
    b0.Parameters_(1);
    b0.Parameter_();
    b0.PrimitiveType("int");
    b0.Name("n");
    b0._Parameter();
    b0._Parameters();
    b0.BlockStatement_(3);
    b0.VariableDeclaration_();
    b0.PrimitiveType("int");
    b0.Name("result");
    b0.IntLiteral(1);
    b0._VariableDeclaration();
    b0.WhileStatement_();
    b0.GreaterThan_();
    b0.NameExpression("n");
    b0.IntLiteral(0);
    b0._GreaterThan();
    b0.BlockStatement_(2);
    b0.ExpressionStatement_();
    b0.AssignmentExpression_();
    b0.Name("result");
    b0.Multiplication_();
    b0.NameExpression("result");
    b0.NameExpression("n");
    b0._Multiplication();
    b0._AssignmentExpression();
    b0._ExpressionStatement();
    b0.ExpressionStatement_();
    b0.AssignmentExpression_();
    b0.Name("n");
    b0.Subtraction_();
    b0.NameExpression("n");
    b0.IntLiteral(1);
    b0._Subtraction();
    b0._AssignmentExpression();
    b0._ExpressionStatement();
    b0._BlockStatement();
    b0._WhileStatement();
    b0.ReturnStatement_();
    b0.NameExpression("result");
    b0._ReturnStatement();
    b0._BlockStatement();
    b0._FunctionDeclaration();
    b0.FunctionDeclaration_();
    b0.PrimitiveType("int");
    b0.Name("rfact");
    b0.Parameters_(1);
    b0.Parameter_();
    b0.PrimitiveType("int");
    b0.Name("n");
    b0._Parameter();
    b0._Parameters();
    b0.IfElseStatement_();
    b0.LessOrEquals_();
    b0.NameExpression("n");
    b0.IntLiteral(1);
    b0._LessOrEquals();
    b0.ReturnStatement_();
    b0.IntLiteral(1);
    b0._ReturnStatement();
    b0.ReturnStatement_();
    b0.Multiplication_();
    b0.NameExpression("n");
    b0.FunctionInvocationExpression_();
    b0.NameExpression("rfact");
    b0.Arguments_(1);
    b0.Subtraction_();
    b0.NameExpression("n");
    b0.IntLiteral(1);
    b0._Subtraction();
    b0._Arguments();
    b0._FunctionInvocationExpression();
    b0._Multiplication();
    b0._ReturnStatement();
    b0._IfElseStatement();
    b0._FunctionDeclaration();
    b0.PrintlnStatement_();
    b0.FunctionInvocationExpression_();
    b0.NameExpression("ifact");
    b0.Arguments_(1);
    b0.IntLiteral(4);
    b0._Arguments();
    b0._FunctionInvocationExpression();
    b0._PrintlnStatement();
    b0.PrintlnStatement_();
    b0.FunctionInvocationExpression_();
    b0.NameExpression("rfact");
    b0.Arguments_(1);
    b0.IntLiteral(3);
    b0._Arguments();
    b0._FunctionInvocationExpression();
    b0._PrintlnStatement();
    b0._BlockStatement();
    b0._FunctionDeclaration();
}
Also used : IImpBuilder(org.whole.examples.lang.imp.builders.IImpBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 3 with IImpBuilder

use of org.whole.examples.lang.imp.builders.IImpBuilder in project whole by wholeplatform.

the class FunctionParam method apply.

public void apply(IBuilderOperation op) {
    IImpBuilder b0 = (IImpBuilder) op.wGetBuilder(ImpLanguageKit.URI);
    ICommonsBuilder cb = (ICommonsBuilder) op.wGetBuilder(CommonsLanguageKit.URI);
    b0.FunctionDeclaration_();
    b0.PrimitiveType("void");
    b0.Name("testFunctionParam");
    cb.Resolver();
    b0.BlockStatement_(4);
    b0.FunctionDeclaration_();
    b0.PrimitiveType("int");
    b0.Name("ifact");
    b0.Parameters_(1);
    b0.Parameter_();
    b0.PrimitiveType("int");
    b0.Name("n");
    b0._Parameter();
    b0._Parameters();
    b0.BlockStatement_(3);
    b0.VariableDeclaration_();
    b0.PrimitiveType("int");
    b0.Name("result");
    b0.IntLiteral(1);
    b0._VariableDeclaration();
    b0.WhileStatement_();
    b0.GreaterThan_();
    b0.NameExpression("n");
    b0.IntLiteral(0);
    b0._GreaterThan();
    b0.BlockStatement_(2);
    b0.ExpressionStatement_();
    b0.AssignmentExpression_();
    b0.Name("result");
    b0.Multiplication_();
    b0.NameExpression("result");
    b0.NameExpression("n");
    b0._Multiplication();
    b0._AssignmentExpression();
    b0._ExpressionStatement();
    b0.ExpressionStatement_();
    b0.AssignmentExpression_();
    b0.Name("n");
    b0.Subtraction_();
    b0.NameExpression("n");
    b0.IntLiteral(1);
    b0._Subtraction();
    b0._AssignmentExpression();
    b0._ExpressionStatement();
    b0._BlockStatement();
    b0._WhileStatement();
    b0.ReturnStatement_();
    b0.NameExpression("result");
    b0._ReturnStatement();
    b0._BlockStatement();
    b0._FunctionDeclaration();
    b0.FunctionDeclaration_();
    b0.PrimitiveType("int");
    b0.Name("exec");
    b0.Parameters_(2);
    b0.Parameter_();
    b0.PrimitiveType("function");
    b0.Name("f");
    b0._Parameter();
    b0.Parameter_();
    b0.PrimitiveType("int");
    b0.Name("par");
    b0._Parameter();
    b0._Parameters();
    b0.ReturnStatement_();
    b0.FunctionInvocationExpression_();
    b0.NameExpression("f");
    b0.Arguments_(1);
    b0.NameExpression("par");
    b0._Arguments();
    b0._FunctionInvocationExpression();
    b0._ReturnStatement();
    b0._FunctionDeclaration();
    b0.PrintlnStatement_();
    b0.FunctionInvocationExpression_();
    b0.NameExpression("ifact");
    b0.Arguments_(1);
    b0.IntLiteral(4);
    b0._Arguments();
    b0._FunctionInvocationExpression();
    b0._PrintlnStatement();
    b0.PrintlnStatement_();
    b0.FunctionInvocationExpression_();
    b0.NameExpression("exec");
    b0.Arguments_(2);
    b0.NameExpression("ifact");
    b0.IntLiteral(4);
    b0._Arguments();
    b0._FunctionInvocationExpression();
    b0._PrintlnStatement();
    b0._BlockStatement();
    b0._FunctionDeclaration();
}
Also used : IImpBuilder(org.whole.examples.lang.imp.builders.IImpBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 4 with IImpBuilder

use of org.whole.examples.lang.imp.builders.IImpBuilder in project whole by wholeplatform.

the class MetaProgram method apply.

public void apply(IBuilderOperation op) {
    IImpBuilder b0 = (IImpBuilder) op.wGetBuilder(ImpLanguageKit.URI);
    ICommonsBuilder cb = (ICommonsBuilder) op.wGetBuilder(CommonsLanguageKit.URI);
    b0.FunctionDeclaration_();
    b0.PrimitiveType("void");
    b0.Name("testTemplates");
    cb.Resolver();
    b0.BlockStatement_(6);
    b0.VariableDeclaration_();
    b0.PrimitiveType("entity");
    b0.Name("l");
    cb.StageUpFragment_();
    b0.StringLiteral("ciao");
    cb._StageUpFragment();
    b0._VariableDeclaration();
    b0.VariableDeclaration_();
    b0.PrimitiveType("entity");
    b0.Name("e");
    cb.StageUpFragment_();
    b0.PrintlnStatement_();
    cb.StageDownFragment_();
    b0.NameExpression("l");
    cb._StageDownFragment();
    b0._PrintlnStatement();
    cb._StageUpFragment();
    b0._VariableDeclaration();
    b0.PrintlnStatement_();
    b0.NameExpression("e");
    b0._PrintlnStatement();
    b0.VariableDeclaration_();
    b0.PrimitiveType("entity");
    b0.Name("f");
    cb.StageUpFragment_();
    b0.FunctionDeclaration_();
    b0.PrimitiveType("void");
    b0.Name("t");
    cb.Resolver();
    b0.BlockStatement_(2);
    b0.PrintlnStatement_();
    b0.StringLiteral("test");
    b0._PrintlnStatement();
    cb.StageDownFragment_();
    b0.NameExpression("e");
    cb._StageDownFragment();
    b0._BlockStatement();
    b0._FunctionDeclaration();
    cb._StageUpFragment();
    b0._VariableDeclaration();
    b0.PrintlnStatement_();
    b0.NameExpression("f");
    b0._PrintlnStatement();
    b0.ExpressionStatement_();
    b0.FunctionInvocationExpression_();
    b0.NameExpression("f");
    cb.Resolver();
    b0._FunctionInvocationExpression();
    b0._ExpressionStatement();
    b0._BlockStatement();
    b0._FunctionDeclaration();
}
Also used : IImpBuilder(org.whole.examples.lang.imp.builders.IImpBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Aggregations

IImpBuilder (org.whole.examples.lang.imp.builders.IImpBuilder)4 ICommonsBuilder (org.whole.lang.commons.builders.ICommonsBuilder)3 ImpGenericBuilderAdapter (org.whole.examples.lang.imp.builders.ImpGenericBuilderAdapter)1 ImpSpecificBuilderAdapter (org.whole.examples.lang.imp.builders.ImpSpecificBuilderAdapter)1 BytecodeGeneratorOperation (org.whole.examples.lang.imp.visitors.BytecodeGeneratorOperation)1 ImpBytecodeGeneratorVisitor (org.whole.examples.lang.imp.visitors.ImpBytecodeGeneratorVisitor)1 ImpDefUseValidatorVisitor (org.whole.examples.lang.imp.visitors.ImpDefUseValidatorVisitor)1 ImpInterpreterVisitor (org.whole.examples.lang.imp.visitors.ImpInterpreterVisitor)1 ImpPrettyPrinterVisitor (org.whole.examples.lang.imp.visitors.ImpPrettyPrinterVisitor)1 ImpResolverValidatorVisitor (org.whole.examples.lang.imp.visitors.ImpResolverValidatorVisitor)1 IBuilder (org.whole.lang.builders.IBuilder)1 IBuilderFactory (org.whole.lang.builders.IBuilderFactory)1 IEntityContext (org.whole.lang.contexts.IEntityContext)1 IOperation (org.whole.lang.operations.IOperation)1 PrettyPrinterOperation (org.whole.lang.operations.PrettyPrinterOperation)1 ValidatorOperation (org.whole.lang.operations.ValidatorOperation)1 IVisitor (org.whole.lang.visitors.IVisitor)1 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)1