diff options
author | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1996-03-06 18:40:10 -0300 |
---|---|---|
committer | Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | 1996-03-06 18:40:10 -0300 |
commit | e33a3b8e0dced86ecae6d7d6e337984c38eb8a33 (patch) | |
tree | 53ebeb99aeb279bc92add542c106015defc8c650 | |
parent | 9a6cccb08c4701755787bfface1933cf052fd59a (diff) | |
download | lua-e33a3b8e0dced86ecae6d7d6e337984c38eb8a33.tar.gz lua-e33a3b8e0dced86ecae6d7d6e337984c38eb8a33.tar.bz2 lua-e33a3b8e0dced86ecae6d7d6e337984c38eb8a33.zip |
now loads size as two words
-rw-r--r-- | undump.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** load bytecodes from files | 3 | ** load bytecodes from files |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char* rcs_undump="$Id: undump.c,v 1.8 1996/03/06 01:41:18 lhf Exp lhf $"; | 6 | char* rcs_undump="$Id: undump.c,v 1.9 1996/03/06 16:01:08 lhf Exp lhf $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -43,7 +43,7 @@ static int LoadWord(FILE* D) | |||
43 | fread(&w,sizeof(w),1,D); | 43 | fread(&w,sizeof(w),1,D); |
44 | if (swapword) | 44 | if (swapword) |
45 | { | 45 | { |
46 | Byte* p=&w; | 46 | Byte* p=&w; /* TODO: need union? */ |
47 | Byte t; | 47 | Byte t; |
48 | t=p[0]; p[0]=p[1]; p[1]=t; | 48 | t=p[0]; p[0]=p[1]; p[1]=t; |
49 | } | 49 | } |
@@ -57,6 +57,15 @@ static char* LoadBlock(int size, FILE* D) | |||
57 | return b; | 57 | return b; |
58 | } | 58 | } |
59 | 59 | ||
60 | static int LoadSize(FILE* D) | ||
61 | { | ||
62 | Word hi=LoadWord(D); | ||
63 | Word lo=LoadWord(D); | ||
64 | int s=(hi<<16)|lo; | ||
65 | if ((Word)s != s) panic("code too long"); | ||
66 | return s; | ||
67 | } | ||
68 | |||
60 | static char* LoadString(FILE* D) | 69 | static char* LoadString(FILE* D) |
61 | { | 70 | { |
62 | return LoadBlock(LoadWord(D),D); | 71 | return LoadBlock(LoadWord(D),D); |
@@ -70,7 +79,7 @@ static void LoadFunction(FILE* D) | |||
70 | TFunc* tf=new(TFunc); | 79 | TFunc* tf=new(TFunc); |
71 | tf->next=NULL; | 80 | tf->next=NULL; |
72 | tf->locvars=NULL; | 81 | tf->locvars=NULL; |
73 | tf->size=LoadWord(D); /* TODO: Long? */ | 82 | tf->size=LoadSize(D); |
74 | tf->lineDefined=LoadWord(D); | 83 | tf->lineDefined=LoadWord(D); |
75 | if (IsMain(tf)) /* new main */ | 84 | if (IsMain(tf)) /* new main */ |
76 | { | 85 | { |
@@ -141,7 +150,7 @@ static void LoadHeader(FILE* D) /* TODO: error handling */ | |||
141 | fread(&f,sizeof(f),1,D); /* a float for testing byte ordering */ | 150 | fread(&f,sizeof(f),1,D); /* a float for testing byte ordering */ |
142 | if (f!=tf) | 151 | if (f!=tf) |
143 | { | 152 | { |
144 | swapfloat=1; | 153 | swapfloat=1; /* TODO: only one test? */ |
145 | if (f!=tf) warn("different float representation"); | 154 | if (f!=tf) warn("different float representation"); |
146 | } | 155 | } |
147 | } | 156 | } |