Skip to content

Commit

Permalink
work towards making libjulia combilable with a c++ compiler (required…
Browse files Browse the repository at this point in the history
… for MSVC)
  • Loading branch information
tknopp committed Jan 15, 2014
1 parent c6d359b commit 25be69f
Show file tree
Hide file tree
Showing 37 changed files with 269 additions and 224 deletions.
8 changes: 7 additions & 1 deletion Windows.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ WINVER = 0x0600

###############################################################################

!ifdef INTEL
CC = icl /nologo /Qstd=c99
LINK = xilink /nologo
AR = xilib /nologo
!else
CC = cl /nologo /TP
LINK = link /nologo
AR = lib /nologo
!endif

###############################################################################

CFLAGS = /c /DCRTAPI1=_cdecl /DCRTAPI2=_cdecl /GS /D_WINNT /D_WIN32_WINNT=$(WINVER) /DNTDDI_VERSION=$(WINVER)0000 /DWINVER=$(WINVER) /DWIN32 /D_WIN32
LFLAGS = /INCREMENTAL:NO
LFLAGS = /INCREMENTAL:NO /NODEFAULTLIB:MSVCRT

!if "$(CPU)" == "i386"
CFLAGS = $(CFLAGS) /D_X86_=1
Expand Down
10 changes: 7 additions & 3 deletions src/Windows.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ LIBSUPPORT = support\libsupport.lib
LIBUV = ..\deps\libuv\libuv.lib
FLISP = flisp\flisp.exe

INCLUDE = $(INCLUDE);$(MAKEDIR)\..\deps\libuv\include;$(MAKEDIR)\flisp;$(MAKEDIR)\support;C:\Program Files\LLVM\include;
LIB = $(LIB);C:\Program Files\LLVM\lib;
INCLUDE = $(INCLUDE);$(MAKEDIR)\..\deps\libuv\include;$(MAKEDIR)\flisp;$(MAKEDIR)\support;C:\Program Files\llvm\include
!ifdef DEBUG
LIB = $(LIB);C:\Program Files\llvm\lib\Debug
!else
LIB = $(LIB);C:\Program Files\llvm\lib\Release
!endif

CFLAGS = $(CFLAGS) -DCOPY_STACKS -D_CRT_SECURE_NO_WARNINGS
CFLAGS = $(CFLAGS) -DJL_SYSTEM_IMAGE_PATH=\"../lib/julia/sys.ji\"
CFLAGS = $(CFLAGS) -DJL_SYSTEM_IMAGE_PATH=\"../lib/julia/sys.ji\" -DLIBRARY_EXPORTS

LIBWINDOWS = \
kernel32.lib \
Expand Down
42 changes: 21 additions & 21 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ jl_sym_t *jl_symbol_lookup(const char *str)

DLLEXPORT jl_sym_t *jl_symbol_n(const char *str, int32_t len)
{
char name[len+1];
char* name = (char*) alloca(len+1);
memcpy(name, str, len);
name[len] = '\0';
return jl_symbol(name);
Expand All @@ -497,7 +497,7 @@ DLLEXPORT jl_sym_t *jl_gensym(void)
DLLEXPORT jl_sym_t *jl_tagged_gensym(const char* str, int32_t len)
{
static char gs_name[14];
char name[sizeof(gs_name)+len+3];
char *name = (char*) alloca(sizeof(gs_name)+len+3);
char *n;
name[0] = '#'; name[1] = '#'; name[2+len] = '#';
memcpy(name+2, str, len);
Expand Down Expand Up @@ -714,7 +714,7 @@ jl_value_t *jl_box##nb(jl_datatype_t *t, int##nb##_t x) \
{ \
assert(jl_is_bitstype(t)); \
assert(jl_datatype_size(t) == sizeof(x)); \
jl_value_t *v = alloc_##nw##w(); \
jl_value_t *v = (jl_value_t*) alloc_##nw##w(); \
v->type = (jl_value_t*)t; \
*(int##nb##_t*)jl_data_ptr(v) = x; \
return v; \
Expand Down Expand Up @@ -748,13 +748,13 @@ UNBOX_FUNC(float32, float)
UNBOX_FUNC(float64, double)
UNBOX_FUNC(voidpointer, void*)

#define BOX_FUNC(typ,c_type,pfx,nw) \
jl_value_t *pfx##_##typ(c_type x) \
{ \
jl_value_t *v = alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
#define BOX_FUNC(typ,c_type,pfx,nw) \
jl_value_t *pfx##_##typ(c_type x) \
{ \
jl_value_t *v = (jl_value_t*) alloc_##nw##w();\
v->type = (jl_value_t*)jl_##typ##_type; \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
BOX_FUNC(float32, float, jl_box, 2)
BOX_FUNC(voidpointer, void*, jl_box, 2) //2 pointers == two words on all platforms
Expand All @@ -773,21 +773,21 @@ jl_value_t *jl_box_##typ(c_type x) \
c_type idx = x+NBOX_C/2; \
if ((u##c_type)idx < (u##c_type)NBOX_C) \
return boxed_##typ##_cache[idx]; \
jl_value_t *v = alloc_##nw##w(); \
jl_value_t *v = (jl_value_t*) alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
#define UIBOX_FUNC(typ,c_type,nw) \
static jl_value_t *boxed_##typ##_cache[NBOX_C]; \
jl_value_t *jl_box_##typ(c_type x) \
{ \
if (x < NBOX_C) \
return boxed_##typ##_cache[x]; \
jl_value_t *v = alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
#define UIBOX_FUNC(typ,c_type,nw) \
static jl_value_t *boxed_##typ##_cache[NBOX_C]; \
jl_value_t *jl_box_##typ(c_type x) \
{ \
if (x < NBOX_C) \
return boxed_##typ##_cache[x]; \
jl_value_t *v = (jl_value_t*) alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
SIBOX_FUNC(int16, int16_t, 2)
SIBOX_FUNC(int32, int32_t, 2)
Expand Down
22 changes: 11 additions & 11 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
size_t doffs = tsz;
tsz += tot;
tsz = (tsz+15)&-16; // align whole object 16
a = allocobj(tsz);
a = (jl_array_t*) allocobj(tsz);
a->type = atype;
a->how = 0;
data = (char*)a + doffs;
Expand All @@ -83,7 +83,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
}
else {
tsz = (tsz+15)&-16; // align whole object size 16
a = allocobj(tsz);
a = (jl_array_t*) allocobj(tsz);
JL_GC_PUSH1(&a);
a->type = atype;
// temporarily initialize to make gc-safe
Expand Down Expand Up @@ -143,7 +143,7 @@ jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data, jl_tuple_t *di
size_t ndims = jl_tuple_len(dims);

int ndimwords = jl_array_ndimwords(ndims);
a = allocobj((sizeof(jl_array_t) + sizeof(void*) + ndimwords*sizeof(size_t) + 15)&-16);
a = (jl_array_t*) allocobj((sizeof(jl_array_t) + sizeof(void*) + ndimwords*sizeof(size_t) + 15)&-16);
a->type = atype;
a->ndims = ndims;
a->offset = 0;
Expand Down Expand Up @@ -208,7 +208,7 @@ jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data, size_t nel,
else
elsz = sizeof(void*);

a = allocobj((sizeof(jl_array_t)+jl_array_ndimwords(1)*sizeof(size_t)+15)&-16);
a = (jl_array_t*) allocobj((sizeof(jl_array_t)+jl_array_ndimwords(1)*sizeof(size_t)+15)&-16);
a->type = atype;
a->data = data;
#ifdef STORE_ARRAY_LEN
Expand Down Expand Up @@ -256,7 +256,7 @@ jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, jl_tuple_t *dims,
elsz = sizeof(void*);

int ndimwords = jl_array_ndimwords(ndims);
a = allocobj((sizeof(jl_array_t) + ndimwords*sizeof(size_t)+15)&-16);
a = (jl_array_t*) allocobj((sizeof(jl_array_t) + ndimwords*sizeof(size_t)+15)&-16);
a->type = atype;
a->data = data;
#ifdef STORE_ARRAY_LEN
Expand Down Expand Up @@ -292,7 +292,7 @@ jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, jl_tuple_t *dims,
jl_array_t *jl_new_array(jl_value_t *atype, jl_tuple_t *dims)
{
size_t ndims = jl_tuple_len(dims);
size_t *adims = alloca(ndims*sizeof(size_t));
size_t *adims = (size_t*) alloca(ndims*sizeof(size_t));
size_t i;
for(i=0; i < ndims; i++)
adims[i] = jl_unbox_long(jl_tupleref(dims,i));
Expand Down Expand Up @@ -326,9 +326,9 @@ jl_array_t *jl_pchar_to_array(const char *str, size_t len)
jl_value_t *jl_array_to_string(jl_array_t *a)
{
// TODO: check type of array?
jl_datatype_t* string_type = u8_isvalid(a->data, jl_array_len(a)) == 1 ? // ASCII
jl_datatype_t* string_type = u8_isvalid( (char*) a->data, jl_array_len(a)) == 1 ? // ASCII
jl_ascii_string_type : jl_utf8_string_type;
jl_value_t *s = alloc_2w();
jl_value_t *s = (jl_value_t*) alloc_2w();
s->type = (jl_value_t*)string_type;
jl_set_nth_field(s, 0, (jl_value_t*)a);
return s;
Expand Down Expand Up @@ -523,21 +523,21 @@ static void array_resize_buffer(jl_array_t *a, size_t newlen, size_t oldlen, siz
char *newdata;
if (a->how == 2) {
// already malloc'd - use realloc
newdata = jl_gc_managed_realloc((char*)a->data - oldoffsnb, nbytes,
newdata = (char*) jl_gc_managed_realloc((char*)a->data - oldoffsnb, nbytes,
oldnbytes+oldoffsnb, a->isaligned);
if (offs != a->offset) {
memmove(&newdata[offsnb], &newdata[oldoffsnb], oldnbytes);
}
}
else {
if (nbytes >= MALLOC_THRESH) {
newdata = jl_gc_managed_malloc(nbytes);
newdata = (char*) jl_gc_managed_malloc(nbytes);
jl_gc_track_malloced_array(a);
a->how = 2;
a->isaligned = 1;
}
else {
newdata = allocb(nbytes);
newdata = (char*) allocb(nbytes);
a->how = 1;
}
memcpy(newdata + offsnb, (char*)a->data, oldnbytes);
Expand Down
6 changes: 3 additions & 3 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "julia.h"
#include "flisp.h"

static char flisp_system_image[] = {
static uint8_t flisp_system_image[] = {
#include "julia_flisp.boot.inc"
};

Expand Down Expand Up @@ -111,7 +111,7 @@ DLLEXPORT void jl_init_frontend(void)
fl_init(2*512*1024);
value_t img = cvalue(iostreamtype, sizeof(ios_t));
ios_t *pi = value2c(ios_t*, img);
ios_static_buffer(pi, flisp_system_image, sizeof(flisp_system_image));
ios_static_buffer(pi, (char*) flisp_system_image, sizeof(flisp_system_image));

if (fl_load_system_image(img)) {
JL_PRINTF(JL_STDERR, "fatal error loading system image\n");
Expand Down Expand Up @@ -240,7 +240,7 @@ static jl_value_t *scm_to_julia_(value_t e, int eo)
return (jl_value_t*)scmsym_to_julia(e);
}
if (fl_isstring(e)) {
return jl_pchar_to_string(cvalue_data(e), cvalue_len(e));
return jl_pchar_to_string( (char*) cvalue_data(e), cvalue_len(e));
}
if (e == FL_F) {
return jl_false;
Expand Down
3 changes: 2 additions & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ JL_CALLABLE(jl_f_apply)
jl_tuple_len(args[1]));
}
}
jl_value_t **newargs;
size_t n=0, i, j;
for(i=1; i < nargs; i++) {
if (jl_is_tuple(args[i])) {
Expand All @@ -275,7 +276,7 @@ JL_CALLABLE(jl_f_apply)
goto fancy_apply;
}
}
jl_value_t **newargs = alloca(n * sizeof(jl_value_t*));
newargs = (jl_value_t**) alloca(n * sizeof(jl_value_t*));
n = 0;
for(i=1; i < nargs; i++) {
if (jl_is_tuple(args[i])) {
Expand Down
2 changes: 1 addition & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static Type *julia_type_to_llvm(jl_value_t *jt)
return ret;
}
else {
Type *types[ntypes];
Type **types = (Type**) alloca(ntypes*sizeof(Type*));
size_t j = 0;
for (size_t i = 0; i < ntypes; ++i) {
Type *ty = julia_struct_to_llvm(jl_tupleref(jt,i));
Expand Down
2 changes: 1 addition & 1 deletion src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static uv_lib_t *jl_load_dynamic_library_(char *modname, unsigned flags, int thr
char *ext;
char path[PATHBUF];
int i;
uv_lib_t *handle=malloc(sizeof(uv_lib_t));
uv_lib_t *handle = (uv_lib_t*) malloc(sizeof(uv_lib_t));
handle->errmsg=NULL;

if (modname == NULL) {
Expand Down
Loading

0 comments on commit 25be69f

Please sign in to comment.