aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-29 18:09:12 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-29 18:09:12 -0500
commitf66f8ad7119207b99f00ea2ea389550ee65db5b3 (patch)
tree5b5a7c887b311e3de2f2cb293b1228598c5b9eb1 /typecheck.c
parent4b5e4cd1f21582f5e5fa682ab4e4bff252963468 (diff)
Add serialization and deserialization
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c
index a37357d2..ba228305 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -721,6 +721,11 @@ type_t *get_type(env_t *env, ast_t *ast)
}
case FunctionCall: {
auto call = Match(ast, FunctionCall);
+
+ // HACK:
+ if (call->fn->tag == Var && streq(Match(call->fn, Var)->name, "serialize"))
+ return Type(ArrayType, Type(ByteType));
+
type_t *fn_type_t = get_type(env, call->fn);
if (!fn_type_t)
code_err(call->fn, "I couldn't find this function");
@@ -741,6 +746,10 @@ type_t *get_type(env_t *env, ast_t *ast)
}
case MethodCall: {
auto call = Match(ast, MethodCall);
+
+ if (streq(call->name, "serialize"))
+ return Type(ArrayType, Type(ByteType));
+
type_t *self_value_t = value_type(get_type(env, call->self));
switch (self_value_t->tag) {
case ArrayType: {
@@ -1245,6 +1254,8 @@ type_t *get_type(env_t *env, ast_t *ast)
}
case Moment: return Type(MomentType);
case Unknown: code_err(ast, "I can't figure out the type of: %W", ast);
+ case Serialize: return Type(ArrayType, Type(ByteType));
+ case Deserialize: return parse_type_ast(env, Match(ast, Deserialize)->type);
}
#pragma GCC diagnostic pop
code_err(ast, "I can't figure out the type of: %W", ast);