aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
commit2b5bc5d1a81579a76c13e638de2592e2c39c73f0 (patch)
tree8294278f9fbd2565d3a2cd11642fed41982824bd /opcode.c
parent94686ce58554a80374eeff115ee5b87c184ed173 (diff)
downloadlua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.gz
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.bz2
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.zip
new module for memory allocation
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/opcode.c b/opcode.c
index 7f5f8bd6..b6955aee 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,17 +3,14 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.11 1994/11/13 16:17:04 roberto Exp $"; 6char *rcs_opcode="$Id: opcode.c,v 3.12 1994/11/16 16:03:48 roberto Exp roberto $";
7 7
8#include <setjmp.h>
8#include <stdio.h> 9#include <stdio.h>
9#include <stdlib.h>
10#include <string.h> 10#include <string.h>
11#include <setjmp.h>
12#include <math.h> 11#include <math.h>
13#ifdef __GNUC__
14#include <floatingpoint.h>
15#endif
16 12
13#include "mem.h"
17#include "opcode.h" 14#include "opcode.h"
18#include "hash.h" 15#include "hash.h"
19#include "inout.h" 16#include "inout.h"
@@ -89,9 +86,7 @@ void lua_error (char *s)
89static void lua_initstack (void) 86static void lua_initstack (void)
90{ 87{
91 maxstack = STACK_BUFFER; 88 maxstack = STACK_BUFFER;
92 stack = (Object *)calloc(maxstack, sizeof(Object)); 89 stack = newvector(maxstack, Object);
93 if (stack == NULL)
94 lua_error("stack - not enough memory");
95 top = stack; 90 top = stack;
96} 91}
97 92
@@ -108,9 +103,7 @@ static void lua_checkstack (Word n)
108 lua_initstack(); 103 lua_initstack();
109 t = top-stack; 104 t = top-stack;
110 maxstack *= 2; 105 maxstack *= 2;
111 stack = (Object *)realloc(stack, maxstack*sizeof(Object)); 106 stack = growvector(stack, maxstack, Object);
112 if (stack == NULL)
113 lua_error("stack - not enough memory");
114 top = stack + t; 107 top = stack + t;
115 } 108 }
116} 109}
@@ -126,16 +119,11 @@ static char *lua_strconc (char *l, char *r)
126 int nl = strlen(l); 119 int nl = strlen(l);
127 int n = nl+strlen(r)+1; 120 int n = nl+strlen(r)+1;
128 if (n > buffer_size) 121 if (n > buffer_size)
129 { 122 {
130 buffer_size = n; 123 buffer_size = n;
131 if (buffer != NULL) 124 if (buffer != NULL)
132 free(buffer); 125 luaI_free(buffer);
133 buffer = (char *)malloc(buffer_size); 126 buffer = newvector(buffer_size, char);
134 if (buffer == NULL)
135 {
136 buffer_size = 0;
137 lua_error("concat - not enough memory");
138 }
139 } 127 }
140 strcpy(buffer,l); 128 strcpy(buffer,l);
141 strcpy(buffer+nl, r); 129 strcpy(buffer+nl, r);
@@ -149,11 +137,10 @@ static char *lua_strconc (char *l, char *r)
149*/ 137*/
150static int lua_tonumber (Object *obj) 138static int lua_tonumber (Object *obj)
151{ 139{
152 char c;
153 float t; 140 float t;
154 if (tag(obj) != LUA_T_STRING) 141 if (tag(obj) != LUA_T_STRING)
155 return 1; 142 return 1;
156 else if (sscanf(svalue(obj), "%f %c",&t,&c) == 1) 143 else if (sscanf(svalue(obj), "%f %*c",&t) == 1)
157 { 144 {
158 nvalue(obj) = t; 145 nvalue(obj) = t;
159 tag(obj) = LUA_T_NUMBER; 146 tag(obj) = LUA_T_NUMBER;
@@ -353,7 +340,7 @@ static int do_protectedmain (void)
353 else 340 else
354 status = 1; 341 status = 1;
355 if (code) 342 if (code)
356 free(code); 343 luaI_free(code);
357 errorJmp = oldErr; 344 errorJmp = oldErr;
358 CBase = oldCBase; 345 CBase = oldCBase;
359 top = stack+CBase; 346 top = stack+CBase;
@@ -467,9 +454,9 @@ int lua_storesubscript (void)
467lua_Object lua_createTable (int initSize) 454lua_Object lua_createTable (int initSize)
468{ 455{
469 adjustC(0); 456 adjustC(0);
457 tag(top) = LUA_T_ARRAY;
458 avalue(top) = lua_createarray(initSize);
470 top++; 459 top++;
471 tag(top-1) = LUA_T_ARRAY;
472 avalue(top-1) = lua_createarray(initSize);
473 CBase++; /* incorporate object in the stack */ 460 CBase++; /* incorporate object in the stack */
474 return Ref(top-1); 461 return Ref(top-1);
475} 462}
@@ -540,7 +527,8 @@ void *lua_getuserdata (lua_Object object)
540lua_Object lua_getlocked (int ref) 527lua_Object lua_getlocked (int ref)
541{ 528{
542 adjustC(0); 529 adjustC(0);
543 *(top++) = *luaI_getlocked(ref); 530 *top = *luaI_getlocked(ref);
531 top++;
544 CBase++; /* incorporate object in the stack */ 532 CBase++; /* incorporate object in the stack */
545 return Ref(top-1); 533 return Ref(top-1);
546} 534}
@@ -552,7 +540,8 @@ lua_Object lua_getglobal (char *name)
552{ 540{
553 int n = luaI_findsymbolbyname(name); 541 int n = luaI_findsymbolbyname(name);
554 adjustC(0); 542 adjustC(0);
555 *(top++) = s_object(n); 543 *top = s_object(n);
544 top++;
556 CBase++; /* incorporate object in the stack */ 545 CBase++; /* incorporate object in the stack */
557 return Ref(top-1); 546 return Ref(top-1);
558} 547}
@@ -854,9 +843,9 @@ static int lua_execute (Byte *pc, int base)
854 { 843 {
855 CodeWord size; 844 CodeWord size;
856 get_word(size,pc); 845 get_word(size,pc);
846 tag(top) = LUA_T_ARRAY;
847 avalue(top) = lua_createarray(size.w);
857 top++; 848 top++;
858 tag(top-1) = LUA_T_ARRAY;
859 avalue(top-1) = lua_createarray(size.w);
860 } 849 }
861 break; 850 break;
862 851