aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-03-15 10:13:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-03-15 10:13:13 -0300
commit3e1f7318269e56e557d423f07547da1a87ea6d4f (patch)
tree9c9d9eaf2e505ba621cf5e82a3c39dd6c9e2b7ad
parentf86c1367db7fb0559f80ef2025e62e71d8986d86 (diff)
downloadlua-3e1f7318269e56e557d423f07547da1a87ea6d4f.tar.gz
lua-3e1f7318269e56e557d423f07547da1a87ea6d4f.tar.bz2
lua-3e1f7318269e56e557d423f07547da1a87ea6d4f.zip
integration with undump (execution of pre-compiled chuncks)
-rw-r--r--opcode.c58
-rw-r--r--opcode.h3
2 files changed, 32 insertions, 29 deletions
diff --git a/opcode.c b/opcode.c
index d6b9830a..4a6fb62b 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.58 1996/02/22 20:34:33 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.59 1996/03/04 14:46:35 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -18,6 +18,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.58 1996/02/22 20:34:33 roberto Exp roberto $
18#include "table.h" 18#include "table.h"
19#include "lua.h" 19#include "lua.h"
20#include "fallback.h" 20#include "fallback.h"
21#include "undump.h"
21 22
22#define tonumber(o) ((tag(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) 23#define tonumber(o) ((tag(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0))
23#define tostring(o) ((tag(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) 24#define tostring(o) ((tag(o) != LUA_T_STRING) && (lua_tostring(o) != 0))
@@ -128,17 +129,9 @@ static void growstack (void)
128*/ 129*/
129static char *lua_strconc (char *l, char *r) 130static char *lua_strconc (char *l, char *r)
130{ 131{
131 static char *buffer = NULL; 132 int nl = strlen(l);
132 static int buffer_size = 0; 133 char *buffer = luaI_buffer(nl+strlen(r)+1);
133 int nl = strlen(l); 134 strcpy(buffer, l);
134 int n = nl+strlen(r)+1;
135 if (n > buffer_size)
136 {
137 buffer_size = n;
138 luaI_free(buffer);
139 buffer = newvector(buffer_size, char);
140 }
141 strcpy(buffer,l);
142 strcpy(buffer+nl, r); 135 strcpy(buffer+nl, r);
143 return buffer; 136 return buffer;
144} 137}
@@ -171,7 +164,7 @@ static int lua_tonumber (Object *obj)
171*/ 164*/
172static int lua_tostring (Object *obj) 165static int lua_tostring (Object *obj)
173{ 166{
174 static char s[256]; 167 char s[256];
175 if (tag(obj) != LUA_T_NUMBER) 168 if (tag(obj) != LUA_T_NUMBER)
176 return 1; 169 return 1;
177 if ((int) nvalue(obj) == nvalue(obj)) 170 if ((int) nvalue(obj) == nvalue(obj))
@@ -179,8 +172,6 @@ static int lua_tostring (Object *obj)
179 else 172 else
180 sprintf (s, "%g", nvalue(obj)); 173 sprintf (s, "%g", nvalue(obj));
181 tsvalue(obj) = lua_createstring(s); 174 tsvalue(obj) = lua_createstring(s);
182 if (tsvalue(obj) == NULL)
183 return 1;
184 tag(obj) = LUA_T_STRING; 175 tag(obj) = LUA_T_STRING;
185 return 0; 176 return 0;
186} 177}
@@ -500,6 +491,16 @@ static int do_protectedrun (int nResults)
500 return status; 491 return status;
501} 492}
502 493
494int luaI_dorun (TFunc *tf)
495{
496 int status;
497 adjustC(1); /* one slot for the pseudo-function */
498 stack[CBase].tag = LUA_T_FUNCTION;
499 stack[CBase].value.tf = tf;
500 status = do_protectedrun(0);
501 adjustC(0);
502 return status;
503}
503 504
504static int do_protectedmain (void) 505static int do_protectedmain (void)
505{ 506{
@@ -508,15 +509,12 @@ static int do_protectedmain (void)
508 jmp_buf myErrorJmp; 509 jmp_buf myErrorJmp;
509 jmp_buf *oldErr = errorJmp; 510 jmp_buf *oldErr = errorJmp;
510 errorJmp = &myErrorJmp; 511 errorJmp = &myErrorJmp;
511 adjustC(1); /* one slot for the pseudo-function */
512 stack[CBase].tag = LUA_T_FUNCTION;
513 stack[CBase].value.tf = &tf;
514 luaI_initTFunc(&tf); 512 luaI_initTFunc(&tf);
515 tf.fileName = lua_parsedfile; 513 tf.fileName = lua_parsedfile;
516 if (setjmp(myErrorJmp) == 0) 514 if (setjmp(myErrorJmp) == 0)
517 { 515 {
518 lua_parse(&tf); 516 lua_parse(&tf);
519 status = do_protectedrun(0); 517 status = luaI_dorun(&tf);
520 } 518 }
521 else 519 else
522 { 520 {
@@ -561,9 +559,13 @@ int lua_call (char *funcname)
561int lua_dofile (char *filename) 559int lua_dofile (char *filename)
562{ 560{
563 int status; 561 int status;
564 if (lua_openfile(filename)) 562 int c;
563 FILE *f = lua_openfile(filename);
564 if (f == NULL)
565 return 1; 565 return 1;
566 status = do_protectedmain(); 566 c = fgetc(f);
567 ungetc(c, f);
568 status = (c == ID_CHUNK) ? luaI_undump(f) : do_protectedmain();
567 lua_closefile(); 569 lua_closefile();
568 return status; 570 return status;
569} 571}
@@ -622,8 +624,9 @@ static StkId Cblocks[MAX_C_BLOCKS];
622*/ 624*/
623void lua_beginblock (void) 625void lua_beginblock (void)
624{ 626{
625 if (numCblocks < MAX_C_BLOCKS) 627 if (numCblocks >= MAX_C_BLOCKS)
626 Cblocks[numCblocks] = CBase; 628 lua_error("`lua_beginblock': too many nested blocks");
629 Cblocks[numCblocks] = CBase;
627 numCblocks++; 630 numCblocks++;
628} 631}
629 632
@@ -633,11 +636,8 @@ void lua_beginblock (void)
633void lua_endblock (void) 636void lua_endblock (void)
634{ 637{
635 --numCblocks; 638 --numCblocks;
636 if (numCblocks < MAX_C_BLOCKS) 639 CBase = Cblocks[numCblocks];
637 { 640 adjustC(0);
638 CBase = Cblocks[numCblocks];
639 adjustC(0);
640 }
641} 641}
642 642
643/* 643/*
@@ -793,6 +793,8 @@ void lua_pushstring (char *s)
793 } 793 }
794 incr_top; 794 incr_top;
795} 795}
796/*>>>>>>>>>#undef lua_pushliteral
797void lua_pushliteral(char *s) { lua_pushstring(s); }*/
796 798
797/* 799/*
798** Push an object (tag=cfunction) to stack. 800** Push an object (tag=cfunction) to stack.
diff --git a/opcode.h b/opcode.h
index ec5b45ca..9b404a83 100644
--- a/opcode.h
+++ b/opcode.h
@@ -1,6 +1,6 @@
1/* 1/*
2** TeCGraf - PUC-Rio 2** TeCGraf - PUC-Rio
3** $Id: opcode.h,v 3.18 1996/03/01 16:54:00 roberto Exp $ 3** $Id: opcode.h,v 3.19 1996/03/06 13:11:23 roberto Exp $
4*/ 4*/
5 5
6#ifndef opcode_h 6#ifndef opcode_h
@@ -138,5 +138,6 @@ void lua_travstack (int (*fn)(Object *));
138Object *luaI_Address (lua_Object o); 138Object *luaI_Address (lua_Object o);
139void luaI_pushobject (Object *o); 139void luaI_pushobject (Object *o);
140void luaI_gcFB (Object *o); 140void luaI_gcFB (Object *o);
141int luaI_dorun (TFunc *tf);
141 142
142#endif 143#endif