projects
/
fur
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e087351
)
Removed not-yet-relevant string type
author
David Kerkeslager
<kerkeslager@gmail.com>
Tue, 8 Aug 2017 04:01:35 +0000
(
00:01
-0400)
committer
David Kerkeslager
<kerkeslager@gmail.com>
Tue, 8 Aug 2017 04:01:35 +0000
(
00:01
-0400)
templates/program.c
patch
|
blob
|
history
diff --git
a/templates/program.c
b/templates/program.c
index
1d283be
..
3b65e02
100644
(file)
--- a/
templates/program.c
+++ b/
templates/program.c
@@
-19,12
+19,6
@@
typedef struct Object Object;
struct Runtime;
typedef struct Runtime Runtime;
struct Runtime;
typedef struct Runtime Runtime;
-struct String
-{
- size_t length;
- char* characters;
-};
-
const char * const SYMBOL_LIST[] = {
{% for symbol in symbol_list %}
"{{ symbol }}",
const char * const SYMBOL_LIST[] = {
{% for symbol in symbol_list %}
"{{ symbol }}",
@@
-42,7
+36,7
@@
union Instance
{
bool boolean;
int32_t integer;
{
bool boolean;
int32_t integer;
-
String
* string;
+
char
* string;
};
struct Object
};
struct Object
@@
-127,7
+121,7
@@
struct Runtime
{
size_t permanentStringsLength;
size_t permanentStringsAllocated;
{
size_t permanentStringsLength;
size_t permanentStringsAllocated;
-
String
** permanentStrings;
+
char
** permanentStrings;
};
Runtime* Runtime_construct()
};
Runtime* Runtime_construct()
@@
-141,16
+135,11
@@
Runtime* Runtime_construct()
void Runtime_destruct(Runtime* self)
{
void Runtime_destruct(Runtime* self)
{
- for(size_t i = 0; i < self->permanentStringsLength; i++)
- {
- free(self->permanentStrings[i]);
- }
-
free(self->permanentStrings);
free(self);
}
free(self->permanentStrings);
free(self);
}
-void Runtime_addPermanentString(Runtime* self,
String*
string)
+void Runtime_addPermanentString(Runtime* self,
char* const
string)
{
// TODO Make this function thread-safe
if(self->permanentStringsLength == self->permanentStringsAllocated)
{
// TODO Make this function thread-safe
if(self->permanentStringsLength == self->permanentStringsAllocated)
@@
-166,7
+155,7
@@
void Runtime_addPermanentString(Runtime* self, String* string)
self->permanentStrings = realloc(
self->permanentStrings,
self->permanentStrings = realloc(
self->permanentStrings,
- sizeof(
String*
) * self->permanentStringsAllocated
+ sizeof(
char* const
) * self->permanentStringsAllocated
);
// TODO Handle realloc returning NULL
);
// TODO Handle realloc returning NULL
@@
-184,17
+173,13
@@
Object integerLiteral(int32_t literal)
return result;
}
return result;
}
-Object stringLiteral(Runtime* runtime, c
onst c
har* literal)
+Object stringLiteral(Runtime* runtime, char* literal)
{
{
- String* resultString = malloc(sizeof(String));
- resultString->length = strlen(literal);
- resultString->characters = malloc(resultString->length);
- memcpy(resultString->characters, literal, resultString->length);
- Runtime_addPermanentString(runtime, resultString);
+ Runtime_addPermanentString(runtime, literal);
Object result;
result.type = STRING;
Object result;
result.type = STRING;
- result.instance.string =
resultString
;
+ result.instance.string =
literal
;
return result;
}
return result;
}
@@
-364,7
+349,7
@@
void builtin$print(Object output)
case STRING:
// Using fwrite instead of printf to handle size_t length
case STRING:
// Using fwrite instead of printf to handle size_t length
-
fwrite(output.instance.string->characters, 1, output.instance.string->length, stdout
);
+
printf("%s", output.instance.string
);
break;
default:
break;
default: