Debian Codegraph @

terps/alan3/literal.c

raw symbols SCIP
1 /*----------------------------------------------------------------------*\
2
3 literal
4
5 \*----------------------------------------------------------------------*/
6 #include "literal.h"
7
8 /* IMPORTS */
9 #include <strings.h>
10 #include "types.h"
11 #include "memory.h"
12
13
14 /* CONSTANTS */
15
16
17 /* PUBLIC DATA */
18 int litCount = 0;
19 static LiteralEntry literalTable[100];
20 LiteralEntry *literals = literalTable;
21
22
23 /* PRIVATE TYPES & DATA */
24
25
26 /*+++++++++++++++++++++++++++++++++++++++++++++++++++*/
27
28 /*======================================================================*/
29 int instanceFromLiteral(int literalIndex) {
30 return literalIndex + header->instanceMax;
31 }
32
33 /*----------------------------------------------------------------------*/
34 void createIntegerLiteral(int integerValue) {
35 litCount++;
36 literals[litCount].class = header->integerClassId;
37 literals[litCount].type = NUMERIC_LITERAL;
38 literals[litCount].value = integerValue;
39 }
40
41 /*----------------------------------------------------------------------*/
42 static char *copyAndQuoteDollarSigns(char *unquotedString) {
43 char *quotedString = (char *)allocate(strlen(unquotedString)*2+1);
44 char *source = unquotedString;
45 char *destination = quotedString;
46 while (*source != '\0') {
47 if (*source == '$') {
48 *destination++ = '$';
49 *destination = '_';
50 } else
51 *destination = *source;
52 source++;
53 destination++;
54 }
55 return quotedString;
56 }
57
58
59 /*----------------------------------------------------------------------*/
60 void createStringLiteral(char *unquotedString) {
61 litCount++;
62 literals[litCount].class = header->stringClassId;
63 literals[litCount].type = STRING_LITERAL;
64 literals[litCount].value = toAptr(copyAndQuoteDollarSigns(unquotedString));
65 }
66
67 /*----------------------------------------------------------------------*/
68 void freeLiterals() {
69 int i;
70
71 for (i = 0; i <= litCount; i++)
72 if (literals[i].type == STRING_LITERAL && literals[i].value != 0) {
73 deallocate((void *)fromAptr(literals[i].value));
74 }
75 litCount = 0;}
76
77
78
79 /*======================================================================*/
80 int literalFromInstance(int instance) {
81 return instance - header->instanceMax;
82 }