Permalink
Browse files

binding as semantic act

  • Loading branch information...
1 parent 5a9cc21 commit d3d664c2f4ba0582b8bc84ac9804789e90b10c02 @neleai committed May 12, 2012
Showing with 17 additions and 26 deletions.
  1. +0 −1 regreg/representation.c
  2. +11 −2 regreg/ruby_wrapper.c
  3. +1 −1 regreg/ruby_wrapper.rc
  4. +1 −12 regreg/stackmachine.c
  5. +2 −2 regreg/stackmachine.h
  6. +1 −7 regreg/stackmachine.rc
  7. +1 −1 regreg/types.rb
View
@@ -304,7 +304,6 @@ void inspect_exp(exp *e) {
exp_act *e2=(exp_act *)e;
fprintf(debug,"act[");
fprintf(debug," varc: %i",e2->varc);
- fprintf(debug," arg: %s",e2->arg);
fprintf(debug,"]");
break;
}
View
@@ -91,7 +91,16 @@ exp * trans(VALUE exp2) {
e.arg=trans(rb_iv_get(exp2,"@arg"));
return normalize_act(&e);
}
-// else if (typetest(exp2,"Rbind")) { exp_act e; e.tp=TP_act; e.varc=1;e.vars=malloc(sizeof(long));e.vars[0]=trans(rb_iv_get(exp2,"@var")); e.fn=bind_callback; e.arg=e.vars[0]; return normalize_act(&e);}
+ else if (typetest(exp2,"Rbind")) {
+ exp_act e;
+ e.tp=TP_act;
+ e.varc=1;
+ e.vars=malloc(sizeof(long));
+ e.vars[0]=trans(rb_iv_get(exp2,"@var"));
+ e.fn=bind_callback;
+ e.arg=e.vars[0];
+ return normalize_act(&e);
+ }
else if (typetest(exp2,"Rseq")) {
exp_seq e;
e.tp=TP_seq;
@@ -137,7 +146,7 @@ exp * trans(VALUE exp2) {
e.varc=(long) trans(rb_iv_get(exp2,"@varc"));
e.vars=(long *) trans(rb_iv_get(exp2,"@vars"));
e.fn=(void *) trans(rb_iv_get(exp2,"@fn"));
- e.arg=(char *) trans(rb_iv_get(exp2,"@arg"));
+ e.arg=(void *) trans(rb_iv_get(exp2,"@arg"));
return (exp *) normalize_act(&e);
}
else if (typetest(exp2,"Rmake_lambda")) {
View
@@ -57,7 +57,7 @@ exp * trans(VALUE exp2){int i;
else if (typetest(exp2,"Rcall" )) { char *name=(char *)trans(rb_iv_get(exp2,"@name")); exp_call e;e.tp=TP_call; e.name=name; e.body=getrule(name)->body; e.argc=trans(rb_iv_get(exp2,"@argc")); e.afrom=trans(rb_iv_get(exp2,"@afrom")); return (exp *) normalize_call(&e);}
else if (typetest(exp2,"Rrule" )) { char *name=(char *)trans(rb_iv_get(exp2,"@name")); exp *body=trans(rb_iv_get(exp2,"@body")); rule *r=getrule(name); r->body->locals=(long)trans(rb_iv_get(exp2,"@locals")); r->body->body=body; return (exp*)r->body;}
else if (typetest(exp2,"Ract" )) { exp_act e; e.tp=TP_act; e.varc=trans(rb_iv_get(exp2,"@varc")); e.vars=trans(rb_iv_get(exp2,"@vars")); e.fn=callback; e.arg=trans(rb_iv_get(exp2,"@arg")); return normalize_act(&e);}
-// else if (typetest(exp2,"Rbind")) { exp_act e; e.tp=TP_act; e.varc=1;e.vars=malloc(sizeof(long));e.vars[0]=trans(rb_iv_get(exp2,"@var")); e.fn=bind_callback; e.arg=e.vars[0]; return normalize_act(&e);}
+ else if (typetest(exp2,"Rbind")) { exp_act e; e.tp=TP_act; e.varc=1;e.vars=malloc(sizeof(long));e.vars[0]=trans(rb_iv_get(exp2,"@var")); e.fn=bind_callback; e.arg=e.vars[0]; return normalize_act(&e);}
<%=
$nodes.map{|n,a| "else if (typetest(exp2,\"R#{n}\")){
exp_#{n} e; e.tp=TP_#{n};
View
@@ -46,7 +46,7 @@ exp *make_nested(exp* body) {
return (exp *) e;
}
-exp *make_act(long varc,long * vars,void * fn,char * arg) {
+exp *make_act(long varc,long * vars,void * fn,void * arg) {
exp_act *e=malloc(sizeof(exp_act));
e->tp=TP_act;
e->varc=varc;
@@ -372,17 +372,6 @@ void *match(exp* e,void *extra,Args a) {
fprintf(debug,"\n");
- fprintf(debug,"saving %i %i\n",a.closure[e->var],e->var);
- *(void **)stack_match=a.closure[e->var];
- stack_match+=sizeof(void *);
- *(long *)stack_match =e->var;
- stack_match+=sizeof(long);
- *stack_match=bind_restore;
- stack_match+=1;
- a.closure[e->var]=r.returned;
- memcpy(stack_match,a.cont,st_siz);
- stack_match+=st_siz;
- a.cont=a.cont->previous;
break;
}
View
@@ -122,10 +122,10 @@ typedef struct {
long varc;
long * vars;
void * fn;
- char * arg;
+ void * arg;
} exp_act;
exp_act* normalize_act(exp_act*o);
-exp *make_act(long varc,long * vars,void * fn,char * arg);
+exp *make_act(long varc,long * vars,void * fn,void * arg);
typedef struct {
char tp;
exp* body;
View
@@ -121,13 +121,7 @@ void *match(exp* e,void *extra,Args a){
#{push_exp("e->to")}
")+
ecase("bind","
- fprintf(debug,\"saving %i %i\\n\",a.closure[e->var],e->var);
- *(void **)stack_match=a.closure[e->var];stack_match+=sizeof(void *);
- *(long *)stack_match =e->var; stack_match+=sizeof(long);
- *stack_match=bind_restore; stack_match+=1;
- a.closure[e->var]=r.returned;
- #{cont_call()}
- ")+
+ ")+
ecase("many","
if (e->stops & a.stops){
#{set("a.stops")}=a.stops&(~e->stops);
View
@@ -7,7 +7,7 @@ def cnst(*names); names.map{|name|"#define #{name} #{$nums+=1}\n"}*"";end
["stop",[["long","stops"]]],
["bind",[["long","var"]]],
["nested",[["exp*","body"]]],
- ["act",[["long","varc"],["long *","vars"],["void *","fn"],["char *","arg"]]],
+ ["act",[["long","varc"],["long *","vars"],["void *","fn"],["void *","arg"]]],
["make_lambda",[["exp*","body"]]],
["use_lambda",[["long" ,"placeholder"]]],
["return",[["long","state"]]],

0 comments on commit d3d664c

Please sign in to comment.