aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtins/nums.h3
-rw-r--r--examples/vectors.tm14
-rw-r--r--typecheck.c2
3 files changed, 12 insertions, 7 deletions
diff --git a/builtins/nums.h b/builtins/nums.h
index 4205274b..2ac942f4 100644
--- a/builtins/nums.h
+++ b/builtins/nums.h
@@ -53,4 +53,7 @@ CONSTFUNC static inline float Num32$clamped(float x, float low, float high) {
}
extern const TypeInfo Num32$info;
+#define Num_to_Num32(n) ((Num32_t)(n))
+#define Num32_to_Num(n) ((Num_t)(n))
+
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/examples/vectors.tm b/examples/vectors.tm
index 9f0ef20d..8560f9df 100644
--- a/examples/vectors.tm
+++ b/examples/vectors.tm
@@ -27,10 +27,10 @@ struct Vec2(x,y:Num):
return v
len := v:length()
return Vec2(v.x/len, v.y/len)
- func mix(v,other:Vec2, amount:Num)->Vec2:
+ func mix(a,b:Vec2, amount:Num)->Vec2:
return Vec2(
- v.x:mix(other.x, amount),
- v.y:mix(other.y, amount),
+ amount:mix(a.x, b.x),
+ amount:mix(a.y, b.y),
)
struct Vec3(x,y,z:Num):
@@ -58,11 +58,11 @@ struct Vec3(x,y,z:Num):
return v
len := v:length()
return Vec3(v.x/len, v.y/len, v.z/len)
- func mix(v,other:Vec3, amount:Num)->Vec3:
+ func mix(a,b:Vec3, amount:Num)->Vec3:
return Vec3(
- v.x:mix(other.x, amount),
- v.y:mix(other.y, amount),
- v.z:mix(other.z, amount),
+ amount:mix(a.x, b.x),
+ amount:mix(a.y, b.y),
+ amount:mix(a.z, b.z),
)
diff --git a/typecheck.c b/typecheck.c
index 70d94dbf..5d3ffb48 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -263,6 +263,8 @@ void bind_statement(env_t *env, ast_t *statement)
bind_statement(env, decl->value);
}
type_t *type = get_type(env, decl->value);
+ if (!type)
+ code_err(decl->value, "I couldn't figure out the type of this value");
if (type->tag == FunctionType)
type = Type(ClosureType, type);
CORD prefix = namespace_prefix(env->libname, env->namespace);