about summary refs log tree commit diff
path: root/users/glittershark/achilles/src/parser/mod.rs
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-03-20T00·46-0400
committerglittershark <grfn@gws.fyi>2021-03-20T20·20+0000
commit2c838ab845bc54c5ef6cb0561332c84f34249368 (patch)
treec54c95ebc7f503a1db255566b3e25494bbaa28b3 /users/glittershark/achilles/src/parser/mod.rs
parentfec6595d211e7e3ea616d8335fe5d143a4a7507d (diff)
feat(gs/achilles): Implement extern decls, for glibc functions r/2293
Implement extern decls, which codegen to LLVM as forward-declared
functions, and use these as a hook into calling glibc functions.

We can print to the terminal now! The integration tests can test this
now.

Change-Id: I70af4546b417b888ad9fbb18798db240f77f4e71
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2614
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'users/glittershark/achilles/src/parser/mod.rs')
-rw-r--r--users/glittershark/achilles/src/parser/mod.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/users/glittershark/achilles/src/parser/mod.rs b/users/glittershark/achilles/src/parser/mod.rs
index dd7874aff853..c7e541ce48a0 100644
--- a/users/glittershark/achilles/src/parser/mod.rs
+++ b/users/glittershark/achilles/src/parser/mod.rs
@@ -9,6 +9,7 @@ mod type_;
 
 use crate::ast::{Arg, Decl, Fun, Ident};
 pub use expr::expr;
+use type_::function_type;
 pub use type_::type_;
 
 pub type Error = nom::Err<nom::error::Error<String>>;
@@ -79,9 +80,24 @@ named!(arg(&str) -> Arg, alt!(
     ascripted_arg
 ));
 
+named!(extern_decl(&str) -> Decl, do_parse!(
+    complete!(tag!("extern"))
+        >> multispace1
+        >> name: ident
+        >> multispace0
+        >> char!(':')
+        >> multispace0
+        >> type_: function_type
+        >> multispace0
+        >> (Decl::Extern {
+            name,
+            type_
+        })
+));
+
 named!(fun_decl(&str) -> Decl, do_parse!(
     complete!(tag!("fn"))
-        >> multispace0
+        >> multispace1
         >> name: ident
         >> multispace1
         >> args: separated_list0!(multispace1, arg)
@@ -112,7 +128,8 @@ named!(ascription_decl(&str) -> Decl, do_parse!(
 
 named!(pub decl(&str) -> Decl, alt!(
     ascription_decl |
-    fun_decl
+    fun_decl |
+    extern_decl
 ));
 
 named!(pub toplevel(&str) -> Vec<Decl>, terminated!(many0!(decl), multispace0));