diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-29 20:19:46 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-29 20:19:46 -0400 |
| commit | 076f87361dd4bb6fcafbe5468353dfa7804d3636 (patch) | |
| tree | 0ca18d7806be3d6e40f9468b748b89916105756b | |
| parent | f03587be8d1001db0d9bf7fbd8be1f8f9c42d702 (diff) | |
Support using DateTime() as a constructor
| -rw-r--r-- | compile.c | 5 | ||||
| -rw-r--r-- | typecheck.c | 2 |
2 files changed, 6 insertions, 1 deletions
@@ -2967,6 +2967,11 @@ CORD compile(env_t *env, ast_t *ast) return compile_string_literal(Match(Match(call->args->value, TextJoin)->children->ast, TextLiteral)->cord); type_t *actual = get_type(env, call->args->value); return CORD_all("Text$as_c_string(", expr_as_text(env, compile(env, call->args->value), actual, "no"), ")"); + } else if (t->tag == DateTimeType) { + // DateTime constructor: + binding_t *new_binding = get_binding(Match(fn_t, TypeInfoType)->env, "new"); + CORD arg_code = compile_arguments(env, ast, Match(new_binding->type, FunctionType)->args, call->args); + return CORD_all(new_binding->code, "(", arg_code, ")"); } else { code_err(call->fn, "This is not a type that has a constructor"); } diff --git a/typecheck.c b/typecheck.c index fd0b9d63..fa7ca19c 100644 --- a/typecheck.c +++ b/typecheck.c @@ -756,7 +756,7 @@ type_t *get_type(env_t *env, ast_t *ast) if (fn_type_t->tag == TypeInfoType) { type_t *t = Match(fn_type_t, TypeInfoType)->type; if (t->tag == StructType || t->tag == IntType || t->tag == BigIntType || t->tag == NumType - || t->tag == TextType || t->tag == CStringType) + || t->tag == TextType || t->tag == CStringType || t->tag == DateTimeType) return t; // Constructor code_err(call->fn, "This is not a type that has a constructor"); } |
