Skip to content

Commit d4c0101

Browse files
committed
Bugfix for assumption that int64 is the last foreign type
1 parent e2c56f9 commit d4c0101

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

aiscm/core.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
//
17+
#include <assert.h>
1718
#include <libguile.h>
1819
#include <llvm-c/Analysis.h>
1920
#include <llvm-c/Core.h>
@@ -139,8 +140,11 @@ static LLVMTypeRef llvm_type(int type)
139140
case SCM_FOREIGN_TYPE_UINT64:
140141
case SCM_FOREIGN_TYPE_INT64:
141142
return LLVMInt64Type();
142-
default:
143+
case SCM_FOREIGN_TYPE_VOID:
143144
return LLVMVoidType();
145+
default:
146+
assert(0);
147+
scm_misc_error("llvm-type", "Unknown scheme type: ~a", scm_list_1(scm_from_int(type)));
144148
};
145149
}
146150

@@ -165,9 +169,11 @@ static int llvm_type_index(LLVMTypeRef type)
165169
case 64:
166170
return SCM_FOREIGN_TYPE_INT64;
167171
default:
172+
scm_misc_error("llvm-type-index", "Unknown integer type width: ~a", scm_list_1(scm_from_int(LLVMGetIntTypeWidth(type))));
168173
return SCM_FOREIGN_TYPE_VOID;
169174
};
170175
default:
176+
scm_misc_error("llvm-type-index", "Unknown LLVM type kind", SCM_EOL);
171177
return SCM_FOREIGN_TYPE_VOID;
172178
};
173179
}
@@ -191,6 +197,7 @@ static LLVMValueRef scm_to_llvm_value(int type, SCM scm_value)
191197
case SCM_FOREIGN_TYPE_INT64:
192198
return LLVMConstInt(llvm_type(type), scm_to_int64(scm_value), 1);
193199
default:
200+
scm_misc_error("scm-to-llvm-value", "Unknown foreign type: ~a", scm_list_1(scm_from_int(type)));
194201
return NULL;
195202
};
196203
}
@@ -286,13 +293,13 @@ SCM llvm_compile_module(SCM scm_llvm, SCM scm_name)
286293
{
287294
struct llvm_module_t *self = get_llvm(scm_llvm);
288295
if (self->engine != NULL)
289-
scm_misc_error("llvm-compile", "LLVM module already compiled", SCM_EOL);
296+
scm_misc_error("llvm-compile-module", "LLVM module already compiled", SCM_EOL);
290297

291298
char *error = NULL;
292299
if (LLVMCreateJITCompilerForModule(&self->engine, self->module, 2, &error)) {
293300
SCM scm_error = scm_from_locale_string(error);
294301
LLVMDisposeMessage(error);
295-
scm_misc_error("llvm-compile", "Error initialising JIT engine: ~a", scm_list_1(scm_error));
302+
scm_misc_error("llvm-compile-module", "Error initialising JIT engine: ~a", scm_list_1(scm_error));
296303
};
297304

298305
LLVMPassManagerRef pass_manager = LLVMCreatePassManager();
@@ -318,7 +325,7 @@ SCM llvm_verify_module(SCM scm_llvm)
318325
if (LLVMVerifyModule(llvm->module, LLVMPrintMessageAction, &error)) {
319326
SCM scm_error = scm_from_locale_string(error);
320327
LLVMDisposeMessage(error);
321-
scm_misc_error("verify-module", "Module is not valid: ~a", scm_list_1(scm_error));
328+
scm_misc_error("llvm-verify-module", "Module is not valid: ~a", scm_list_1(scm_error));
322329
};
323330
return SCM_UNSPECIFIED;
324331
}
@@ -706,6 +713,7 @@ void init_core(void)
706713

707714
llvm_basic_block_tag = scm_make_smob_type("llvm_basic_block", sizeof(struct llvm_basic_block_t));
708715

716+
scm_c_define("bool" , scm_from_int(SCM_FOREIGN_TYPE_LAST + 1));
709717
scm_c_define("llvm-bool" , scm_from_int(SCM_FOREIGN_TYPE_LAST + 1));
710718
scm_c_define("llvm-void" , scm_from_int(SCM_FOREIGN_TYPE_VOID ));
711719
scm_c_define("llvm-float" , scm_from_int(SCM_FOREIGN_TYPE_FLOAT ));

aiscm/core.scm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@
8989
(define signed 'signed)
9090
(define unsigned 'unsigned)
9191

92-
(define bool (1+ int64)); int64 is last foreign type
93-
9492
(define-class* <void> <object> <meta<void>> <class>
9593
(value #:init-keyword #:value #:getter get))
9694

tests/test_core.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
(test-eq "Create boolean type"
4141
<bool> (class-of (make <bool> #:value #t)))
4242
(test-eqv "Foreign type of boolean is boolean"
43-
(1+ int64) (foreign-type <bool>)))
43+
(+ int64 3) (foreign-type <bool>)))
4444

4545
(test-group "construct integer types"
4646
(for-each

0 commit comments

Comments
 (0)