• R/O
  • SSH
  • HTTPS

descartes: Commit


Commit MetaInfo

Revision1632 (tree)
Time2012-11-01 22:20:08
Authorhniwa

Log Message

Processing sharing of sysmodule parameter

Change Summary

Incremental Difference

--- trunk/descartes/sysmodule.c (revision 1631)
+++ trunk/descartes/sysmodule.c (revision 1632)
@@ -421,6 +421,42 @@
421421 return 1;
422422 }
423423
424+int Parm3(Context* cx, Node* goalscar, List* module, const char* msg1,
425+ const char* msg2, Node* &parm1, Node* &parm2, Node* &parm3)
426+{
427+ Node* g = goalscar->Cdr();
428+ if (ListLength(g) != 3) {
429+ syserr(msg1);
430+ return 0;
431+ }
432+
433+ parm1 = g->Car()->Val();
434+ int rn;
435+
436+ if ((rn = FuncArg(cx, parm1, goalscar, module)) <= 0) {
437+ syserr(msg2);
438+ return 0;
439+ }
440+
441+ g = g->Cdr();
442+ parm2 = g->Car()->Val();
443+
444+ if ((rn = FuncArg(cx, parm2, goalscar, module)) <= 0) {
445+ syserr(msg2);
446+ return 0;
447+ }
448+
449+ g = g->Cdr();
450+ parm3 = g->Car()->Val();
451+
452+ if ((rn = FuncArg(cx, parm3, goalscar, module)) <= 0) {
453+ syserr(msg2);
454+ return 0;
455+ }
456+
457+ return 1;
458+}
459+
424460 int sysmodule(Context* cx, Node* goalscar, Node* goalscdr,
425461 Node* goals, List* module, int& r)
426462 {
@@ -3815,49 +3851,33 @@
38153851 {
38163852 Node* env;
38173853
3818- if (ListLength(goalscar->Cdr()) != 3) {
3819- syserr("usage : <leftstr VAR STRING NUM>\n");
3820- return 0;
3854+ Node* nvar = Nil;
3855+ Node* nstr = Nil;
3856+ Node* nn = Nil;
3857+ if (!Parm3(cx, goalscar, module, "usage : <leftstr VAR STRING NUM>\n",
3858+ "leftstr: failed in the evaluation of the argument. \n",
3859+ nvar, nstr, nn)) {
3860+ return 0;
38213861 }
38223862
3823- Node* nvar = goalscar->Cdr()->Car()->Val();
3824- Node* nstr = goalscar->Cdr()->Cdr()->Car()->Val();
3825- Node* nn = goalscar->Cdr()->Cdr()->Cdr()->Car()->Val();
3826-
3827- int rn;
3828-
3829- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
3830- syserr("leftstr: failed in the evaluation of the argument. \n");
3831- return 0;
3832- }
3833-
38343863 if (nvar->kind() != UNDEF) {
38353864 syserr("usage : <leftstr VAR STRING NUM>\n");
38363865 return 0;
38373866 }
38383867
3839- if ((rn = FuncArg(cx, nstr, goalscar, module)) <= 0) {
3840- syserr("leftstr: failed in the evaluation of the argument. \n");
3868+ if (nstr->kind() != ATOM) {
3869+ syserr("usage : <leftstr VAR STRING NUM>\n");
38413870 return 0;
38423871 }
38433872
3844-
3845- if (nstr->kind() != ATOM) {
3873+ if (nn->kind() != ATOM) {
38463874 syserr("usage : <leftstr VAR STRING NUM>\n");
38473875 return 0;
38483876 }
3877+
38493878 std::string s;
38503879 ((Atom*)nstr)->toString(s);
38513880
3852- if ((rn = FuncArg(cx, nn, goalscar, module)) <= 0) {
3853- syserr("leftstr: failed in the evaluation of the argument. \n");
3854- return 0;
3855- }
3856-
3857- if (nn->kind() != ATOM) {
3858- syserr("usage : <leftstr VAR STRING NUM>\n");
3859- return 0;
3860- }
38613881 long long n;
38623882 if (!((Atom*)nn)->toInt(n)) {
38633883 syserr("usage : <leftstr VAR STRING NUM>\n");
@@ -3900,48 +3920,33 @@
39003920 {
39013921 Node* env;
39023922
3903- if (ListLength(goalscar->Cdr()) != 3) {
3904- syserr("usage : <rightstr VAR STRING NUM>\n");
3905- return 0;
3923+ Node* nvar = Nil;
3924+ Node* nstr = Nil;
3925+ Node* nn = Nil;
3926+ if (!Parm3(cx, goalscar, module, "usage : <rightstr VAR STRING NUM>\n",
3927+ "rightstr: failed in the evaluation of the argument. \n",
3928+ nvar, nstr, nn)) {
3929+ return 0;
39063930 }
39073931
3908- Node* nvar = goalscar->Cdr()->Car()->Val();
3909- Node* nstr = goalscar->Cdr()->Cdr()->Car()->Val();
3910- Node* nn = goalscar->Cdr()->Cdr()->Cdr()->Car()->Val();
3911-
3912- int rn;
3913-
3914- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
3915- syserr("rightstr: failed in the evaluation of the argument. \n");
3916- return 0;
3917- }
3918-
39193932 if (nvar->kind() != UNDEF) {
39203933 syserr("usage : <rightstr VAR STRING NUM>\n");
39213934 return 0;
39223935 }
39233936
3924- if ((rn = FuncArg(cx, nstr, goalscar, module)) <= 0) {
3925- syserr("rightstr: failed in the evaluation of the argument. \n");
3926- return 0;
3927- }
3928-
39293937 if (nstr->kind() != ATOM) {
39303938 syserr("usage : <rightstr VAR STRING NUM>\n");
39313939 return 0;
39323940 }
3933- std::string s;
3934- ((Atom*)nstr)->toString(s);
39353941
3936- if ((rn = FuncArg(cx, nn, goalscar, module)) <= 0) {
3937- syserr("rightstr: failed in the evaluation of the argument. \n");
3938- return 0;
3939- }
3940-
39413942 if (nn->kind() != ATOM) {
39423943 syserr("usage : <rightstr VAR STRING NUM>\n");
39433944 return 0;
39443945 }
3946+
3947+ std::string s;
3948+ ((Atom*)nstr)->toString(s);
3949+
39453950 long long n;
39463951 if (!((Atom*)nn)->toInt(n)) {
39473952 syserr("usage : <rightstr VAR STRING NUM>\n");
@@ -4491,50 +4496,32 @@
44914496
44924497 int And(Context* cx, Node* goalscar, List* module)
44934498 {
4494- if (ListLength(goalscar->Cdr()) != 3) {
4495- syserr("usage : <bitand VAR NUM1 NUM2>\n");
4496- return 0;
4499+ Node* nvar = Nil;
4500+ Node* n1 = Nil;
4501+ Node* n2 = Nil;
4502+ if (!Parm3(cx, goalscar, module, "usage : <bitand VAR NUM1 NUM2>\n",
4503+ "bitand: failed in the evaluation of the argument. \n",
4504+ nvar, n1, n2)) {
4505+ return 0;
44974506 }
44984507
4499- Node* g = goalscar->Cdr()->Val();
4500- Node* nvar = g->Car()->Val();
4501- Node* n1 = g->Cdr()->Car()->Val();
4502- Node* n2 = g->Cdr()->Cdr()->Car()->Val();
4503- long long nn1, nn2;
4504-
4505- int rn;
4506-
4507- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
4508- syserr("bitand: failed in the evaluation of the argument. \n");
4509- return 0;
4510- }
4511-
45124508 if (nvar->kind() != UNDEF) {
45134509 syserr("usage : <bitand VAR NUM1 NUM2>\n");
45144510 return 0;
45154511 }
45164512
4517- if ((rn = FuncArg(cx, n1, goalscar, module)) <= 0) {
4518- syserr("bitand: failed in the evaluation of the argument. \n");
4519- return 0;
4520- }
4521-
45224513 if (n1->kind() != ATOM) {
45234514 syserr("usage : <bitand VAR NUM1 NUM2>\n");
45244515 return 0;
45254516 }
45264517
4527- if (!((Atom*)n1)->toInt(nn1)) {
4518+ if (n2->kind() != ATOM) {
45284519 syserr("usage : <bitand VAR NUM1 NUM2>\n");
45294520 return 0;
45304521 }
45314522
4532- if ((rn = FuncArg(cx, n2, goalscar, module)) <= 0) {
4533- syserr("bitand: failed in the evaluation of the argument. \n");
4534- return 0;
4535- }
4536-
4537- if (n2->kind() != ATOM) {
4523+ long long nn1, nn2;
4524+ if (!((Atom*)n1)->toInt(nn1)) {
45384525 syserr("usage : <bitand VAR NUM1 NUM2>\n");
45394526 return 0;
45404527 }
@@ -4546,14 +4533,7 @@
45464533
45474534 Node* env = Nil->Cons(Nil);
45484535
4549- long long nn3;
4550- if (nn1 != 1) {
4551- nn3 = -1;
4552- } else if (nn2 != 1) {
4553- nn3 = -1;
4554- } else {
4555- nn3 = 1;
4556- }
4536+ long long nn3 = nn1 & nn2;
45574537
45584538 SetEnv(env, nvar);
45594539 ((Undef*)nvar)->Set(mka(nn3));
@@ -4565,50 +4545,32 @@
45654545
45664546 int Or(Context* cx, Node* goalscar, List* module)
45674547 {
4568- if (ListLength(goalscar->Cdr()) != 3) {
4569- syserr("usage : <bitor VAR NUM1 NUM2>\n");
4570- return 0;
4548+ Node* nvar = Nil;
4549+ Node* n1 = Nil;
4550+ Node* n2 = Nil;
4551+ if (!Parm3(cx, goalscar, module, "usage : <bitor VAR NUM1 NUM2>\n",
4552+ "bitor: failed in the evaluation of the argument. \n",
4553+ nvar, n1, n2)) {
4554+ return 0;
45714555 }
45724556
4573- Node* g = goalscar->Cdr()->Val();
4574- Node* nvar = g->Car()->Val();
4575- Node* n1 = g->Cdr()->Car()->Val();
4576- Node* n2 = g->Cdr()->Cdr()->Car()->Val();
4577- long long nn1, nn2;
4578- int rn;
4579-
4580- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
4581- syserr("bitor: failed in the evaluation of the argument. \n");
4582- return 0;
4583- }
4584-
45854557 if (nvar->kind() != UNDEF) {
45864558 syserr("usage : <bitor VAR NUM1 NUM2>\n");
45874559 return 0;
45884560 }
45894561
4590-
4591- if ((rn = FuncArg(cx, n1, goalscar, module)) <= 0) {
4592- syserr("bitor: failed in the evaluation of the argument. \n");
4593- return 0;
4594- }
4595-
45964562 if (n1->kind() != ATOM) {
45974563 syserr("usage : <bitor VAR NUM1 NUM2>\n");
45984564 return 0;
45994565 }
46004566
4601- if (!((Atom*)n1)->toInt(nn1)) {
4567+ if (n2->kind() != ATOM) {
46024568 syserr("usage : <bitor VAR NUM1 NUM2>\n");
46034569 return 0;
46044570 }
46054571
4606- if ((rn = FuncArg(cx, n2, goalscar, module)) <= 0) {
4607- syserr("bitor: failed in the evaluation of the argument. \n");
4608- return 0;
4609- }
4610-
4611- if (n2->kind() != ATOM) {
4572+ long long nn1, nn2;
4573+ if (!((Atom*)n1)->toInt(nn1)) {
46124574 syserr("usage : <bitor VAR NUM1 NUM2>\n");
46134575 return 0;
46144576 }
@@ -4618,14 +4580,7 @@
46184580 return 0;
46194581 }
46204582
4621- long long nn3;
4622- if (nn1 == 1) {
4623- nn3 = 1;
4624- } else if (nn2 == 1) {
4625- nn3 = 1;
4626- } else {
4627- nn3 = -1;
4628- }
4583+ long long nn3 = nn1 | nn2;
46294584
46304585 Node* env = Nil->Cons(Nil);
46314586
@@ -4639,50 +4594,32 @@
46394594
46404595 int Xor(Context* cx, Node* goalscar, List* module)
46414596 {
4642- if (ListLength(goalscar->Cdr()) != 3) {
4643- syserr("usage : <bitxor VAR NUM1 NUM2>\n");
4644- return 0;
4597+ Node* nvar = Nil;
4598+ Node* n1 = Nil;
4599+ Node* n2 = Nil;
4600+ if (!Parm3(cx, goalscar, module, "usage : <bitxor VAR NUM1 NUM2>\n",
4601+ "bitxor: failed in the evaluation of the argument. \n",
4602+ nvar, n1, n2)) {
4603+ return 0;
46454604 }
46464605
4647- Node* g = goalscar->Cdr()->Val();
4648- Node* nvar = g->Car()->Val();
4649- Node* n1 = g->Cdr()->Car()->Val();
4650- Node* n2 = g->Cdr()->Cdr()->Car()->Val();
4651- long long nn1, nn2, nn3;
4652-
4653- int rn;
4654-
4655- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
4656- syserr("bitxor: failed in the evaluation of the argument. \n");
4657- return 0;
4658- }
4659-
46604606 if (nvar->kind() != UNDEF) {
46614607 syserr("usage : <bitxor VAR NUM1 NUM2>\n");
46624608 return 0;
46634609 }
46644610
4665- if ((rn = FuncArg(cx, n1, goalscar, module)) <= 0) {
4666- syserr("bitxor: failed in the evaluation of the argument. \n");
4667- return 0;
4668- }
4669-
46704611 if (n1->kind() != ATOM) {
46714612 syserr("usage : <bitxor VAR NUM1 NUM2>\n");
46724613 return 0;
46734614 }
46744615
4675- if (!((Atom*)n1)->toInt(nn1)) {
4616+ if (n2->kind() != ATOM) {
46764617 syserr("usage : <bitxor VAR NUM1 NUM2>\n");
46774618 return 0;
46784619 }
46794620
4680- if ((rn = FuncArg(cx, n2, goalscar, module)) <= 0) {
4681- syserr("bitxor: failed in the evaluation of the argument. \n");
4682- return 0;
4683- }
4684-
4685- if (n2->kind() != ATOM) {
4621+ long long nn1, nn2;
4622+ if (!((Atom*)n1)->toInt(nn1)) {
46864623 syserr("usage : <bitxor VAR NUM1 NUM2>\n");
46874624 return 0;
46884625 }
@@ -4692,15 +4629,7 @@
46924629 return 0;
46934630 }
46944631
4695- if ((nn1 == 1) && (nn2 == 1)){
4696- nn3 = -1;
4697- } else if (nn1 == 1) {
4698- nn3 = 1;
4699- } else if (nn2 == 1) {
4700- nn3 = 1;
4701- } else {
4702- nn3 = -1;
4703- }
4632+ long long nn3 = nn1 ^ nn2;
47044633
47054634 Node* env = Nil->Cons(Nil);
47064635
@@ -4751,50 +4680,32 @@
47514680
47524681 int ShiftL(Context* cx, Node* goalscar, List* module)
47534682 {
4754- if (ListLength(goalscar->Cdr()) != 3) {
4755- syserr("usage : <shiftl VAR NUM SHIFT>\n");
4756- return 0;
4683+ Node* nvar = Nil;
4684+ Node* n1 = Nil;
4685+ Node* nsft = Nil;
4686+ if (!Parm3(cx, goalscar, module, "usage : <shiftl VAR NUM SHIFT>\n",
4687+ "shiftl: failed in the evaluation of the argument. \n",
4688+ nvar, n1, nsft)) {
4689+ return 0;
47574690 }
47584691
4759- Node* g = goalscar->Cdr()->Val();
4760- Node* nvar = g->Car()->Val();
4761- Node* n1 = g->Cdr()->Car()->Val();
4762- Node* nsft = g->Cdr()->Cdr()->Car()->Val();
4763- long long nn1, nnsft;
4764-
4765- int rn;
4766-
4767- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
4768- syserr("shiftl: failed in the evaluation of the argument. \n");
4769- return 0;
4770- }
4771-
47724692 if (nvar->kind() != UNDEF) {
47734693 syserr("usage : <shiftl VAR NUM SHIFT>\n");
47744694 return 0;
47754695 }
47764696
4777- if ((rn = FuncArg(cx, n1, goalscar, module)) <= 0) {
4778- syserr("shiftl: failed in the evaluation of the argument. \n");
4779- return 0;
4780- }
4781-
47824697 if (n1->kind() != ATOM) {
47834698 syserr("usage : <shiftl VAR NUM SHIFT>\n");
47844699 return 0;
47854700 }
47864701
4787- if (!((Atom*)n1)->toInt(nn1)) {
4702+ if (nsft->kind() != ATOM) {
47884703 syserr("usage : <shiftl VAR NUM SHIFT>\n");
47894704 return 0;
47904705 }
47914706
4792- if ((rn = FuncArg(cx, nsft, goalscar, module)) <= 0) {
4793- syserr("shiftl: failed in the evaluation of the argument. \n");
4794- return 0;
4795- }
4796-
4797- if (nsft->kind() != ATOM) {
4707+ long long nn1, nnsft;
4708+ if (!((Atom*)n1)->toInt(nn1)) {
47984709 syserr("usage : <shiftl VAR NUM SHIFT>\n");
47994710 return 0;
48004711 }
@@ -4815,50 +4726,32 @@
48154726
48164727 int ShiftR(Context* cx, Node* goalscar, List* module)
48174728 {
4818- if (ListLength(goalscar->Cdr()) != 3) {
4819- syserr("usage : <shiftr VAR NUM SHIFT>\n");
4820- return 0;
4729+ Node* nvar = Nil;
4730+ Node* n1 = Nil;
4731+ Node* nsft = Nil;
4732+ if (!Parm3(cx, goalscar, module, "usage : <shiftr VAR NUM SHIFT>\n",
4733+ "shiftr: failed in the evaluation of the argument. \n",
4734+ nvar, n1, nsft)) {
4735+ return 0;
48214736 }
48224737
4823- Node* g = goalscar->Cdr()->Val();
4824- Node* nvar = g->Car()->Val();
4825- Node* n1 = g->Cdr()->Car()->Val();
4826- Node* nsft = g->Cdr()->Cdr()->Car()->Val();
4827- long long nn1, nnsft;
4828- int rn;
4829-
4830- if ((rn = FuncArg(cx, nvar, goalscar, module)) <= 0) {
4831- syserr("shiftr: failed in the evaluation of the argument. \n");
4832- return 0;
4833- }
4834-
4835-
48364738 if (nvar->kind() != UNDEF) {
48374739 syserr("usage : <shiftr VAR NUM SHIFT>\n");
48384740 return 0;
48394741 }
48404742
4841- if ((rn = FuncArg(cx, n1, goalscar, module)) <= 0) {
4842- syserr("shiftr: failed in the evaluation of the argument. \n");
4843- return 0;
4844- }
4845-
48464743 if (n1->kind() != ATOM) {
48474744 syserr("usage : <shiftr VAR NUM SHIFT>\n");
48484745 return 0;
48494746 }
48504747
4851- if (!((Atom*)n1)->toInt(nn1)) {
4748+ if (nsft->kind() != ATOM) {
48524749 syserr("usage : <shiftr VAR NUM SHIFT>\n");
48534750 return 0;
48544751 }
48554752
4856- if ((rn = FuncArg(cx, nsft, goalscar, module)) <= 0) {
4857- syserr("shiftr: failed in the evaluation of the argument. \n");
4858- return 0;
4859- }
4860-
4861- if (nsft->kind() != ATOM) {
4753+ long long nn1, nnsft;
4754+ if (!((Atom*)n1)->toInt(nn1)) {
48624755 syserr("usage : <shiftr VAR NUM SHIFT>\n");
48634756 return 0;
48644757 }
Show on old repository browser