diff --git a/src/ffi.c b/src/ffi.c index 67eb72fc..4a2ac77c 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -353,6 +353,7 @@ static u32 readUInt(u32** p) { r = r*10 + *c-'0'; c++; } + if (c == *p) thrM("Type parser: expected number"); *p = c; return r; } @@ -513,7 +514,7 @@ ParsedType ffi_parseType(u32** src, bool inPtr, bool top) { // parse actual type if (n!=64) goto badW; } else thrM("Type parser: Unexpected character after \":\""); - if (isC32(ro) && n > myWidth*8) thrF("Type parser: Representation wider than the value for \"%S:%c%i\"", sty_names[styG(ro)], (u32)t, n); + if (isC32(ro) && n > myWidth*8) thrF("Type parser: Representation wider than the value within", sty_names[styG(ro)], (u32)t, n); // TODO figure out what to do with i32:i32 etc B roP = ro; @@ -722,7 +723,7 @@ void genObj(B o, B c, bool anyMut, void* ptr) { // doesn't consume; mutates ffiO incG(c); B cG; bool mut = t->ty==cty_ptr? t->mutPtr : false; - switch(styG(e)) { default: thrF("FFI: \"*%S\" argument type not yet implemented", sty_names[styG(e)]); + switch(styG(e)) { default: thrF("FFI: Unimplemented pointer element type within %R", ty_fmt(o)); case sty_i8: ffi_checkRange(c, mut, "i8", I8_MIN, I8_MAX); cG = mut? taga(cpyI8Arr (c)) : toI8Any (c); break; case sty_i16: ffi_checkRange(c, mut, "i16", I16_MIN, I16_MAX); cG = mut? taga(cpyI16Arr(c)) : toI16Any(c); break; case sty_i32: ffi_checkRange(c, mut, "i32", I32_MIN, I32_MAX); cG = mut? taga(cpyI32Arr(c)) : toI32Any(c); break; diff --git a/test/cases/ffi.bqn b/test/cases/ffi.bqn index dd4116c4..e6307abd 100644 --- a/test/cases/ffi.bqn +++ b/test/cases/ffi.bqn @@ -11,11 +11,12 @@ !"FFI: Type must be a string" % @•FFI "hello" !"FFI: Too many arguments" % @•FFI""‿"bqn_init"∾70000⥊<"i32" !"Type parser: Unexpected character '?'" % @•FFI""‿"bqn_init"‿"?" -!"Type parser: Bad array type" % @•FFI""‿"bqn_init"‿"[" +!"Type parser: expected number" % @•FFI""‿"bqn_init"‿"[" !"Type parser: Bad array type" % @•FFI""‿"bqn_init"‿"[0" !"Type parser: Unexpected end of input" % @•FFI""‿"bqn_init"‿"[1]" +!"Type parser: expected number" % @•FFI""‿"bqn_init"‿"[]i32" !"Type parser: Unexpected end of input" % @•FFI""‿"bqn_init"‿"{" -!"Type parser: Bad integer width" % @•FFI""‿"bqn_init"‿"i" +!"Type parser: expected number" % @•FFI""‿"bqn_init"‿"i" !"Type parser: Bad float width" % @•FFI""‿"bqn_init"‿"f80" !"Type parser: Bad float width" % @•FFI""‿"bqn_init"‿"f128" !"Type parser: Bad float width" % @•FFI""‿"bqn_init"‿"f16" @@ -53,15 +54,15 @@ # !"Type parser: Structs currently cannot contain mutable references" % @•FFI""‿"bqn_init"‿"{[2]&i32}" # TODO # : -!"Type parser: Unexpected character after "":""" % @•FFI""‿"bqn_init"‿"i32:" +!"Type parser: expected number" % @•FFI""‿"bqn_init"‿"i32:" !"Type parser: Unexpected character after "":""" % f←@•FFI""‿"bqn_init"‿">*u64:q8" -!"Type parser: Unsupported width in :i0" % @•FFI""‿"bqn_init"‿"i32:i" +!"Type parser: expected number" % @•FFI""‿"bqn_init"‿"i32:i" !"Type parser: Unsupported width in :i9" % @•FFI""‿"bqn_init"‿"i32:i9" !"Type parser: Unsupported width in :u16" % @•FFI""‿"bqn_init"‿"i32:u16" !"Type parser: Unsupported width in :i64" % @•FFI"i32:i64"‿"bqn_init" !"Type parser: Unsupported width in :f32" % @•FFI""‿"bqn_init"‿"i32:f32" !"Type parser: number literal too large" % @•FFI""‿"bqn_init"‿"i32:u9999999999999999" -!"Type parser: Representation wider than the value for ""i32:f64""" % @•FFI""‿"bqn_init"‿"i32:f64" +!"Type parser: Representation wider than the value within" % @•FFI""‿"bqn_init"‿"i32:f64" !"Type parser: Garbage at end of type" % @•FFI""‿"bqn_init"‿"i32 hello world" # pointers @@ -172,9 +173,9 @@ # unimplemented stuff -!"FFI: ""*i64"" argument type not yet implemented" % f←@•FFI""‿"bqn_init"‿">&i64" ⋄ F ↕10 -!"FFI: ""*i64"" argument type not yet implemented" % f←@•FFI""‿"bqn_init"‿">*i64" ⋄ F ↕10 -!"FFI: ""*u64"" argument type not yet implemented" % f←@•FFI""‿"bqn_init"‿">&u64" ⋄ F ↕10 +!"FFI: Unimplemented pointer element type within ""&i64""" % f←@•FFI""‿"bqn_init"‿">&i64" ⋄ F ↕10 +!"FFI: Unimplemented pointer element type within ""*i64""" % f←@•FFI""‿"bqn_init"‿">*i64" ⋄ F ↕10 +!"FFI: Unimplemented pointer element type within ""&u64""" % f←@•FFI""‿"bqn_init"‿">&u64" ⋄ F ↕10 !"FFI: Pointer element type not implemented" % f←@•FFI""‿"bqn_init"‿">**u64" ⋄ F ⟨↕2⟩