From 02b759a05bd97d324eb9f0dbf49b621adb9b0c0e Mon Sep 17 00:00:00 2001 From: Sam Vervaeck Date: Sun, 24 May 2020 11:18:52 +0200 Subject: [PATCH] stlib: Add draft of some IO primitives --- stdlib/io.bolt | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 stdlib/io.bolt diff --git a/stdlib/io.bolt b/stdlib/io.bolt new file mode 100644 index 000000000..3fb7e92e4 --- /dev/null +++ b/stdlib/io.bolt @@ -0,0 +1,40 @@ + +pub struct String; + +pub struct Either { + is_right: bool, + value: L | R, +} + +mod io { + + pub type Result = Either; + + pub foreign "JS" fn print(message: String) { + process.stdout.write(message); + } + + pub trait Read { + fn read(self, count: usize, target: Vec) -> Result; + } + + impl Read for File { + + foreign "JS" fn read(self, count, target) -> Result { + + import * as fs from "fs" + + try { + return Ok(fs.readSync(self.fd, target, 0, count, null)); + } catch (e) { + return Err(e.code); + } + + } + + } + +} + +print("Hello, world!"); +