AnyDSL/impala

How to read user input?

enty8080 opened this issue · 2 comments

How to read user input in impala? Like in cpp:

#include <iostream>
using namespace std;

int main() {
    int a; cin >> a;
}

The focus of AnyDSL is mainly on writhing high-performance libraries. For input/output, we rely typically on C/C++.
See https://anydsl.github.io/Tutorial.html for how this can be done.

Alternatively, you can import C functions, like fgets:

struct FILE {}
extern "C" {
    fn "stdin_" stdin() -> &FILE;
    fn fgets(&mut [u8], i32, &FILE) -> &[u8];
}

fn main() -> i32 {
    let mut str : [u8 * 256];
    fgets(&mut str, 256, stdin());
    0
}

You'll need to compile and link with the C standard library and this additional C file containing a definition for stdin:

#include <stdio.h>
void* stdin_(void) { return stdin; }

Note that this will not work if you compile the above file as a C++ file as the name of the function will be mangled (use gcc, not g++).