2015-07-03 18:34:46 -04:00
|
|
|
import string;
|
2015-08-21 11:03:10 -04:00
|
|
|
import vector;
|
2015-06-01 01:43:23 -04:00
|
|
|
import mem:*
|
2015-03-11 01:58:10 -04:00
|
|
|
|
2015-04-04 01:32:40 -04:00
|
|
|
__if_comp__ __C__ simple_passthrough """
|
2014-05-01 01:18:01 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
"""
|
|
|
|
|
|
2015-05-09 06:24:56 -04:00
|
|
|
fun println() : void {
|
2014-06-30 01:57:50 -07:00
|
|
|
print("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 01:43:23 -04:00
|
|
|
fun println<T>(toPrint: T) : void {
|
|
|
|
|
print(toPrint)
|
|
|
|
|
print("\n")
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-04 17:02:51 -04:00
|
|
|
fun print(toPrint: *char) : void {
|
2014-05-01 01:18:01 -04:00
|
|
|
__if_comp__ __C__ {
|
2015-04-04 01:32:40 -04:00
|
|
|
simple_passthrough(toPrint = toPrint::) """
|
2015-06-08 21:47:02 -04:00
|
|
|
printf("%s", toPrint);
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun print(toPrint: char) : void {
|
|
|
|
|
__if_comp__ __C__ {
|
|
|
|
|
simple_passthrough(toPrint = toPrint::) """
|
|
|
|
|
printf("%c", toPrint);
|
2014-05-01 01:18:01 -04:00
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 18:34:46 -04:00
|
|
|
fun print(toPrint: string::string) : void {
|
2015-06-01 01:43:23 -04:00
|
|
|
var charArr = toPrint.toCharArray()
|
|
|
|
|
defer delete(charArr)
|
|
|
|
|
print(charArr);
|
2015-03-11 01:58:10 -04:00
|
|
|
}
|
|
|
|
|
|
2015-06-27 18:06:02 -04:00
|
|
|
fun print(toPrint: bool): void {
|
|
|
|
|
if (toPrint)
|
|
|
|
|
print("true")
|
|
|
|
|
else
|
|
|
|
|
print("false")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 06:24:56 -04:00
|
|
|
fun print(toPrint: int): void {
|
2014-05-01 01:18:01 -04:00
|
|
|
__if_comp__ __C__ {
|
2015-04-04 01:32:40 -04:00
|
|
|
simple_passthrough(toPrint = toPrint::) """
|
2014-05-01 01:18:01 -04:00
|
|
|
printf("%d", toPrint);
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 06:24:56 -04:00
|
|
|
fun print(toPrint: float): void {
|
2014-05-01 01:18:01 -04:00
|
|
|
__if_comp__ __C__ {
|
2015-04-04 01:32:40 -04:00
|
|
|
simple_passthrough(toPrint = toPrint::) """
|
2014-05-01 01:18:01 -04:00
|
|
|
printf("%f", toPrint);
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
return;
|
2014-06-26 01:45:44 -07:00
|
|
|
}
|
|
|
|
|
|
2015-05-09 06:24:56 -04:00
|
|
|
fun print(toPrint: double) : void{
|
2014-07-18 08:52:15 -07:00
|
|
|
__if_comp__ __C__ {
|
2015-04-04 01:32:40 -04:00
|
|
|
simple_passthrough(toPrint = toPrint::) """
|
2014-07-18 08:52:15 -07:00
|
|
|
printf("%f", toPrint);
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 18:34:46 -04:00
|
|
|
// Ok, just some DEAD simple file io for now
|
|
|
|
|
fun read_file(path: string::string): string::string {
|
2015-08-21 11:03:10 -04:00
|
|
|
var toRet.construct(read_file_binary(path)): string::string
|
|
|
|
|
return toRet
|
|
|
|
|
}
|
|
|
|
|
fun write_file(path: string::string, data: string::string) {
|
|
|
|
|
var char_path = path.toCharArray()
|
|
|
|
|
defer delete(char_path)
|
|
|
|
|
var char_data = data.toCharArray()
|
|
|
|
|
defer delete(char_data)
|
|
|
|
|
__if_comp__ __C__ {
|
|
|
|
|
simple_passthrough(char_path,char_data::) """
|
|
|
|
|
FILE *fp = fopen(char_path, "w");
|
|
|
|
|
fprintf(fp, "%s", char_data);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fun read_file_binary(path: string::string): vector::vector<char> {
|
2015-07-03 18:34:46 -04:00
|
|
|
var char_path = path.toCharArray()
|
|
|
|
|
defer delete(char_path)
|
2015-07-04 17:02:51 -04:00
|
|
|
var data: *char
|
2015-08-21 11:03:10 -04:00
|
|
|
var size: int
|
2015-07-03 18:34:46 -04:00
|
|
|
__if_comp__ __C__ {
|
2015-08-21 11:03:10 -04:00
|
|
|
simple_passthrough(char_path = char_path:data = data, size = size:) """
|
2015-07-03 18:34:46 -04:00
|
|
|
FILE *fp = fopen(char_path, "r");
|
|
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
|
|
|
long size = ftell(fp);
|
|
|
|
|
fseek(fp, 0L, SEEK_SET);
|
|
|
|
|
char *data = malloc(size+1);
|
|
|
|
|
size_t readSize = fread(data, 1, size, fp);
|
|
|
|
|
data[readSize] = 0;
|
|
|
|
|
fclose(fp);
|
|
|
|
|
"""
|
|
|
|
|
}
|
2015-08-21 11:03:10 -04:00
|
|
|
var toRet.construct(size): vector::vector<char>
|
|
|
|
|
for (var i = 0; i < size; i++;)
|
|
|
|
|
toRet.add(data[i])
|
|
|
|
|
|
2015-07-03 18:34:46 -04:00
|
|
|
__if_comp__ __C__ {
|
|
|
|
|
simple_passthrough(data = data::) """
|
|
|
|
|
free(data)
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
return toRet
|
|
|
|
|
}
|
2015-08-21 11:03:10 -04:00
|
|
|
fun write_file_binary(path: string::string, vdata: vector::vector<char>) {
|
2015-08-11 01:07:16 -04:00
|
|
|
var char_path = path.toCharArray()
|
|
|
|
|
defer delete(char_path)
|
2015-08-21 11:03:10 -04:00
|
|
|
var data = vdata.getBackingMemory()
|
|
|
|
|
var size = vdata.size
|
2015-08-11 01:07:16 -04:00
|
|
|
__if_comp__ __C__ {
|
2015-08-21 11:03:10 -04:00
|
|
|
simple_passthrough(char_path, data, size::) """
|
2015-08-11 01:07:16 -04:00
|
|
|
FILE *fp = fopen(char_path, "w");
|
2015-08-21 11:03:10 -04:00
|
|
|
fwrite(data, 1, size, fp);
|
2015-08-11 01:07:16 -04:00
|
|
|
fclose(fp);
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-03 18:34:46 -04:00
|
|
|
|