Пример #1
0
 public static FunctionCallNode CreateFunctionCall(AstNode call, params AstNode[] parameters)
 {
     List<AstNode> parameterList = new List<AstNode>();
     foreach (var parameter in parameters)
         parameterList.Add(parameter);
     return new FunctionCallNode(ModuleBuilder.SourceLocation, call, new ArgumentListNode(ModuleBuilder.SourceLocation, parameterList), new List<BinaryOperationNode>());
 }
 public TernaryOperationNode(SourceLocation location, AstNode predicate, AstNode trueStatement, AstNode falseStatement)
 {
     this.SourceLocation = location;
     Children.Add(predicate);
     Children.Add(trueStatement);
     Children.Add(falseStatement);
 }
Пример #3
0
 public SwitchNode(SourceLocation location, AstNode expression, List<Case> cases, AstNode defaultCase)
 {
     this.SourceLocation = location;
     Children.Add(expression);
     Children.Add(defaultCase);
     Cases = cases;
 }
Пример #4
0
 public IfNode(SourceLocation location, AstNode predicate, AstNode body, AstNode elseBody)
 {
     this.SourceLocation = location;
     Children.Add(predicate);
     Children.Add(body);
     Children.Add(elseBody);
 }
 public EnforcedAssignmentNode(SourceLocation location, string type, string variable, AstNode value)
 {
     this.SourceLocation = location;
     Type = type;
     Variable = variable;
     Children.Add(value);
 }
Пример #6
0
 public ForeachNode(SourceLocation location, string variable, AstNode target, AstNode body)
 {
     this.SourceLocation = location;
     Variable = variable;
     Children.Add(target);
     Children.Add(body);
 }
Пример #7
0
 public BinaryOperationNode(SourceLocation location, BinaryOperation operation, AstNode left, AstNode right)
 {
     this.SourceLocation = location;
     BinaryOperation = operation;
     Children.Add(left);
     Children.Add(right);
 }
Пример #8
0
 public FunctionCallNode(SourceLocation location, AstNode target, ArgumentListNode parameters, List<BinaryOperationNode> initialAttributes)
 {
     this.SourceLocation = location;
     Children.Add(target);
     Children.Add(parameters);
     InitialAttributes = initialAttributes;
 }
Пример #9
0
 public ForNode(SourceLocation location, AstNode startStatement, AstNode predicate, AstNode repeatStatement, AstNode body)
 {
     this.SourceLocation = location;
     Children.Add(startStatement);
     Children.Add(predicate);
     Children.Add(repeatStatement);
     Children.Add(body);
 }
Пример #10
0
 public PropertyNode(SourceLocation location, string variable, AstNode getBody, AstNode setBody)
 {
     this.SourceLocation = location;
     Variable = variable;
     Children.Add(getBody);
     Children.Add(setBody);
     IsPrivate = false;
 }
Пример #11
0
 public TryCatchNode(SourceLocation location, AstNode tryBody, AstNode catchBody)
 {
     this.SourceLocation = location;
     Children.Add(tryBody);
     Children.Add(catchBody);
 }
Пример #12
0
 public SymbolTable Analyze(AstNode ast)
 {
     code = ast;
     result = new SymbolTable();
     result.PushScope();
     code.VisitChildren(this);
     return result;
 }
Пример #13
0
 public Case(BinaryOperation operation, List<AstNode> expressions, AstNode body)
 {
     Operation = operation;
     Expressions = expressions;
     Body = body;
 }
Пример #14
0
 public ThreadNode(SourceLocation location, bool runImmediately, AstNode body)
 {
     this.SourceLocation = location;
     RunImmediately = runImmediately;
     Children.Add(body);
 }
Пример #15
0
        public HassiumModule Compile(AstNode ast, SymbolTable table)
        {
            this.table = table;
            module = new HassiumModule();
            method = new HassiumMethod();

            var globalParent = new HassiumClass();
            foreach (AstNode child in ast.Children)
            {
                if (child is FuncNode)
                {
                    compileFunc(child as FuncNode);
                    method.Parent = new HassiumClass();
                    if (module.Attributes.ContainsKey(method.Name))
                    {
                        if (module.Attributes[method.Name] is HassiumMultiFunc)
                            ((HassiumMultiFunc)module.Attributes[method.Name]).Methods.Add(method);
                        else if (module.Attributes[method.Name] is HassiumMethod)
                            module.Attributes[method.Name] = new HassiumMultiFunc(new List<HassiumMethod>() { method, (HassiumMethod)module.Attributes[method.Name] });
                    }
                    else
                        module.Attributes.Add(method.Name, method);
                }
                else if (child is ClassNode)
                {
                    var clazz = compileClass(child as ClassNode);
                    clazz.Parent = globalParent;
                    module.Attributes.Add(clazz.Name, clazz);
                }
                else if (child is ExpressionStatementNode)
                {
                    if (child.Children[0] is BinaryOperationNode)
                    {
                        var binop = child.Children[0] as BinaryOperationNode;
                        if (binop.BinaryOperation == BinaryOperation.Assignment)
                        {
                            string variable = ((IdentifierNode)binop.Left).Identifier;
                            table.AddGlobalSymbol(variable);
                            var temp = method;
                            method = new HassiumMethod();
                            method.Name = variable;
                            method.SourceRepresentation = string.Format("set_{0}", variable);
                            binop.Right.Visit(this);
                            method.Emit(child.SourceLocation, InstructionType.Return);
                            module.InitialVariables.Add(table.GetGlobalSymbol(variable), method);
                            method = temp;
                        }
                    }
                }
                else if (child is TraitNode || child is PropertyNode || child is UseNode || child is EnumNode)
                    child.Visit(this);
            }
            preformInherits(module);
            return module;
        }
Пример #16
0
 public AttributeAccessNode(SourceLocation location, AstNode left, string right)
 {
     this.SourceLocation = location;
     Children.Add(left);
     Right = right;
 }
Пример #17
0
 public RaiseNode(SourceLocation location, AstNode expression)
 {
     this.SourceLocation = location;
     Children.Add(expression);
 }
Пример #18
0
 public WhileNode(SourceLocation location, AstNode predicate, AstNode body)
 {
     this.SourceLocation = location;
     Children.Add(predicate);
     Children.Add(body);
 }
Пример #19
0
 public static BinaryOperationNode CreateBinaryOperation(BinaryOperation operation, AstNode left, AstNode right)
 {
     return new BinaryOperationNode(ModuleBuilder.SourceLocation, operation, left, right);
 }
Пример #20
0
 public void AddAstNode(AstNode ast)
 {
     FunctionBody.Children.Add(ast);
 }
Пример #21
0
 public LambdaNode(SourceLocation location, ArgumentListNode parameters, AstNode body)
 {
     this.SourceLocation = location;
     Children.Add(parameters);
     Children.Add(body);
 }
Пример #22
0
 public KeyValuePairNode(SourceLocation location, AstNode key, AstNode value)
 {
     this.SourceLocation = location;
     Children.Add(key);
     Children.Add(value);
 }
 public ExpressionStatementNode(SourceLocation location, AstNode expression)
 {
     this.SourceLocation = location;
     Children.Add(expression);
 }
Пример #24
0
 public UsingNode(SourceLocation location, AstNode body, AstNode expression)
 {
     this.SourceLocation = location;
     Children.Add(body);
     Children.Add(expression);
 }
Пример #25
0
 public MultiAssignmentNode(List<AstNode> left, AstNode value)
 {
     Assignments = new List<BinaryOperationNode>();
     foreach (var ast in left)
         Assignments.Add(new BinaryOperationNode(value.SourceLocation, BinaryOperation.Assignment, ast, value));
 }
Пример #26
0
 public GlobalNode(SourceLocation location, string variable, AstNode value)
 {
     this.SourceLocation = location;
     Variable = variable;
     Children.Add(value);
 }
Пример #27
0
 public UnaryOperationNode(SourceLocation location, AstNode target, UnaryOperation unaryOperation)
 {
     this.SourceLocation = location;
     Children.Add(target);
     UnaryOperation = unaryOperation;
 }
Пример #28
0
 public ReturnNode(SourceLocation location, AstNode value)
 {
     Children.Add(value);
 }
Пример #29
0
 public ListAccessNode(SourceLocation location, AstNode target, AstNode element)
 {
     this.SourceLocation = location;
     Children.Add(target);
     Children.Add(element);
 }