extern statement
This commit is contained in:
@@ -26,7 +26,7 @@ func main[] : I64
|
|||||||
io.print("Too high!")
|
io.print("Too high!")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quick Start
|
## Quickstart
|
||||||
```
|
```
|
||||||
cargo install --git https://github.com/antpiasecki/zern
|
cargo install --git https://github.com/antpiasecki/zern
|
||||||
zern -m -r hello.zr
|
zern -m -r hello.zr
|
||||||
|
|||||||
@@ -1,42 +1,40 @@
|
|||||||
// musl doesnt like dlopen, needs to be compiled with -m
|
// musl doesnt like dlopen, needs to be compiled with -m -C="/usr/local/lib/libraylib.a -lm"
|
||||||
|
|
||||||
func main[] : I64
|
func main[] : I64
|
||||||
let rl: Ptr = c.dlopen("libraylib.so", 2)
|
extern InitWindow
|
||||||
|
extern SetTargetFPS
|
||||||
|
extern WindowShouldClose
|
||||||
|
extern BeginDrawing
|
||||||
|
extern EndDrawing
|
||||||
|
extern ClearBackground
|
||||||
|
extern CloseWindow
|
||||||
|
extern DrawRectangle
|
||||||
|
extern IsKeyDown
|
||||||
|
|
||||||
let rl.InitWindow: Ptr = c.dlsym(rl, "InitWindow")
|
let KEY_W: I64 = 87
|
||||||
let rl.SetTargetFPS: Ptr = c.dlsym(rl, "SetTargetFPS")
|
let KEY_S: I64 = 83
|
||||||
let rl.WindowShouldClose: Ptr = c.dlsym(rl, "WindowShouldClose")
|
let KEY_A: I64 = 65
|
||||||
let rl.BeginDrawing: Ptr = c.dlsym(rl, "BeginDrawing")
|
let KEY_D: I64 = 68
|
||||||
let rl.EndDrawing: Ptr = c.dlsym(rl, "EndDrawing")
|
|
||||||
let rl.ClearBackground: Ptr = c.dlsym(rl, "ClearBackground")
|
|
||||||
let rl.CloseWindow: Ptr = c.dlsym(rl, "CloseWindow")
|
|
||||||
let rl.DrawRectangle: Ptr = c.dlsym(rl, "DrawRectangle")
|
|
||||||
let rl.IsKeyDown: Ptr = c.dlsym(rl, "IsKeyDown")
|
|
||||||
|
|
||||||
let rl.KEY_W: I64 = 87
|
|
||||||
let rl.KEY_S: I64 = 83
|
|
||||||
let rl.KEY_A: I64 = 65
|
|
||||||
let rl.KEY_D: I64 = 68
|
|
||||||
|
|
||||||
let x: I64 = 200
|
let x: I64 = 200
|
||||||
let y: I64 = 200
|
let y: I64 = 200
|
||||||
|
|
||||||
rl.InitWindow(800, 600, "Hello, World!")
|
InitWindow(800, 600, "Hello, World!")
|
||||||
rl.SetTargetFPS(60)
|
SetTargetFPS(60)
|
||||||
|
|
||||||
while !rl.WindowShouldClose()
|
while !WindowShouldClose()
|
||||||
if rl.IsKeyDown(rl.KEY_W) & 255
|
if IsKeyDown(KEY_W) & 255
|
||||||
y = y - 10
|
y = y - 10
|
||||||
if rl.IsKeyDown(rl.KEY_S) & 255
|
if IsKeyDown(KEY_S) & 255
|
||||||
y = y + 10
|
y = y + 10
|
||||||
if rl.IsKeyDown(rl.KEY_A) & 255
|
if IsKeyDown(KEY_A) & 255
|
||||||
x = x - 10
|
x = x - 10
|
||||||
if rl.IsKeyDown(rl.KEY_D) & 255
|
if IsKeyDown(KEY_D) & 255
|
||||||
x = x + 10
|
x = x + 10
|
||||||
|
|
||||||
rl.BeginDrawing()
|
BeginDrawing()
|
||||||
rl.ClearBackground(0xffffffff)
|
ClearBackground(0xffffffff)
|
||||||
rl.DrawRectangle(x, y, 100, 100, 0xff0000ff)
|
DrawRectangle(x, y, 100, 100, 0xff0000ff)
|
||||||
rl.EndDrawing()
|
EndDrawing()
|
||||||
|
|
||||||
rl.CloseWindow()
|
CloseWindow()
|
||||||
@@ -87,6 +87,7 @@ impl Analyzer {
|
|||||||
}
|
}
|
||||||
Stmt::Break => {}
|
Stmt::Break => {}
|
||||||
Stmt::Continue => {}
|
Stmt::Continue => {}
|
||||||
|
Stmt::Extern(_) => {}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,6 +281,9 @@ _builtin_set64:
|
|||||||
// TODO: skips incrementing when used in a for loop
|
// TODO: skips incrementing when used in a for loop
|
||||||
emit!(&mut self.output, " jmp {}", env.loop_begin_label);
|
emit!(&mut self.output, " jmp {}", env.loop_begin_label);
|
||||||
}
|
}
|
||||||
|
Stmt::Extern(name) => {
|
||||||
|
emit!(&mut self.output, " extern {}", name.lexeme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ pub enum Stmt {
|
|||||||
Return(Expr),
|
Return(Expr),
|
||||||
Break,
|
Break,
|
||||||
Continue,
|
Continue,
|
||||||
|
Extern(Token),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -198,6 +199,10 @@ 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()?))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ pub enum TokenType {
|
|||||||
KeywordReturn,
|
KeywordReturn,
|
||||||
KeywordBreak,
|
KeywordBreak,
|
||||||
KeywordContinue,
|
KeywordContinue,
|
||||||
|
KeywordExtern,
|
||||||
|
|
||||||
Indent,
|
Indent,
|
||||||
Dedent,
|
Dedent,
|
||||||
@@ -334,6 +335,7 @@ impl Tokenizer {
|
|||||||
"return" => TokenType::KeywordReturn,
|
"return" => TokenType::KeywordReturn,
|
||||||
"break" => TokenType::KeywordBreak,
|
"break" => TokenType::KeywordBreak,
|
||||||
"continue" => TokenType::KeywordContinue,
|
"continue" => TokenType::KeywordContinue,
|
||||||
|
"extern" => TokenType::KeywordExtern,
|
||||||
"true" => TokenType::True,
|
"true" => TokenType::True,
|
||||||
"false" => TokenType::False,
|
"false" => TokenType::False,
|
||||||
_ => TokenType::Identifier,
|
_ => TokenType::Identifier,
|
||||||
|
|||||||
Reference in New Issue
Block a user