Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for big-endian architectures #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions doc/impl.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ to keep the implementation terse, but should not hinder normal usage:
* The garbage collector recurses on the `CAR` of objects thus deeply nested
`CAR`s may overflow the C stack — an object's `CDR` is looped on and will not
overflow the stack
* The storage of an object's type and GC mark assumes a little-endian system and
will not work correctly on systems of other endianness
* Proper tailcalls are not implemented — `while` can be used for iterating over
lists
* Strings are null-terminated and therefor not binary safe
9 changes: 5 additions & 4 deletions src/fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@
#define unused(x) ( (void) (x) )
#define car(x) ( (x)->car.o )
#define cdr(x) ( (x)->cdr.o )
#define tag(x) ( (x)->car.c )
#define tag(x) ( (x)->car.s[!endian.c * STRBUFSIZE] )
#define isnil(x) ( (x) == &nil )
#define type(x) ( tag(x) & 0x1 ? tag(x) >> 2 : FE_TPAIR )
#define settype(x,t) ( tag(x) = (t) << 2 | 1 )
#define number(x) ( (x)->cdr.n )
#define prim(x) ( (x)->cdr.c )
#define prim(x) ( (x)->cdr.s[!endian.c * STRBUFSIZE] )
#define cfunc(x) ( (x)->cdr.f )
#define strbuf(x) ( &(x)->car.c + 1 )
#define strbuf(x) ( (x)->car.s + endian.c )

#define STRBUFSIZE ( (int) sizeof(fe_Object*) - 1 )
#define GCMARKBIT ( 0x2 )
#define GCSTACKSIZE ( 256 )

static const union { size_t u; char c; } endian = { 0x1 };

enum {
P_LET, P_SET, P_IF, P_FN, P_MAC, P_WHILE, P_QUOTE, P_AND, P_OR, P_DO, P_CONS,
Expand All @@ -57,7 +58,7 @@ static const char *typenames[] = {
"func", "macro", "prim", "cfunc", "ptr"
};

typedef union { fe_Object *o; fe_CFunc f; fe_Number n; char c; } Value;
typedef union { fe_Object *o; fe_CFunc f; fe_Number n; char s[STRBUFSIZE + 1]; } Value;

struct fe_Object { Value car, cdr; };

Expand Down