From 04dbd5a7b6ce54d6aa3ce6bac281233b093bdfe5 Mon Sep 17 00:00:00 2001 From: Marek Maskarinec Date: Mon, 2 May 2022 22:22:03 +0200 Subject: [PATCH 1/5] add umka --- umka.html.markdown | 173 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 umka.html.markdown diff --git a/umka.html.markdown b/umka.html.markdown new file mode 100644 index 00000000..8c4ae059 --- /dev/null +++ b/umka.html.markdown @@ -0,0 +1,173 @@ +--- +name: Umka +category: language +language: Umka +filename: learnumka.um +contributors: + - ["Marek Maškarinec", "https://github.com/marekmaskarinec"] +--- + +Umka is a statically typed scripting language meant to be embedded into +programs, useful in cases like mod support in games, or user scripting. + +It draws inspiration from Pascal and Go. + +``` +// Single line comment +/* Multi line comments + they cant't be nested */ + +// The import statement can import other files +import ( + "std.um" // the standard library - included in the interpretor + "map.um" // hashmaps + "utf8.um" // utf8 encoding and decoding +) + +// Functions are declared with the fn keyword. They have to be declared before +// usage. To combat this, umka allows function prototypes. +// The main function serves as an entry point when running the file. +// Included files can contain main too. +fn main() { + // printf works the same as in c. It is builtin, so you don't need to + // import any file to use it. + printf("Hello world!\n") + + // Variables have to be declared before use. There are multiple ways to do so. + var x: int = 3 // full declaration + var y: uint32 // you can ignore the value + var z = 5 // you can also ignore the type + a := 6 // umka also allows short declarations like in go + + y = 4 // variable assignement + + // there aren't doubles or floats in umka. They are called real and + // real32 instead. + var pi: real = 3.14 + + // if statements + if pi == 3.14 { + printf("Close enough.\n") + } else if pi == 3 { + printf("You should learn about real values.\n") + } else { + printf("You live in a strange world.\n") + } + + // Umka has only one key word for loops. + // Traditional while loop: + for z > 0 { + printf("%d\n", z) + z-- + } + + // for loop: + for i:=0; i < y; i++ { + printf("%d\n", i) + } + + // the string type is called str + var name: str = "John" + // string concatenation + name += " Doe" + + // Umka has two types of arrays - fixed and dynamic. Fixed have fixed size, + // are stored on the stack and passed by value. Dynamic are the opposite. + // You can append and slice them, they are stored on the heap and passed by + // reference. + + // A fixed array + names := [4]str{"Jonathan", "Joseph", "Jotaro", "Josuke"} + + // Making a dynamic array is done by just removing the number + dynNames := []str{"Jonathan", "Joseph", "Jotaro", "Josuke"} + // It is also possible to create a zero initialized dynamic array of a given + // length. The length doesn't have to be a constant. + arr := make([]int, 23) + + // Dynamic arrays can be appended. Be aware, that the array is allways newly + // allocated, and the old elements are copied. This makes the process of + // appending very slow. + dynNames = append(dynNames, "Giorno") + + // You can also delete an element from an array. + dynNames = delete(dynNames, 3) // => { "Jonathan", "Joseph", "Jotaro", "Giorno" } + + // You can also slice them. Start inclusive, end exclusive. + part1 := slice(dynNames, 0, 2) + // You can ommit the ending index and it will be replaced by the length of the array. + part2 := slice(dynNames, 2) + + // You can iterate over a string, array and a dynamic array using the for in loop. + for index, value in dynNames { + printf("%d: %s\n", index, value) + } + + // Umka supports pointers. You can make a pointer type by writing a ^ before + // the base type. + var xPointer: ^int + + // Values are referenced using an & + xPointer = &x + + // You can dereference them by writing a ^ after the value + printf("%s: %d\n", repr(xPointer), xPointer^) // => 0xaddress : 3 +} + +// Functions are declared using the fn keyword. Parameters are in parenthesis, +// the return type follows after a :. Functions don't have to take parameters, +// or return any values. +fn learnFunctions(a, b: int, c: real): real { + return a + b * c +} + +// Functions can return multiple values. +fn learnMultiple(): (int, int) { + x, y := getPosition() + + x *= 2 + y *= 2 + + return x, y +} + +// The type keywords allows type aliases +type Number int + +// You can use it to define your own structure types. +type Vector2 = struct { + x, y: real +} + +fn newVector2(x, y: read): Vector2 { + // Structure literals + return Vector2{ x, y } +} + +// You can define methods on any type from the current module. +fn (v: ^Vector2) multiply(x: real) { + v.x *= x + v.y *= x +} + +// An interface is a form of duck typing in Umka. It defines a set of methods, +// that must be implemented by a type to implement said interface. +type Representable = interface { + toStr(): str +} + +// Vector2 now implements Representable +fn (v: ^Vector2) toStr(): str { + return "[ " + repr(v.x) + repr(v.y) + "]" +} + +// This function takes a variadic number of Representable values +fn println(args ...Representable) { + // variadic arguments act like an array inside a function + for arg in args { + printf("%s", repr(arg)) + } + + printf("\n") +} + From 584a9440f7ea0f6a22c1e92c68ab469aa3504cda Mon Sep 17 00:00:00 2001 From: Marek Maskarinec Date: Mon, 2 May 2022 22:28:30 +0200 Subject: [PATCH 2/5] fix missing ending --- umka.html.markdown | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/umka.html.markdown b/umka.html.markdown index 8c4ae059..2f57e965 100644 --- a/umka.html.markdown +++ b/umka.html.markdown @@ -95,10 +95,12 @@ fn main() { // You can also slice them. Start inclusive, end exclusive. part1 := slice(dynNames, 0, 2) - // You can ommit the ending index and it will be replaced by the length of the array. + // You can ommit the ending index and it will be replaced by the length + // of the array. part2 := slice(dynNames, 2) - // You can iterate over a string, array and a dynamic array using the for in loop. + // You can iterate over a string, array and a dynamic array + // using the "for in" loop. for index, value in dynNames { printf("%d: %s\n", index, value) } @@ -170,4 +172,9 @@ fn println(args ...Representable) { printf("\n") } +``` +## Further reading + +You can learn more details in the [spec](https://github.com/vtereshkov/umka-lang/tree/master/spec.md). +If you want to read real umka code, read some of the [examples](https://github.com/vtereshkov/umka-lang/tree/master/examples). From 32909336c138da84b45a84c968217c36c9c5d044 Mon Sep 17 00:00:00 2001 From: Marek Maskarinec Date: Mon, 2 May 2022 22:31:30 +0200 Subject: [PATCH 3/5] change contributor url --- umka.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umka.html.markdown b/umka.html.markdown index 2f57e965..87ece832 100644 --- a/umka.html.markdown +++ b/umka.html.markdown @@ -4,7 +4,7 @@ category: language language: Umka filename: learnumka.um contributors: - - ["Marek Maškarinec", "https://github.com/marekmaskarinec"] + - ["Marek Maškarinec", "https://mrms.cz"] --- Umka is a statically typed scripting language meant to be embedded into From c6d089b9dc40f03105016c5209d4a77517ec957b Mon Sep 17 00:00:00 2001 From: Boris Verkhovskiy Date: Fri, 17 May 2024 12:08:20 -0600 Subject: [PATCH 4/5] Update link and typos --- umka.html.markdown | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/umka.html.markdown b/umka.html.markdown index 87ece832..9edbafca 100644 --- a/umka.html.markdown +++ b/umka.html.markdown @@ -1,6 +1,4 @@ --- -name: Umka -category: language language: Umka filename: learnumka.um contributors: @@ -15,11 +13,11 @@ It draws inspiration from Pascal and Go. ``` // Single line comment /* Multi line comments - they cant't be nested */ + they can't be nested */ // The import statement can import other files import ( - "std.um" // the standard library - included in the interpretor + "std.um" // the standard library - included in the interpreter "map.um" // hashmaps "utf8.um" // utf8 encoding and decoding ) @@ -39,7 +37,7 @@ fn main() { var z = 5 // you can also ignore the type a := 6 // umka also allows short declarations like in go - y = 4 // variable assignement + y = 4 // variable assignment // there aren't doubles or floats in umka. They are called real and // real32 instead. @@ -85,7 +83,7 @@ fn main() { // length. The length doesn't have to be a constant. arr := make([]int, 23) - // Dynamic arrays can be appended. Be aware, that the array is allways newly + // Dynamic arrays can be appended. Be aware, that the array is always newly // allocated, and the old elements are copied. This makes the process of // appending very slow. dynNames = append(dynNames, "Giorno") @@ -176,5 +174,5 @@ fn println(args ...Representable) { ## Further reading -You can learn more details in the [spec](https://github.com/vtereshkov/umka-lang/tree/master/spec.md). -If you want to read real umka code, read some of the [examples](https://github.com/vtereshkov/umka-lang/tree/master/examples). +You can learn more details in the [documentation](https://github.com/vtereshkov/umka-lang/tree/master/doc). +If you want to read real Umka code, read some of the [examples](https://github.com/vtereshkov/umka-lang/tree/master/examples). From 0a0ae973faeb729a463435e1f8397e4de3d111a8 Mon Sep 17 00:00:00 2001 From: Marek Maskarinec Date: Fri, 17 May 2024 20:24:54 +0200 Subject: [PATCH 5/5] Update umka.html.markdown Co-authored-by: Boris Verkhovskiy --- umka.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umka.html.markdown b/umka.html.markdown index 9edbafca..1b76bbc4 100644 --- a/umka.html.markdown +++ b/umka.html.markdown @@ -139,7 +139,7 @@ type Vector2 = struct { x, y: real } -fn newVector2(x, y: read): Vector2 { +fn newVector2(x, y: real): Vector2 { // Structure literals return Vector2{ x, y } }