aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-09-06 15:41:09 +0100
committergingerBill <bill@gingerbill.org>2021-09-06 15:41:09 +0100
commita3a891a7f4b0c099af49eb180dc8ce2e09527b50 (patch)
tree4d40fdbcfdb01f885743eb1d1f071f2025c87e2a /src/check_builtin.cpp
parentb31a24e5e8c3a31858da9b8f5d689f5749f13594 (diff)
Add `intrinsics.is_package_imported(<string>)`
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 05a5fceda..ffd622e4a 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -1871,6 +1871,29 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
operand->type = alloc_type_simd_vector(count, elem);
break;
}
+
+ case BuiltinProc_is_package_imported: {
+ bool value = false;
+
+ if (!is_type_string(operand->type) && (operand->mode != Addressing_Constant)) {
+ error(ce->args[0], "Expected a constant string for '%.*s'", LIT(builtin_name));
+ } else if (operand->value.kind == ExactValue_String) {
+ String pkg_name = operand->value.value_string;
+ // TODO(bill): probably should have this be a `StringMap` eventually
+ for_array(i, c->info->packages.entries) {
+ AstPackage *pkg = c->info->packages.entries[i].value;
+ if (pkg->name == pkg_name) {
+ value = true;
+ break;
+ }
+ }
+ }
+
+ operand->mode = Addressing_Constant;
+ operand->type = t_untyped_bool;
+ operand->value = exact_value_bool(value);
+ break;
+ }
case BuiltinProc_soa_struct: {
Operand x = {};