Exemplo n.º 1
0
        public string listMethods(Dictionary <String, bluntFunction> methods)
        {
            StringBuilder ret = new StringBuilder();

            foreach (string name in methods.Keys)
            {
                bluntFunction f = methods[name];

                if (f.fparams.Length > 0)
                {
                    ret.Append(f.fparams[0].typeName + " ");
                }
                ret.Append(name + "(");
                bool first = true;
                for (int i = 1; i < f.fparams.Length; i++)
                {
                    bluntParam p = f.fparams[i];
                    if (p.ptype != vtype.constant)
                    {
                        if (!first)
                        {
                            ret.Append(", ");
                        }
                        first = false;

                        ret.Append(p.typeName + " " + p.name);
                    }
                }
                //f.fparams[0].ptype

                ret.Append(")\r\n");
            }

            return(ret.ToString());
        }
Exemplo n.º 2
0
        // pass 1
        public void getMethods(astNode n)
        {
            //get declared function signatures and local stack space
            if (n.type == "FN DECL")
            {
                int nParams = (n.children.Count - 2) / 2 + 1;

                bluntParam[] pTypes = new bluntParam[nParams];
                //return type
                pTypes[0] = getParam(n.children[0]);
                bluntFunction lf = new bluntFunction(n.name, pTypes, -1);

                for (int p = 1; p < nParams; p++)
                {
                    astNode ptype = n.children[(p << 1) - 1];
                    pTypes[p] = getParam(ptype);

                    astNode param = n.children[(p << 1)];
                    pTypes[p].name = param.name;
                    lf.locals.Add(param.name, new bluntVar(p - 1, pTypes[p].ptype, ptype.name)
                    {
                        typename = pTypes[p].objectType
                    });
                }
                getLabels(n, lf.labels);
                lf.locals.Add("@@ret_addr_place_holder", new bluntVar(nParams - 1, vtype.num, null));
                lf.locals.Add("@@stack_frame_place_holder", new bluntVar(nParams, vtype.num, null));
                lf.locals.Add("@@function_frame_place_holder", new bluntVar(nParams + 1, vtype.num, null));

                //find stack usage for local vars
                getLocals(n.children[n.children.Count - 1], lf);

                lf.localStackUsage = lf.locals.Count - (nParams - 1);
                lf.functionType    = fType.SCRIPT;
                if (functions.ContainsKey(lf.mangledName))
                {
                    compilerError(n, "function " + n.name + " with same parameters already declared");
                }
                else
                {
                    functions.Add(lf);
                }
                n.context = lf;
            }
            else if (n.children != null)
            {
                foreach (var child in n.children)
                {
                    getMethods(child);
                }
            }
        }
Exemplo n.º 3
0
        private bluntParam getParam(astNode node)
        {
            bluntParam ret = new bluntParam();

            if (node.name == "code")
            {
                ret.ptype = vtype.code;
            }
            else if (ret.name == "num")
            {
                ret.ptype = vtype.num;
            }
            else
            {
                ret.ptype = vtype.obj;
            }
            ret.objectType = node.name;
            return(ret);
        }