public virtual bool compileMethod(BehavioralObject methodClass, Functor1 <bool, MethodDeclarationNode> compileMethodFromMethodDeclarationNode) { ParseTreeNode rootParseNode = parser.methodParseTree(); if (parser.ErrorCount > 0) { return(false); } switch (rootParseNode.ParseNodeType) { case ParseNodeType.MethodDeclaration: case ParseNodeType.PrimitiveMethodDeclaration: abstractSyntaxTreeGenerator = newASTGenerator(); var methodDeclarationNode = abstractSyntaxTreeGenerator.applyTo(rootParseNode) as MethodDeclarationNode; if (methodDeclarationNode == null) { return(false); } if (ErrorCount < 1 && !methodDeclarationNode.IsCompilable) { return(false); } return(compileMethodFromMethodDeclarationNode(methodDeclarationNode)); default: return(false); } }
protected virtual bool compileMethodsFor(BehavioralObject methodClass, FileInfo methodDeclarationFile) { if (methodDeclarationFile == null) { return(true); } if (IsVerbose) { Console.WriteLine("Compiling methods for: " + methodClass.QualifiedName); } Object value; return(evaluateAsSelfExpression(methodClass, methodClass, methodDeclarationFile, out value)); }
public virtual bool compileMethod(BehavioralObject methodClass, Functor2 <bool, MethodDeclarationNode, LambdaExpression> compileMethodFromLambdaExpression) { return(compileMethod(methodClass, (MethodDeclarationNode methodDeclarationNode) => { var lambda = methodDeclarationNode.lambdaFor(methodClass, methodClass); var undeclaredVariables = methodDeclarationNode.UndeclaredVariables; if (undeclaredVariables != null && undeclaredVariables.Count > 0) { handleUndeclaredVariableReferences(undeclaredVariables, SourceSpan.None); } if (ErrorCount > 0) { return false; } return compileMethodFromLambdaExpression(methodDeclarationNode, lambda); })); }
public virtual bool compileMethod(BehavioralObject methodClass, ESSymbol protocol, out ESMethod compiledMethod) { ESMethod method = null; if (compileMethod( methodClass, (MethodDeclarationNode methodDeclarationNode, Delegate function) => { if (function == null) { return(false); } method = objectSpace.newMethod(methodClass, methodClass, methodDeclarationNode, protocol); return(true); })) { compiledMethod = method; return(true); } else { compiledMethod = null; return(false); } }
public virtual bool compileMethod(BehavioralObject methodClass, Functor2 <bool, MethodDeclarationNode, Delegate> createCompiledMethodFromDelegate) { return(compileMethod(methodClass, (MethodDeclarationNode methodDeclarationNode, LambdaExpression lambdaExpression) => { return createCompiledMethodFromDelegate(methodDeclarationNode, lambdaExpression.Compile()); })); }
public HashSet <ESSymbol> bindNonLocalVariablesToEnvironment(NamespaceObject environment, BehavioralObject methodHomeClass) { if (nonLocalBindings == null) { if (outerScope != null) { return(outerScope.bindNonLocalVariablesToEnvironment(environment, methodHomeClass)); } return(null); } String nameContext; instanceVariableBindings = null; namespaceResidentBindings = null; HashSet <ESSymbol> instVarNames = null; if (environment == null) { if (methodHomeClass != null) { environment = methodHomeClass; } } if (methodHomeClass == null) { methodHomeClass = environment as BehavioralObject; } var envName = environment == null ? "??" : environment.QualifiedName; var methodName = Context.MethodSelector; if (methodName != null) { if (methodHomeClass == null) { nameContext = envName + " ## " + methodName.PrimitiveValue + " => "; } else { nameContext = methodHomeClass.QualifiedName + ">>" + methodName.PrimitiveValue + " => "; methodHomeClass.allInstVarNamesAndIndexesDo((instVarName, index) => { if (instVarNames == null) { instVarNames = new HashSet <ESSymbol>(); } instVarNames.Add(instVarName); NonLocalVariableDeclaration nonLocalVar; if (nonLocalBindings.TryGetValue(instVarName, out nonLocalVar)) { var instanceVar = declareInstanceVariable(instVarName.PrimitiveValue, null); instanceVar.Index = (int)index; nonLocalVar.occurrencesDo(occurrence => occurrence.Declaration = instanceVar); } }); } } else { nameContext = envName + " => "; } HashSet <ESSymbol> undeclared = null; foreach (var kvp in nonLocalBindings) { var nonLocalVar = kvp.Value; var nonLocalName = nonLocalVar.NameSymbol; if (instVarNames == null || !instVarNames.Contains(nonLocalName)) { var ns = environment ?? Context.ObjectSpace.UndeclaredNamespace; var nsResidentVar = declareNamespaceVariable(ns, nonLocalName, null); nonLocalVar.occurrencesDo(occurrence => occurrence.Declaration = nsResidentVar); if (environment == null && methodHomeClass == null) { continue; } /* * if (nonLocalName.PrimitiveValue == "symbolTag") * Console.WriteLine(); */ var binding = nonLocalName.bindingInNamespaceIfAbsent(ns, AccessPrivilegeLevel.Local, ImportTransitivity.Transitive, null); if (binding == null) { if (undeclared == null) { undeclared = new HashSet <ESSymbol>(); } var nameInContext = Context.symbolFor(nameContext + nonLocalName); undeclared.Add(nameInContext); } } } if (environment == null && methodHomeClass == null) { return(null); } return(undeclared); }
protected MessageSendBinder(DynamicBindingGuru dynamicBindingGuru, MessageReceiverKind receiverKind, BehavioralObject selfReceiverClass, ESSymbol selector) : this(dynamicBindingGuru, receiverKind, selector) { this.selfReceiverClass = selfReceiverClass; }
public MessageSendBinder canonicalBinderFor(MessageReceiverKind receiverKind, BehavioralObject selfReceiverClass, ESSymbol selector) { Dictionary <ESSymbol, MessageSendBinder> registry = null; MessageSendBinder binder; if (selfReceiverClass == null) { selfReceiverClass = UnknownClass; } switch (receiverKind) { case MessageReceiverKind.Self: /* * if (!traitSelfReceiverRegistry.TryGetValue(selfReceiverClass, out registry)) { * registry = new Dictionary<ESSymbol, MessageSendBinder>(); * traitSelfReceiverRegistry[selfReceiverClass] = registry; * } * if (!registry.TryGetValue(selector, out binder)) { * binder = new MessageSendBinder(DynamicBindingGuru, receiverKind, selfReceiverClass, selector); * registry[selector] = binder; * } * return binder; */ registry = selfReceiverRegistry; break; case MessageReceiverKind.General: registry = generalReceiverRegistry; break; case MessageReceiverKind.Super: registry = superReceiverRegistry; break; case MessageReceiverKind.ThisContext: registry = thisContextReceiverRegistry; break; } if (!registry.TryGetValue(selector, out binder)) { binder = new MessageSendBinder(DynamicBindingGuru, receiverKind, selector); registry[selector] = binder; } return(binder); }
public ConstantExpression messageSendCallSiteConstantFor(MessageReceiverKind receiverKind, BehavioralObject selfReceiverClass, ESSymbol messageSelector) { switch (receiverKind) { case MessageReceiverKind.General: logMessageSent(messageSelector); break; case MessageReceiverKind.Self: logMessageSentToSelf(messageSelector); break; case MessageReceiverKind.Super: logMessageSentToSuper(messageSelector); break; case MessageReceiverKind.ThisContext: logMessageSentToThisContext(messageSelector); break; } var binder = MessageSendBinderRegistry.canonicalBinderFor(receiverKind, selfReceiverClass, messageSelector); switch (messageSelector.NumArgs) { case 0: return(Expression.Constant(CallSite <Functor2 <Object, CallSite, Object> > .Create(binder))); case 1: return(Expression.Constant(CallSite <Functor3 <Object, CallSite, Object, Object> > .Create(binder))); case 2: return(Expression.Constant(CallSite <Functor4 <Object, CallSite, Object, Object, Object> > .Create(binder))); case 3: return(Expression.Constant(CallSite <Functor5 <Object, CallSite, Object, Object, Object, Object> > .Create(binder))); case 4: return(Expression.Constant(CallSite <Functor6 <Object, CallSite, Object, Object, Object, Object, Object> > .Create(binder))); case 5: return(Expression.Constant(CallSite <Functor7 <Object, CallSite, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 6: return(Expression.Constant(CallSite <Functor8 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 7: return(Expression.Constant(CallSite <Functor9 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 8: return(Expression.Constant(CallSite <Functor10 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 9: return(Expression.Constant(CallSite <Functor11 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 10: return(Expression.Constant(CallSite <Functor12 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 11: return(Expression.Constant(CallSite <Functor13 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 12: return(Expression.Constant(CallSite <Functor14 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 13: return(Expression.Constant(CallSite <Functor15 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 14: return(Expression.Constant(CallSite <Functor16 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 15: return(Expression.Constant(CallSite <Functor17 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 16: return(Expression.Constant(CallSite <Functor18 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 17: return(Expression.Constant(CallSite <Functor19 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 18: return(Expression.Constant(CallSite <Functor20 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 19: return(Expression.Constant(CallSite <Functor21 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 20: return(Expression.Constant(CallSite <Functor22 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 21: return(Expression.Constant(CallSite <Functor23 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 22: return(Expression.Constant(CallSite <Functor24 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 23: return(Expression.Constant(CallSite <Functor25 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 24: return(Expression.Constant(CallSite <Functor26 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 25: return(Expression.Constant(CallSite <Functor27 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 26: return(Expression.Constant(CallSite <Functor28 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 27: return(Expression.Constant(CallSite <Functor29 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 28: return(Expression.Constant(CallSite <Functor30 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 29: return(Expression.Constant(CallSite <Functor31 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 30: return(Expression.Constant(CallSite <Functor32 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 31: return(Expression.Constant(CallSite <Functor33 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); case 32: return(Expression.Constant(CallSite <Functor34 <Object, CallSite, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object> > .Create(binder))); default: return(null); } }