diff --git a/mapgen/main.go b/mapgen/main.go index e1f644e..b51fad5 100644 --- a/mapgen/main.go +++ b/mapgen/main.go @@ -6,6 +6,7 @@ import ( "go/token" "go/types" "os" + "unicode" "golang.org/x/tools/go/packages" ) @@ -78,7 +79,7 @@ func main() { switch obj := obj.(type) { case *types.Func: - scopeData.Functions[name] = buildFunction(obj) + scopeData.Functions[LowerFirst(name)] = buildFunction(obj) case *types.TypeName: if strct, ok := buildStruct(obj); ok { @@ -99,6 +100,15 @@ func main() { fmt.Println(string(out)) } +func LowerFirst(s string) string { + if s == "" { + return "" + } + r := []rune(s) + r[0] = unicode.ToLower(r[0]) + return string(r) +} + func buildFunction(fn *types.Func) FunctionSymbol { sig := fn.Type().(*types.Signature) @@ -166,7 +176,7 @@ func buildStruct(tn *types.TypeName) (StructSymbol, bool) { continue } - methods[m.Name()] = buildFunction(m) + methods[LowerFirst(m.Name())] = buildFunction(m) } return StructSymbol{ diff --git a/semantic/src/lib.rs b/semantic/src/lib.rs index 80dcc83..9af6dfa 100644 --- a/semantic/src/lib.rs +++ b/semantic/src/lib.rs @@ -14,7 +14,7 @@ pub mod top_level; pub fn walk_ast(top_scope: Arc, tl: &mut Vec) { for tl in tl { match tl { - parser::ast::TopLevel::Import(package) => {} + parser::ast::TopLevel::Import(_) => {} parser::ast::TopLevel::Package(_) => {} parser::ast::TopLevel::FunctionDecl { diff --git a/semantic/src/scope.rs b/semantic/src/scope.rs index 403224e..6cd3f5c 100644 --- a/semantic/src/scope.rs +++ b/semantic/src/scope.rs @@ -120,6 +120,11 @@ impl LocalScope { *id = field.name.clone(); current_type = field.var_type.clone(); } + TypeRef::Package(p) => { + let var_ref = p.variables.get(id)?; + *id = var_ref.name.clone(); + current_type = var_ref.var_type.clone(); + } _ => unimplemented!(), }, Postfix::Call(_args) => match &*current_type { diff --git a/test/mist.map.json b/test/mist.map.json index cf63929..529a5df 100644 --- a/test/mist.map.json +++ b/test/mist.map.json @@ -3,7 +3,7 @@ "package_name": "fmt", "structs": {}, "functions": { - "Append": { + "append": { "export": true, "name": "Append", "params": { @@ -22,7 +22,7 @@ "[]byte" ] }, - "Appendf": { + "appendf": { "export": true, "name": "Appendf", "params": { @@ -46,7 +46,7 @@ "[]byte" ] }, - "Appendln": { + "appendln": { "export": true, "name": "Appendln", "params": { @@ -65,7 +65,7 @@ "[]byte" ] }, - "Errorf": { + "errorf": { "export": true, "name": "Errorf", "params": { @@ -84,7 +84,7 @@ "error" ] }, - "FormatString": { + "formatString": { "export": true, "name": "FormatString", "params": { @@ -103,7 +103,7 @@ "string" ] }, - "Fprint": { + "fprint": { "export": true, "name": "Fprint", "params": { @@ -123,7 +123,7 @@ "error" ] }, - "Fprintf": { + "fprintf": { "export": true, "name": "Fprintf", "params": { @@ -148,7 +148,7 @@ "error" ] }, - "Fprintln": { + "fprintln": { "export": true, "name": "Fprintln", "params": { @@ -168,7 +168,7 @@ "error" ] }, - "Fscan": { + "fscan": { "export": true, "name": "Fscan", "params": { @@ -188,7 +188,7 @@ "error" ] }, - "Fscanf": { + "fscanf": { "export": true, "name": "Fscanf", "params": { @@ -213,7 +213,7 @@ "error" ] }, - "Fscanln": { + "fscanln": { "export": true, "name": "Fscanln", "params": { @@ -233,7 +233,7 @@ "error" ] }, - "Print": { + "print": { "export": true, "name": "Print", "params": { @@ -248,7 +248,7 @@ "error" ] }, - "Printf": { + "printf": { "export": true, "name": "Printf", "params": { @@ -268,7 +268,7 @@ "error" ] }, - "Println": { + "println": { "export": true, "name": "Println", "params": { @@ -283,7 +283,7 @@ "error" ] }, - "Scan": { + "scan": { "export": true, "name": "Scan", "params": { @@ -298,7 +298,7 @@ "error" ] }, - "Scanf": { + "scanf": { "export": true, "name": "Scanf", "params": { @@ -318,7 +318,7 @@ "error" ] }, - "Scanln": { + "scanln": { "export": true, "name": "Scanln", "params": { @@ -333,7 +333,7 @@ "error" ] }, - "Sprint": { + "sprint": { "export": true, "name": "Sprint", "params": { @@ -347,7 +347,7 @@ "string" ] }, - "Sprintf": { + "sprintf": { "export": true, "name": "Sprintf", "params": { @@ -366,7 +366,7 @@ "string" ] }, - "Sprintln": { + "sprintln": { "export": true, "name": "Sprintln", "params": { @@ -380,7 +380,7 @@ "string" ] }, - "Sscan": { + "sscan": { "export": true, "name": "Sscan", "params": { @@ -400,7 +400,7 @@ "error" ] }, - "Sscanf": { + "sscanf": { "export": true, "name": "Sscanf", "params": { @@ -425,7 +425,7 @@ "error" ] }, - "Sscanln": { + "sscanln": { "export": true, "name": "Sscanln", "params": { diff --git a/test/src/main.ms b/test/src/main.ms index 99646a0..d994a44 100644 --- a/test/src/main.ms +++ b/test/src/main.ms @@ -3,5 +3,5 @@ package main; import "fmt"; function main() { - fmt.Println("hello"); + fmt.println("hello"); }