public Finalizer(LexicalScope/*!*/ definedScope, Statements statements, SourceSpan location) : base(location) { Assert.NotNull(definedScope); _definedScope = definedScope; _statements = statements; }
public ModuleDefinition(LexicalScope/*!*/ definedScope, ConstantVariable/*!*/ qualifiedName, Body/*!*/ body, SourceSpan location) : base(definedScope, body, location) { ContractUtils.RequiresNotNull(qualifiedName, "qualifiedName"); _qualifiedName = qualifiedName; }
public override bool ResolveNames(LexicalScope scope) { // Step 1: Create new scope and populate the symbol table var newScope = getNewScope(scope, null); // Step 1a: add all class declarations to the current scope foreach (Statement each in ClassDeclarations) { Declaration classDec = each as Declaration; if (classDec != null) { classDec.AddItemsToSymbolTable(newScope); } } // Step 2: ResolveNames for each part of the complilation unit bool loopResolve = true; if (ClassDeclarations != null) { foreach (ClassDeclaration each in ClassDeclarations) { loopResolve = loopResolve & each.ResolveNames(newScope); } } // need to do something special with package declarations and import declarations - Nathan return(loopResolve); }
public static LexicalScope getNewScope(LexicalScope oldScope, List<Expression> variableList) { // Step 1: Create scope that includes standard libraries (ie Java.Lang) if oldScope == null. if (oldScope == null) { var JLnode = new JavaLang(); oldScope = new LexicalScope(); oldScope.Symbol_table = new Dictionary<string, Declaration>(); JLnode.AddItemsToSymbolTable(oldScope); } // Step 1: set the new scope var newScope = new LexicalScope(); newScope.ParentScope = oldScope; newScope.Symbol_table = new Dictionary<string, Declaration>(); // Step 2: Check for declarations in the new scope and add to symbol_table of old scope if (variableList != null) { foreach (Expression each in variableList) { Declaration decl = each as Declaration; // try to cast statement as a declaration if (decl != null) { decl.AddItemsToSymbolTable(newScope); } } } return newScope; }
private static void BuildScopesInFunctionParameters( LexicalScope containingScope, FunctionDeclarationSyntax function, ExpressionLexicalScopesBuilder binder) { if (function.GenericParameters != null) { foreach (var parameter in function.GenericParameters) { binder.VisitExpression(parameter.TypeExpression, containingScope); } } foreach (var parameter in function.Parameters) { switch (parameter) { case NamedParameterSyntax namedParameter: binder.VisitExpression(namedParameter.TypeExpression, containingScope); break; case SelfParameterSyntax _: case FieldParameterSyntax _: // Nothing to bind break; default: throw NonExhaustiveMatchException.For(parameter); } } }
public override bool ResolveNames(LexicalScope scope) { // Step 1: Create new scope and populate the symbol table // Special case with blocks - add to symbol table line by line as the names are resolved. // This is the catch the situation where the declaration is after the use of the variable. //var newScope = getNewScope(scope, null); // Step 2: ResolveNames for each part of the complilation unit bool loopResolve = true; if (statements != null) { foreach (Statement each in statements) { Declaration decl = each as Declaration; // try to cast statement as a declaration if (decl != null) { decl.AddItemsToSymbolTable(scope); } loopResolve = loopResolve & each.ResolveNames(scope); } } return(loopResolve); }
public ModuleDefinition(LexicalScope /*!*/ definedScope, ConstantVariable /*!*/ qualifiedName, Body /*!*/ body, SourceSpan location) : base(definedScope, body, location) { ContractUtils.RequiresNotNull(qualifiedName, "qualifiedName"); _qualifiedName = qualifiedName; }
public ForLoopExpression(LexicalScope /*!*/ definedScope, CompoundLeftValue /*!*/ variables, Expression /*!*/ list, Statements body, SourceSpan location) : base(location) { Assert.NotNull(definedScope, variables, list); _block = new BlockDefinition(definedScope, variables, body, location); _list = list; }
public Initializer(LexicalScope/*!*/ definedScope, List<Expression> statements, SourceSpan location) : base(location) { Assert.NotNull(definedScope); _definedScope = definedScope; _statements = statements; }
public SingletonDefinition(LexicalScope /*!*/ definedScope, Expression /*!*/ singleton, Body /*!*/ body, SourceSpan location) : base(definedScope, body, location) { ContractUtils.RequiresNotNull(singleton, "singleton"); _singleton = singleton; }
public override bool ResolveNames(LexicalScope scope) { bool loopResolve = true; if (args != null) { foreach (Expression argument in args) { loopResolve = loopResolve & argument.ResolveNames(scope); } } // check for valid declaration of method... if (scope != null) { declarationRef = scope.Resolve(name); } if (declarationRef == null) { Console.WriteLine("Error: Undeclared method indentifier", name); throw new Exception("Name Resolution Error - can not resolve method name"); } return((declarationRef != null) & loopResolve); }
private LexicalScope BuildNamespaceScopes( LexicalScope containingScope, RootName ns) { Name name; switch (ns) { case GlobalNamespaceName _: return(containingScope); case QualifiedName qualifiedName: containingScope = BuildNamespaceScopes(containingScope, qualifiedName.Qualifier); name = qualifiedName; break; case SimpleName simpleName: name = simpleName; break; default: throw NonExhaustiveMatchException.For(ns); } var symbolsInNamespace = allSymbols.Where(s => s.FullName.HasQualifier(name)); var symbolsNestedInNamespace = allSymbols.Where(s => s.FullName.IsNestedIn(name)); return(new NestedScope(containingScope, symbolsInNamespace, symbolsNestedInNamespace)); }
public SingletonDefinition(LexicalScope/*!*/ definedScope, Expression/*!*/ singleton, Body/*!*/ body, SourceSpan location) : base(definedScope, body, location) { ContractUtils.RequiresNotNull(singleton, "singleton"); _singleton = singleton; }
public ForLoopExpression(LexicalScope/*!*/ definedScope, Parameters/*!*/ variables, Expression/*!*/ list, Statements body, SourceSpan location) : base(location) { Assert.NotNull(definedScope, variables, list); _block = new BlockDefinition(definedScope, variables, body, location); _list = list; }
public ClassDefinition(LexicalScope/*!*/ definedScope, ConstantVariable/*!*/ name, Expression superClass, Body/*!*/ body, SourceSpan location) : base(definedScope, name, body, location) { ContractUtils.RequiresNotNull(name, "name"); _superClass = superClass; }
public ClassDefinition(LexicalScope /*!*/ definedScope, ConstantVariable /*!*/ name, Expression superClass, Body /*!*/ body, SourceSpan location) : base(definedScope, name, body, location) { ContractUtils.RequiresNotNull(name, "name"); _superClass = superClass; }
public void EnterMethodDefinition( ScopeBuilder /*!*/ locals, MSA.Expression /*!*/ selfParameter, MSA.ParameterExpression /*!*/ runtimeScopeVariable, MSA.Expression blockParameter, string /*!*/ methodName, Parameters parameters) { Assert.NotNull(locals, selfParameter, runtimeScopeVariable); MethodScope method = new MethodScope( locals, selfParameter, runtimeScopeVariable, blockParameter, methodName, parameters ); method.Parent = _currentElement; method.ParentRescue = _currentRescue; method.ParentLoop = _currentLoop; method.ParentBlock = _currentBlock; method.ParentVariableScope = _currentVariableScope; method.ParentMethod = _currentMethod; _currentElement = method; _currentRescue = null; _currentLoop = null; _currentBlock = null; _currentVariableScope = method; _currentMethod = method; }
public FileInitializerStatement(LexicalScope /*!*/ definedScope, Statements /*!*/ statements, SourceSpan location) : base(location) { Assert.NotNull(definedScope); _definedScope = definedScope; _statements = statements; }
public BlockDefinition(LexicalScope/*!*/ definedScope, CompoundLeftValue/*!*/ parameters, Statements/*!*/ body, SourceSpan location) : base(location) { Assert.NotNull(definedScope, parameters, body); _definedScope = definedScope; _body = body; _parameters = parameters; }
public FunctionDeclarationStatementNode(LexicalScope scope, string name, ParameterNode[] parameters, ElementNode[] body, SourceSpan sourceSpan) : base(sourceSpan) { this.scope = scope; this.name = name; this.parameters = parameters; this.body = body; }
internal override Expression/*!*/ ToCondition(LexicalScope/*!*/ currentScope) { var newExpression = _expression.ToCondition(currentScope); if (newExpression != _expression) { return new NotExpression(newExpression, Location); } return this; }
public BlockDefinition(LexicalScope/*!*/ definedScope, Parameters parameters, Statements/*!*/ body, SourceSpan location) : base(location) { Assert.NotNull(definedScope, body); _definedScope = definedScope; _body = body; _parameters = parameters ?? Parameters.Empty; }
public override bool ResolveNames(LexicalScope scope) { // 1. create new scope var newScope = getNewScope(scope, null); // 2. resolve names in while condition and statement(s) return(Cond.ResolveNames(newScope) & Statements.ResolveNames(newScope)); }
public override bool ResolveNames(LexicalScope scope) { // Step 1: Add variables to symboltable AddItemsToSymbolTable(scope); // Step 2: ResolveName on variable type return(varType.ResolveNames(scope)); }
public Finalizer(LexicalScope /*!*/ definedScope, List <Expression> statements, SourceSpan location) : base(location) { Assert.NotNull(definedScope); _definedScope = definedScope; _statements = statements; }
public BlockDefinition(LexicalScope definedScope, CompoundLeftValue/*!*/ parameters, List<Expression>/*!*/ body, SourceSpan location) : base(location) { Assert.NotNull(parameters, body); _definedScope = definedScope; _body = body; _parameters = parameters; }
public void LeaveFileInitializer() { Debug.Assert(_currentElement == _currentVariableScope); VariableScope oldScope = _currentVariableScope; _currentElement = oldScope.Parent; _currentVariableScope = oldScope.ParentVariableScope; }
protected DefinitionExpression(LexicalScope/*!*/ definedScope, Body/*!*/ body, SourceSpan location) : base(location) { ContractUtils.RequiresNotNull(definedScope, "definedScope"); ContractUtils.RequiresNotNull(body, "body"); _definedScope = definedScope; _body = body; }
private void CompileLet(object form, LexicalScope lexScope) { throw new NotImplementedException(); // Cons consForm = form as Cons; // if(consForm == null) // { // throw new CompilerError("{0} is not let-form!", form); // } // Cons formArgs = consForm.Tail as Cons; // if(formArgs == null) // { // throw new CompilerError("{0} is not let-form!", form); // } // Cons bindingList = formArgs.Head as Cons; // if(bindingList == null) // { // throw new CompilerError("{0} is not let-form!", form); // } // while(bindingList != Cons.Nil) // { // object arg = bindingList.Head; // String type = TypeResolver.GetTypeRef(arg.GetType()); // switch(type) // { // case "symbol": // lexScope.Bind(arg as Symbol, "value", Cons.Nil); // break; // case "cons": // Cons argSpec = arg as Cons; // Symbol sym = argSpec.Head as Symbol; // if(sym == null) // { // throw new TypeError(argSpec.Head, typeof(Symbol)); // } // Cons specTail = argSpec.Tail as Cons; // if(specTail == null) // { // throw new TypeError(specTail.Tail, typeof(Cons)); // } // object value = specTail.Head; // lexScope.Bind(sym, "value", value); // break; // default: // throw new TypeError(arg, typeof(Symbol)); // } // Cons newArgs = bindingList.Tail as Cons; // if(newArgs == null) // { // throw new TypeError(newArgs, typeof(Cons)); // } // bindingList = newArgs; // } }
public BlockDefinition(LexicalScope definedScope, CompoundLeftValue /*!*/ parameters, List <Expression> /*!*/ body, SourceSpan location) : base(location) { Assert.NotNull(parameters, body); _definedScope = definedScope; _body = body; _parameters = parameters; }
public BlockDefinition(LexicalScope /*!*/ definedScope, CompoundLeftValue /*!*/ parameters, Statements /*!*/ body, SourceSpan location) : base(location) { Assert.NotNull(definedScope, parameters, body); _definedScope = definedScope; _body = body; _parameters = parameters; }
public MethodDefinition(LexicalScope/*!*/ definedScope, Expression target, string/*!*/ name, Parameters parameters, Body/*!*/ body, SourceSpan location) : base(definedScope, body, location) { Assert.NotNull(name); _target = target; _name = name; _parameters = parameters ?? Parameters.Empty; }
public BlockDefinition(LexicalScope /*!*/ definedScope, Parameters parameters, Statements /*!*/ body, SourceSpan location) : base(location) { Assert.NotNull(definedScope, body); _definedScope = definedScope; _body = body; _parameters = parameters ?? Parameters.Empty; }
public void LeaveModuleDefinition() { Debug.Assert(_currentElement == _currentModule); ModuleScope oldModule = _currentModule; _currentElement = oldModule.Parent; _currentVariableScope = oldModule.ParentVariableScope; _currentModule = oldModule.ParentModule; }
protected DefinitionExpression(LexicalScope /*!*/ definedScope, Body /*!*/ body, SourceSpan location) : base(location) { ContractUtils.RequiresNotNull(definedScope, "definedScope"); ContractUtils.RequiresNotNull(body, "body"); _definedScope = definedScope; _body = body; }
public ForStatementNode(LexicalScope scope, StatementNode initializer, ExpressionNode condition, ExpressionNode incrementer, StatementNode body, SourceSpan span) : base(span) { this.scope = scope; this.initializer = initializer; this.condition = condition; this.incrementer = incrementer; this.body = body; }
public MethodDefinition(LexicalScope /*!*/ definedScope, Expression target, string /*!*/ name, Parameters parameters, Body /*!*/ body, SourceSpan location) : base(definedScope, body, location) { Assert.NotNull(name); _target = target; _name = name; _parameters = parameters ?? Parameters.Empty; }
internal override Expression/*!*/ ToCondition(LexicalScope/*!*/ currentScope) { var newLeft = _left.ToCondition(currentScope); var newRight = _right.ToCondition(currentScope); if (newLeft != _left || newRight != _right) { return new OrExpression(newLeft, newRight, Location); } return this; }
public void LeaveSourceUnit() { Debug.Assert(_currentElement == _currentMethod && _currentVariableScope == _currentMethod); Debug.Assert(_currentLoop == null && _currentRescue == null); Debug.Assert(_currentBlock == null); _currentElement = null; _currentMethod = null; _currentVariableScope = null; }
internal override Expression/*!*/ ToCondition(LexicalScope/*!*/ currentScope) { int intBegin, intEnd; if (!IsIntegerRange(out intBegin, out intEnd)) { return new RangeCondition( this, currentScope.GetInnerMostTopScope().AddVariable("#FlipFlopState" + Interlocked.Increment(ref _flipFlopVariableId), Location) ); } return this; }
/// <summary> /// Gets the inner most scope that compiles to a lambda expression. /// </summary> private VariableScope /*!*/ GetCurrentLambdaScope() { LexicalScope scope = _currentVariableScope; while (!scope.IsLambda) { scope = scope.Parent; } return((VariableScope)scope); }
public ArgumentVariable(int index, string name, LexicalScope parentScope, IChelaType type) : base(type, parentScope.GetModule()) { base.SetName(name); this.parentScope = parentScope; // Add the variable into the scope. this.index = index; parentScope.AddArgument(this); }
public ArgumentVariable(int index, string name, LexicalScope parentScope, IChelaType type) : base(type, parentScope.GetModule()) { base.SetName(name); this.parentScope = parentScope; // Add the variable into the scope. this.index = index; parentScope.AddArgument(this); }
internal override Expression /*!*/ ToCondition(LexicalScope /*!*/ currentScope) { // propagates 'in condition' property if we have a single element: if (_statements != null && _statements.Count == 1 && !HasExceptionHandling) { return(_statements.First.ToCondition(currentScope)); } return(this); }
public void EnterRescueClause(MSA.Expression /*!*/ retryingVariable, MSA.LabelTarget /*!*/ breakLabel, MSA.LabelTarget /*!*/ continueLabel) { Assert.NotNull(retryingVariable, breakLabel, continueLabel); RescueScope body = new RescueScope(retryingVariable, breakLabel, continueLabel); body.Parent = _currentElement; body.ParentRescue = _currentRescue; _currentElement = _currentRescue = body; }
public void EnterLoop(MSA.Expression /*!*/ redoVariable, MSA.Expression /*!*/ resultVariable, MSA.LabelTarget /*!*/ breakLabel, MSA.LabelTarget /*!*/ continueLabel) { Assert.NotNull(redoVariable, resultVariable, breakLabel, continueLabel); LoopScope loop = new LoopScope(redoVariable, resultVariable, breakLabel, continueLabel); loop.Parent = _currentElement; loop.ParentLoop = _currentLoop; _currentElement = _currentLoop = loop; }
internal override Expression /*!*/ ToCondition(LexicalScope /*!*/ currentScope) { var newExpression = _expression.ToCondition(currentScope); if (newExpression != _expression) { return(new NotExpression(newExpression, Location)); } return(this); }
public void LeaveBlockDefinition() { Debug.Assert(_currentElement == _currentBlock); BlockScope oldBlock = _currentBlock; _currentElement = oldBlock.Parent; _currentRescue = oldBlock.ParentRescue; _currentLoop = oldBlock.ParentLoop; _currentVariableScope = oldBlock.ParentVariableScope; _currentBlock = oldBlock.ParentBlock; }
public MethodDefinition(LexicalScope/*!*/ definedScope, Expression target, string/*!*/ name, Parameters parameters, Body/*!*/ body, SourceSpan location) : base(definedScope, body, location) { Assert.NotNull(name); // only for-loop block might use other than local variable for unsplat: Debug.Assert(parameters.Unsplat == null || parameters.Unsplat is LocalVariable); _target = target; _name = name; _parameters = parameters ?? Parameters.Empty; }
public ScopeBuilder(AstParameters parameters, int firstClosureParam, int localCount, ScopeBuilder parent, LexicalScope/*!*/ lexicalScope) { Debug.Assert(parent == null || parent.LexicalScope == lexicalScope.OuterScope); #if DEBUG _id = Interlocked.Increment(ref _Id); #endif _parent = parent; _parameters = parameters; _localCount = localCount; _firstClosureParam = firstClosureParam; _lexicalScope = lexicalScope; _hiddenVariables = new AstParameters(); _localsTuple = DefineHiddenVariable("#locals", MakeLocalsTupleType()); _outermostClosureReferredTo = this; }
public LocalVariable(string name, LexicalScope parentScope, IChelaType type, bool pseudoLocal) : base(type, parentScope.GetModule()) { base.SetName(name); this.parentScope = parentScope; // Add the variable into this. this.isPseudoLocal = pseudoLocal; this.index = parentScope.AddLocal(this); this.argumentIndex = -1; this.position = null; // Check for generated locals. if(name.StartsWith("._gsym")) localType = LocalType.Generated; }
private void CompileProgn(Cons formList, LexicalScope lexScope) { if(formList.Head != Cons.Nil) { while (formList.Tail != Cons.Nil) { CompileForm(formList.Head, lexScope); _gen.Emit(OpCodes.Pop); Assert.TypeIs(formList.Tail, typeof(Cons)); formList = formList.Tail as Cons; } CompileForm(formList.Head, lexScope); } else { var fldInfo = typeof(Cons).GetField("Nil", BindingFlags.Public | BindingFlags.Static); _gen.Emit(OpCodes.Ldsfld, fldInfo); } }
private void CompileFuncall(Symbol fnSym, Cons paramList, LexicalScope lexScope) { if(lexScope.IsBound(fnSym, Symbol.FunctionSlot)) { GenLexSymValue(lexScope, fnSym, Symbol.FunctionSlot); } else { FieldInfo functionSlotFld = typeof(Symbol).GetField("FunctionSlot"); if(functionSlotFld == null) { throw new CompilerError("Unable to find VM.Types.Symbol.FunctionSlot field"); } GenDynSymValue(fnSym, functionSlotFld); } MethodInfo invokeMethInfo = typeof(Function).GetMethod("Invoke"); if(invokeMethInfo == null) { throw new CompilerError("Unable to find VM.Function.Invoke method"); } var paramCount = ConsAux.Reduce(paramList, (x, counter) => counter + 1, 0); _gen.Emit(OpCodes.Newarr, paramCount); ConsAux.Reduce(paramList, (x, counter) => { _gen.Emit(OpCodes.Dup); _gen.Emit(OpCodes.Ldc_I4, counter + 1); CompileForm(x, lexScope); _gen.Emit(OpCodes.Stelem_Ref); return counter + 1; }, 0); _gen.Emit(OpCodes.Call, invokeMethInfo); }
public void LeaveMethodDefinition() { Debug.Assert(_currentElement == _currentMethod); MethodScope oldMethod = _currentMethod; _currentElement = oldMethod.Parent; _currentRescue = oldMethod.ParentRescue; _currentLoop = oldMethod.ParentLoop; _currentBlock = oldMethod.ParentBlock; _currentVariableScope = oldMethod.ParentVariableScope; _currentMethod = oldMethod.ParentMethod; }
internal override Expression/*!*/ ToCondition(LexicalScope/*!*/ currentScope) { return new RegularExpressionCondition(this); }
public void EnterMethodDefinition( ScopeBuilder/*!*/ locals, MSA.Expression/*!*/ selfParameter, MSA.ParameterExpression/*!*/ runtimeScopeVariable, MSA.Expression blockParameter, string/*!*/ methodName, Parameters parameters) { Assert.NotNull(locals, selfParameter, runtimeScopeVariable); MethodScope method = new MethodScope( locals, selfParameter, runtimeScopeVariable, blockParameter, methodName, parameters ); method.Parent = _currentElement; method.ParentRescue = _currentRescue; method.ParentLoop = _currentLoop; method.ParentBlock = _currentBlock; method.ParentVariableScope = _currentVariableScope; method.ParentMethod = _currentMethod; _currentElement = method; _currentRescue = null; _currentLoop = null; _currentBlock = null; _currentVariableScope = method; _currentMethod = method; }
public void EnterModuleDefinition( ScopeBuilder/*!*/ locals, MSA.Expression/*!*/ selfVariable, MSA.ParameterExpression/*!*/ runtimeScopeVariable, bool isSingleton) { Assert.NotNull(locals, selfVariable, runtimeScopeVariable); ModuleScope module = new ModuleScope(locals, selfVariable, runtimeScopeVariable, isSingleton); module.Parent = _currentElement; module.ParentVariableScope = _currentVariableScope; module.ParentModule = _currentModule; _currentElement = module; _currentVariableScope = module; _currentModule = module; }
public void LeaveModuleDefinition() { Debug.Assert(_currentElement == _currentModule); ModuleScope oldModule = _currentModule; _currentElement = oldModule.Parent; _currentVariableScope = oldModule.ParentVariableScope; _currentModule = oldModule.ParentModule; }
protected ModuleDefinition(LexicalScope/*!*/ definedScope, Body/*!*/ body, SourceSpan location) : base(definedScope, body, location) { _qualifiedName = null; }
public void LeaveSourceUnit() { Debug.Assert(_currentElement == _currentMethod && _currentVariableScope == _currentMethod); Debug.Assert(_currentLoop == null && _currentRescue == null); Debug.Assert(_currentBlock == null); _currentElement = null; _currentMethod = null; _currentVariableScope = null; }