Ejemplo n.º 1
0
    floor(KurumiScript script, KurumiValueList args)
    {
        KurumiNumber value = (KurumiNumber)args.pop();

        value.number = Math.Floor(value.number);
        args.add(value);
    }
Ejemplo n.º 2
0
    print(KurumiScript script, KurumiValueList args)
    {
        int size = args.size();

        for (int i = 0; i < size; i++)
        {
            KurumiValue v = args.pop();
            Console.WriteLine(v.to_string());
        }
        args.add(new KurumiNull());
    }
Ejemplo n.º 3
0
    public KurumiScript(KurumiStorage storage, KurumiValueList expression)
    {
        int storage_size = storage.size();

        this.storage    = storage;
        this.expression = expression;
        data            = new KurumiReference[storage_size];
        for (int i = 0; i < storage_size; i++)
        {
            data[i] = new KurumiReference(i);
        }
        init_library();
    }
Ejemplo n.º 4
0
    parse(string string_data)
    {
        try {
            expression         = new KurumiValueList();
            goto_storage       = new KurumiGotoStarage();
            value_i            = 0;
            if_statement_count = 0;
            storage            = new KurumiStorage();
            IterableString s = new IterableString(string_data);
            list = s.tokenize();
            generate_code();

            return(new KurumiScript(storage, expression));
        } catch (Exception e) {
            Console.WriteLine("{0}", e.Message);
            return(null);
        }
    }
Ejemplo n.º 5
0
 call(KurumiScript script, KurumiValueList args)
 {
     reference.call(script, args);
 }
Ejemplo n.º 6
0
 call(KurumiScript script, KurumiValueList args)
 {
     throw new Exception("Type cannot be used as a function.");
 }
Ejemplo n.º 7
0
    execute_command(KurumiCommand command)
    {
        //Console.WriteLine("execute_command: {0}", command.command_type.ToString());
        //stack_debug();
        switch (command.command_type)
        {
        case KurumiCommandType.JMPIN: {
            KurumiValue jmpp = expression[vp++];
            KurumiValue expv = value_stack[--sp];
            if (expv.to_bool() == false)
            {
                vp = (int)jmpp.to_number();
            }
            break;
        }

        case KurumiCommandType.JMP: {
            KurumiValue jmpp = expression[vp++];
            vp = (int)jmpp.to_number();
            break;
        }

        case KurumiCommandType.ASSIGN: {
            KurumiValue rexp = value_stack[--sp];
            KurumiValue lexp = value_stack[--sp];
            ((KurumiReference)lexp).reference = rexp.clone();
            break;
        }

        case KurumiCommandType.ADD: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = rexp.add(lexp);
            break;
        }

        case KurumiCommandType.SUB: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp] = lexp.sub(rexp);
            sp++;
            break;
        }

        case KurumiCommandType.MUL: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.mul(rexp);
            break;
        }

        case KurumiCommandType.DIV: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.div(rexp);
            break;
        }

        case KurumiCommandType.EQUAL: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.equal(rexp);
            break;
        }

        case KurumiCommandType.NOTEQ: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.noteq(rexp);
            break;
        }

        case KurumiCommandType.GTHAN: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.gthan(rexp);
            break;
        }

        case KurumiCommandType.LTHAN: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.lthan(rexp);
            break;
        }

        case KurumiCommandType.GOREQ: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.goreq(rexp);
            break;
        }

        case KurumiCommandType.LOREQ: {
            KurumiValue rexp = value_stack[--sp].dereference();
            KurumiValue lexp = value_stack[--sp].dereference();
            value_stack[sp++] = lexp.loreq(rexp);
            break;
        }

        case KurumiCommandType.CALL: {
            KurumiValue     func = value_stack[--sp];
            KurumiValue     retc = expression[vp++];
            KurumiValue     size = expression[vp++];
            int             sz   = (int)size.to_number();
            int             rc   = (int)retc.to_number();
            KurumiValueList args = new KurumiValueList();
            if (sz > 0)
            {
                for (int i = 0; i < sz; i++)
                {
                    args.add(value_stack[--sp].dereference());
                }
            }
            func.call(this, args);
            if (rc > 0)
            {
                value_stack[sp++] = args.top();
            }
            break;
        }

        case KurumiCommandType.REF: {
            KurumiValue refv = expression[vp++];
            value_stack[sp++] = data[(int)refv.to_number()];
            break;
        }
        }
        //Console.WriteLine("after_execute_command");
        //stack_debug();
    }