1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-11 00:52:44 +03:00
mal/skew/util.sk
Dov Murik 034e82adc5 Add Skew implementation
See http://skew-lang.org/ for details on the Skew language. Currently
Mal only compiles to Javascript, as there are some issues with the C#
backend for Skew (https://github.com/evanw/skew/issues/19).

Tested with Skew 0.7.42.
2016-11-20 10:10:41 +00:00

56 lines
1.1 KiB
Plaintext

def argv List<string> {
return process.argv.slice(2)
}
def timeMs int {
return Date.new.getTime()
}
var fs = require("fs")
def readFile(filename string) string {
return fs.readFileSync(filename, "utf-8")
}
def writeString(s string) {
fs.writeSync(1, s)
}
def printLn(s string) {
writeString(s)
writeString("\n")
}
def readLine(prompt string) string {
writeString(prompt)
var buffer = Buffer.new(1024) # in newer Node this should be Buffer.alloc
var stdin = fs.openSync("/dev/stdin", "rs")
var bytesread int
var anycharseen = false
var total = 0
while (bytesread = fs.readSync(stdin, buffer, total, 1)) > 0 {
anycharseen = true
var lastchar = buffer.slice(total, total + bytesread).toString()
if lastchar == "\n" {
break
}
total += bytesread
}
fs.closeSync(stdin)
return anycharseen ? buffer.slice(0, total).toString() : null
}
def stringToInt(str string) int {
return parseInt(str)
}
@import {
const process dynamic
const Buffer dynamic
const Date dynamic
const Error dynamic
def parseInt(str string) int
def require(name string) dynamic
}