* core: retrieve the ast for a closure using `cl code tree`. still need to work...
author_why <why@whytheluckystiff.net>
Tue, 30 Jun 2009 16:39:20 +0000 (09:39 -0700)
committer_why <why@whytheluckystiff.net>
Tue, 30 Jun 2009 16:39:20 +0000 (09:39 -0700)
core/compile.c
core/objmodel.c
core/potion.h

index ef2264e5e932415ad2d6c8b94f04f68d9f5deaea..6c75098ab870c2840a7a77b06f89335fe9105e42 100644 (file)
@@ -31,6 +31,10 @@ const struct {
   {"tailcall", 2}, {"return", 1}, {"proto", 2}, {"class", 2}
 };
 
+PN potion_proto_tree(Potion *P, PN cl, PN self) {
+  return PN_PROTO(self)->tree;
+}
+
 PN potion_proto_call(Potion *P, PN cl, PN self, PN args) {
   return potion_vm(P, self, P->lobby, args, 0, NULL);
 }
@@ -666,6 +670,7 @@ PN potion_source_compile(Potion *P, PN cl, PN self, PN source, PN sig) {
   f->locals = PN_TUP0();
   f->upvals = PN_TUP0();
   f->values = PN_TUP0();
+  f->tree = self;
   f->sig = (sig == PN_NIL ? PN_TUP0() : potion_sig_compile(P, f, sig));
   f->asmb = (PN)potion_asm_new(P);
 
@@ -839,5 +844,6 @@ PN potion_eval(Potion *P, const char *str) {
 void potion_compiler_init(Potion *P) {
   PN pro_vt = PN_VTABLE(PN_TPROTO);
   potion_method(pro_vt, "call", potion_proto_call, 0);
+  potion_method(pro_vt, "tree", potion_proto_tree, 0);
   potion_method(pro_vt, "string", potion_proto_string, 0);
 }
index 3e645f8c6b8a322864df567b87887b556144c1a4..4bbfe2378d7185a98bc155a8a8c43b84a43da251 100644 (file)
@@ -25,6 +25,12 @@ PN potion_closure_new(Potion *P, PN_F meth, PN sig, PN_SIZE extra) {
   return (PN)c;
 }
 
+PN potion_closure_code(Potion *P, PN cl, PN self) {
+  if (PN_CLOSURE(self)->extra > 0 && PN_IS_PROTO(PN_CLOSURE(self)->data[0])) 
+    return PN_CLOSURE(self)->data[0];
+  return PN_NIL;
+}
+
 PN potion_closure_string(Potion *P, PN cl, PN self, PN len) {
   int x = 0;
   PN out = potion_byte_str(P, "Function(");
@@ -299,6 +305,7 @@ void potion_object_init(Potion *P) {
   PN clo_vt = PN_VTABLE(PN_TCLOSURE);
   PN ref_vt = PN_VTABLE(PN_TWEAK);
   PN obj_vt = PN_VTABLE(PN_TOBJECT);
+  potion_method(clo_vt, "code", potion_closure_code, 0);
   potion_method(clo_vt, "string", potion_closure_string, 0);
   potion_method(ref_vt, "string", potion_ref_string, 0);
   potion_method(obj_vt, "forward", potion_object_forward, 0);
index ec97040ca0927eb12a544532fd38a3cb8aaf2b8b..9d78ce8958553b974eee34899fed3e578c365117 100644 (file)
@@ -266,6 +266,7 @@ struct PNProto {
   PN upvals; // variables in upper scopes
   PN values; // numbers, strings, etc.
   PN protos; // nested closures
+  PN tree; // abstract syntax tree
   PN_SIZE pathsize, localsize, upvalsize;
   PN asmb;   // assembled instructions
   PN_F jit;  // jit function pointer