Skip to content

Commit 19f854b

Browse files
committed
dsl: add cvx operator
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 36abc28 commit 19f854b

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

Tmain/optscript.d/error-undefined-if-if.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ top| |bottom
44
Execution stack:
55
top| a {a} --if-- {true {a} if} --if-- |bottom
66
Dictionary stack:
7-
top| -dict:1- -dict:88- |bottom
7+
top| -dict:1- -dict:89- |bottom

Tmain/optscript.d/error-undefined-if.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ top| |bottom
44
Execution stack:
55
top| a {a} --if-- |bottom
66
Dictionary stack:
7-
top| -dict:1- -dict:88- |bottom
7+
top| -dict:1- -dict:89- |bottom

Tmain/optscript.d/typeattrconv.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ arraytype
3131
(--arraytype--)
3232
(--dicttype--)
3333
(--arraytype--)
34+
3
35+
abc
36+
/abc
37+
true
38+
{}
39+
[]
40+
true

Tmain/optscript.d/typeattrconv.ps

109 Bytes
Binary file not shown.

dsl/optscript.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static EsObject* OPT_KEY_dstack;
153153
*/
154154

155155
static EsObject* array_new (unsigned int attr);
156+
static EsObject* array_shared_new (EsObject* original, unsigned int attr);
156157

157158
static EsObject* array_es_init_fat (void *fat, void *ptr, void *extra);
158159
static void array_es_free (void *ptr, void *fat);
@@ -375,8 +376,8 @@ declop(execstack);
375376
declop(type);
376377
declop(cvn);
377378
declop(cvs);
378-
379-
/* cvlit, cvx, xcheck, executeonly, noacess, readonly,
379+
declop(cvx);
380+
/* cvlit, xcheck, executeonly, noacess, readonly,
380381
rcheck, wcheck, cvi, cvr, cvrs, cvs,... */
381382

382383
/* Operators for Virtual Memory Operators */
@@ -570,6 +571,7 @@ opt_init (void)
570571
defop (opt_system_dict, type, 1, "any TYPE name");
571572
defop (opt_system_dict, cvn, 1, "string CVN name");
572573
defop (opt_system_dict, cvs, 2, "any string CVS string");
574+
defop (opt_system_dict, cvx, 1, "any CVX any");
573575

574576
defop (opt_system_dict, null, 0, "- NULL null");
575577
defop (opt_system_dict, bind, 1, "proc BIND proc");
@@ -1973,6 +1975,14 @@ array_new (unsigned int attr)
19731975
return es_fatptr_new (OPT_TYPE_ARRAY, a, &attr);
19741976
}
19751977

1978+
static EsObject*
1979+
array_shared_new (EsObject* original, unsigned int attr)
1980+
{
1981+
ptrArray *a = es_pointer_get (original);
1982+
ptrArrayRef (a);
1983+
return es_fatptr_new (OPT_TYPE_ARRAY, a, &attr);
1984+
}
1985+
19761986
static EsObject*
19771987
array_es_init_fat (void *fat, void *ptr, void *extra)
19781988
{
@@ -1991,9 +2001,6 @@ array_es_free (void *ptr, void *fat)
19912001
static int
19922002
array_es_equal (const void *a, const void *afat, const void *b, const void *bfat)
19932003
{
1994-
if (((ArrayFat *)afat)->attr != ((ArrayFat *)bfat)->attr)
1995-
return 0;
1996-
19972004
if (ptrArrayIsEmpty ((ptrArray *)a) && ptrArrayIsEmpty ((ptrArray*)b))
19982005
return 1;
19992006
else if (a == b)
@@ -3931,6 +3938,34 @@ op_cvs (OptVM *vm, EsObject *name)
39313938
return es_false;
39323939
}
39333940

3941+
static EsObject*
3942+
op_cvx (OptVM *vm, EsObject *name)
3943+
{
3944+
EsObject *o = ptrArrayLast (vm->ostack);
3945+
3946+
if (es_object_get_type (o) == OPT_TYPE_ARRAY
3947+
&& (! (((ArrayFat *)es_fatptr_get (o))->attr & ATTR_EXECUTABLE)))
3948+
{
3949+
EsObject *xarray = array_shared_new (o,
3950+
((ArrayFat *)es_fatptr_get (o))->attr | ATTR_EXECUTABLE);
3951+
ptrArrayDeleteLast (vm->ostack);
3952+
vm_ostack_push (vm, xarray);
3953+
es_object_unref(xarray);
3954+
3955+
}
3956+
else if (es_object_get_type (o) == OPT_TYPE_NAME
3957+
&& (! (((NameFat *)es_fatptr_get (o))->attr & ATTR_EXECUTABLE)))
3958+
{
3959+
EsObject *symbol = es_pointer_get (o);
3960+
EsObject *xname = name_new (symbol, ((NameFat *)es_fatptr_get (o))->attr | ATTR_EXECUTABLE);
3961+
ptrArrayDeleteLast (vm->ostack);
3962+
vm_ostack_push (vm, xname);
3963+
es_object_unref(xname);
3964+
}
3965+
3966+
return es_false;
3967+
}
3968+
39343969

39353970
/*
39363971
* Misc operators

0 commit comments

Comments
 (0)