public void treeprint(string prefix, AstNode tree, int depth) { if (tree == null) { return; } tree.Print(depth); }
public void BuildEnv(AstNode node) { if (node == null) return; AstNode cur = node; while (node != null) { node.BuildEnv(); node = node.sibling; } }
public AstNode(AstNode node) { nodetype = node.nodetype; symbol = node.symbol; val = node.val; type = node.type; child = node.child; sibling = node.sibling; localenv = node.localenv; closure = node.closure; }
private void GeneratePlangCore(AstNode root) { // generate all global field //foreach (var keyvalue in EnviromentList.Global.table) { // EnviromentNode node = keyvalue.Value; // if( node.Type != "__function__" && node.Type != "__lambda__" ) // node.field = program.DefineField(keyvalue.Key, typeof(TypeBase), System.Reflection.FieldAttributes.Private | System.Reflection.FieldAttributes.Static); //} // then generate global sentenses main = program.DefineMethod("Main", System.Reflection.MethodAttributes.Static | System.Reflection.MethodAttributes.Public, System.Reflection.CallingConventions.Standard, typeof(void), null); _gen.SetEntryPoint(main); AstNode sentense = root; while (sentense != null) { sentense.Gen(program, main); sentense = sentense.sibling; } main.GetILGenerator().Emit(OpCodes.Ret); }
public bool AddSymbol(string symbol, AstNode _node, bool global, int paramIndex = -1) { if (string.IsNullOrEmpty(symbol)) return false; if (table.Keys.Contains(symbol)) return false; else { EnviromentNode node = new EnviromentNode(); node.BlockName = Name; node.Symbol = symbol; if (_node != null) { node.Type = _node.type; node.Grammer = _node; } node.IsGlobal = global; node.ParamIndex = paramIndex; table.Add(symbol, node); return true; } }
public void Generate(AstNode root) { GenerateProgram(); GeneratePlangCore(root); }
public DoubleNode(AstNode node) : base(node) { }
public FunctorNode(AstNode node) : base(node) { }
public FunctionCallNode(AstNode node) : base(node) { }
public StringNode(AstNode node) : base(node) { }
public bool AddSymbol(string symbol, AstNode node, int paramIndex = -1) { // FIXME // dont add to global if (current == null) return Global.AddSymbol(symbol, node, true, paramIndex); else return current.AddSymbol(symbol, node, false, paramIndex); }
public MulDivNode(AstNode node) : base(node) { }
public CaculatorNode(AstNode node) : base(node) { }
public PoweredNode(AstNode node) : base(node) { }
public OverriteNode(AstNode node) : base(node) { }
public AssignNode(AstNode node) : base(node) { }
public BoolNode(AstNode node) : base(node) { }
public ArrayNode(AstNode node) : base(node) { }
public IdentifyNode(AstNode node) : base(node) { }
private bool CheckFunctor( MethodBuilder up, AstNode functor ) { if (functor.type == "__lambda__") return false; var node = EnviromentList.Instance.LoopupSymbol( functor.symbol ); if (node != null && node.method == up) return true; else return false; }
public FunctionAbs(AstNode node) : base(node) { }
public EmptyNode(AstNode node) : base(node) { }
private bool IsTailRecury( AstNode sentense, MethodBuilder up, bool jumpToLast = true) { if (EnviromentList.Instance.EnableTailRecury == false) return false; AstNode body = sentense; AstNode last = sentense; if (jumpToLast) { while (body != null) { last = body; body = body.sibling; } } // 查看最后一条是不是 // 1. function call // 2. if then else, 并且最终结果要么是值,要么是function call // 3. 并且function call是up if (last is IfCondition) { AstNode condition = last.child; AstNode match = condition.sibling; AstNode notmatch = match.sibling; return IsTailRecury( match , up, false) && IsTailRecury( notmatch, up, false); } else if (last is FunctionCallNode) { FunctionCallNode call = last as FunctionCallNode; AstNode functor = call.child.child; return CheckFunctor( up, functor ); }else if ( last is CharNode || last is DigitNode || last is DoubleNode || last is StringNode || last is ArrayNode || last is LambdaNode || last is IdentifyNode){ return true; } else { return false; } }
public void eval(AstNode tree) { }
public FunctionBodyNode(AstNode node) : base(node) { }
internal void appendchild(AstNode parent, AstNode child) { parent.child = child; }
public FunctionDeclearNode(AstNode node) : base(node) { }
internal void appendsibling(AstNode parent, AstNode sibling) { if (parent.sibling == null) { parent.sibling = sibling; } else { AstNode last = parent.sibling; while (last.sibling != null) last = last.sibling; last.sibling = sibling; } }
public ParametersNode(AstNode node) : base(node) { }
public ArrayBound(AstNode node) : base(node) { }