fallback list moved from opcode.c to fallback.c
This commit is contained in:
42
fallback.c
42
fallback.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_fallback="$Id: fallback.c,v 1.2 1994/11/08 19:56:39 roberto Exp roberto $";
|
char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -14,6 +14,46 @@ char *rcs_fallback="$Id: fallback.c,v 1.2 1994/11/08 19:56:39 roberto Exp robert
|
|||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Warning: This list must be in the same order as the #define's
|
||||||
|
*/
|
||||||
|
struct FB luaI_fallBacks[] = {
|
||||||
|
{"error", {LUA_T_CFUNCTION, luaI_errorFB}},
|
||||||
|
{"index", {LUA_T_CFUNCTION, luaI_indexFB}},
|
||||||
|
{"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}},
|
||||||
|
{"arith", {LUA_T_CFUNCTION, luaI_arithFB}},
|
||||||
|
{"order", {LUA_T_CFUNCTION, luaI_orderFB}},
|
||||||
|
{"concat", {LUA_T_CFUNCTION, luaI_concatFB}},
|
||||||
|
{"unminus", {LUA_T_CFUNCTION, luaI_arithFB}},
|
||||||
|
{"settable", {LUA_T_CFUNCTION, luaI_gettableFB}}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB))
|
||||||
|
|
||||||
|
void luaI_setfallback (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *name = lua_getstring(lua_getparam(1));
|
||||||
|
lua_Object func = lua_getparam(2);
|
||||||
|
if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func)))
|
||||||
|
{
|
||||||
|
lua_pushnil();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i=0; i<N_FB; i++)
|
||||||
|
{
|
||||||
|
if (strcmp(luaI_fallBacks[i].kind, name) == 0)
|
||||||
|
{
|
||||||
|
luaI_pushobject(&luaI_fallBacks[i].function);
|
||||||
|
luaI_fallBacks[i].function = *luaI_Address(func);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* name not found */
|
||||||
|
lua_pushnil();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaI_errorFB (void)
|
void luaI_errorFB (void)
|
||||||
{
|
{
|
||||||
lua_Object o = lua_getparam(1);
|
lua_Object o = lua_getparam(1);
|
||||||
|
|||||||
17
fallback.h
17
fallback.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: fallback.h,v 1.1 1994/11/07 15:20:56 roberto Exp roberto $
|
** $Id: fallback.h,v 1.2 1994/11/08 19:56:39 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef fallback_h
|
#ifndef fallback_h
|
||||||
@@ -7,6 +7,21 @@
|
|||||||
|
|
||||||
#include "opcode.h"
|
#include "opcode.h"
|
||||||
|
|
||||||
|
extern struct FB {
|
||||||
|
char *kind;
|
||||||
|
Object function;
|
||||||
|
} luaI_fallBacks[];
|
||||||
|
|
||||||
|
#define FB_ERROR 0
|
||||||
|
#define FB_INDEX 1
|
||||||
|
#define FB_GETTABLE 2
|
||||||
|
#define FB_ARITH 3
|
||||||
|
#define FB_ORDER 4
|
||||||
|
#define FB_CONCAT 5
|
||||||
|
#define FB_UNMINUS 6
|
||||||
|
#define FB_SETTABLE 7
|
||||||
|
|
||||||
|
void luaI_setfallback (void);
|
||||||
void luaI_errorFB (void);
|
void luaI_errorFB (void);
|
||||||
void luaI_indexFB (void);
|
void luaI_indexFB (void);
|
||||||
void luaI_gettableFB (void);
|
void luaI_gettableFB (void);
|
||||||
|
|||||||
74
opcode.c
74
opcode.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_opcode="$Id: opcode.c,v 3.6 1994/11/08 19:56:39 roberto Exp roberto $";
|
char *rcs_opcode="$Id: opcode.c,v 3.7 1994/11/09 18:13:29 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -50,65 +50,13 @@ static int lua_execute (Byte *pc, int base);
|
|||||||
static void do_call (Object *func, int base, int nResults, int whereRes);
|
static void do_call (Object *func, int base, int nResults, int whereRes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Object *luaI_Address (lua_Object o)
|
Object *luaI_Address (lua_Object o)
|
||||||
{
|
{
|
||||||
return Address(o);
|
return Address(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Fallbacks
|
|
||||||
*/
|
|
||||||
|
|
||||||
static struct FB {
|
|
||||||
char *kind;
|
|
||||||
Object function;
|
|
||||||
} fallBacks[] = {
|
|
||||||
#define FB_ERROR 0
|
|
||||||
{"error", {LUA_T_CFUNCTION, luaI_errorFB}},
|
|
||||||
#define FB_INDEX 1
|
|
||||||
{"index", {LUA_T_CFUNCTION, luaI_indexFB}},
|
|
||||||
#define FB_GETTABLE 2
|
|
||||||
{"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}},
|
|
||||||
#define FB_ARITH 3
|
|
||||||
{"arith", {LUA_T_CFUNCTION, luaI_arithFB}},
|
|
||||||
#define FB_ORDER 4
|
|
||||||
{"order", {LUA_T_CFUNCTION, luaI_orderFB}},
|
|
||||||
#define FB_CONCAT 5
|
|
||||||
{"concat", {LUA_T_CFUNCTION, luaI_concatFB}},
|
|
||||||
#define FB_UNMINUS 6
|
|
||||||
{"unminus", {LUA_T_CFUNCTION, luaI_arithFB}},
|
|
||||||
#define FB_SETTABLE 7
|
|
||||||
{"settable", {LUA_T_CFUNCTION, luaI_gettableFB}}
|
|
||||||
};
|
|
||||||
|
|
||||||
#define N_FB (sizeof(fallBacks)/sizeof(struct FB))
|
|
||||||
|
|
||||||
|
|
||||||
void luaI_setfallback (void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *name = lua_getstring(lua_getparam(1));
|
|
||||||
lua_Object func = lua_getparam(2);
|
|
||||||
if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func)))
|
|
||||||
{
|
|
||||||
lua_pushnil();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (i=0; i<N_FB; i++)
|
|
||||||
{
|
|
||||||
if (strcmp(fallBacks[i].kind, name) == 0)
|
|
||||||
{
|
|
||||||
luaI_pushobject(&fallBacks[i].function);
|
|
||||||
fallBacks[i].function = *Address(func);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* name not found */
|
|
||||||
lua_pushnil();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Error messages
|
** Error messages
|
||||||
*/
|
*/
|
||||||
@@ -116,7 +64,7 @@ void luaI_setfallback (void)
|
|||||||
static void lua_message (char *s)
|
static void lua_message (char *s)
|
||||||
{
|
{
|
||||||
lua_pushstring(s);
|
lua_pushstring(s);
|
||||||
do_call(&fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1);
|
do_call(&luaI_fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -311,12 +259,12 @@ static void do_call (Object *func, int base, int nResults, int whereRes)
|
|||||||
static void pushsubscript (void)
|
static void pushsubscript (void)
|
||||||
{
|
{
|
||||||
if (tag(top-2) != LUA_T_ARRAY)
|
if (tag(top-2) != LUA_T_ARRAY)
|
||||||
do_call(&fallBacks[FB_GETTABLE].function, (top-stack)-2, 1, (top-stack)-2);
|
do_call(&luaI_fallBacks[FB_GETTABLE].function, (top-stack)-2, 1, (top-stack)-2);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Object *h = lua_hashget(avalue(top-2), top-1);
|
Object *h = lua_hashget(avalue(top-2), top-1);
|
||||||
if (h == NULL)
|
if (h == NULL)
|
||||||
do_call(&fallBacks[FB_INDEX].function, (top-stack)-2, 1, (top-stack)-2);
|
do_call(&luaI_fallBacks[FB_INDEX].function, (top-stack)-2, 1, (top-stack)-2);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
--top;
|
--top;
|
||||||
@@ -332,7 +280,7 @@ static void pushsubscript (void)
|
|||||||
static void storesubscript (void)
|
static void storesubscript (void)
|
||||||
{
|
{
|
||||||
if (tag(top-3) != LUA_T_ARRAY)
|
if (tag(top-3) != LUA_T_ARRAY)
|
||||||
do_call(&fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3);
|
do_call(&luaI_fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Object *h = lua_hashdefine (avalue(top-3), top-2);
|
Object *h = lua_hashdefine (avalue(top-3), top-2);
|
||||||
@@ -688,7 +636,7 @@ int lua_type (lua_Object o)
|
|||||||
static void call_arith (char *op)
|
static void call_arith (char *op)
|
||||||
{
|
{
|
||||||
lua_pushstring(op);
|
lua_pushstring(op);
|
||||||
do_call(&fallBacks[FB_ARITH].function, (top-stack)-3, 1, (top-stack)-3);
|
do_call(&luaI_fallBacks[FB_ARITH].function, (top-stack)-3, 1, (top-stack)-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void comparison (lua_Type tag_less, lua_Type tag_equal,
|
static void comparison (lua_Type tag_less, lua_Type tag_equal,
|
||||||
@@ -702,7 +650,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal,
|
|||||||
else if (tostring(l) || tostring(r))
|
else if (tostring(l) || tostring(r))
|
||||||
{
|
{
|
||||||
lua_pushstring(op);
|
lua_pushstring(op);
|
||||||
do_call(&fallBacks[FB_ORDER].function, (top-stack)-3, 1, (top-stack)-3);
|
do_call(&luaI_fallBacks[FB_ORDER].function, (top-stack)-3, 1, (top-stack)-3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -824,7 +772,7 @@ static int lua_execute (Byte *pc, int base)
|
|||||||
*(top) = *(top-2-n);
|
*(top) = *(top-2-n);
|
||||||
*(top-1) = *(top-3-n);
|
*(top-1) = *(top-3-n);
|
||||||
top += 2;
|
top += 2;
|
||||||
do_call(&fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3);
|
do_call(&luaI_fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1016,7 +964,7 @@ static int lua_execute (Byte *pc, int base)
|
|||||||
Object *l = top-2;
|
Object *l = top-2;
|
||||||
Object *r = top-1;
|
Object *r = top-1;
|
||||||
if (tostring(r) || tostring(l))
|
if (tostring(r) || tostring(l))
|
||||||
do_call(&fallBacks[FB_CONCAT].function, (top-stack)-2, 1, (top-stack)-2);
|
do_call(&luaI_fallBacks[FB_CONCAT].function, (top-stack)-2, 1, (top-stack)-2);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
svalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r)));
|
svalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r)));
|
||||||
@@ -1027,7 +975,7 @@ static int lua_execute (Byte *pc, int base)
|
|||||||
|
|
||||||
case MINUSOP:
|
case MINUSOP:
|
||||||
if (tonumber(top-1))
|
if (tonumber(top-1))
|
||||||
do_call(&fallBacks[FB_UNMINUS].function, (top-stack)-1, 1, (top-stack)-1);
|
do_call(&luaI_fallBacks[FB_UNMINUS].function, (top-stack)-1, 1, (top-stack)-1);
|
||||||
else
|
else
|
||||||
nvalue(top-1) = - nvalue(top-1);
|
nvalue(top-1) = - nvalue(top-1);
|
||||||
break;
|
break;
|
||||||
|
|||||||
3
opcode.h
3
opcode.h
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** TeCGraf - PUC-Rio
|
** TeCGraf - PUC-Rio
|
||||||
** $Id: opcode.h,v 3.5 1994/11/07 16:34:44 roberto Exp roberto $
|
** $Id: opcode.h,v 3.6 1994/11/09 18:10:58 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef opcode_h
|
#ifndef opcode_h
|
||||||
@@ -160,7 +160,6 @@ char *lua_lasttext (void); /* from "lex.c" module */
|
|||||||
int yylex (void); /* from "lex.c" module */
|
int yylex (void); /* from "lex.c" module */
|
||||||
void lua_parse (Byte **code); /* from "lua.stx" module */
|
void lua_parse (Byte **code); /* from "lua.stx" module */
|
||||||
void lua_travstack (void (*fn)(Object *));
|
void lua_travstack (void (*fn)(Object *));
|
||||||
void luaI_setfallback (void);
|
|
||||||
Object *luaI_Address (lua_Object o);
|
Object *luaI_Address (lua_Object o);
|
||||||
void luaI_pushobject (Object *o);
|
void luaI_pushobject (Object *o);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user