mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 10:48:29 +00:00
Add LISP interpreter
This commit is contained in:
parent
4f98ad1054
commit
d31bebdd2d
84 changed files with 9081 additions and 0 deletions
67
tool/plinko/lib/cons.h
Normal file
67
tool/plinko/lib/cons.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_PLINKO_LIB_CONS_H_
|
||||
#define COSMOPOLITAN_TOOL_PLINKO_LIB_CONS_H_
|
||||
#include "tool/plinko/lib/error.h"
|
||||
#include "tool/plinko/lib/plinko.h"
|
||||
#include "tool/plinko/lib/types.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
forceinline void Set(int i, dword t) {
|
||||
#ifndef NDEBUG
|
||||
DCHECK_NE(0, i);
|
||||
DCHECK_LT(i, TERM);
|
||||
DCHECK_LT(LO(t), TERM);
|
||||
DCHECK_LE(HI(t), TERM);
|
||||
if (i < 0) {
|
||||
DCHECK_LT(i, LO(t), "topology compromised");
|
||||
DCHECK_LT(i, HI(t), "topology compromised");
|
||||
} else {
|
||||
DCHECK_GE(LO(t), 0);
|
||||
DCHECK_GE(HI(t), 0);
|
||||
}
|
||||
#endif
|
||||
g_mem[i & (BANE | MASK(BANE))] = t;
|
||||
++cSets;
|
||||
}
|
||||
|
||||
forceinline int Alloc(dword t) {
|
||||
int c = cx;
|
||||
if (!__builtin_sub_overflow(c, 1, &c)) {
|
||||
Set(c, t);
|
||||
return cx = c;
|
||||
}
|
||||
OutOfMemory();
|
||||
}
|
||||
|
||||
forceinline void SetShadow(int i, dword t) {
|
||||
#ifndef NDEBUG
|
||||
DCHECK_GE(i, cx);
|
||||
DCHECK_LT(i, TERM);
|
||||
DCHECK_GE(LO(t), 0);
|
||||
/* if (i < 0) DCHECK_GE(HI(t), i, "topology compromised"); */
|
||||
#endif
|
||||
((__seg_fs dword *)((uintptr_t)g_mem))[i & (BANE | MASK(BANE))] = t;
|
||||
}
|
||||
|
||||
forceinline int Cons(int x, int y) {
|
||||
int c;
|
||||
c = Alloc(MAKE(x, y));
|
||||
SetShadow(c, DF(DispatchPlan));
|
||||
return c;
|
||||
}
|
||||
|
||||
forceinline int Alist(int x, int y, int z) {
|
||||
return Cons(Cons(x, y), z);
|
||||
}
|
||||
|
||||
int List(int, int);
|
||||
int List3(int, int, int);
|
||||
int List4(int, int, int, int);
|
||||
int Shadow(int, int);
|
||||
int GetCommonCons(int, int);
|
||||
int ShareCons(int, int);
|
||||
int ShareList(int, int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_TOOL_PLINKO_LIB_CONS_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue