Skip to content

Commit 1c54956

Browse files
committedMay 6, 2020
Merge branch 'pico8' into zepto8
2 parents a977458 + 865e10d commit 1c54956

File tree

7 files changed

+19
-36
lines changed

7 files changed

+19
-36
lines changed
 

‎fix32.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,15 @@ struct fix32
147147

148148
inline fix32 operator <<(int y) const
149149
{
150-
// XXX: not exactly the same as the pico8_shl()
151-
return frombits(bits() << (y & 0x1f));
150+
// If y is negative, use lshr() instead.
151+
return y < 0 ? lshr(*this, -y) : frombits(y >= 32 ? 0 : bits() << y);
152152
}
153153

154154
inline fix32 operator >>(int y) const
155155
{
156-
// If y is negative, it is interpreted modulo 32. If y is >= 32,
157-
// only the sign is preserved, so it's the same as for y == 31.
158156
using std::min;
159-
return frombits(bits() >> (min(y, 31) & 0x1f));
157+
// If y is negative, use << instead.
158+
return y < 0 ? *this << -y : frombits(bits() >> min(y, 31));
160159
}
161160

162161
inline fix32& operator +=(fix32 x) { return *this = *this + x; }
@@ -180,8 +179,8 @@ struct fix32
180179

181180
static inline fix32 lshr(fix32 x, int y)
182181
{
183-
// XXX: not exactly the same as the pico8_lshr()
184-
return frombits(uint32_t(x.bits()) >> (y & 0x1f));
182+
// If y is negative, use << instead.
183+
return y < 0 ? x << -y : frombits(y >= 32 ? 0 : uint32_t(x.bits()) >> y);
185184
}
186185

187186
static inline fix32 rotl(fix32 x, int y)

‎llex.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const char *const luaX_tokens [] = {
4040
"return", "then", "true", "until", "while",
4141
"..", "...", "==", ">=", "<=", "~=", "!=", "::",
4242
"<eof>", "<number>", "<name>", "<string>", "?",
43-
"<eol>", "@@", "^^", "<<", ">>", ">>>", "<<>", ">><",
43+
"<eol>", "^^", "<<", ">>", ">>>", "<<>", ">><",
4444
"+=", "-=", "*=", "/=", "%=", "^=", "\\=", "&=", "|=",
4545
"^^=", "<<=", ">>=", ">>>=", "<<>=", ">><=", "..=",
4646
};
@@ -530,11 +530,6 @@ static int llex (LexState *ls, SemInfo *seminfo) {
530530
if (ls->current == '=') { next(ls); return TK_LSHRE; }
531531
else return TK_LSHR;
532532
}
533-
case '@': {
534-
next(ls);
535-
if (ls->current != '@') return '@';
536-
else { next(ls); return TK_DBAT; }
537-
}
538533
case ':': {
539534
next(ls);
540535
if (ls->current != ':') return ':';

‎llex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum RESERVED {
2727
TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
2828
/* other terminal symbols */
2929
TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NE2, TK_DBCOLON,
30-
TK_EOS, TK_NUMBER, TK_NAME, TK_STRING, TK_PRINT, TK_EOL, TK_DBAT,
30+
TK_EOS, TK_NUMBER, TK_NAME, TK_STRING, TK_PRINT, TK_EOL,
3131
TK_BXOR, TK_SHL, TK_SHR, TK_LSHR, TK_ROTL, TK_ROTR,
3232
/* these must be last and match "ORDER OPR" */
3333
TK_ADDE, TK_SUBE, TK_MULE, TK_DIVE, TK_MODE, TK_POWE, TK_IDIVE,

‎lopcodes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ OP_UNM,/* A B R(A) := -R(B) */
204204
OP_BNOT,/* A B R(A) := ~R(B) */
205205
OP_NOT,/* A B R(A) := not R(B) */
206206
OP_PEEK,/* A B R(A) := @ R(B) */
207-
OP_PEEK2,/* A B R(A) := @@ R(B) */
207+
OP_PEEK2,/* A B R(A) := % R(B) */
208208
OP_PEEK4,/* A B R(A) := $ R(B) */
209209
OP_LEN,/* A B R(A) := length of R(B) */
210210

‎lparser.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static UnOpr getunopr (int op) {
993993
case '-': return OPR_MINUS;
994994
case '~': return OPR_BNOT;
995995
case '@': return OPR_PEEK;
996-
case TK_DBAT: return OPR_PEEK2;
996+
case '%': return OPR_PEEK2;
997997
case '$': return OPR_PEEK4;
998998
case '#': return OPR_LEN;
999999
default: return OPR_NOUNOPR;
@@ -1040,10 +1040,10 @@ static const struct {
10401040
{11, 11}, {11, 11}, {11, 11}, /* `*' `/' `%' */
10411041
{13, 12}, /* ^ (right associative) */
10421042
{11, 11}, /* `\' */
1043-
{8, 8}, {6, 6}, {7, 7}, /* `&' `|' `^^' */
1044-
{9, 9}, {9, 9}, {9, 9}, /* `<<' `>>' `>>>' */
1045-
{9, 9}, {9, 9}, /* `<<>' `>><' */
1046-
{5, 4}, /* .. (right associative) */
1043+
{6, 6}, {4, 4}, {5, 5}, /* `&' `|' `^^' */
1044+
{7, 7}, {7, 7}, {7, 7}, /* `<<' `>>' `>>>' */
1045+
{7, 7}, {7, 7}, /* `<<>' `>><' */
1046+
{9, 8}, /* .. (right associative) */
10471047
{3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
10481048
{3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
10491049
{2, 2}, {1, 1} /* and, or */

‎lpico8lib.c

+5-13
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,27 @@ static int pico8_bnot(lua_State *l) {
114114
}
115115

116116
static int pico8_shl(lua_State *l) {
117-
// XXX: not exactly the same as fix32::operator<<
118-
// If y is negative, it is interpreted modulo 32.
119-
// If y is >= 32, result is always zero.
120-
int32_t xbits = lua_tonumber(l, 1).bits();
121-
int y = (int)lua_tonumber(l, 2);
122-
lua_pushnumber(l, lua_Number::frombits(y >= 32 ? 0 : xbits << (y & 0x1f)));
117+
lua_pushnumber(l, lua_tonumber(l, 1) << int(lua_tonumber(l, 2)));
123118
return 1;
124119
}
125120

126121
static int pico8_lshr(lua_State *l) {
127-
// XXX: not exactly the same as fix32::lshr
128-
uint32_t xbits = uint32_t(lua_tonumber(l, 1).bits());
129-
int y = int(lua_tonumber(l, 2));
130-
lua_pushnumber(l, lua_Number::frombits(y >= 32 ? 0 : xbits >> (y & 0x1f)));
122+
lua_pushnumber(l, lua_Number::lshr(lua_tonumber(l, 1), int(lua_tonumber(l, 2))));
131123
return 1;
132124
}
133125

134126
static int pico8_shr(lua_State *l) {
135-
lua_pushnumber(l, lua_tonumber(l, 1) >> (int)lua_tonumber(l, 2));
127+
lua_pushnumber(l, lua_tonumber(l, 1) >> int(lua_tonumber(l, 2)));
136128
return 1;
137129
}
138130

139131
static int pico8_rotl(lua_State *l) {
140-
lua_pushnumber(l, lua_Number::rotl(lua_tonumber(l, 1), (int)lua_tonumber(l, 2)));
132+
lua_pushnumber(l, lua_Number::rotl(lua_tonumber(l, 1), int(lua_tonumber(l, 2))));
141133
return 1;
142134
}
143135

144136
static int pico8_rotr(lua_State *l) {
145-
lua_pushnumber(l, lua_Number::rotr(lua_tonumber(l, 1), (int)lua_tonumber(l, 2)));
137+
lua_pushnumber(l, lua_Number::rotr(lua_tonumber(l, 1), int(lua_tonumber(l, 2))));
146138
return 1;
147139
}
148140

‎lua.c

-3
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@ int main (int argc, char **argv) {
484484
l_message(argv[0], "cannot create state: not enough memory");
485485
return EXIT_FAILURE;
486486
}
487-
unsigned char ram[65536];
488-
for (int i = 0; i < 65536; ++i) ram[i] = i %256;
489-
lua_setpico8memory(L, ram);
490487
/* call 'pmain' in protected mode */
491488
lua_pushcfunction(L, &pmain);
492489
lua_pushinteger(L, argc); /* 1st argument */

0 commit comments

Comments
 (0)