{"id":22874126,"url":"https://github.com/joakimthun/elsa","last_synced_at":"2025-05-06T19:24:06.486Z","repository":{"id":53094048,"uuid":"42125263","full_name":"joakimthun/Elsa","owner":"joakimthun","description":"The Elsa Programming Language","archived":false,"fork":false,"pushed_at":"2017-04-02T19:26:20.000Z","size":698,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-11T15:34:52.716Z","etag":null,"topics":["bytecode","compiler","elsa-programming-language","interpreter","language","pratt-parser","programming-language","virtual-machine"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joakimthun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-08T16:37:40.000Z","updated_at":"2023-08-03T04:13:07.000Z","dependencies_parsed_at":"2022-08-27T03:08:50.453Z","dependency_job_id":null,"html_url":"https://github.com/joakimthun/Elsa","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimthun%2FElsa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimthun%2FElsa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimthun%2FElsa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimthun%2FElsa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joakimthun","download_url":"https://codeload.github.com/joakimthun/Elsa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229556892,"owners_count":18091837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode","compiler","elsa-programming-language","interpreter","language","pratt-parser","programming-language","virtual-machine"],"created_at":"2024-12-13T14:33:22.398Z","updated_at":"2024-12-13T14:33:23.004Z","avatar_url":"https://github.com/joakimthun.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## The Elsa Programming Language\nA statically typed, garbage collected language that runs on a custom stack based vm.\nElsa is written just for fun(and educational purposes) and is not really intended for actual use.\n\n#### Examples:\n[Bouncy](../master/src/examples/bouncy): A Breakout clone written in Elsa\n![alt tag](https://raw.githubusercontent.com/joakimthun/Elsa/master/src/examples/bouncy.png)\n\n#### Running Bouncy\nDownload the latest release from [here](https://github.com/joakimthun/Elsa/releases).\nThen just run \"elsa bouncy/main.elsa\" from the command line\n\n#### Language features:\n\n###### Basic functions\n```\n  // The main function is the entry point of all Elsa programs and is always required\n  fn main() {\n     \n  }\n  \n  // A function that takes no arguments and returns void\n  fn hello() {\n     PrintLn(\"Hello world!\");\n  }\n \n  // A function that takes an integer argument and returns an integer\n  fn returnInt(int x) : int {\n     return x;\n  }\n```\n\nWhen passing arguments to functions all built-in types are passed by value while structs and arrays are passed by reference(pointers)\n\n###### Closures\n```\n  // All types of functions(including member functions) in Elsa are treated as any other \n  // \"object\" and can be passed around and assigned to variables.\n  \n  // If a functions uses any variables or fields from the context in which it was declared \n  // the function will keep a reference to that variable or field\n  \n  var x = 10;\n  \n  // A function that takes no arguments and returns the integer captured from the outer scope\n  var ret = fn : int =\u003e { return x; };\n  \n  // A function that takes no arguments, returns void and increments the captured variable by 1\n  var inc = fn =\u003e { x = x + 1; }; \n  \n  inc(); // x is now 11\n  PrintLn(ret()); // Prints 11\n  \n  // A function that takes another function(taking no arguments and returns void) as an argument\n  // and invokes the passed function twice\n  fn callTwice(fn f) {\n     f();\n     f();\n  }\n  \n  callTwice(inc); // callTwice will call our inc function twice\n  PrintLn(ret()); // Prints 13\n  PrintLn(x); // Prints 13\n```\n\n\n###### Variables and built-in types\n```\n  int i = 0;\n  int h = 0xffff;\n  float f = 0.0;\n  char c = '0';\n  bool t = true;\n  byte b = byte(0);\n  byte b2 = byte(0xff);\n  \n  // Variables can also be declared by using the var keyword \n  // and letting the compiler infer the type\n  var x = 15; // int\n  \n  // All built-in types in Elsa have default values\n  int: 0\n  float: 0.0\n  char: '\\0'\n  byte: 0\n  \n  // Array and struct instances will be null pointers if not instantiated \n  // with the new keyword (see the struct section)\n```\n\n###### Strings\n```\n  // The String struct in Elsa is very incomplete but has some basic functionality\n\n  // Creating new string instances\n  var str = \"Hello World!\";\n  var first =  \"123\";\n  var second = \"123\";\n\n  // Retrives a char at the specified index\n  str.CharAt(1) // e\n  \n  // Returns the length of the string as an integer\n  str.Length() // 12\n\n  // Comparing strings, the String struct define its own Equals-function\n  // see the Structs section for more info\n  first.Equals(second)); // true\n  first == second;       // true    \n  first != second;       // false\n  \n  // Concatenating strings\n  var third = first.Concat(second); // third == \"123123\"\n  \n  // Substring, substring takes 2 integer arguments\n  // the start index and the number of chars to grab\n  third.Substring(0, 3); // \"123\"\n```\n\nThe source code for the String struct can be found [here](../master/src/std/string.elsa)\n\n###### Type conversions\n```\n  var floatToInt = int(10.0);\n  var intToFloat = float(10);\n  var intToChar = char(33);\n  var charToInt = int('!');\n  var intToByte = byte(10);\n```\n\n\n###### Operators and precedence\n```\n  var x1 = (3 + 5) * 6;                                 // 48\n  var x2 = (3 + 5) * (6 + 8);                           // 112\n  var x3 = (3 + 5 * 6) * 6;                             // 198\n  var x4 = (3 + 5  / (1 * 6)) * (6 + 8 * (2 - 1));      // 42\n  var x5 = true || (true \u0026\u0026 false);                     // true\n  var x6 = (true \u0026\u0026 false) || (false || false);         // false\n  var x7 = (1 == 1 \u0026\u0026 2 == 2) \u0026\u0026 (7 == 8 || 0 != 8);    // true\n  var x8 = 10 % 3;                                      // 1\n  \n  // Binary operators\n  x \u003c\u003c 1;\n  x \u003e\u003e 1;\n  x | y;\n  x \u0026 y;\n  \n  byte x1 = 0xFF;\n  byte y1 = 0xFF;\n  var r = (int(x1) \u003c\u003c 8) | int(y1);   // 65535\n```\n\n\n###### Arrays\n```\n  var arr = new int[10]; // An array of integers with an intial capacity of 10\n  var arr2 = new [1, 2, 3, 4, 5, 6]; // Arrays can also be defined by using array literals\n  \n  // Array member functions\n  arr.Push(1);  // Adds the integer 1 to the back of the array\n  arr.Pop();    // Pops the last element in the array, pop returns the popped element\n  arr.Length(); // Returns the array length\n  \n  // Array operators\n  arr[2];       // Access the element at index 2 in the array\n```\n\n\n###### Branching\n```\n  if(x == 10) {\n     PrintLn(\"x == 10\");\n  }\n  else {\n     // The else block can be omitted\n     PrintLn(\"x == 10\");\n  }\n``` \n\n\n###### Loops\n```\n  for(var i = 0; i \u003c arr.Length(); i++)\n  {\n     PrintLn(arr[i]);\n  }\n  \n  while(y || x) {\n     PrintLn(\"Loopy loop\");\n  }\n``` \n\n\n###### Structs\n```\n  struct Bitmap {\n     // Fields are declared like this\n     byte[] data;\n     int width;\n     int height;\n\n     // Member functions are declared like any other function but inside a struct declaration\n     fn GetPixel(int x, int y) : Color {\n        var stride = 4;\n        var base = stride * x * width + y * stride;\n        return new Color { R: data[base], G: data[base + 1], B: data[base + 2], A: data[base + 3] };\n     }\n     \n     // The Equals-function is special. If two struct instances(of the same type) are compared with the\n     // == operator the Equals-function is automatically called.\n     // If no Equals-function is declared, a check for reference equality is done\n     fn Equals(Bitmap other) : bool {\n        return true;\n     }\n  };\n  \n  struct Color {\n     byte R;\n     byte G;\n     byte B;\n     byte A;\n  };\n  \n  // Struct instances are created by using the new keyword\n  var red = new Color;\n  \n  // Elsa also supports initializer lists\n  var red = new Color { R: 0xFF, G: o, B: o, A: 0xFF }; \n``` \n\n\n###### Enums\n```\n  // Enums in Elsa are just integers converted by the compiler at compile time\n  enum Enum {\n     Zero,      // 0\n     Three = 3, // 3\n     Four,      // 4\n     Seven = 7  // 7\n  };\n``` \n\n###### Working with multiple source files\n```\n  // Including stuff from other .elsa source files is done with the use keyword\n  use \"std/io\";\n\n  fn main() {\n     PrintLn(z);\n  }\n```\n\n###### Standard library\nElsa has a very small standard library with basic functions for printing stuff to the console, \nopening a window(and drawing basic shapes), reading files etc.\n\nAll standard library functions and structs can be found [here](../master/src/std)\n\n#### Building and OS support\nElsa only runs on Windows(at least right now) and has only been tested with the Visual C++ Compiler\n\n###### Example VM-program:\n```\n    // factorial (10)\n\ticonst, 1,\n\tl_arg, 0,\n\tbr_ineq, 9,\n\ticonst, 1,\n\tret,\n\tl_arg, 0,\n\tl_arg, 0,\n\ticonst, 1,\n\tisub,\n\tcall, 0,\n\timul,\n\tret,\n\n\t// main\n\ticonst, 10,\n\tcall, 0,\n\thalt\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoakimthun%2Felsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoakimthun%2Felsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoakimthun%2Felsa/lists"}