floor(KurumiScript script, KurumiValueList args) { KurumiNumber value = (KurumiNumber)args.pop(); value.number = Math.Floor(value.number); args.add(value); }
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()); }
keyword_expression(KurumiKeyword keyword) { switch (keyword) { case KurumiKeyword.IF: KurumiNumber stop_p = new KurumiNumber(-1); if_statement(stop_p); break; case KurumiKeyword.ELSE: case KurumiKeyword.ELIF: if (if_statement_count <= 0) { throw new Exception("Keyword 'else' or 'elif' without if statement."); } break; case KurumiKeyword.GOTO: next(); KurumiToken current = get_current_token(); expression.add(new KurumiCommand(KurumiCommandType.JMP)); expression.add(goto_storage.get(current.data)); next(); break; default: break; } }
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(); }