Files
spl/stage1/test13_extern.spl
zzy 459b6188a9 stage1 - 全面重构 stage1 编译器架构:类型系统(arena + items)、IR 发射层(spl_emit.h/c)、统一所有 emit 调用点。
- 实现 as 类型转换运算符、修复 &&/|| 短路求值 bug。
- 在 splc1.spl 中实现 Vec/Map/Emit 基础库(~50 个方法)。
- 修复实例方法调用中 self 参数被错误丢弃的 bug。
2026-07-20 20:53:41 +08:00

36 lines
978 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* ===== 模块6函数 =====
* test13_extern — 外部 VM 函数与字符串
* 难度2/5
* 验证点:@extern(vm) 声明、vm_printf 调用、
* 字符串字面量、字符串参数传递
*/
@extern(vm) fn vm_printf(fmt: *u8, ...) void;
@extern(vm) fn vm_strlen(s: *i8) i32;
@extern(vm) fn vm_strcmp(a: *i8, b: *i8) i32;
fn main() i32 {
/* vm_printf 输出测试 */
vm_printf("hello spl\n");
vm_printf("%d %d %d\n", 1, 2, 3);
vm_printf("chars: %c%c\n", 'A', 'B');
/* 字符串字面量用于 extern */
var len := vm_strlen("hello");
if len != 5 { ret 1; }
/* 字符串比较 */
var cmp := vm_strcmp("abc", "abc");
if cmp != 0 { ret 2; }
var cmp2 := vm_strcmp("abc", "def");
if cmp2 == 0 { ret 3; }
/* 字符串作为格式化参数 */
vm_printf("string test: %s %s\n", "foo", "bar");
/* vm_printf 返回 void不关心返回值*/
vm_printf("all extern tests done\n");
ret 0;
}