Skip to content

Commit

Permalink
improvement: rename keyword function to fn (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra authored Sep 30, 2019
1 parent f6af8b8 commit 48e7b0b
Show file tree
Hide file tree
Showing 34 changed files with 593 additions and 589 deletions.
15 changes: 8 additions & 7 deletions crates/mun/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ extern crate lazy_static;
const LLVM_VERSION_MAJOR: u32 = 7;
const LLVM_VERSION_MINOR: u32 = 0;

/// Environment variables that can guide compilation
///
/// When adding new ones, they should also be added to main() to force a
/// rebuild if they are changed.
// Environment variables that can guide compilation
//
// When adding new ones, they should also be added to main() to force a
// rebuild if they are changed.

lazy_static! {
/// A single path to search for LLVM in (containing bin/llvm-config)
static ref ENV_LLVM_PREFIX: String =
Expand Down Expand Up @@ -47,9 +48,9 @@ lazy_static! {

static ref LLVM_CONFIG_BINARY_NAMES: Vec<String> = {
vec![
"llvm-config".into(),
format!("llvm-config-{}", LLVM_VERSION_MAJOR),
format!("llvm-config-{}.{}", LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR),
format!("llvm-config{}", std::env::consts::EXE_SUFFIX),
format!("llvm-config-{}{}", LLVM_VERSION_MAJOR, std::env::consts::EXE_SUFFIX),
format!("llvm-config-{}.{}{}", LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, std::env::consts::EXE_SUFFIX),
]
};

Expand Down
14 changes: 7 additions & 7 deletions crates/mun/test/main.mun
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Function to add two floats
function add(a:float, b:float):float {
// function to add two floats
fn add(a:float, b:float):float {
let c = a+b+5.0
c
}

// Function to subtract two floats
function subtract(a:float, b:float):float {
// function to subtract two floats
fn subtract(a:float, b:float):float {
a-b
}

// Function to subtract two floats
function multiply(a:float, b:float):float {
// function to subtract two floats
fn multiply(a:float, b:float):float {
a*b
}

function main():int {
fn main():int {
5
}
2 changes: 1 addition & 1 deletion crates/mun_codegen/tests/data/ir/0001_function.mun
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
function main() {
fn main() {
}
2 changes: 1 addition & 1 deletion crates/mun_codegen/tests/data/ir/0002_return_type.mun
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function main():int {
fn main():int {
0
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function main(a:int):int {
fn main(a:int):int {
a
}
6 changes: 3 additions & 3 deletions crates/mun_codegen/tests/data/ir/0004_binary_expressions.mun
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function add(a:int, b:int):int {
fn add(a:int, b:int):int {
a+b
}

function subtract(a:int, b:int):int {
fn subtract(a:int, b:int):int {
a-b
}

function multiply(a:int, b:int):int {
fn multiply(a:int, b:int):int {
a*b
}
2 changes: 1 addition & 1 deletion crates/mun_codegen/tests/data/ir/0005_let_statement.mun
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main(a:int):int {
fn main(a:int):int {
let b = a+1
b
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main() {
fn main() {
let a = 3+3.0;
let b = 3.0+3;
}
6 changes: 3 additions & 3 deletions crates/mun_codegen/tests/data/ir/0007_update_operators.mun
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function add(a:int, b:int):int {
fn add(a:int, b:int):int {
let result = a
result += b
result
}

function subtract(a:int, b:int):int {
fn subtract(a:int, b:int):int {
let result = a
result -= b
result
}

function multiply(a:int, b:int):int {
fn multiply(a:int, b:int):int {
let result = a
result *= b
result
Expand Down
Binary file added crates/mun_runtime/tmp/main.dll
Binary file not shown.
24 changes: 15 additions & 9 deletions crates/mun_syntax/src/ast/generated.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ the below applies to the result of this template
//! `.borrowed` functions. Most of the code works with borrowed mode, and only
//! this mode has all AST accessors.

use rowan::TransparentNewType;

use crate::{
SyntaxNode, SyntaxKind::{self, *},
ast::{self, AstNode},
SyntaxKind::{self, *},
SyntaxNode,
};

{% for node, methods in ast %}
// {{ node }}
{% for node, methods in ast %}// {{ node }}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct {{ node }} {
Expand All @@ -36,22 +34,30 @@ impl AstNode for {{ node }} {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) { Some({{ node }} { syntax }) } else { None }
if Self::can_cast(syntax.kind()) {
Some({{ node }} { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}

{%- if methods.enum %}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum {{ node }}Kind{
pub enum {{ node }}Kind {
{%- for kind in methods.enum %}
{{ kind }}({{ kind }}),
{%- endfor %}
}

{%- for kind in methods.enum %}
impl From<{{ kind }}> for {{ node }} {
fn from(n: {{ kind }}) -> {{ node }} { {{ node }} { syntax: n.syntax } }
fn from(n: {{ kind }}) -> {{ node }} {
{{ node }} { syntax: n.syntax }
}
}
{%- endfor %}

Expand Down
2 changes: 1 addition & 1 deletion crates/mun_syntax/src/grammar.ron
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Grammar(
// "end", // We use braces
"false",
"for",
"function",
"fn",
"if",
"in",
// "local", // We use let
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn api_walkthrough() {
use ast::NameOwner;

let source_code = "
function foo() {
fn foo() {
}
";
Expand Down
6 changes: 3 additions & 3 deletions crates/mun_syntax/src/parsing/grammar/declarations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::T;

pub(super) const DECLARATION_RECOVERY_SET: TokenSet = token_set![FUNCTION_KW, EXPORT_KW];
pub(super) const DECLARATION_RECOVERY_SET: TokenSet = token_set![FN_KW, EXPORT_KW];

pub(super) fn mod_contents(p: &mut Parser) {
while !p.matches(EOF) {
Expand Down Expand Up @@ -35,7 +35,7 @@ pub(super) fn maybe_declaration(p: &mut Parser, m: Marker) -> Result<(), Marker>
opt_visibility(p);

match p.current() {
FUNCTION_KW => {
FN_KW => {
fn_def(p);
m.complete(p, FUNCTION_DEF);
}
Expand All @@ -45,7 +45,7 @@ pub(super) fn maybe_declaration(p: &mut Parser, m: Marker) -> Result<(), Marker>
}

pub(super) fn fn_def(p: &mut Parser) {
assert!(p.matches(FUNCTION_KW));
assert!(p.matches(FN_KW));
p.bump();

name_recovery(p, DECLARATION_RECOVERY_SET.union(token_set![L_PAREN]));
Expand Down
6 changes: 3 additions & 3 deletions crates/mun_syntax/src/parsing/lexer/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) fn scan_number(c: char, cursor: &mut Cursor) -> SyntaxKind {
cursor.bump();
scan_digits(cursor, true);
}
'0'...'9' | '_' | '.' | 'e' | 'E' => {
'0'..='9' | '_' | '.' | 'e' | 'E' => {
scan_digits(cursor, true);
}
_ => return INT_NUMBER,
Expand Down Expand Up @@ -42,10 +42,10 @@ pub(crate) fn scan_number(c: char, cursor: &mut Cursor) -> SyntaxKind {
fn scan_digits(cursor: &mut Cursor, allow_hex: bool) {
while let Some(c) = cursor.current() {
match c {
'_' | '0'...'9' => {
'_' | '0'..='9' => {
cursor.bump();
}
'a'...'f' | 'A'...'F' if allow_hex => {
'a'..='f' | 'A'..='F' if allow_hex => {
cursor.bump();
}
_ => return,
Expand Down
13 changes: 5 additions & 8 deletions crates/mun_syntax/src/syntax_kind/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum SyntaxKind {
ELSE_KW,
FALSE_KW,
FOR_KW,
FUNCTION_KW,
FN_KW,
IF_KW,
IN_KW,
NIL_KW,
Expand Down Expand Up @@ -154,7 +154,7 @@ macro_rules! T {
(else) => { $crate::SyntaxKind::ELSE_KW };
(false) => { $crate::SyntaxKind::FALSE_KW };
(for) => { $crate::SyntaxKind::FOR_KW };
(function) => { $crate::SyntaxKind::FUNCTION_KW };
(fn) => { $crate::SyntaxKind::FN_KW };
(if) => { $crate::SyntaxKind::IF_KW };
(in) => { $crate::SyntaxKind::IN_KW };
(nil) => { $crate::SyntaxKind::NIL_KW };
Expand Down Expand Up @@ -197,7 +197,7 @@ impl SyntaxKind {
| ELSE_KW
| FALSE_KW
| FOR_KW
| FUNCTION_KW
| FN_KW
| IF_KW
| IN_KW
| NIL_KW
Expand Down Expand Up @@ -316,7 +316,7 @@ impl SyntaxKind {
ELSE_KW => &SyntaxInfo { name: "ELSE_KW" },
FALSE_KW => &SyntaxInfo { name: "FALSE_KW" },
FOR_KW => &SyntaxInfo { name: "FOR_KW" },
FUNCTION_KW => &SyntaxInfo { name: "FUNCTION_KW" },
FN_KW => &SyntaxInfo { name: "FN_KW" },
IF_KW => &SyntaxInfo { name: "IF_KW" },
IN_KW => &SyntaxInfo { name: "IN_KW" },
NIL_KW => &SyntaxInfo { name: "NIL_KW" },
Expand Down Expand Up @@ -379,7 +379,7 @@ impl SyntaxKind {
"else" => ELSE_KW,
"false" => FALSE_KW,
"for" => FOR_KW,
"function" => FUNCTION_KW,
"fn" => FN_KW,
"if" => IF_KW,
"in" => IN_KW,
"nil" => NIL_KW,
Expand Down Expand Up @@ -431,6 +431,3 @@ impl SyntaxKind {
Some(tok)
}
}



2 changes: 1 addition & 1 deletion crates/mun_syntax/tests/data/lexer/0007_keywords.mun
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
and break do else false for function if in nil not or
and break do else false for fn if in nil not or
return then true while let mut class public protected
private
2 changes: 1 addition & 1 deletion crates/mun_syntax/tests/data/lexer/0007_keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FALSE_KW 5 "false"
WHITESPACE 1 " "
FOR_KW 3 "for"
WHITESPACE 1 " "
FUNCTION_KW 8 "function"
FN_KW 2 "fn"
WHITESPACE 1 " "
IF_KW 2 "if"
WHITESPACE 1 " "
Expand Down
8 changes: 4 additions & 4 deletions crates/mun_syntax/tests/data/parser/ok/0001_function.mun
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Source file comment

// Comment that belongs to the function
function a() {}
function b(value:number) {}
export function c() {}
function b(value:number):number {}
fn a() {}
fn b(value:number) {}
export fn c() {}
fn b(value:number):number {}
Loading

0 comments on commit 48e7b0b

Please sign in to comment.