Skip to content

Commit

Permalink
removing random number code from flisp
Browse files Browse the repository at this point in the history
removing some other unused code from flisp
  • Loading branch information
JeffBezanson committed Jul 2, 2011
1 parent 180b9b7 commit c163411
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 179 deletions.
44 changes: 0 additions & 44 deletions src/flisp/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,44 +397,6 @@ static value_t fl_os_setenv(value_t *args, uint32_t nargs)
return FL_T;
}

static value_t fl_rand(value_t *args, u_int32_t nargs)
{
(void)args; (void)nargs;
fixnum_t r;
#ifdef __LP64__
r = ((((uint64_t)random())<<32) | random()) & 0x1fffffffffffffffLL;
#else
r = random() & 0x1fffffff;
#endif
return fixnum(r);
}
static value_t fl_rand32(value_t *args, u_int32_t nargs)
{
(void)args; (void)nargs;
unsigned long r = random();
#ifdef __LP64__
return fixnum(r);
#else
return mk_uint32(r);
#endif
}
static value_t fl_rand64(value_t *args, u_int32_t nargs)
{
(void)args; (void)nargs;
uint64_t r = (((uint64_t)random())<<32) | random();
return mk_uint64(r);
}
static value_t fl_randd(value_t *args, u_int32_t nargs)
{
(void)args; (void)nargs;
return mk_double(rand_double());
}
static value_t fl_randf(value_t *args, u_int32_t nargs)
{
(void)args; (void)nargs;
return mk_float(rand_float());
}

extern void stringfuncs_init();
extern void table_init();
extern void iostream_init();
Expand Down Expand Up @@ -465,12 +427,6 @@ static builtinspec_t builtin_info[] = {
{ "time.string", fl_time_string },
{ "time.fromstring", fl_time_fromstring },

{ "rand", fl_rand },
{ "rand.uint32", fl_rand32 },
{ "rand.uint64", fl_rand64 },
{ "rand.double", fl_randd },
{ "rand.float", fl_randf },

{ "path.cwd", fl_path_cwd },
{ "path.exists?", fl_path_exists },

Expand Down
102 changes: 1 addition & 101 deletions src/flisp/cvalues.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ value_t floatsym, doublesym;
value_t gftypesym, stringtypesym, wcstringtypesym;
value_t emptystringsym;

value_t structsym, arraysym, enumsym, cfunctionsym, voidsym, pointersym;
value_t unionsym;
value_t arraysym, cfunctionsym, voidsym, pointersym;

static htable_t TypeTable;
static htable_t reverse_dlsym_lookup_table;
Expand Down Expand Up @@ -333,50 +332,6 @@ size_t toulong(value_t n, char *fname)
return 0;
}

static int cvalue_enum_init(fltype_t *ft, value_t arg, void *dest)
{
int n=0;
value_t syms;
value_t type = ft->type;

syms = car(cdr(type));
if (!isvector(syms))
type_error("enum", "vector", syms);
if (issymbol(arg)) {
for(n=0; n < (int)vector_size(syms); n++) {
if (vector_elt(syms, n) == arg) {
*(int*)dest = n;
return 0;
}
}
lerror(ArgError, "enum: invalid enum value");
}
if (isfixnum(arg)) {
n = (int)numval(arg);
}
else if (iscprim(arg)) {
cprim_t *cp = (cprim_t*)ptr(arg);
n = conv_to_int32(cp_data(cp), cp_numtype(cp));
}
else {
type_error("enum", "number", arg);
}
if ((unsigned)n >= vector_size(syms))
lerror(ArgError, "enum: value out of range");
*(int*)dest = n;
return 0;
}

value_t cvalue_enum(value_t *args, u_int32_t nargs)
{
argcount("enum", nargs, 2);
value_t type = fl_list2(enumsym, args[0]);
fltype_t *ft = get_type(type);
value_t cv = cvalue(ft, sizeof(int32_t));
cvalue_enum_init(ft, args[1], cp_data((cprim_t*)ptr(cv)));
return cv;
}

static int isarray(value_t v)
{
return iscvalue(v) && cv_class((cvalue_t*)ptr(v))->eltype != NULL;
Expand Down Expand Up @@ -485,48 +440,6 @@ size_t cvalue_arraylen(value_t v)
return cv_len(cv)/(cv_class(cv)->elsz);
}

static size_t cvalue_struct_offs(value_t type, value_t field, int computeTotal,
int *palign)
{
value_t fld = car(cdr_(type));
size_t fsz, ssz = 0;
int al;
*palign = 0;

while (iscons(fld)) {
fsz = ctype_sizeof(car(cdr(car_(fld))), &al);

ssz = LLT_ALIGN(ssz, al);
if (al > *palign)
*palign = al;

if (!computeTotal && field==car_(car_(fld))) {
// found target field
return ssz;
}

ssz += fsz;
fld = cdr_(fld);
}
return LLT_ALIGN(ssz, *palign);
}

static size_t cvalue_union_size(value_t type, int *palign)
{
value_t fld = car(cdr_(type));
size_t fsz, usz = 0;
int al;
*palign = 0;

while (iscons(fld)) {
fsz = ctype_sizeof(car(cdr(car_(fld))), &al);
if (al > *palign) *palign = al;
if (fsz > usz) usz = fsz;
fld = cdr_(fld);
}
return LLT_ALIGN(usz, *palign);
}

// *palign is an output argument giving the alignment required by type
size_t ctype_sizeof(value_t type, int *palign)
{
Expand Down Expand Up @@ -570,16 +483,6 @@ size_t ctype_sizeof(value_t type, int *palign)
size_t sz = toulong(n, "sizeof");
return sz * ctype_sizeof(t, palign);
}
else if (hed == structsym) {
return cvalue_struct_offs(type, NIL, 1, palign);
}
else if (hed == unionsym) {
return cvalue_union_size(type, palign);
}
else if (hed == enumsym) {
*palign = ALIGN4;
return 4;
}
}
lerror(ArgError, "sizeof: invalid c type");
return 0;
Expand Down Expand Up @@ -964,10 +867,7 @@ static void cvalues_init()
ctor_cv_intern(double);

ctor_cv_intern(array);
ctor_cv_intern(enum);
cv_intern(pointer);
cv_intern(struct);
cv_intern(union);
cv_intern(void);
cfunctionsym = symbol("c-function");

Expand Down
8 changes: 3 additions & 5 deletions src/flisp/flisp.boot
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
__start #fn("8000r1e0302|NF6D0|Nk12^k22e3|\x84315E0|k12]k22e4e5312e6302c7`41;" [__init_globals
*argv* *interactive* __script princ *banner* repl #fn(exit)] __start)
abs #fn("7000r1|`X650|y;|;" [] abs) any
#fn("8000r2}F16D02|}M3117:02e0|}N42;" [any] any) arg-counts #table(#.not 1 #.atom? 1 #.number? 1 #.cons 2 #.set-cdr! 2 #.equal? 2 #.fixnum? 1 #.bound? 1 #.eq? 2 #.symbol? 1 #.builtin? 1 #.< 2 #.aset! 3 #.div0 2 #.cdr 1 #.null? 1 #.eqv? 2 #.compare 2 #.aref 2 #.car 1 #.set-car! 2 #.pair? 1 #.= 2 #.vector? 1 #.boolean? 1)
#fn("8000r2}F16D02|}M3117:02e0|}N42;" [any] any) arg-counts #table(#.equal? 2 #.atom? 1 #.set-cdr! 2 #.symbol? 1 #.car 1 #.eq? 2 #.aref 2 #.boolean? 1 #.not 1 #.null? 1 #.eqv? 2 #.number? 1 #.pair? 1 #.builtin? 1 #.aset! 3 #.div0 2 #.= 2 #.bound? 1 #.compare 2 #.vector? 1 #.cdr 1 #.set-car! 2 #.< 2 #.fixnum? 1 #.cons 2)
argc-error #fn("<000r2e0c1|c2}}aW670c3540c445;" [error "compile error: "
" expects " " argument."
" arguments."] argc-error)
Expand All @@ -105,7 +105,7 @@
#fn("<000r2]|F16902|Mc0<@6E02e1|M31}Km12|Nm05\x0f/2c2|F6>0e3}|\x84L1325J0|\x85:0e4}315>0e3}e5|31L13241;" [unquote
bq-bracket #fn("8000r1|N\x8550|M;e0|b23216H02e0|Mb23216;02c1e2|31<6>0c3e4|31|\x84L3;c5|K;" [length=
#.list caar #.cons cadar nconc]) nreconc reverse! bq-process])])] bq-process)
builtin->instruction #fn("9000r1c0~|^43;" [#fn(get)] [#table(#.number? number? #.cons cons #.fixnum? fixnum? #.equal? equal? #.eq? eq? #.symbol? symbol? #.div0 div0 #.builtin? builtin? #.aset! aset! #.- - #.boolean? boolean? #.not not #.apply apply #.atom? atom? #.set-cdr! set-cdr! #./ / #.function? function? #.vector vector #.list list #.bound? bound? #.< < #.* * #.cdr cdr #.null? null? #.+ + #.eqv? eqv? #.compare compare #.aref aref #.set-car! set-car! #.car car #.pair? pair? #.= = #.vector? vector?)
builtin->instruction #fn("9000r1c0~|^43;" [#fn(get)] [#table(#.equal? equal? #.* * #.car car #.apply apply #.aref aref #.- - #.boolean? boolean? #.builtin? builtin? #.null? null? #.eqv? eqv? #.function? function? #.bound? bound? #.cdr cdr #.list list #.set-car! set-car! #.cons cons #.atom? atom? #.set-cdr! set-cdr! #.symbol? symbol? #.eq? eq? #.vector vector #.not not #.pair? pair? #.number? number? #.div0 div0 #.aset! aset! #.+ + #.= = #.compare compare #.vector? vector? #./ / #.< < #.fixnum? fixnum?)
()])
caaaar #fn("6000r1|MMMM;" [] caaaar) caaadr
#fn("6000r1|\x84MM;" [] caaadr) caaar #fn("6000r1|MMM;" [] caaar)
Expand Down Expand Up @@ -156,7 +156,7 @@
largc lvargc vargc argc compile-in lastcdr caddr ret values #fn(function)
encode-byte-code bcode:code const-to-idx-vec]) filter keyword-arg?])
#fn(length)]) #fn(length)]) make-code-emitter lastcdr lambda-vars filter #.pair?
lambda])] #0=[#:g691 ()])
lambda])] #0=[#:g689 ()])
compile-for #fn(":000r5e0g4316X0e1|}^g2342e1|}^g3342e1|}^g4342e2|c342;e4c541;" [1arg-lambda?
compile-in emit for error "for: third form must be a 1-argument lambda"] compile-for)
compile-if #fn("<000r4c0qe1|31e1|31g3\x84e2g331e3g331F6;0e4g331560e53045;" [#fn(";000r5g2]\x82>0e0~\x7fi02g344;g2^\x82>0e0~\x7fi02g444;e0~\x7f^g2342e1~c2|332e0~\x7fi02g3342i026<0e1~c3325:0e1~c4}332e5~|322e0~\x7fi02g4342e5~}42;" [compile-in
Expand Down Expand Up @@ -356,8 +356,6 @@
printable? #fn("7000r1c0|3117802c1|31@;" [#fn(iostream?)
#fn(eof-object?)] printable?)
quote-value #fn("7000r1e0|31640|;c1|L2;" [self-evaluating? quote] quote-value)
random #fn("8000r1c0|316<0e1c230|42;c330|T2;" [#fn(integer?) mod #fn(rand)
#fn(rand.double)] random)
read-all #fn("8000r1e0c1|42;" [read-all-of #fn(read)] read-all)
read-all-of #fn("9000r2c0q]31_|}3142;" [#fn("6000r1c0qm02|;" [#fn("9000r2c0i1131680e1|41;~}|Ki10i113142;" [#fn(io.eof?)
reverse!])])] read-all-of)
Expand Down
4 changes: 2 additions & 2 deletions src/flisp/flisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ extern value_t QUOTE;
extern value_t int8sym, uint8sym, int16sym, uint16sym, int32sym, uint32sym;
extern value_t int64sym, uint64sym;
extern value_t longsym, ulongsym, bytesym, wcharsym;
extern value_t structsym, arraysym, enumsym, cfunctionsym, voidsym, pointersym;
extern value_t arraysym, cfunctionsym, voidsym, pointersym;
extern value_t stringtypesym, wcstringtypesym, emptystringsym;
extern value_t unionsym, floatsym, doublesym;
extern value_t floatsym, doublesym;
extern fltype_t *bytetype, *wchartype;
extern fltype_t *stringtype, *wcstringtype;
extern fltype_t *builtintype;
Expand Down
18 changes: 0 additions & 18 deletions src/flisp/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,24 +694,6 @@ static void cvalue_printdata(ios_t *f, void *data, size_t len, value_t type,
else
outc(']', f);
}
else if (car_(type) == enumsym) {
int n = *(int*)data;
value_t syms = car(cdr_(type));
assert(isvector(syms));
if (!weak) {
outsn("#enum(", f, 6);
fl_print_child(f, syms);
outc(' ', f);
}
if (n >= (int)vector_size(syms)) {
cvalue_printdata(f, data, len, int32sym, 1);
}
else {
fl_print_child(f, vector_elt(syms, n));
}
if (!weak)
outc(')', f);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/flisp/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static value_t read_string()
size_t i=0, j, sz = 64, ndig;
int c;
value_t s;
u_int32_t wc;
u_int32_t wc=0;

buf = malloc(sz);
while (1) {
Expand Down
4 changes: 0 additions & 4 deletions src/flisp/system.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@
-1))
0)))
(define (mod x y) (- x (* (div x y) y)))
(define (random n)
(if (integer? n)
(mod (rand) n)
(* (rand.double) n)))
(define (abs x) (if (< x 0) (- x) x))
(define (max x0 . xs)
(if (null? xs) x0
Expand Down
4 changes: 0 additions & 4 deletions src/flisp/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ fltype_t *get_type(value_t t)
ft->init = &cvalue_array_init;
eltype->artype = ft;
}
else if (car_(t) == enumsym) {
ft->numtype = T_INT32;
ft->init = &cvalue_enum_init;
}
}
*bp = ft;
return ft;
Expand Down

0 comments on commit c163411

Please sign in to comment.