From a8e52c1e13a6cea5cf4197393002c0da206a99d4 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 24 Jan 2020 22:50:50 -0500 Subject: fixed return declarations --- tests/foreign/expected | 1 + tests/foreign/foreign.toc | 32 ++++++++++++++++++++++++++++++++ tests/foreign/got | 1 + tests/foreign/test.sh | 3 +++ 4 files changed, 37 insertions(+) create mode 100644 tests/foreign/expected create mode 100644 tests/foreign/foreign.toc create mode 100644 tests/foreign/got create mode 100755 tests/foreign/test.sh (limited to 'tests/foreign') diff --git a/tests/foreign/expected b/tests/foreign/expected new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/tests/foreign/expected @@ -0,0 +1 @@ +Hello, world! diff --git a/tests/foreign/foreign.toc b/tests/foreign/foreign.toc new file mode 100644 index 0000000..beaa822 --- /dev/null +++ b/tests/foreign/foreign.toc @@ -0,0 +1,32 @@ +voidptr ::= &u8; + +getstdout ::= fn() voidptr { + #builtin("stdout") +}; + + +fwrite :: fn(voidptr, u64, u64, voidptr) u64 = #foreign "fwrite", "libc.so.6"; +fputc :: fn(i32, voidptr) i32 = #foreign "fputc", "libc.so.6"; + +writes ::= fn(x : []char) { + fwrite(&x[0] as voidptr, 1, x.len as u64, getstdout()); +}; + +puts ::= fn(x : []char) { + writes(x); + fputc('\n' as i32, getstdout()); +}; + +hw ::= fn() int { + writes("Hello,"); + if #builtin("compiling") { + writes(" compiling"); + } + puts(" world!"); + 3 +}; + +main ::= fn() { + hw(); + x ::= hw(); +}; \ No newline at end of file diff --git a/tests/foreign/got b/tests/foreign/got new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/tests/foreign/got @@ -0,0 +1 @@ +Hello, world! diff --git a/tests/foreign/test.sh b/tests/foreign/test.sh new file mode 100755 index 0000000..1d6eb8f --- /dev/null +++ b/tests/foreign/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +./foreign.bin > got || exit 1 +diff got expected || exit 1 -- cgit v1.2.3