Ok, just to get this to people possibly interested...
Brian was kind enough to forward a patch to enable double presision
floating points in Genesis...
Naturelly this isn't of much use in it's current form as it's against
Genesis-1.1p5-STABLE but some of the powers that be have expressed
interest in possibly incorporating it into a more current genesis so...
Anywho, I can't make hassle or tails of it all, but for those interested,
here it is ;)
-- Simmie.
diff -rc Genesis-1.1p5-STABLE.old/src/codegen.c Genesis-1.1p5-STABLE/src/codegen.c
*** Genesis-1.1p5-STABLE.old/src/codegen.c Tue Jul 21 23:16:02 1998
--- Genesis-1.1p5-STABLE/src/codegen.c Wed Dec 23 16:12:30 1998
***************
*** 41,46 ****
--- 41,49 ----
static void check_instr_buf(Int pos);
static void code(Long val);
static void code_str(char *str);
+ #ifdef USE_BIG_FLOATS
+ static void code_float(Float fnum);
+ #endif
static void code_errors(Id_list *errors);
static Int new_jump_dest(void);
static void set_jump_dest_here(Int dest);
***************
*** 1225,1231 ****
--- 1228,1238 ----
case FLOAT:
code(FLOAT);
+ #ifdef USE_BIG_FLOATS
+ code_float(expr->u.fnum);
+ #else
code(*((Long*)(&expr->u.fnum)));
+ #endif
break;
***************
*** 1749,1754 ****
--- 1756,1769 ----
instr_buf[instr_loc++].str = str;
}
+ #ifdef USE_BIG_FLOATS
+ static void code_float(Float fnum)
+ {
+ check_instr_buf(instr_loc);
+ instr_buf[instr_loc++].fnum = fnum;
+ }
+ #endif
+
/* Requires: errors should be good until the next pfree() of compiler_pile, at
* least. Putting it in the instruction buffer doesn't cause it to
* be freed.
***************
*** 1865,1870 ****
--- 1880,1892 ----
method->opcodes[i] = object_add_string(object, string);
string_discard(string);
break;
+
+ #ifdef USE_BIG_FLOATS
+ case FLOAT:
+ method->opcodes[i] = object_add_float(object,
+ instr_buf[i].fnum);
+ break;
+ #endif
case IDENT:
method->opcodes[i] = object_add_ident(object,
Only in Genesis-1.1p5-STABLE/src: codegen.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/data/object.c Genesis-1.1p5-STABLE/src/data/object.c
*** Genesis-1.1p5-STABLE.old/src/data/object.c Tue Jul 21 23:59:34 1998
--- Genesis-1.1p5-STABLE/src/data/object.c Wed Dec 23 16:12:30 1998
***************
*** 67,72 ****
--- 67,79 ----
cnew->idents = EMALLOC(Ident_entry, IDENTS_STARTING_SIZE);
cnew->idents_size = IDENTS_STARTING_SIZE;
cnew->num_idents = 0;
+
+ #ifdef USE_BIG_FLOATS
+ /* Initialize float table. */
+ cnew->floats = EMALLOC(Float_entry, FLOATS_STARTING_SIZE);
+ cnew->floats_size = FLOATS_STARTING_SIZE;
+ cnew->num_floats = 0;
+ #endif
cnew->search = START_SEARCH_AT;
***************
*** 130,135 ****
--- 137,148 ----
}
}
efree(object->idents);
+
+ #ifdef USE_BIG_FLOATS
+ /* Discard floats. */
+ efree(object->floats);
+ #endif
+
}
/*
***************
*** 446,451 ****
--- 459,516 ----
{
return object->strings[ind].str;
}
+
+ #ifdef USE_BIG_FLOATS
+ Int object_add_float(Obj *object, Float fnum)
+ {
+ Int i, blank = -1;
+
+ /* Get the object dirty now, so we can return with a clean conscience. */
+ object->dirty = 1;
+
+ /* Look for blanks while checking for an equivalent float. */
+ for (i = 0; i < object->num_floats; i++) {
+ if (!object->floats[i].refs) {
+ blank = i;
+ } else if (object->floats[i].fnum == fnum) {
+ object->floats[i].refs++;
+ return i;
+ }
+ }
+
+ /* Fill in a blank if we found one. */
+ if (blank != -1) {
+ object->floats[blank].fnum = fnum;
+ object->floats[blank].refs = 1;
+ return blank;
+ }
+
+ /* Check to see if we have to enlarge the table. */
+ if (i >= object->floats_size) {
+ object->floats_size = object->floats_size * 2 + MALLOC_DELTA;
+ object->floats = EREALLOC(object->floats, Float_entry,
+ object->floats_size);
+ }
+
+ /* Add the string to the end of the table. */
+ object->floats[i].fnum = fnum;
+ object->floats[i].refs = 1;
+ object->num_floats++;
+
+ return i;
+ }
+
+ void object_discard_float(Obj *object, Int ind)
+ {
+ object->floats[ind].refs--;
+ object->dirty = 1;
+ }
+
+ cFloat object_get_float(Obj *object, Int ind)
+ {
+ return object->floats[ind].fnum;
+ }
+ #endif
Int object_add_ident(Obj *object, char *ident)
{
Only in Genesis-1.1p5-STABLE/src/data: object.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/dbpack.c Genesis-1.1p5-STABLE/src/dbpack.c
*** Genesis-1.1p5-STABLE.old/src/dbpack.c Wed Aug 26 21:07:13 1998
--- Genesis-1.1p5-STABLE/src/dbpack.c Wed Dec 23 16:12:30 1998
***************
*** 146,151 ****
--- 146,165 ----
#endif
}
+ #ifdef USE_BIG_FLOATS
+ void write_float(Float n, FILE *fp)
+ {
+ fwrite(&n, sizeof(Float), 1, fp);
+ }
+
+ Float read_float(FILE *fp)
+ {
+ Float k;
+
+ fread(&k, sizeof(Float), 1, fp);
+ return k;
+ }
+ #endif
void write_ident(Long id, FILE *fp)
{
***************
*** 602,607 ****
--- 616,666 ----
return size;
}
+ #ifdef USE_BIG_FLOATS
+ INTERNAL void pack_floats(Obj *obj, FILE *fp)
+ {
+ Int i;
+
+ write_long(obj->floats_size, fp);
+ write_long(obj->num_floats, fp);
+ for (i = 0; i < obj->num_floats; i++) {
+ write_long(obj->floats[i].refs, fp);
+ if (obj->floats[i].refs)
+ write_float(obj->floats[i].fnum, fp);
+ }
+ }
+
+ INTERNAL void unpack_floats(Obj *obj, FILE *fp)
+ {
+ Int i;
+
+ obj->floats_size = read_long(fp);
+ obj->num_floats = read_long(fp);
+ obj->floats = EMALLOC(Float_entry, obj->floats_size);
+ for (i = 0; i < obj->num_floats; i++) {
+ obj->floats[i].refs = read_long(fp);
+ if(obj->floats[i].refs)
+ obj->floats[i].fnum = read_float(fp);
+ }
+ }
+
+ INTERNAL Int size_floats(Obj *obj)
+ {
+ Int size = 0, i;
+
+ size += size_long(obj->floats_size);
+ size += size_long(obj->num_floats);
+ for (i = 0; i < obj->num_floats; i++) {
+ size += size_long(obj->floats[i].refs);
+ if (obj->floats[i].refs)
+ size += sizeof(Float);
+ }
+
+ return size;
+ }
+
+ #endif
+
void pack_data(cData *data, FILE *fp)
{
write_long(data->type, fp);
***************
*** 612,618 ****
--- 671,681 ----
break;
case FLOAT:
+ #ifdef USE_BIG_FLOATS
+ write_float(data->u.fval, fp);
+ #else
write_long(*((Long*)(&data->u.fval)), fp);
+ #endif
break;
case STRING:
***************
*** 668,678 ****
--- 731,747 ----
data->u.val = read_long(fp);
break;
+ #ifdef USE_BIG_FLOATS
+ case FLOAT:
+ data->u.fval = read_float(fp);
+ break;
+ #else
case FLOAT: {
Long k = read_long(fp);
data->u.fval = *((cFloat*)(&k));
break;
}
+ #endif
case STRING:
data->u.str = string_unpack(fp);
***************
*** 731,737 ****
--- 800,810 ----
break;
case FLOAT:
+ #ifdef USE_BIG_FLOATS
+ size += sizeof(Float);
+ #else
size += size_long(*((Long*)(&data->u.fval)));
+ #endif
break;
case STRING:
***************
*** 787,792 ****
--- 860,868 ----
pack_methods(obj, fp);
pack_strings(obj, fp);
pack_idents(obj, fp);
+ #ifdef USE_BIG_FLOATS
+ pack_floats(obj, fp);
+ #endif
write_ident(obj->objname, fp);
#if 0
write_long(obj->search, fp);
***************
*** 801,806 ****
--- 877,885 ----
unpack_methods(obj, fp);
unpack_strings(obj, fp);
unpack_idents(obj, fp);
+ #ifdef USE_BIG_FLOATS
+ unpack_floats(obj, fp);
+ #endif
obj->objname = read_ident(fp);
#if 0
obj->search = read_long(fp);
***************
*** 817,822 ****
--- 896,904 ----
size += size_methods(obj);
size += size_strings(obj);
size += size_idents(obj);
+ #ifdef USE_BIG_FLOATS
+ size += size_floats(obj);
+ #endif
if (obj->objname != -1)
size += size_ident(obj->objname);
#if 0
Only in Genesis-1.1p5-STABLE/src: dbpack.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/decode.c Genesis-1.1p5-STABLE/src/decode.c
*** Genesis-1.1p5-STABLE.old/src/decode.c Tue Jul 21 23:36:03 1998
--- Genesis-1.1p5-STABLE/src/decode.c Wed Dec 23 16:12:30 1998
***************
*** 827,833 ****
--- 827,837 ----
break;
case FLOAT:
+ #ifdef USE_BIG_FLOATS
+ stack = expr_list(float_expr(the_object->floats[the_opcodes[pos + 1]].fnum), stack);
+ #else
stack = expr_list(float_expr(*((Float*)(&the_opcodes[pos+1]))), stack);
+ #endif
pos += 2;
break;
Only in Genesis-1.1p5-STABLE/src: decode.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/include/cdc_types.h Genesis-1.1p5-STABLE/src/include/cdc_types.h
*** Genesis-1.1p5-STABLE.old/src/include/cdc_types.h Wed Jul 22 00:02:59 1998
--- Genesis-1.1p5-STABLE/src/include/cdc_types.h Wed Dec 23 16:12:30 1998
***************
*** 24,29 ****
--- 24,32 ----
typedef struct ident_entry Ident_entry;
typedef struct string_entry String_entry;
+ #ifdef USE_BIG_FLOATS
+ typedef struct float_entry Float_entry;
+ #endif
typedef struct var Var;
typedef struct error_list Error_list;
typedef Int Object_string;
Only in Genesis-1.1p5-STABLE/src/include: cdc_types.h.orig
diff -rc Genesis-1.1p5-STABLE.old/src/include/code_prv.h Genesis-1.1p5-STABLE/src/include/code_prv.h
*** Genesis-1.1p5-STABLE.old/src/include/code_prv.h Tue Jul 21 23:36:15 1998
--- Genesis-1.1p5-STABLE/src/include/code_prv.h Wed Dec 23 16:12:30 1998
***************
*** 14,19 ****
--- 14,22 ----
union instr {
Long val;
char *str;
+ #ifdef USE_BIG_FLOATS
+ Float fnum;
+ #endif
Id_list *errors;
};
Only in Genesis-1.1p5-STABLE/src/include: code_prv.h.orig
diff -rc Genesis-1.1p5-STABLE.old/src/include/defs.h Genesis-1.1p5-STABLE/src/include/defs.h
*** Genesis-1.1p5-STABLE.old/src/include/defs.h Wed Aug 26 21:15:24 1998
--- Genesis-1.1p5-STABLE/src/include/defs.h Wed Dec 23 16:12:30 1998
***************
*** 28,34 ****
// system can handle 64bit + words. You do not need to specify both
// (You can specify just USE_BIG_FLOATS, and not numbers).
*/
! #if DISABLED
# define USE_BIG_FLOATS
#endif
--- 28,34 ----
// system can handle 64bit + words. You do not need to specify both
// (You can specify just USE_BIG_FLOATS, and not numbers).
*/
! #if ENABLED
# define USE_BIG_FLOATS
#endif
Only in Genesis-1.1p5-STABLE/src/include: defs.h.orig
diff -rc Genesis-1.1p5-STABLE.old/src/include/object.h Genesis-1.1p5-STABLE/src/include/object.h
*** Genesis-1.1p5-STABLE.old/src/include/object.h Tue Jul 21 23:20:42 1998
--- Genesis-1.1p5-STABLE/src/include/object.h Wed Dec 23 16:12:30 1998
***************
*** 44,49 ****
--- 44,56 ----
Int num_idents;
Int idents_size;
+ #ifdef USE_BIG_FLOATS
+ /* Table for float references in methods. */
+ Float_entry *floats;
+ Int num_floats;
+ Int floats_size;
+ #endif
+
/* Information for the cache. */
cObjnum objnum;
Int refs;
***************
*** 85,90 ****
--- 92,105 ----
Int refs;
};
+ #ifdef USE_BIG_FLOATS
+ /* Again for floats. */
+ struct float_entry {
+ Float fnum;
+ Int refs;
+ };
+ #endif
+
struct var {
Ident name;
cObjnum cclass;
***************
*** 179,184 ****
--- 194,202 ----
#define METHOD_STARTING_SIZE (16 - MALLOC_DELTA - 1)
#define STRING_STARTING_SIZE (16 - MALLOC_DELTA)
#define IDENTS_STARTING_SIZE (16 - MALLOC_DELTA)
+ #ifdef USE_BIG_FLOATS
+ #define FLOATS_STARTING_SIZE (16 - MALLOC_DELTA)
+ #endif
#define METHOD_CACHE_SIZE 2551
/* ..................................................................... */
***************
*** 229,234 ****
--- 247,257 ----
Int object_add_string(Obj *object, cStr *string);
void object_discard_string(Obj *object, Int ind);
cStr *object_get_string(Obj *object, Int ind);
+ #ifdef USE_BIG_FLOATS
+ Int object_add_float(Obj *object, Float fnum);
+ void object_discard_float(Obj *object, Int ind);
+ Float object_get_float(Obj *object, Int ind);
+ #endif
Int object_add_ident(Obj *object, char *ident);
void object_discard_ident(Obj *object, Int ind);
Long object_get_ident(Obj *object, Int ind);
***************
*** 285,290 ****
--- 308,318 ----
extern Int object_add_string(Obj *object, cStr *string);
extern void object_discard_string(Obj *object, Int ind);
extern cStr *object_get_string(Obj *object, Int ind);
+ #ifdef USE_BIG_FLOATS
+ extern Int object_add_float(Obj *object, Float fnum);
+ extern void object_discard_float(Obj *object, Int ind);
+ extern Float object_get_float(Obj *object, Int ind);
+ #endif
extern Int object_add_ident(Obj *object, char *ident);
extern void object_discard_ident(Obj *object, Int ind);
extern Long object_get_ident(Obj *object, Int ind);
Only in Genesis-1.1p5-STABLE/src/include: object.h.orig
diff -rc Genesis-1.1p5-STABLE.old/src/opcodes.c Genesis-1.1p5-STABLE/src/opcodes.c
*** Genesis-1.1p5-STABLE.old/src/opcodes.c Tue Jul 21 23:59:25 1998
--- Genesis-1.1p5-STABLE/src/opcodes.c Wed Dec 23 16:12:30 1998
***************
*** 47,55 ****
--- 47,59 ----
{ ONE, "ONE", op_one },
{ INTEGER, "INTEGER", op_integer, INTEGER },
+ #ifdef USE_BIG_FLOATS
+ { FLOAT, "FLOAT", op_float, FLOAT},
+ #else
/* By the time it examines the arg, the FLOAT has already been
cast into an INTEGER, so we just need to let it know its an INT */
{ FLOAT, "FLOAT", op_float, INTEGER },
+ #endif
{ STRING, "STRING", op_string, STRING },
{ OBJNUM, "OBJNUM", op_objnum, INTEGER },
{ SYMBOL, "SYMBOL", op_symbol, IDENT },
Only in Genesis-1.1p5-STABLE/src: opcodes.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/ops/object.c Genesis-1.1p5-STABLE/src/ops/object.c
*** Genesis-1.1p5-STABLE.old/src/ops/object.c Wed Jul 22 00:07:38 1998
--- Genesis-1.1p5-STABLE/src/ops/object.c Wed Dec 23 16:12:30 1998
***************
*** 914,920 ****
--- 914,924 ----
break;
case FLOAT:
d.type = FLOAT;
+ #ifdef USE_BIG_FLOATS
+ d.u.fval = object_get_float(obj, op);
+ #else
d.u.fval = *((Float*)(&op));
+ #endif
break;
case T_ERROR:
d.type = T_ERROR;
Only in Genesis-1.1p5-STABLE/src/ops: object.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/ops/operators.c Genesis-1.1p5-STABLE/src/ops/operators.c
*** Genesis-1.1p5-STABLE.old/src/ops/operators.c Wed Jul 22 00:07:39 1998
--- Genesis-1.1p5-STABLE/src/ops/operators.c Wed Dec 23 16:12:30 1998
***************
*** 602,608 ****
--- 602,616 ----
}
void op_float(void) {
+ #ifdef USE_BIG_FLOATS
+ cFloat fl;
+ Int ind = cur_frame->opcodes[cur_frame->pc++];
+
+ fl = object_get_float(cur_frame->method->object, ind);
+ push_float(fl);
+ #else
push_float(*((cFloat*)(&cur_frame->opcodes[cur_frame->pc++])));
+ #endif
}
void op_string(void) {
Only in Genesis-1.1p5-STABLE/src/ops: operators.c.orig
diff -rc Genesis-1.1p5-STABLE.old/src/util.c Genesis-1.1p5-STABLE/src/util.c
*** Genesis-1.1p5-STABLE.old/src/util.c Tue Jul 21 23:59:29 1998
--- Genesis-1.1p5-STABLE/src/util.c Wed Dec 23 16:12:30 1998
***************
*** 132,138 ****
--- 132,142 ----
char * float_to_ascii(Float num, Number_buf nbuf) {
int i;
+ #ifdef USE_BIG_FLOATS
+ sprintf (nbuf, "%.15g", num);
+ #else
sprintf (nbuf, "%g", num);
+ #endif
for (i=0; nbuf[i]; i++)
if (nbuf[i]=='.' || nbuf[i]=='e')
return nbuf;
Only in Genesis-1.1p5-STABLE/src: util.c.orig
|