|
|
| version 1.2, 2001/03/10 11:03:46 | version 1.15, 2001/03/13 17:17:25 |
|---|---|
| Line 1 | Line 1 |
| /* | /* |
| $Id$ | Parser |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | |
| */ | */ |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "_int.h" | #include "_int.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| #include "pa_vint.h" | #include "pa_vint.h" |
| #include "_string.h" | |
| // global var | // global var |
| VClass *int_class; | VStateless_class *int_class; |
| // methods | // methods |
| static void _int(Request& r, Array *) { | static void _int(Request& r, const String&, Array *) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VInt *vint=static_cast<VInt *>(r.self); | VInt *vint=static_cast<VInt *>(r.self); |
| Value& value=*new(pool) VInt(pool, vint->get_int()); | Value& value=*new(pool) VInt(pool, vint->get_int()); |
| r.wcontext->write(value); | r.write_no_lang(value); |
| } | } |
| static void _double(Request& r, Array *) { | static void _double(Request& r, const String&, Array *) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VInt *vint=static_cast<VInt *>(r.self); | VInt *vint=static_cast<VInt *>(r.self); |
| Value& value=*new(pool) VDouble(pool, vint->get_double()); | Value& value=*new(pool) VDouble(pool, vint->get_double()); |
| r.wcontext->write(value); | r.write_no_lang(value); |
| } | } |
| static void _inc(Request& r, Array *params) { | typedef void (*vint_op_func_ptr)(VInt& vint, double param); |
| static void __inc(VInt& vint, double param) { vint.inc((int)param); } | |
| static void __dec(VInt& vint, double param) { vint.inc((int)-param); } | |
| static void __mul(VInt& vint, double param) { vint.mul(param); } | |
| static void __div(VInt& vint, double param) { vint.div(param); } | |
| static void __mod(VInt& vint, double param) { vint.mod((int)param); } | |
| static void vint_op(Request& r, Array *params, | |
| vint_op_func_ptr func) { | |
| VInt *vint=static_cast<VInt *>(r.self); | VInt *vint=static_cast<VInt *>(r.self); |
| int increment=params->size()? | double param=params->size()? |
| static_cast<int>(static_cast<Value *>(params->get(0))->get_double()):1; | r.process( |
| vint->inc(increment); | *static_cast<Value *>(params->get(0)), |
| 0/*no name*/, | |
| false/*don't intercept string*/).get_double():1; | |
| (*func)(*vint, param); | |
| } | } |
| void initialize_int_class(Pool& pool, VClass& vclass) { | static void _inc(Request& r, const String&, Array *params) { vint_op(r, params, &__inc); } |
| // ^int.int[] | static void _dec(Request& r, const String&, Array *params) { vint_op(r, params, &__dec); } |
| String& INT_NAME=*new(pool) String(pool); | static void _mul(Request& r, const String&, Array *params) { vint_op(r, params, &__mul); } |
| INT_NAME.APPEND_CONST("int"); | static void _div(Request& r, const String&, Array *params) { vint_op(r, params, &__div); } |
| static void _mod(Request& r, const String&, Array *params) { vint_op(r, params, &__mod); } | |
| Method& INT_METHOD=*new(pool) Method(pool, | // initialize |
| INT_NAME, | |
| 0, 0, // min,max numbered_params_count | |
| 0/*params_names*/, 0/*locals_names*/, | |
| 0/*parser_code*/, _int | |
| ); | |
| vclass.add_method(INT_NAME, INT_METHOD); | |
| void initialize_int_class(Pool& pool, VStateless_class& vclass) { | |
| // ^int.int[] | // ^int.int[] |
| String& DOUBLE_NAME=*new(pool) String(pool); | vclass.add_native_method("int", _int, 0, 0); |
| DOUBLE_NAME.APPEND_CONST("int"); | |
| Method& DOUBLE_METHOD=*new(pool) Method(pool, | // ^int.double[] |
| DOUBLE_NAME, | vclass.add_native_method("double", _double, 0, 0); |
| 0, 0, // min,max numbered_params_count | |
| 0/*params_names*/, 0/*locals_names*/, | // ^int.inc[] |
| 0/*parser_code*/, _int | // ^int.inc[offset] |
| ); | vclass.add_native_method("inc", _inc, 0, 1); |
| vclass.add_method(DOUBLE_NAME, DOUBLE_METHOD); | // ^int.dec[] |
| // ^int.dec[offset] | |
| // ^int.inc[] ^int.inc[offset] | vclass.add_native_method("dec", _dec, 0, 1); |
| String& INC_NAME=*new(pool) String(pool); | // ^int.mul[k] |
| INC_NAME.APPEND_CONST("inc"); | vclass.add_native_method("mul", _mul, 1, 1); |
| // ^int.div[d] | |
| Method& INC_METHOD=*new(pool) Method(pool, | vclass.add_native_method("div", _div, 1, 1); |
| INC_NAME, | // ^int.mod[offset] |
| 0, 1, // min,max numbered_params_count | vclass.add_native_method("mod", _mod, 1, 1); |
| 0/*params_names*/, 0/*locals_names*/, | |
| 0/*parser_code*/, _inc | |
| ); | |
| vclass.add_method(INC_NAME, INC_METHOD); | |
| } | |
| // ^int.format[] | |
| vclass.add_native_method("format", _string_format, 1, 1); | |
| } |