Skip to content

Commit

Permalink
Attempting to run eve_string_concat for the + operator; currently seg…
Browse files Browse the repository at this point in the history
…faults.
  • Loading branch information
Jonathan Tang committed Feb 8, 2010
1 parent 5b4aaed commit 1cf98a1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bootstrap_compiler/CodeGen.hs
Expand Up @@ -93,6 +93,8 @@ constInt :: Int -> FFI.ValueRef
constInt n = FFI.constInt FFI.int32Type (fromIntegral n) 1

externData = [
("add", ("eve_string_concat",
functionType False [stringType, stringType] stringType)),
("print", ("puts", functionType False [cStringType] FFI.int32Type))
]

Expand Down
3 changes: 2 additions & 1 deletion bootstrap_compiler/Types.hs
Expand Up @@ -75,12 +75,13 @@ type Assumptions = [(String, Type)]
intBinop = tFunc [tInt, tInt] tInt
intBoolBinop = tFunc [tInt, tInt] tBool
boolBinop = tFunc [tBool, tBool] tBool
stringBinop = tFunc [tString, tString] tString

defaultAssumptions = [
("pow", intBinop),
("mul", intBinop),
("div", intBinop),
("add", intBinop),
("add", stringBinop),
("sub", intBinop),
("eq", intBoolBinop),
("ne", intBoolBinop),
Expand Down
11 changes: 9 additions & 2 deletions runtime/strings.c
@@ -1,15 +1,22 @@
#include <stdlib.h>
#include <strings.h>

#include "process.h"
#include "heap.h"
#include "strings.h"

EveString* eve_new_string(int length) {
EveString* eve_string_new(int length) {
EveHeap* heap = eve_process_get_heap(eve_get_current_process());
EveString* retval = (EveString*) eve_gcmalloc(
heap, (size_t) length + sizeof(int) + sizeof(char));
retval->length = length;
retval->c[length] = '\0';
return retval;
return NULL;
}

EveString* eve_string_concat(EveString* str1, EveString* str2) {
EveString* retval = eve_string_new(str1->length + str2->length);
strncpy(retval->c, str1->c, str1->length);
strncpy(retval->c + str1->length, str2->c, str2->length);
return retval;
}
3 changes: 2 additions & 1 deletion runtime/strings.h
Expand Up @@ -6,6 +6,7 @@ typedef struct {
char c[];
} EveString;

EveString* eve_new_string(int length);
EveString* eve_string_new(int length);
EveString* eve_string_concat(EveString* str1, EveString* str2);

#endif

0 comments on commit 1cf98a1

Please sign in to comment.