public override AstNode Visit(FunctionPrototype node) { // Add the parent static flag. if (currentContainer.IsStatic()) { MemberFlags oldInstance = node.GetFlags() & MemberFlags.InstanceMask; if (oldInstance == MemberFlags.Static || oldInstance == MemberFlags.Instanced) { MemberFlags flags = node.GetFlags() & ~MemberFlags.InstanceMask; node.SetFlags(flags | MemberFlags.Static); } else { Error(node, "static class member cannot be {0}.", oldInstance.ToString().ToLower()); } } // Add the parent unsafe flag. if (IsUnsafe) { MemberFlags flags = node.GetFlags() & ~MemberFlags.SecurityMask; node.SetFlags(flags | MemberFlags.Unsafe); } return(node); }
public FunctionConstructor(EcmaState state) { FunctionPrototype prototype = new FunctionPrototype(); this.Put("prototype", EcmaValue.Object(prototype)); this.Property["prototype"].DontDelete = true; this.Property["prototype"].DontEnum = true; this.Property["prototype"].ReadOnly = true; this.State = state; }
public void LinearEquations(FunctionPrototype functionPrototype) { for (int j = 0; j < N; j++) { a[j] = 1 - 0.5 * pfunc(x[j]) * h; b[j] = 2 - qfunc(x[j]) * h * h; c[j] = 1 + 0.5 * pfunc(x[j]) * h; d[j] = functionPrototype(x[j]) * h * h; } }
internal WeakMapConstructor( Engine engine, Realm realm, FunctionPrototype prototype, ObjectPrototype objectPrototype) : base(engine, realm, _functionName) { _prototype = prototype; PrototypeObject = new WeakMapPrototype(engine, realm, this, objectPrototype); _length = new PropertyDescriptor(0, PropertyFlag.Configurable); _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden); }
internal SetConstructor( Engine engine, Realm realm, FunctionPrototype functionPrototype, ObjectPrototype objectPrototype) : base(engine, realm, _functionName, FunctionThisMode.Global) { _prototype = functionPrototype; PrototypeObject = new SetPrototype(engine, realm, this, objectPrototype); _length = new PropertyDescriptor(0, PropertyFlag.Configurable); _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden); }
internal BooleanConstructor( Engine engine, Realm realm, FunctionPrototype functionPrototype, ObjectPrototype objectPrototype) : base(engine, realm, _functionName) { _prototype = functionPrototype; PrototypeObject = new BooleanPrototype(engine, realm, this, objectPrototype); _length = new PropertyDescriptor(JsNumber.PositiveOne, PropertyFlag.Configurable); _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden); }
public StringConstructor( Engine engine, Realm realm, FunctionPrototype functionPrototype, ObjectPrototype objectPrototype) : base(engine, realm, _functionName, FunctionThisMode.Global) { _prototype = functionPrototype; PrototypeObject = new StringPrototype(engine, realm, this, objectPrototype); _length = new PropertyDescriptor(JsNumber.PositiveOne, PropertyFlag.Configurable); _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden); }
private JsValue Construct(JsValue thisObject, JsValue[] arguments) { var targetArgument = arguments.At(0); var target = AssertConstructor(_engine, targetArgument); var newTargetArgument = arguments.At(2, arguments[0]); AssertConstructor(_engine, newTargetArgument); var args = FunctionPrototype.CreateListFromArrayLike(_realm, arguments.At(1)); return(target.Construct(args, newTargetArgument)); }
public GameObject consoleContent; //objeto de la consola #endregion void Start() { if (instance == null) //instance es la consola, es lo primero que se declaro. Habla que si la consola es nula, que esto es instance { instance = this; } else { GameObject.Destroy(this); //Si la consola no es nula, destruila. } functionPrototype = Start; //iguala la funcion a la funcion start consoleContent = this.transform.FindChild("Image").gameObject; //Encuentra la imagen de la consola }
private JsValue Apply(JsValue thisObject, JsValue[] arguments) { var target = arguments.At(0); var thisArgument = arguments.At(1); var argumentsList = arguments.At(2); if (!target.IsCallable) { ExceptionHelper.ThrowTypeError(_realm); } var args = FunctionPrototype.CreateListFromArrayLike(_realm, argumentsList); // 3. Perform PrepareForTailCall(). return(((ICallable)target).Call(thisArgument, args)); }
private FunctionPrototype GenerateFunctionPrototype(GenericModifier modifier) { Assert.AssertTypeMatch(parser.LastToken, TokenType.Fun); var prototype = new FunctionPrototype(); prototype.Modifier = modifier; parser.ProceedToken(); // fun を消費 Assert.AssertTypeMatch(parser.LastToken, TokenType.Identifier); prototype.FunctionName = parser.LastToken.Value; parser.ProceedToken(); // 関数名を消費 prototype.args = GenerateArgs(); // TODO 戻り値 parser.ProceedToken(); // : を消費 return(prototype); }
internal LayeClosure(LayeKit kit, FunctionPrototype proto, LayeTypeDef definedType = null, LayeObject[] defaults = null) : base(TYPE) { if (kit == null) throw new ArgumentNullException("kit"); this.kit = kit; this.proto = proto; outers = new OuterValue[proto.outers.Length]; this.definedType = definedType == null ? NULL : definedType; var numParams = proto.hasVargs ? proto.numParams - 1 : proto.numParams; this.defaults = new LayeObject[numParams]; if (defaults == null || defaults.Length == 0) for (int i = 0; i < numParams; i++) this.defaults[i] = NULL; else { for (uint i = 0; i < numParams - defaults.Length; i++) this.defaults[i] = NULL; for (uint i = numParams - (uint)defaults.Length, j = 0; i < numParams; i++, j++) this.defaults[i] = defaults[j]; } }
public void Registercomand(string commandName, FunctionPrototype function, string description) { allCommandsEffects.Add(commandName, function); allCommands.Add(commandName, description); }
public override AstNode Visit(FunctionPrototype node) { return(node); }
public void RegisterCommand(string commandName, FunctionPrototype command, string description) { commandDictionary.Add(commandName, command); commandDescriptions.Add(commandName, description); }
public override AstNode Visit(FunctionPrototype node) { // Get the name expression. Expression nameExpression = node.GetNameExpression(); if (nameExpression == null) { return(node); } // Visit the name expression. nameExpression.SetHints(Expression.MemberHint); nameExpression.Accept(this); // Get the function and his type. Function function = node.GetFunction(); FunctionType functionType = function.GetFunctionType(); if (!function.IsMethod()) { Error(node, "expected a method prototype."); } Method method = (Method)function; // It must be a function selector. IChelaType nameType = nameExpression.GetNodeType(); if (!nameType.IsFunctionGroup()) { Error(nameExpression, "expected a function group."); } FunctionGroupSelector selector = (FunctionGroupSelector)nameExpression.GetNodeValue(); FunctionGroup group = selector.GetFunctionGroup(); // Find a matching function in the group. Function match = null; foreach (FunctionGroupName gname in group.GetFunctions()) { // Ignore static functions. if (gname.IsStatic()) { continue; } // Check for match. FunctionType candidate = gname.GetFunctionType(); // Found a match?. if (MatchFunction(candidate, functionType, 1)) { match = (Function)gname.GetFunction(); break; } } // Raise an error. if (match == null) { Error(nameExpression, "couldn't find matching interface member for {0}", functionType.GetName()); } // TODO: Rename the method. // Bind the contract. method.SetExplicitContract(match); return(node); }
public void DownloadGL4() { if (!Directory.Exists("cache")) { Directory.CreateDirectory("cache"); } var index = "https://raw.githubusercontent.com/KhronosGroup/OpenGL-Refpages/master/gl4/html/indexflat.php"; var contents = string.Empty; var webRequest = WebRequest.Create(index); using (var response = webRequest.GetResponse()) using (var content = response.GetResponseStream()) { using (var reader = new StreamReader(content)) { contents = reader.ReadToEnd(); } } var matches = indexRegex.Matches(contents); foreach (Match match in matches) { var name = match.Groups[1].Value; gl4Files.Add(name); Console.WriteLine("DocHandler - GL4 - Parsing: {0}", name); var xmlContents = string.Empty; if (!File.Exists("cache/" + name + ".xml")) { try { var xmlRequest = WebRequest.Create("https://raw.githubusercontent.com/KhronosGroup/OpenGL-Refpages/master/gl4/" + name + ".xml"); using (var response = xmlRequest.GetResponse()) using (var content = response.GetResponseStream()) { using (var reader = new StreamReader(content)) { xmlContents = reader.ReadToEnd(); File.WriteAllText("cache/" + name + ".xml", xmlContents); } } } catch { //System.Console.WriteLine("https://raw.githubusercontent.com/KhronosGroup/OpenGL-Refpages/master/gl4/" + name + ".xml"); } } else { xmlContents = File.ReadAllText("cache/" + name + ".xml"); } var functions = functionsRegex.Matches(xmlContents); foreach (Match function in functions) { var nameMatch = functionNameRegex.Match(function.Groups[1].Value); var functionName = nameMatch.Groups[1].Value; var paramsMatches = functionParamRegex.Matches(function.Groups[1].Value); var f = new FunctionPrototype(); f.Name = functionName; foreach (Match param in paramsMatches) { f.Params.Add(param.Groups[1].Value); } Prototypes[functionName] = f; if (!map.ContainsKey(functionName)) { map[functionName] = name; } } } }
public static string ParseFunctionPrototypes(string source, Preset preset) { StringBuilder s = new StringBuilder(); string prefix = preset.GetProperty("Prefix"); string loadMacro = preset.GetProperty("LoadMacro"); string loadLibHandle = preset.GetProperty("LoadLibHandle"); string loadLibName = preset.GetProperty("LoadLibName"); string loadLibFieldPrefix = preset.GetProperty("LoadLibFieldPrefix"); try { List <FunctionPrototype> funcs = new List <FunctionPrototype>(); if (!string.IsNullOrEmpty(source)) { List <FunctionTokenizer.Token> tokens = FunctionTokenizer.Tokenize(source); List <FunctionTokenizer.Token> leftCache = new List <FunctionTokenizer.Token>(); List <FunctionTokenizer.Token> argumentsCache = new List <FunctionTokenizer.Token>(); ParseState state = ParseState.FunctionStart; FunctionPrototype func = null; int tokenIndex = 0; while (tokenIndex < tokens.Count) { FunctionTokenizer.Token token = tokens[tokenIndex]; switch (state) { case ParseState.FunctionStart: { if (token.Type == FunctionTokenizer.TokenType.BraceBegin) { if (leftCache.Count == 0) { throw new Exception($"No tokens before '{token}'!"); } FunctionTokenizer.Token nameToken = leftCache.Last(); if (nameToken.Type != FunctionTokenizer.TokenType.Ident) { throw new Exception($"Expected token type '{FunctionTokenizer.TokenType.Ident}' but got token '{token}'!"); } string funcName = nameToken.GetValue(); leftCache.RemoveAt(leftCache.Count - 1); func = new FunctionPrototype() { Name = funcName, }; funcs.Add(func); foreach (var returnTok in leftCache) { func.Returns.Add(returnTok.GetValue()); } leftCache.Clear(); ++tokenIndex; state = ParseState.FunctionArgs; } else { leftCache.Add(token); ++tokenIndex; } } break; case ParseState.FunctionArgs: { Debug.Assert(leftCache.Count == 0); Debug.Assert(func != null); List <string> argNames = new List <string>(); while (tokenIndex < tokens.Count) { token = tokens[tokenIndex]; if (token.Type == FunctionTokenizer.TokenType.BraceEnd) { ++tokenIndex; FunctionArgumentPrototype newArg = new FunctionArgumentPrototype(); newArg.Names.AddRange(argNames); func.Args.Add(newArg); // Done with function func = null; state = ParseState.FunctionStart; break; } else if (token.Type == FunctionTokenizer.TokenType.ArgumentSeparator) { ++tokenIndex; FunctionArgumentPrototype newArg = new FunctionArgumentPrototype(); newArg.Names.AddRange(argNames); func.Args.Add(newArg); argNames.Clear(); if (tokenIndex == tokens.Count) { throw new IndexOutOfRangeException($"Missing token after argument separator ',' on token '{token}'"); } token = tokens[tokenIndex]; if (token.Type != FunctionTokenizer.TokenType.Ident) { throw new Exception($"Expected token type '{FunctionTokenizer.TokenType.Ident}' but got token '{token}'!"); } } else { argNames.Add(token.GetValue()); ++tokenIndex; } } } break; default: throw new Exception($"Unsupported parse state '{state}' on token '{token}'"); } } } if (funcs.Count > 0) { s.AppendLine("// Prototypes"); Dictionary <FunctionPrototype, string> funcToTypeNameMap = new Dictionary <FunctionPrototype, string>(); Dictionary <FunctionPrototype, string> funcToNameMap = new Dictionary <FunctionPrototype, string>(); foreach (var func in funcs) { funcToTypeNameMap.Add(func, $"{prefix.ToLower()}{func.Name}"); funcToNameMap.Add(func, func.Name); s.Append($"#define {prefix}{func.Name}(name) "); string returnStr = PrintNames(func.Returns); s.Append(returnStr); if (s[s.Length - 1] != '*') { s.Append(" "); } s.Append("name("); for (int argIndex = 0; argIndex < func.Args.Count; ++argIndex) { if (argIndex > 0) { s.Append(", "); } string argStr = PrintNames(func.Args[argIndex].Names); s.Append(argStr); } s.Append(")"); s.AppendLine(); s.Append($"typedef {prefix}{func.Name}({prefix.ToLower()}{func.Name});"); s.AppendLine(); } s.AppendLine(); s.AppendLine("// Declarations"); foreach (var func in funcs) { string n = funcToTypeNameMap[func]; s.AppendLine($"{n} *{func.Name};"); } s.AppendLine(); s.AppendLine("// Load"); foreach (var func in funcs) { string funcName = funcToNameMap[func]; string typeName = funcToTypeNameMap[func]; s.AppendLine($"{loadMacro}({loadLibHandle}, {loadLibName}, {loadLibFieldPrefix}{funcName}, {typeName}, \"{funcName}\");"); } } } catch (Exception e) { s.AppendLine($"Error: {e.Message}"); } return(s.ToString()); }
public FunctionType(MelonEngine engine) : base(engine) { Prototype = new FunctionPrototype(engine, this); }
//Registro public void RegisterCommand(string name, FunctionPrototype command) //Creas la funcion para crear comandos. El primero con el nombre de la funcion y el segundo toma la funcion. //Esto sirve para unir el nombre con la funcion en el diccionario { allCommands[name] = command; //registro en el diccionado llamado allCommands }
internal LayeKit(string fileLocation, FunctionPrototype proto) : base(TYPE) { this.fileLocation = fileLocation; body = new LayeClosure(this, proto); }
public void Model(FunctionPrototype functionPrototype) { CreateGrid(); LinearEquations(functionPrototype); TridiagonalMatrixAlgorithm(); }
/// <summary> /// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys /// </summary> public override List <JsValue> GetOwnPropertyKeys(Types types = Types.None | Types.String | Types.Symbol) { if (!TryCallHandler(TrapOwnKeys, new JsValue[] { _target }, out var result)) { return(_target.GetOwnPropertyKeys(types)); } var trapResult = new List <JsValue>(FunctionPrototype.CreateListFromArrayLike(_engine.Realm, result, Types.String | Types.Symbol)); if (trapResult.Count != new HashSet <JsValue>(trapResult).Count) { ExceptionHelper.ThrowTypeError(_engine.Realm); } var extensibleTarget = _target.Extensible; var targetKeys = _target.GetOwnPropertyKeys(); var targetConfigurableKeys = new List <JsValue>(); var targetNonconfigurableKeys = new List <JsValue>(); foreach (var property in targetKeys) { var desc = _target.GetOwnProperty(property); if (desc != PropertyDescriptor.Undefined && !desc.Configurable) { targetNonconfigurableKeys.Add(property); } else { targetConfigurableKeys.Add(property); } } var uncheckedResultKeys = new HashSet <JsValue>(trapResult); for (var i = 0; i < targetNonconfigurableKeys.Count; i++) { var key = targetNonconfigurableKeys[i]; if (!uncheckedResultKeys.Remove(key)) { ExceptionHelper.ThrowTypeError(_engine.Realm); } } if (extensibleTarget) { return(trapResult); } for (var i = 0; i < targetConfigurableKeys.Count; i++) { var key = targetConfigurableKeys[i]; if (!uncheckedResultKeys.Remove(key)) { ExceptionHelper.ThrowTypeError(_engine.Realm); } } if (uncheckedResultKeys.Count > 0) { ExceptionHelper.ThrowTypeError(_engine.Realm); } return(trapResult); }