diff options
author | Teddy <[email protected]> | 2013-08-12 15:00:17 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-12 15:00:17 +0800 |
commit | b525cc4808cbbe68132e5941187030d3dd38abc2 (patch) | |
tree | e90d3e160657b33e11606813cbb84ec181f1f845 | |
parent | 4e933956abb5045efaad4b68decce1ca4bd43700 (diff) |
Removed uncessary `new UnspecObj()`, use a global pointer instead.
-rw-r--r-- | builtin.cpp | 19 | ||||
-rw-r--r-- | main.cpp | 5 | ||||
-rw-r--r-- | types.cpp | 1 |
3 files changed, 14 insertions, 11 deletions
diff --git a/builtin.cpp b/builtin.cpp index 1096d7a..760aa2a 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -9,8 +9,9 @@ #include "types.h" using std::stringstream; -extern EmptyList *empty_list; +extern EmptyList *empty_list; +extern UnspecObj *unspec_obj; SpecialOptIf::SpecialOptIf() : SpecialOptObj("if") {} @@ -72,7 +73,7 @@ Pair *SpecialOptIf::call(Pair *args, Environment * &envt, } else { - *top_ptr++ = new UnspecObj(); + *top_ptr++ = unspec_obj; return ret_addr->next; } } @@ -232,7 +233,7 @@ Pair *SpecialOptDefine::call(Pair *args, Environment * &envt, obj = new ProcObj(body, envt, params); } envt->add_binding(id, obj); - *top_ptr++ = new UnspecObj(); + *top_ptr++ = unspec_obj; return ret_addr->next; } @@ -276,7 +277,7 @@ Pair *SpecialOptSet::call(Pair *args, Environment * &envt, bool flag = envt->add_binding(id, TO_PAIR(args->cdr)->car, false); if (!flag) throw TokenError(id->ext_repr(), RUN_ERR_UNBOUND_VAR); - *top_ptr++ = new UnspecObj(); + *top_ptr++ = unspec_obj; return ret_addr->next; } @@ -804,7 +805,7 @@ BUILTIN_PROC_DEF(pair_set_car) { if (!args->car->is_pair_obj()) throw TokenError("pair", RUN_ERR_WRONG_TYPE); TO_PAIR(args->car)->car = TO_PAIR(args->cdr)->car; - return new UnspecObj(); + return unspec_obj; } BUILTIN_PROC_DEF(pair_set_cdr) { @@ -812,7 +813,7 @@ BUILTIN_PROC_DEF(pair_set_cdr) { if (!args->car->is_pair_obj()) throw TokenError("pair", RUN_ERR_WRONG_TYPE); TO_PAIR(args->car)->cdr = TO_PAIR(args->cdr)->car; - return new UnspecObj(); + return unspec_obj; } BUILTIN_PROC_DEF(is_null) { @@ -1282,7 +1283,7 @@ BUILTIN_PROC_DEF(make_vector) { args = TO_PAIR(args->cdr); if (args == empty_list) - fill = new UnspecObj(); + fill = unspec_obj; else if (args->cdr == empty_list) fill = args->car; else @@ -1317,7 +1318,7 @@ BUILTIN_PROC_DEF(vector_set) { throw TokenError(name, RUN_ERR_WRONG_NUM_OF_ARGS); vect->set(k, args->car); - return new UnspecObj(); + return unspec_obj; } BUILTIN_PROC_DEF(vector_ref) { @@ -1356,5 +1357,5 @@ BUILTIN_PROC_DEF(vector_length) { BUILTIN_PROC_DEF(display) { ARGS_EXACTLY_ONE; printf("%s", args->car->ext_repr().c_str()); - return new UnspecObj(); + return unspec_obj; } @@ -42,7 +42,7 @@ void print_help(const char *cmd) { " FILE \t\tload Scheme source code from FILE, and exit\n" "The above switches stop argument processing\n\n" " -l FILE \tload Scheme source code from FILE\n" - " -h display \tthis help and exit\n", cmd); + " -h, --help \tdisplay this help and exit\n", cmd); exit(0); } @@ -62,7 +62,8 @@ int main(int argc, char **argv) { print_help(*argv); } } - else if (strcmp(argv[i], "-h") == 0) + else if (strcmp(argv[i], "-h") == 0 || + strcmp(argv[i], "--help") == 0) print_help(*argv); else { @@ -12,6 +12,7 @@ const double EPS = 1e-16; const int PREC = 16; EmptyList *empty_list = new EmptyList(); +UnspecObj *unspec_obj = new UnspecObj(); Pair::Pair(EvalObj *_car, EvalObj *_cdr) : EvalObj(CLS_PAIR_OBJ), car(_car), cdr(_cdr), |