Skip to content

Commit

Permalink
* Import lazyk.c from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Mar 1, 2016
1 parent 0c5b5d4 commit 86f3b4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ I used the following Ubuntu deb packages to test this program.
| |iconx |9.4.3-4.2ubuntu1
64 |INTERCAL |intercal |30:0.30-1
65 |Jasmin |jasmin-sable |2.4.0-5
66 |Java |openjdk-6-jdk |6b37-1.13.9-1ubuntu0.15.10.1
66 |Java |openjdk-6-jdk |6b38-1.13.10-0ubuntu0.15.10.1
67 |JavaScript |rhino |1.7R4-3
68 |Jq |jq |1.4-2.1
69 |Julia |julia |0.3.11-1ubuntu3
Expand Down
19 changes: 10 additions & 9 deletions vendor/lazyk.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ctype.h>
#include <time.h>
#include <assert.h>
#include <stdint.h>

#define INITIAL_HEAP_SIZE 128*1024
#define RDSTACK_SIZE 100000
Expand All @@ -33,7 +34,7 @@
struct tagPair;
typedef struct tagPair *Cell;
#define CELL(x) ((Cell)(x))
#define TAG(c) ((int)(c) & 0x03)
#define TAG(c) ((intptr_t)(c) & 0x03)

/* pair */
typedef struct tagPair {
Expand All @@ -48,12 +49,12 @@ typedef struct tagPair {
/* integer */
#define isint(c) (TAG(c) == 1)
#define mkint(n) CELL(((n) << 2) + 1)
#define intof(c) ((signed int)(c) >> 2)
#define intof(c) ((intptr_t)(c) >> 2)

/* combinator */
#define iscomb(c) (TAG(c) == 2)
#define mkcomb(n) CELL(((n) << 2) + 2)
#define combof(c) ((int)(c) >> 2)
#define combof(c) ((intptr_t)(c) >> 2)
#define COMB_S mkcomb(0)
#define COMB_K mkcomb(1)
#define COMB_I mkcomb(2)
Expand All @@ -65,12 +66,12 @@ typedef struct tagPair {
#define COMB_CONS mkcomb(8)

/* character */
#define ischar(c) (((int)(c) & 0x07) == 0x03)
#define ischar(c) (((intptr_t)(c) & 0x07) == 0x03)
#define mkchar(n) CELL(((n) << 3) + 0x03)
#define charof(c) ((int)(c) >> 3)
#define charof(c) ((intptr_t)(c) >> 3)

/* immediate objects */
#define isimm(c) (((int)(c) & 0x07) == 0x07)
#define isimm(c) (((intptr_t)(c) & 0x07) == 0x07)
#define mkimm(n) CELL(((n) << 3) + 0x07)
#define NIL mkimm(0)
#define COPIED mkimm(1)
Expand Down Expand Up @@ -102,7 +103,7 @@ void storage_init(int size)
heap_area = malloc(sizeof(Pair) * heap_size);
if (heap_area == NULL)
errexit("Cannot allocate heap storage (%d cells)\n", heap_size);
assert(((int)heap_area & 3) == 0 && (sizeof(Pair) & 3) == 0);
assert(((intptr_t)heap_area & 3) == 0 && (sizeof(Pair) & 3) == 0);

free_ptr = heap_area;
heap_area += heap_size;
Expand Down Expand Up @@ -413,7 +414,7 @@ void eval(Cell root)
}
else if (TOP == COMB_READ && APPLICABLE(2))
{ /* READ NIL f -> CONS CHAR(c) (READ NIL) f */
int c = getchar();
intptr_t c = getchar();
Cell a = alloc(2);
SET(a+0, COMB_CONS, mkchar(c == EOF ? 256 : c));
SET(a+1, COMB_READ, NIL);
Expand Down Expand Up @@ -451,7 +452,7 @@ void eval(Cell root)
SET(TOP, COMB_I, mkint(intof(c) + 1));
}
else if (ischar(TOP) && APPLICABLE(2)) {
int c = charof(TOP);
intptr_t c = charof(TOP);
if (c <= 0) { /* CHAR(0) f z -> z */
Cell z = ARG(2);
DROP(2);
Expand Down

0 comments on commit 86f3b4d

Please sign in to comment.