Permalink
Browse files

Remove the last dispatching bits out of prim.c

  • Loading branch information...
1 parent 1162d8c commit 9362abcd9e7a239407275bbe05f043a926eb08fb @kr committed Feb 19, 2007
Showing with 203 additions and 179 deletions.
  1. +1 −1 TODO
  2. +9 −0 ad-hoc-tests/fin.lx
  3. +2 −0 config.h
  4. +10 −9 file.lx
  5. +13 −20 obj.c
  6. +0 −10 obj.h
  7. +122 −61 pair.c
  8. +18 −19 pair.h
  9. +10 −40 prim.c
  10. +0 −7 prim.h
  11. +7 −7 re.lx
  12. +1 −1 st.c
  13. +10 −4 vm.c
View
2 TODO
@@ -2,7 +2,7 @@
[+] garbage collect vectors
[+] generalized array notation output: (a . b . c . d)
[+] modules
-[ ] convert stuff from prim.c into mixed LX/C modules where possible
+[+] convert stuff from prim.c into mixed LX/C modules where possible
[ ] flesh out int methods
[ ] flesh out str methods
[ ] flesh out other primitive type methods
View
@@ -0,0 +1,9 @@
+
+def (f x):
+ obj () ((destroy!) (pr x))
+
+f "Three"
+
+def (x) (x)
+
+x
View
@@ -1,5 +1,7 @@
#define GC_STATS 0
#define GC_DEBUG 0
+#define GC_DIE 0
+#define BH_DEBUG 0
#define GC_DEBUG_BH 0
#define GC_DEBUG_STR 0
#define VM_DEBUG 0
View
19 file.lx
@@ -31,7 +31,7 @@ def file ():
inline C read <<<<
uint r, len;
datum str;
- FILE *f = (FILE *) obj2pair(rcv)->datums[2];
+ FILE *f = (FILE *) ((pair) rcv)->datums[2];
char *s;
if (!f) die("f:read -- this file is closed");
@@ -48,7 +48,7 @@ def file ():
inline C write <<<<
uint r, len;
- FILE *f = obj2pair(rcv)->datums[2];
+ FILE *f = ((pair) rcv)->datums[2];
char *s;
if (!f) die("f:write -- this file is closed");
@@ -63,16 +63,16 @@ def file ():
>>>>
inline C close <<<<
- FILE *f = obj2pair(rcv)->datums[2];
+ FILE *f = ((pair) rcv)->datums[2];
if (f) {
fclose(f);
- obj2pair(rcv)->datums[2] = nil;
+ ((pair) rcv)->datums[2] = nil;
}
return ok_sym;
>>>>
- (destroy) (f :close)
+ (destroy!) (f :close)
inline C prepare <<<<
char *mode = "rb";
@@ -89,14 +89,15 @@ def file ():
regs[R_VM0] = rcv;
regs[R_VM1] = args;
- d = make_blank(3);
+ d = make_obj(3);
+ printf("made a blank object\n");
args = regs[R_VM1];
rcv = regs[R_VM0];
- car(d) = car(obj2pair(rcv));
- cdr(d) = cdr(obj2pair(rcv));
((pair) d)->datums[2] = fopen(string_contents(%(name)s), mode);
- return pair2obj(d);
+ car(d) = car(rcv);
+ cdr(d) = cdr(rcv);
+ return d;
>>>>
f :: (f :prepare)
View
33 obj.c
@@ -10,38 +10,30 @@
datum int_surrogate, str_surrogate, pair_surrogate, nil_surrogate,
symbol_surrogate;
-datum
-make_compiled_obj(datum env, uint *table)
-{
- pair p = cons(env, (datum) table);
- return pair2obj(p);
-}
-
static datum
get_primitive_surrogate(datum obj)
{
+ if (obj == nil) return nil_surrogate;
if (intp(obj)) return int_surrogate;
+ if (symbolp(obj)) return symbol_surrogate;
+
if (stringp(obj)) return str_surrogate;
if (pairp(obj)) return pair_surrogate;
- if (obj == nil) return nil_surrogate;
- if (symbolp(obj)) return symbol_surrogate;
return nil;
}
datum
compiled_obj_env(datum obj)
{
- pair p;
datum surrogate;
if ((surrogate = get_primitive_surrogate(obj))) {
datum frame = cons(obj, nil);
return cons(frame, genv);
}
- if (!compiled_objp(obj)) die1("not a compiled object", obj);
- p = obj2pair(obj);
- return car(p);
+ if (!objp(obj)) die1("not a compiled object", obj);
+ return car(obj);
}
uint *
@@ -55,11 +47,7 @@ compiled_obj_method(datum obj, datum name)
return compiled_obj_method(surrogate, name);
}
- if (!compiled_objp(obj)) {
- return (uint *) get_primitive_method(obj, name);
- }
-
- table = (datum *) cdr(obj2pair(obj));
+ table = (datum *) cdr(obj);
n = datum2int(*(table++));
for (; n--; table += 2) {
@@ -73,10 +61,15 @@ compiled_obj_has_method(datum obj, datum name)
{
int n;
datum *table;
+ datum surrogate;
+
+ if ((surrogate = get_primitive_surrogate(obj))) {
+ return compiled_obj_has_method(surrogate, name);
+ }
- if (!compiled_objp(obj)) die1("compiled_obj_has_method -- bad object", obj);
+ if (!objp(obj)) die1("compiled_obj_has_method -- bad object", obj);
- table = (datum *) cdr(obj2pair(obj));
+ table = (datum *) cdr(obj);
n = datum2int(*(table++));
for (; n--; table += 2) {
View
10 obj.h
@@ -8,16 +8,6 @@
extern datum int_surrogate, str_surrogate, pair_surrogate, nil_surrogate,
symbol_surrogate;
-datum make_compiled_obj(datum env, uint *table);
-
-#define OBJ_TAG 0x2
-
-#define pair2obj(p) ((datum) (((uint) (p)) | OBJ_TAG))
-#define obj2pair(o) ((pair) (((uint) (o)) & ~OBJ_TAG))
-
-#define obj_sig_matches(x) ((((uint) (x)) & BOX_MASK) == OBJ_TAG)
-#define compiled_objp(x) (in_pair_range(x) && obj_sig_matches(x))
-
datum compiled_obj_env(datum obj);
uint *compiled_obj_method(datum obj, datum name);
int compiled_obj_has_method(datum obj, datum name);
Oops, something went wrong.

0 comments on commit 9362abc

Please sign in to comment.