Permalink
Browse files

misc changes for immutable types, updating comments, adding keyword

  • Loading branch information...
1 parent 489fb09 commit f6cc185de968917aebf61e4adda255b978969170 @JeffBezanson JeffBezanson committed Feb 22, 2013
Showing with 54 additions and 45 deletions.
  1. +1 −1 base/base.jl
  2. +2 −2 base/darray.jl
  3. +2 −2 contrib/julia-mode.el
  4. +3 −5 examples/typetree.jl
  5. +20 −20 src/alloc.c
  6. +9 −7 src/ast.c
  7. +1 −2 src/dump.c
  8. +1 −1 src/gf.c
  9. +8 −4 src/jltypes.c
  10. +7 −1 src/julia.h
View
@@ -120,7 +120,7 @@ object_id(x::ANY) = ccall(:jl_object_id, Uint, (Any,), x)
const isimmutable = x->(isa(x,Tuple) || !typeof(x).mutable)
isstructtype(t::DataType) = t.names!=() || (t.size==0 && !t.abstract)
isstructtype(x) = false
-isbits(t::DataType) = !t.mutable && t.pointerfree && isleaftype(t)
+isbits(t::DataType) = !t.mutable && t.pointerfree
isbits(t::Tuple) = false
isbits(t::Type) = false
isbits(x) = isbits(typeof(x))
View
@@ -56,9 +56,9 @@ function serialize{T,N,dd}(s, d::DArray{T,N,dd})
emptylocl = Array(T, ntuple(length(sz), i->(i==d.distdim ? 0 : sz[i])))
invoke(serialize, (Any, Any),
s,
- ccall(:jl_new_structt, Any, (Any, Any),
+ ccall(:jl_new_struct, Any, (Any, Any...),
DArray{T,N,dd},
- (sz, emptylocl, d.pmap, d.dist, d.distdim, 0, d.go)))
+ sz, emptylocl, d.pmap, d.dist, d.distdim, 0, d.go))
else
serialize(s, d.go)
end
View
@@ -70,7 +70,7 @@
"try" "catch" "return" "local" "abstract" "function" "macro" "ccall"
"finally" "typealias" "break" "continue" "type" "global" "@\\w+"
"module" "using" "import" "export" "const" "let" "bitstype" "do"
- "baremodule" "importall")
+ "baremodule" "importall" "immutable")
"\\|") "\\)\\>")
'font-lock-keyword-face)
'("\\<\\(true\\|false\\|C_NULL\\|Inf\\|NaN\\|Inf32\\|NaN32\\|nothing\\)\\>" . font-lock-constant-face)
@@ -82,7 +82,7 @@
(defconst julia-block-start-keywords
(list "if" "while" "for" "begin" "try" "function" "type" "let" "macro"
- "quote" "do"))
+ "quote" "do" "immutable"))
(defconst julia-block-other-keywords
(list "else" "elseif"))
View
@@ -48,9 +48,7 @@ function insert_type(m,s,x,ex)
end
function add_type(x,t,sup)
- if isa(t, AbstractKind) ||
- isa(t, BitsKind) ||
- isa(t, CompositeKind)
+ if isa(t, DataType)
s = sup ? super(t) : t
s_param = ""
if x != string(t.name)
@@ -59,11 +57,11 @@ function add_type(x,t,sup)
s_param *= " (=" * string(s.name) * "{" * join(s.parameters, ", ") * "})"
end
insert_type(children_map, string(s.name), x, s_param)
- elseif isa(t, UnionKind)
+ elseif isa(t, UnionType)
for c in t.types
add_type(x, c, false)
end
- insert_type(children_map, "UnionKind", x, " = " * string(t))
+ insert_type(children_map, "UnionType", x, " = " * string(t))
elseif isa(t, TypeConstructor)
add_type(x, t.body, false)
#println(typeof(t.body))
View
@@ -130,8 +130,7 @@ void jl_assign_bits(void *dest, jl_value_t *bits)
int jl_field_index(jl_datatype_t *t, jl_sym_t *fld, int err)
{
jl_tuple_t *fn = t->names;
- size_t i;
- for(i=0; i < jl_tuple_len(fn); i++) {
+ for(size_t i=0; i < jl_tuple_len(fn); i++) {
if (jl_tupleref(fn,i) == (jl_value_t*)fld) {
return (int)i;
}
@@ -182,45 +181,49 @@ DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...)
if (type->instance != NULL) return type->instance;
va_list args;
size_t nf = jl_tuple_len(type->names);
- size_t i;
va_start(args, type);
jl_value_t *jv = newstruct(type);
- for(i=0; i < nf; i++) {
+ for(size_t i=0; i < nf; i++) {
jl_set_nth_field(jv, i, va_arg(args, jl_value_t*));
}
if (type->size == 0) type->instance = jv;
va_end(args);
return jv;
}
-DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
+DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args, uint32_t na)
{
if (type->instance != NULL) return type->instance;
+ size_t nf = jl_tuple_len(type->names);
jl_value_t *jv = newstruct(type);
+ for(size_t i=0; i < na; i++) {
+ jl_set_nth_field(jv, i, args[i]);
+ }
+ for(size_t i=na; i < nf; i++) {
+ if (type->fields[i].isptr)
+ *(jl_value_t**)((char*)jv+jl_field_offset(type,i)+sizeof(void*)) = NULL;
+ }
if (type->size == 0) type->instance = jv;
- else memset(&((void**)jv)[1], 0, type->size);
return jv;
}
-DLLEXPORT jl_value_t *jl_new_structt(jl_datatype_t *type, jl_tuple_t *t)
+DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
{
- assert(jl_tuple_len(type->names) == jl_tuple_len(t));
- jl_value_t *jv = jl_new_struct_uninit(type);
- for(size_t i=0; i < jl_tuple_len(t); i++) {
- jl_set_nth_field(jv, i, jl_tupleref(t, i));
- }
+ if (type->instance != NULL) return type->instance;
+ jl_value_t *jv = newstruct(type);
+ if (type->size == 0) type->instance = jv;
+ else memset(&((void**)jv)[1], 0, type->size);
return jv;
}
jl_tuple_t *jl_tuple(size_t n, ...)
{
va_list args;
- size_t i;
if (n == 0) return jl_null;
va_start(args, n);
jl_tuple_t *jv = (jl_tuple_t*)newobj((jl_value_t*)jl_tuple_type, n+1);
jl_tuple_set_len_unsafe(jv, n);
- for(i=0; i < n; i++) {
+ for(size_t i=0; i < n; i++) {
jl_tupleset(jv, i, va_arg(args, jl_value_t*));
}
va_end(args);
@@ -258,8 +261,7 @@ jl_tuple_t *jl_alloc_tuple(size_t n)
{
if (n == 0) return jl_null;
jl_tuple_t *jv = jl_alloc_tuple_uninit(n);
- size_t i;
- for(i=0; i < n; i++) {
+ for(size_t i=0; i < n; i++) {
jl_tupleset(jv, i, NULL);
}
return jv;
@@ -284,8 +286,7 @@ jl_tuple_t *jl_tuple_fill(size_t n, jl_value_t *v)
{
if (n==0) return jl_null;
jl_tuple_t *tup = jl_alloc_tuple_uninit(n);
- size_t i;
- for(i=0; i < n; i++) {
+ for(size_t i=0; i < n; i++) {
jl_tupleset(tup, i, v);
}
return tup;
@@ -482,8 +483,7 @@ void jl_add_constructors(jl_datatype_t *t)
jl_tuple_t *sparams = jl_alloc_tuple_uninit(np*2);
jl_function_t *cfactory = NULL;
JL_GC_PUSH(&sparams, &cfactory);
- size_t i;
- for(i=0; i < np; i++) {
+ for(size_t i=0; i < np; i++) {
jl_tupleset(sparams, i*2+0,
jl_tupleref(((jl_datatype_t*)t->name->primary)->parameters, i));
jl_tupleset(sparams, i*2+1,
View
@@ -93,6 +93,9 @@ static builtinspec_t julia_flisp_ast_ext[] = {
{ NULL, NULL }
};
+static value_t true_sym;
+static value_t false_sym;
+
DLLEXPORT void jl_init_frontend(void)
{
fl_init(2*512*1024);
@@ -111,6 +114,8 @@ DLLEXPORT void jl_init_frontend(void)
NULL, NULL);
assign_global_builtins(julia_flisp_ast_ext);
+ true_sym = symbol("true");
+ false_sym = symbol("false");
}
static jl_sym_t *scmsym_to_julia(value_t s)
@@ -222,13 +227,10 @@ static jl_value_t *scm_to_julia_(value_t e, int eo)
#endif
}
if (issymbol(e)) {
- if (!fl_isgensym(e)) {
- char *sn = symbol_name(e);
- if (!strcmp(sn, "true"))
- return jl_true;
- else if (!strcmp(sn, "false"))
- return jl_false;
- }
+ if (e == true_sym)
+ return jl_true;
+ else if (e == false_sym)
+ return jl_false;
return (jl_value_t*)scmsym_to_julia(e);
}
if (fl_isstring(e)) {
View
@@ -890,8 +890,7 @@ void jl_init_serializer(void)
jl_null, jl_false, jl_true, jl_any_type, jl_symbol("Any"),
jl_symbol("Array"), jl_symbol("TypeVar"),
- jl_symbol("FuncKind"), jl_symbol("Box"),
- jl_symbol("apply"),
+ jl_symbol("Box"), jl_symbol("apply"),
lambda_sym, body_sym, return_sym, call_sym, colons_sym,
null_sym, goto_ifnot_sym, assign_sym,
View
@@ -627,7 +627,7 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tuple_t *type,
Type{TC} nor TypeConstructor is more specific.
To solve this, we identify "kind slots", which are slots
- for which some definition specifies a kind (e.g. AbstractKind).
+ for which some definition specifies a kind (e.g. DataType).
Those tend to be in reflective functions that look at types
themselves. For these slots we specialize on jl_typeof(T) instead
of Type{T}, i.e. the kind of the type rather than the specific
View
@@ -1693,13 +1693,17 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_value_t **env, size_t n,
if (ftypes != NULL) {
// recursively instantiate the types of the fields
ndt->types = (jl_tuple_t*)inst_type_w_((jl_value_t*)ftypes, env, n, stack);
- if (!isabstract)
+ if (!isabstract) {
jl_compute_field_offsets(ndt);
+ }
+ else {
+ ndt->size = 0;
+ ndt->pointerfree = 0;
+ }
if (tn == jl_array_typename)
ndt->pointerfree = 0;
- if (ftypes->length == 0) {
+ if (ftypes->length == 0)
ndt->size = dt->size;
- }
}
if (cacheable) cache_type_((jl_value_t*)ndt);
result = (jl_value_t*)ndt;
@@ -2214,7 +2218,7 @@ static jl_value_t *type_match_(jl_value_t *child, jl_value_t *parent,
int super = 0;
while (tta != (jl_datatype_t*)jl_any_type) {
if (tta->name == ttb->name) {
- // note: CompositeKind <: Type, but Type{T} <: CompositeKind
+ // note: DataType <: Type, but Type{T} <: DataType
// for any specific T.
if (super && morespecific && tta->name != jl_type_type->name)
return jl_true;
View
@@ -562,6 +562,12 @@ static inline int jl_is_structtype(void *v)
!((jl_datatype_t*)(v))->abstract);
}
+static inline int jl_isbits(void *t) // corresponding to isbits() in julia
+{
+ return (jl_is_datatype(t) && !((jl_datatype_t*)t)->mutabl &&
+ ((jl_datatype_t*)t)->pointerfree && !((jl_datatype_t*)t)->abstract);
+}
+
static inline int jl_is_abstracttype(void *v)
{
return (jl_is_datatype(v) && ((jl_datatype_t*)(v))->abstract);
@@ -663,8 +669,8 @@ void jl_set_datatype_super(jl_datatype_t *tt, jl_value_t *super);
jl_value_t *jl_new_bits(jl_datatype_t *bt, void *data);
void jl_assign_bits(void *dest, jl_value_t *bits);
DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...);
+DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args, uint32_t na);
DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type);
-DLLEXPORT jl_value_t *jl_new_structt(jl_datatype_t *type, jl_tuple_t *t);
jl_function_t *jl_new_closure(jl_fptr_t proc, jl_value_t *env,
jl_lambda_info_t *li);
jl_lambda_info_t *jl_new_lambda_info(jl_value_t *ast, jl_tuple_t *sparams);

0 comments on commit f6cc185

Please sign in to comment.