os.shell
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
// needs to be compiled with -m -C="/usr/local/lib/libraylib.a -lm"
|
// needs to be compiled with -m -C="/usr/local/lib/libraylib.a -lm"
|
||||||
|
|
||||||
func main[] : I64
|
|
||||||
extern InitWindow
|
extern InitWindow
|
||||||
extern SetTargetFPS
|
extern SetTargetFPS
|
||||||
extern WindowShouldClose
|
extern WindowShouldClose
|
||||||
@@ -11,6 +10,7 @@ func main[] : I64
|
|||||||
extern DrawRectangle
|
extern DrawRectangle
|
||||||
extern IsKeyDown
|
extern IsKeyDown
|
||||||
|
|
||||||
|
func main[] : I64
|
||||||
let x: I64 = 200
|
let x: I64 = 200
|
||||||
let y: I64 = 200
|
let y: I64 = 200
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// needs to be compiled with -m -C="-lsqlite3"
|
// needs to be compiled with -m -C="-lsqlite3"
|
||||||
|
|
||||||
func main[] : I64
|
|
||||||
extern sqlite3_open
|
extern sqlite3_open
|
||||||
extern sqlite3_exec
|
extern sqlite3_exec
|
||||||
extern sqlite3_prepare_v2
|
extern sqlite3_prepare_v2
|
||||||
@@ -9,6 +7,7 @@ func main[] : I64
|
|||||||
extern sqlite3_errmsg
|
extern sqlite3_errmsg
|
||||||
extern sqlite3_finalize
|
extern sqlite3_finalize
|
||||||
|
|
||||||
|
func main[] : I64
|
||||||
let rc: I64 = 0
|
let rc: I64 = 0
|
||||||
let db: Ptr = mem.alloc(8)
|
let db: Ptr = mem.alloc(8)
|
||||||
let stmt: Ptr = mem.alloc(8)
|
let stmt: Ptr = mem.alloc(8)
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// needs to be compiled with -m -C="-lX11"
|
// needs to be compiled with -m -C="-lX11"
|
||||||
|
|
||||||
func main[] : I64
|
|
||||||
extern XOpenDisplay
|
extern XOpenDisplay
|
||||||
extern XDefaultRootWindow
|
extern XDefaultRootWindow
|
||||||
extern XCreateSimpleWindow
|
extern XCreateSimpleWindow
|
||||||
@@ -14,6 +12,8 @@ func main[] : I64
|
|||||||
extern XDefaultScreen
|
extern XDefaultScreen
|
||||||
extern XDrawString
|
extern XDrawString
|
||||||
|
|
||||||
|
func main[] : I64
|
||||||
|
|
||||||
let dpy: Ptr = XOpenDisplay(0)
|
let dpy: Ptr = XOpenDisplay(0)
|
||||||
let screen: Ptr = XDefaultScreen(dpy)
|
let screen: Ptr = XDefaultScreen(dpy)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct Var {
|
pub struct Var {
|
||||||
// pub var_type: String,
|
|
||||||
pub stack_offset: usize,
|
pub stack_offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +104,7 @@ section .text
|
|||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
|
||||||
for name in &["malloc", "realloc", "free", "system", "gethostbyname"] {
|
for name in &["malloc", "realloc", "free", "gethostbyname"] {
|
||||||
emit!(&mut self.output, "extern {}", name);
|
emit!(&mut self.output, "extern {}", name);
|
||||||
emit!(&mut self.output, "c.{} equ {}", name, name);
|
emit!(&mut self.output, "c.{} equ {}", name, name);
|
||||||
}
|
}
|
||||||
@@ -156,6 +155,12 @@ _builtin_syscall:
|
|||||||
mov r9, [rsp+8]
|
mov r9, [rsp+8]
|
||||||
syscall
|
syscall
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
section .text._builtin_environ
|
||||||
|
_builtin_environ:
|
||||||
|
extern environ
|
||||||
|
mov rax, [rel environ]
|
||||||
|
ret
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ impl Parser {
|
|||||||
if self.match_token(&[TokenType::KeywordFunc]) {
|
if self.match_token(&[TokenType::KeywordFunc]) {
|
||||||
return self.func_declaration();
|
return self.func_declaration();
|
||||||
}
|
}
|
||||||
|
if self.match_token(&[TokenType::KeywordExtern]) {
|
||||||
|
return self.extern_declaration();
|
||||||
|
}
|
||||||
return error!(
|
return error!(
|
||||||
self.peek().loc,
|
self.peek().loc,
|
||||||
"statements not allowed outside function body"
|
"statements not allowed outside function body"
|
||||||
@@ -175,6 +178,12 @@ impl Parser {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extern_declaration(&mut self) -> Result<Stmt, ZernError> {
|
||||||
|
Ok(Stmt::Extern(
|
||||||
|
self.consume(TokenType::Identifier, "expected extern name")?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
fn block(&mut self) -> Result<Stmt, ZernError> {
|
fn block(&mut self) -> Result<Stmt, ZernError> {
|
||||||
self.consume(TokenType::Indent, "expected an indent")?;
|
self.consume(TokenType::Indent, "expected an indent")?;
|
||||||
|
|
||||||
@@ -199,10 +208,6 @@ impl Parser {
|
|||||||
Ok(Stmt::Break)
|
Ok(Stmt::Break)
|
||||||
} else if self.match_token(&[TokenType::KeywordContinue]) {
|
} else if self.match_token(&[TokenType::KeywordContinue]) {
|
||||||
Ok(Stmt::Continue)
|
Ok(Stmt::Continue)
|
||||||
} else if self.match_token(&[TokenType::KeywordExtern]) {
|
|
||||||
Ok(Stmt::Extern(
|
|
||||||
self.consume(TokenType::Identifier, "expected extern name")?,
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(Stmt::Expression(self.expression()?))
|
Ok(Stmt::Expression(self.expression()?))
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/std.zr
21
src/std.zr
@@ -430,6 +430,27 @@ func os.time[] : I64
|
|||||||
mem.free(tv)
|
mem.free(tv)
|
||||||
return seconds * 1000 + microseconds / 1000
|
return seconds * 1000 + microseconds / 1000
|
||||||
|
|
||||||
|
// voodoo magic
|
||||||
|
func os.shell[command: String] : I64
|
||||||
|
let pid: I64 = _builtin_syscall(57) // fork
|
||||||
|
if pid == 0
|
||||||
|
let argv: Array = ["sh", "-c", command, 0]
|
||||||
|
_builtin_syscall(59, "/bin/sh", mem.read64(argv), _builtin_environ()) // execve
|
||||||
|
_builtin_syscall(60, 1) // exit
|
||||||
|
else
|
||||||
|
let status: Ptr = mem.alloc(4)
|
||||||
|
let wp: I64 = _builtin_syscall(61, pid, status, 0, 0) // waitpid
|
||||||
|
if wp == -1
|
||||||
|
mem.free(status)
|
||||||
|
return -1
|
||||||
|
let st: I64 = mem.read32(status)
|
||||||
|
mem.free(status)
|
||||||
|
|
||||||
|
if (st & 0x7f) == 0
|
||||||
|
return (st >> 8) & 0xff
|
||||||
|
else
|
||||||
|
return -(st & 0x7f)
|
||||||
|
|
||||||
func os.listdir[path: String] : Array
|
func os.listdir[path: String] : Array
|
||||||
let fd: I64 = _builtin_syscall(2, path, 0, 0) // open
|
let fd: I64 = _builtin_syscall(2, path, 0, 0) // open
|
||||||
if fd < 0
|
if fd < 0
|
||||||
|
|||||||
10
test.zr
10
test.zr
@@ -1,5 +1,5 @@
|
|||||||
func run_test[x: String] : Void
|
func run_test[x: String] : Void
|
||||||
if str.equal(x, "raylib.zr") | str.equal(x, "x11.zr")
|
if str.equal(x, "raylib.zr") | str.equal(x, "x11.zr") | str.equal(x, "sqlite_todo.zr")
|
||||||
io.print("\033[93mSkipping ")
|
io.print("\033[93mSkipping ")
|
||||||
io.print(x)
|
io.print(x)
|
||||||
io.println("...\033[0m")
|
io.println("...\033[0m")
|
||||||
@@ -11,7 +11,7 @@ func run_test[x: String] : Void
|
|||||||
let cmd: String = str.concat("./target/release/zern examples/", x)
|
let cmd: String = str.concat("./target/release/zern examples/", x)
|
||||||
|
|
||||||
let build_start_time: I64 = os.time()
|
let build_start_time: I64 = os.time()
|
||||||
if c.system(cmd) != 0
|
if os.shell(cmd) != 0
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
let build_end_time: I64 = os.time()
|
let build_end_time: I64 = os.time()
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ func run_test[x: String] : Void
|
|||||||
|
|
||||||
let run_start_time: I64 = os.time()
|
let run_start_time: I64 = os.time()
|
||||||
if str.equal(x, "curl.zr")
|
if str.equal(x, "curl.zr")
|
||||||
if c.system("./out http://example.com") != 0
|
if os.shell("./out http://example.com") != 0
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
else
|
else
|
||||||
if c.system("./out") != 0
|
if os.shell("./out") != 0
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
let run_end_time: I64 = os.time()
|
let run_end_time: I64 = os.time()
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ func run_test[x: String] : Void
|
|||||||
io.println("ms")
|
io.println("ms")
|
||||||
|
|
||||||
func main[] : I64
|
func main[] : I64
|
||||||
c.system("cargo build --release")
|
os.shell("cargo build --release")
|
||||||
|
|
||||||
let files: Array = os.listdir("examples/")
|
let files: Array = os.listdir("examples/")
|
||||||
for i in 0..array.size(files)
|
for i in 0..array.size(files)
|
||||||
|
|||||||
Reference in New Issue
Block a user