aboutsummaryrefslogtreecommitdiff
path: root/fallback.c
blob: 68d052b30f39138b57f294e30499273e4aff0d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
** fallback.c
** TecCGraf - PUC-Rio
*/
 
char *rcs_fallback="$Id: fallback.c,v 1.1 1994/11/07 15:20:56 roberto Exp roberto $";

#include <stdio.h>
#include <stdlib.h>
 
#include "fallback.h"
#include "opcode.h"
#include "lua.h"


void luaI_errorFB (void)
{
  lua_Object o = lua_getparam(1);
  if (lua_isstring(o))
    fprintf (stderr, "lua: %s\n", lua_getstring(o));
  else
    fprintf(stderr, "lua: unknown error\n");
}
 

void luaI_indexFB (void)
{
  lua_pushnil();
}
 

void luaI_gettableFB (void)
{
  lua_error("indexed expression not a table");
}
 

void luaI_arithFB (void)
{
  lua_error("unexpected type at conversion to number");
}

void luaI_concatFB (void)
{
  lua_error("unexpected type at conversion to string");
}


void luaI_orderFB (void)
{
  lua_error("unexpected type at comparison");
}


/*
** Lock routines
*/

static Object *lockArray = NULL;
static int lockSize = 0;

int lua_lock (lua_Object object)
{
  int i;
  int oldSize;
  if (lua_isnil(object))
    return -1;
  for (i=0; i<lockSize; i++)
    if (tag(&lockArray[i]) == LUA_T_NIL)
    {
      lockArray[i] = *luaI_Address(object);
      return i;
    }
  /* no more empty spaces */
  oldSize = lockSize;
  if (lockArray == NULL)
  {
    lockSize = 10;
    lockArray = (Object *)malloc(lockSize);
  }
  else
  {
    lockSize = 3*oldSize/2 + 5;
    lockArray = (Object *)realloc(lockArray, lockSize);
  }
  if (lockArray == NULL)
  {
    lockSize = 0;
    lua_error("lock - not enough memory");
  }
  for (i=oldSize; i<lockSize; i++)
    tag(&lockArray[i]) = LUA_T_NIL;
  lockArray[oldSize] = *luaI_Address(object);
  return oldSize;
}


void lua_unlock (int ref)
{
  tag(&lockArray[ref]) = LUA_T_NIL;
}


Object *luaI_getlocked (int ref)
{
  return &lockArray[ref];
}


void luaI_travlock (void (*fn)(Object *))
{
  int i;
  for (i=0; i<lockSize; i++)
    fn(&lockArray[i]);
}