示例#1
0
        public static ObjString tableFindString(ref Table_t table, char[] chars, int _start, int length, uint hash)
        {
            if (table.count == 0)
            {
                return(null);
            }

            uint index = (uint)(hash & table.capacity);

            for (;;)
            {
                Entry entry = table.entries[index];

                if (entry.key == null)
                {
                    // Stop if we find an empty non-tombstone entry.
                    if (Value.IS_NIL(entry.value))
                    {
                        return(null);
                    }
                }
                else if (entry.key.length == length &&
                         entry.key.hash == hash &&
                         Cfun._memcmp(entry.key.chars, entry.key._start, chars, _start, length))
                {
                    // We found it.
                    return(entry.key);
                }


                index = (uint)((index + 1) & table.capacity);
            }
        }
示例#2
0
        static bool identifiersEqual(ref Token a, ref Token b)
        {
            if (a.length != b.length)
            {
                return(false);
            }

            return(Cfun._memcmp(a._char_ptr, a.start, b._char_ptr, b.start, a.length));
        }
示例#3
0
        private static void method()
        {
            consume(TokenType.TOKEN_IDENTIFIER, "Expect method name.");
            byte constant = identifierConstant(ref parser.previous);

            FunctionType type = FunctionType.TYPE_METHOD;

            if (parser.previous.length == 4 && Cfun._memcmp(parser.previous._char_ptr, parser.previous.start, "init", 4))
            {
                type = FunctionType.TYPE_INITIALIZER;
            }

            function(type);
            emitBytes((byte)OpCode.OP_METHOD, constant);
        }