From 269a9933181da4b3a915f4f999100651f2c45dcc Mon Sep 17 00:00:00 2001 From: kemo Date: Fri, 10 Feb 2023 09:15:03 +0200 Subject: [PATCH] hello there --- .vscode/launch.json | 8 +- Custom-lang/Scripts/arrays.hz | 7 - Custom-lang/Scripts/class.hz | 27 -- Custom-lang/Scripts/enum.hz | 17 -- Custom-lang/out.wasm | Bin 81 -> 0 bytes Custom-lang/test.hz | 13 - DOC.MD | 170 ------------ FEATURES.MD | 251 ++++++++++++++++++ Custom-lang.sln => Horizon-Lang.sln | 2 +- {Custom-lang => Horizon-Lang}/.clang-format | 0 {Custom-lang => Horizon-Lang}/.gitignore | 0 .../Compile/Compiler.ixx | 0 .../Compile/KaleidoscopeJIT.h | 0 {Custom-lang => Horizon-Lang}/Compile/LLVM.h | 0 .../Compile/LLVM.ixx | 0 .../Frontend/AST/Core.ixx | 0 .../Frontend/AST/Expressions.ixx | 0 .../Frontend/AST/Statements.ixx | 0 .../Frontend/Lexer.ixx | 0 .../Frontend/Parser.ixx | 7 +- .../Horizon-Lang.cpp | 6 +- .../Horizon-Lang.vcxproj | 15 +- .../Horizon-Lang.vcxproj.filters | 16 +- {Custom-lang => Horizon-Lang}/Logger.ixx | 0 .../Runtime/Callables.ixx | 0 .../Runtime/ExecutionContext.ixx | 0 .../Runtime/Interpreter/Exprs.ixx | 29 +- .../Runtime/Interpreter/Interpreter.ixx | 0 .../Runtime/Interpreter/Stmts.ixx | 0 .../Runtime/Thread.ixx | 0 .../Runtime/Values/ArrayValue.ixx | 0 .../Runtime/Values/BoolValue.ixx | 0 .../Runtime/Values/EnumValue.ixx | 0 .../Runtime/Values/FloatValue.ixx | 10 + .../Runtime/Values/IntValue.ixx | 10 + .../Runtime/Values/NullValue.ixx | 0 .../Runtime/Values/ObjectValue.ixx | 0 .../Runtime/Values/RuntimeValue.ixx | 6 +- .../Runtime/Values/StringValue.ixx | 0 {Custom-lang => Horizon-Lang}/Safety.ixx | 0 .../Types/ConstexprString.ixx | 0 .../Types/Extensions/String.ixx | 0 .../Types/Extensions/Vector.ixx | 0 .../Types/FlatMap.ixx | 0 .../Types/Reflection.ixx | 0 {Custom-lang => Horizon-Lang}/Types/Types.ixx | 0 Horizon-Lang/test.hz | 11 + README.MD | 95 +++++++ 48 files changed, 421 insertions(+), 279 deletions(-) delete mode 100644 Custom-lang/Scripts/arrays.hz delete mode 100644 Custom-lang/Scripts/class.hz delete mode 100644 Custom-lang/Scripts/enum.hz delete mode 100644 Custom-lang/out.wasm delete mode 100644 Custom-lang/test.hz delete mode 100644 DOC.MD create mode 100644 FEATURES.MD rename Custom-lang.sln => Horizon-Lang.sln (86%) rename {Custom-lang => Horizon-Lang}/.clang-format (100%) rename {Custom-lang => Horizon-Lang}/.gitignore (100%) rename {Custom-lang => Horizon-Lang}/Compile/Compiler.ixx (100%) rename {Custom-lang => Horizon-Lang}/Compile/KaleidoscopeJIT.h (100%) rename {Custom-lang => Horizon-Lang}/Compile/LLVM.h (100%) rename {Custom-lang => Horizon-Lang}/Compile/LLVM.ixx (100%) rename {Custom-lang => Horizon-Lang}/Frontend/AST/Core.ixx (100%) rename {Custom-lang => Horizon-Lang}/Frontend/AST/Expressions.ixx (100%) rename {Custom-lang => Horizon-Lang}/Frontend/AST/Statements.ixx (100%) rename {Custom-lang => Horizon-Lang}/Frontend/Lexer.ixx (100%) rename {Custom-lang => Horizon-Lang}/Frontend/Parser.ixx (99%) rename Custom-lang/Custom-lang.cpp => Horizon-Lang/Horizon-Lang.cpp (98%) rename Custom-lang/Custom-lang.vcxproj => Horizon-Lang/Horizon-Lang.vcxproj (96%) rename Custom-lang/Custom-lang.vcxproj.filters => Horizon-Lang/Horizon-Lang.vcxproj.filters (89%) rename {Custom-lang => Horizon-Lang}/Logger.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Callables.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/ExecutionContext.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Interpreter/Exprs.ixx (91%) rename {Custom-lang => Horizon-Lang}/Runtime/Interpreter/Interpreter.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Interpreter/Stmts.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Thread.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/ArrayValue.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/BoolValue.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/EnumValue.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/FloatValue.ixx (88%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/IntValue.ixx (89%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/NullValue.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/ObjectValue.ixx (100%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/RuntimeValue.ixx (95%) rename {Custom-lang => Horizon-Lang}/Runtime/Values/StringValue.ixx (100%) rename {Custom-lang => Horizon-Lang}/Safety.ixx (100%) rename {Custom-lang => Horizon-Lang}/Types/ConstexprString.ixx (100%) rename {Custom-lang => Horizon-Lang}/Types/Extensions/String.ixx (100%) rename {Custom-lang => Horizon-Lang}/Types/Extensions/Vector.ixx (100%) rename {Custom-lang => Horizon-Lang}/Types/FlatMap.ixx (100%) rename {Custom-lang => Horizon-Lang}/Types/Reflection.ixx (100%) rename {Custom-lang => Horizon-Lang}/Types/Types.ixx (100%) create mode 100644 Horizon-Lang/test.hz create mode 100644 README.MD diff --git a/.vscode/launch.json b/.vscode/launch.json index 1f4cdb6..8fa0fe9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,10 +7,10 @@ "name": "run (debug)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}\\bin\\Debug\\Custom-lang.exe", + "program": "${workspaceFolder}\\bin\\Debug\\Horizon-Lang.exe", "args": [], "stopAtEntry": false, - "cwd": "${workspaceFolder}\\Custom-lang", + "cwd": "${workspaceFolder}\\Horizon-Lang", "environment": [], "console": "integratedTerminal", "preLaunchTask": "build (debug)" @@ -19,10 +19,10 @@ "name": "run (release)", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}\\bin\\Custom-lang.exe", + "program": "${workspaceFolder}\\bin\\Horizon-Lang.exe", "args": [], "stopAtEntry": false, - "cwd": "${workspaceFolder}\\Custom-lang", + "cwd": "${workspaceFolder}\\Horizon-Lang", "environment": [], "console": "integratedTerminal", "preLaunchTask": "build (release)" diff --git a/Custom-lang/Scripts/arrays.hz b/Custom-lang/Scripts/arrays.hz deleted file mode 100644 index b149468..0000000 --- a/Custom-lang/Scripts/arrays.hz +++ /dev/null @@ -1,7 +0,0 @@ -let x = ["", "Ok", "Not Ok"]; - -x = ["Ok", "Not Ok"]; - -x[0] = "Okkk"; - -print(x[0]); \ No newline at end of file diff --git a/Custom-lang/Scripts/class.hz b/Custom-lang/Scripts/class.hz deleted file mode 100644 index 02ab8ef..0000000 --- a/Custom-lang/Scripts/class.hz +++ /dev/null @@ -1,27 +0,0 @@ -class IceCream -{ - IceCream(flavor) - { - this.flavor = flavor; - } - - getFlavor() - { - return this.flavor; - } - - serveOn() - { - return "Cones"; - } -}; - -let food: IceCream = IceCream("badFlavor"); - -food = IceCream("coffee"); - -print(food.getFlavor()); - -let servedOn: String = food.serveOn(); - -print(servedOn); diff --git a/Custom-lang/Scripts/enum.hz b/Custom-lang/Scripts/enum.hz deleted file mode 100644 index b144ad9..0000000 --- a/Custom-lang/Scripts/enum.hz +++ /dev/null @@ -1,17 +0,0 @@ -enum Veggie -{ - Squash, - Cabbage, - Broccoli, -} - -let cart = [Cabbage, Cabbage, Broccoli]; - -let veggie = Broccoli; - -print(veggie); - -if (veggie == Broccoli) -{ - print("We've got the best vegetable!"); -} diff --git a/Custom-lang/out.wasm b/Custom-lang/out.wasm deleted file mode 100644 index 62d74bae7ee7748d8160489f62a5bdad167e55b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 81 zcmZQbEY4+QU|?WmXG~zKuV<`hW@chwU=w1hXLMxXu3>Zm%7FnlyATs=VoFMC5m36g YG${$lVB`{HVrNibP+-jBhS1sE0MVEWC;$Ke diff --git a/Custom-lang/test.hz b/Custom-lang/test.hz deleted file mode 100644 index fe83956..0000000 --- a/Custom-lang/test.hz +++ /dev/null @@ -1,13 +0,0 @@ -//extern putchard(x: Float): Float; - -//putchard(120); - -function adder(x: Int, y: Int): Int -{ - x + y + (2 + 3) -} - -function subber(x: Int, y: Int): Int -{ - x - y -} \ No newline at end of file diff --git a/DOC.MD b/DOC.MD deleted file mode 100644 index 569d5c2..0000000 --- a/DOC.MD +++ /dev/null @@ -1,170 +0,0 @@ -## Operator precedence - -| Operators | Category or name | -| ------------- | ----------------- | -| `x = y`, `x = {...}` | Assignment | -| `x || y` | Conditional OR | -| `x && y` | Conditional AND | -| `x == y`, `x != y` | Equality | -| `x < y`, `x > y`, `x <= y`, `x >= y` | Comparison | -| `x + y`, `x - y` | Additive | -| `x * y`, `x / y`, `x % y` | Multiplicative | -| `x.y`, `f(x)`, `a[i]`, `x++`, `x--` | Primary | - - -## Statements: - -- Variable declaration: - -```haxe -let x = 1; -const x = 1; -``` - -- Print statement: - -```haxe -print x; -print "Hello World"; -``` - -- Loop statement: - -```haxe -// loops 3 times -loop(3) { - print "ok"; -} - -// loops infinitely -let i = 0; -loop { - if (i == 2) - { - i = i + 1; - continue; - } - - print i; - - if (i == 5) - { - break; - } - - i = i + 1; -} -``` - -## Expressions: - -Todo: - -- [ ] Unary: `-x`, `!x` -- [ ] Incremenet/Decrement operators `x++`, `x--` -- [ ] for loops - -- Literal: - -```haxe -1; -("Hello World"); -true; -false; -null; -``` - -- Variable: - -```haxe -x; -``` - -- Assignment: - -```haxe -x = 1; -``` - -- Function call: - -```haxe -f(1, 2, 3); -``` - -- Object: - -```haxe -let bar = { x: 1, y: 1 }; - -print(bar["x"] == bar.y); -``` - -- Arithmetic: - -```haxe -1 + 2; -1 - 2; -1 * 2; -1 / 2; -1 % 2; -``` - -- Block/Scope: - -```haxe -{ - let x = 1; - print(x); -} - -print(x); // Error: x is not defined -``` - -- Logic: - -```haxe -// Conditional AND (&& or "and") -"ok" and "ko" // "false" -"ok" and "ok" // "true" - -// Conditional OR (|| or "or") -"ok" or "ko" // "ok" -false or "ko" // "ko" - -// Equality -"ok" == "ok" // "true" -"ok" == "ko" // "false" - -// Inequality -"ok" != "ok" // "false" -"ok" != "ko" // "true" -``` - -- If: - -```haxe -let x = if (true) { 1 } else { 2 }; - -if (x == 1) { - print("Hello World"); - print(if (x != 1) { "hi" } else { "bye" }); -} -``` - -- Functions: - -```haxe -function foo() -{ - return 100; -} - -let fmt = format("{}: {}", foo(), 300); - -print(fmt) // 100.000000: 300.000000 - -print("{}", 100) // 100.000000 - -print(foo(), 300) // 100.000000 300.000000 -``` \ No newline at end of file diff --git a/FEATURES.MD b/FEATURES.MD new file mode 100644 index 0000000..c9509c3 --- /dev/null +++ b/FEATURES.MD @@ -0,0 +1,251 @@ +## Operator precedence + +| Operators | Category or name | +| ------------------------------------ | ---------------- | --- | -------------- | +| `x = y`, `x = {...}` | Assignment | +| `x | | y` | Conditional OR | +| `x && y` | Conditional AND | +| `x == y`, `x != y` | Equality | +| `x < y`, `x > y`, `x <= y`, `x >= y` | Comparison | +| `x + y`, `x - y` | Additive | +| `x * y`, `x / y`, `x % y` | Multiplicative | +| `x.y`, `f(x)`, `a[i]`, `x++`, `x--` | Primary | + +## Statements: + +- Variable declaration: + +```haxe +let x: Int = 1; +// const x: Int = 1; +let y: String = "Hello World"; +let z: Bool = true; +let a: Array = [1, 2, 3]; +let b: Object = { x: 1, y: 1 }; +let c: Float = 1.0; +// let d: Enum = Squash; +let e: Any = null; +``` + +- Class declaration: + +```haxe +class IceCream +{ + IceCream(flavor) + { + this.flavor = flavor; + } + + getFlavor() + { + return this.flavor; + } + + serveOn() + { + return "Cones"; + } +}; + +let food: IceCream = IceCream("badFlavor"); + +food = IceCream("coffee"); + +print(food.getFlavor()); + +let servedOn: String = food.serveOn(); + +print(servedOn); +``` + +- Enum declaration: + +```haxe +enum Veggie +{ + Squash, + Cabbage, + Broccoli, +} + +let cart: Array = [Cabbage, Cabbage, Broccoli]; + +let veggie: Enum = Broccoli; + +print(veggie); + +if (veggie == Broccoli) +{ + print("We've got the best vegetable!"); +} +``` + +- Builtin functions: + +```haxe +print("Hello {}", "World"); +format("Hello {}", "World"); +sleep(1000); +``` + +- Loop statement: + +```haxe +// loops 3 times +loop(3) { + print("ok"); +} + +// loops infinitely +let i: Int = 0; +loop { + if (i == 2) + { + i = i + 1; + continue; + } + + print(i); + + if (i == 5) + { + break; + } + + i = i + 1; +} +``` + +- Sync statement: + +```haxe +sync +{ + loop (50) + { + print("ok"); + } +} + +sync +{ + loop (50) + { + print("ok"); + } +} +``` + +## Expressions: + +- Literal: + +```haxe +1; +("Hello World"); +true; +false; +null; +``` + +- Variable: + +```haxe +x; +``` + +- Array: + +```haxe +let x: Array = [1, 2, 3]; +``` + +- Assignment: + +```haxe +x = 1; +``` + +- Function call: + +```haxe +f(1, 2, 3); +``` + +- Object: + +```haxe +let bar: Object = { x: 1, y: 1 }; + +print(bar["x"] == bar.y); +``` + +- Arithmetic: + +```haxe +1 + 2; +1 - 2; +1 * 2; +1 / 2; +1 % 2; +``` + +- Block/Scope: + +```haxe +{ + let x: Int = 1; + print(x); +} + +print(x); // Error: x is not defined +``` + +- Logic: + +```haxe +// Conditional AND (&& or "and") +"ok" and "ko" // "false" +"ok" and "ok" // "true" + +// Conditional OR (|| or "or") +"ok" or "ko" // "ok" +false or "ko" // "ko" + +// Equality +"ok" == "ok" // "true" +"ok" == "ko" // "false" + +// Inequality +"ok" != "ok" // "false" +"ok" != "ko" // "true" +``` + +- If: + +```haxe +let x: Int = if (true) { 1 } else { 2 }; + +if (x == 1) { + print("Hello World"); + print(if (x != 1) { "hi" } else { "bye" }); +} +``` + +- Functions: + +```haxe +function foo(): Int +{ + return 100; +} + +let fmt: String = format("{}: {}", foo(), 300); + +print(fmt) + +print("{}", 100) + +print(foo(), 300) +``` diff --git a/Custom-lang.sln b/Horizon-Lang.sln similarity index 86% rename from Custom-lang.sln rename to Horizon-Lang.sln index ad985c1..d542602 100644 --- a/Custom-lang.sln +++ b/Horizon-Lang.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Custom-lang", "Custom-lang\Custom-lang.vcxproj", "{586C6EFE-043F-4691-80C9-F0FE80B6421B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Horizon-Lang", "Horizon-Lang\Horizon-Lang.vcxproj", "{586C6EFE-043F-4691-80C9-F0FE80B6421B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Custom-lang/.clang-format b/Horizon-Lang/.clang-format similarity index 100% rename from Custom-lang/.clang-format rename to Horizon-Lang/.clang-format diff --git a/Custom-lang/.gitignore b/Horizon-Lang/.gitignore similarity index 100% rename from Custom-lang/.gitignore rename to Horizon-Lang/.gitignore diff --git a/Custom-lang/Compile/Compiler.ixx b/Horizon-Lang/Compile/Compiler.ixx similarity index 100% rename from Custom-lang/Compile/Compiler.ixx rename to Horizon-Lang/Compile/Compiler.ixx diff --git a/Custom-lang/Compile/KaleidoscopeJIT.h b/Horizon-Lang/Compile/KaleidoscopeJIT.h similarity index 100% rename from Custom-lang/Compile/KaleidoscopeJIT.h rename to Horizon-Lang/Compile/KaleidoscopeJIT.h diff --git a/Custom-lang/Compile/LLVM.h b/Horizon-Lang/Compile/LLVM.h similarity index 100% rename from Custom-lang/Compile/LLVM.h rename to Horizon-Lang/Compile/LLVM.h diff --git a/Custom-lang/Compile/LLVM.ixx b/Horizon-Lang/Compile/LLVM.ixx similarity index 100% rename from Custom-lang/Compile/LLVM.ixx rename to Horizon-Lang/Compile/LLVM.ixx diff --git a/Custom-lang/Frontend/AST/Core.ixx b/Horizon-Lang/Frontend/AST/Core.ixx similarity index 100% rename from Custom-lang/Frontend/AST/Core.ixx rename to Horizon-Lang/Frontend/AST/Core.ixx diff --git a/Custom-lang/Frontend/AST/Expressions.ixx b/Horizon-Lang/Frontend/AST/Expressions.ixx similarity index 100% rename from Custom-lang/Frontend/AST/Expressions.ixx rename to Horizon-Lang/Frontend/AST/Expressions.ixx diff --git a/Custom-lang/Frontend/AST/Statements.ixx b/Horizon-Lang/Frontend/AST/Statements.ixx similarity index 100% rename from Custom-lang/Frontend/AST/Statements.ixx rename to Horizon-Lang/Frontend/AST/Statements.ixx diff --git a/Custom-lang/Frontend/Lexer.ixx b/Horizon-Lang/Frontend/Lexer.ixx similarity index 100% rename from Custom-lang/Frontend/Lexer.ixx rename to Horizon-Lang/Frontend/Lexer.ixx diff --git a/Custom-lang/Frontend/Parser.ixx b/Horizon-Lang/Frontend/Parser.ixx similarity index 99% rename from Custom-lang/Frontend/Parser.ixx rename to Horizon-Lang/Frontend/Parser.ixx index 2ff5897..647f686 100644 --- a/Custom-lang/Frontend/Parser.ixx +++ b/Horizon-Lang/Frontend/Parser.ixx @@ -356,7 +356,7 @@ export auto Args = Current().Type == LexerTokenType::CloseParen ? Vector>() : ParseArgsList(); Expect(LexerTokenType::CloseParen, "Expected ')'"); - + return Args; } @@ -490,7 +490,10 @@ export const auto Value = ParseExpr(); - Expect(LexerTokenType::Semicolon, "Unexpected token: " + Current().Value + ", expected a ';'"); + if (Current().Type == LexerTokenType::Semicolon) + { + Advance(); // Skip ';' + } return std::make_shared(Value); } diff --git a/Custom-lang/Custom-lang.cpp b/Horizon-Lang/Horizon-Lang.cpp similarity index 98% rename from Custom-lang/Custom-lang.cpp rename to Horizon-Lang/Horizon-Lang.cpp index 9bf99d2..4e3cd28 100644 --- a/Custom-lang/Custom-lang.cpp +++ b/Horizon-Lang/Horizon-Lang.cpp @@ -12,9 +12,9 @@ import AST.Core; import Runtime.ExecutionContext; import Interpreter; -import LLVM; +//import LLVM; -import Compiler; +//import Compiler; /* void repl() @@ -96,6 +96,7 @@ int main(int argc, char** argv) const auto result = Evaluate(program, ctx); // Log("Result: %s", result->ToString().c_str()); + /* llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); llvm::InitializeNativeTargetAsmParser(); @@ -122,6 +123,7 @@ int main(int argc, char** argv) Compile(program); TheModule->print(llvm::errs(), nullptr); + */ return 0; } diff --git a/Custom-lang/Custom-lang.vcxproj b/Horizon-Lang/Horizon-Lang.vcxproj similarity index 96% rename from Custom-lang/Custom-lang.vcxproj rename to Horizon-Lang/Horizon-Lang.vcxproj index 33fe2b3..38e6ad3 100644 --- a/Custom-lang/Custom-lang.vcxproj +++ b/Horizon-Lang/Horizon-Lang.vcxproj @@ -22,7 +22,7 @@ 16.0 Win32Proj {586c6efe-043f-4691-80c9-f0fe80b6421b} - Customlang + HorizonLang 10.0 @@ -89,6 +89,9 @@ x64-windows-release Release + + true + Level3 @@ -122,7 +125,7 @@ Level3 - true + false _DEBUG;_CONSOLE;_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) true stdcpplatest @@ -158,9 +161,6 @@ - - - @@ -172,7 +172,7 @@ - + @@ -191,9 +191,6 @@ - - - diff --git a/Custom-lang/Custom-lang.vcxproj.filters b/Horizon-Lang/Horizon-Lang.vcxproj.filters similarity index 89% rename from Custom-lang/Custom-lang.vcxproj.filters rename to Horizon-Lang/Horizon-Lang.vcxproj.filters index 89be488..5381875 100644 --- a/Custom-lang/Custom-lang.vcxproj.filters +++ b/Horizon-Lang/Horizon-Lang.vcxproj.filters @@ -18,7 +18,7 @@ - + Source Files @@ -105,19 +105,5 @@ Source Files - - Source Files - - - Header Files - - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Custom-lang/Logger.ixx b/Horizon-Lang/Logger.ixx similarity index 100% rename from Custom-lang/Logger.ixx rename to Horizon-Lang/Logger.ixx diff --git a/Custom-lang/Runtime/Callables.ixx b/Horizon-Lang/Runtime/Callables.ixx similarity index 100% rename from Custom-lang/Runtime/Callables.ixx rename to Horizon-Lang/Runtime/Callables.ixx diff --git a/Custom-lang/Runtime/ExecutionContext.ixx b/Horizon-Lang/Runtime/ExecutionContext.ixx similarity index 100% rename from Custom-lang/Runtime/ExecutionContext.ixx rename to Horizon-Lang/Runtime/ExecutionContext.ixx diff --git a/Custom-lang/Runtime/Interpreter/Exprs.ixx b/Horizon-Lang/Runtime/Interpreter/Exprs.ixx similarity index 91% rename from Custom-lang/Runtime/Interpreter/Exprs.ixx rename to Horizon-Lang/Runtime/Interpreter/Exprs.ixx index 0fe9425..efb247c 100644 --- a/Custom-lang/Runtime/Interpreter/Exprs.ixx +++ b/Horizon-Lang/Runtime/Interpreter/Exprs.ixx @@ -40,6 +40,8 @@ Shared EvalBinaryExpr(Shared node, Sharedoperator*(right)); case '/': return NullValue::ValueOrNull(left->operator/(right)); + case '%': + return NullValue::ValueOrNull(left->operator%(right)); default: Safety::Throw("Tried to evalute an unknown numeric operator!!"); } @@ -77,7 +79,12 @@ Shared EvalMemberExpr(Shared node, SharedLookupVar(node->Object->As()->Name); - auto Expr = Evaluate(node->Property, ctx); + Shared Expr = nullptr; + + if (node->Property->Type != ASTNodeType::Identifier) + { + Expr = Evaluate(node->Property, ctx); + } if (Object->Is()) { @@ -285,7 +292,7 @@ Shared EvalLogicalExpr(Shared node, SharedRight, ctx); } case LexerTokenType::Or: { @@ -294,7 +301,7 @@ Shared EvalLogicalExpr(Shared node, SharedRight, ctx); } case LexerTokenType::EqualEqual: { @@ -320,40 +327,40 @@ Shared EvalLogicalExpr(Shared node, SharedAs()->Value > Right->As()->Value) { - return Left; + return std::make_shared(true); } - break; + return std::make_shared(false); } case LexerTokenType::GreaterEqual: { if (Left->As()->Value >= Right->As()->Value) { - return Left; + return std::make_shared(true); } - break; + return std::make_shared(false); } case LexerTokenType::Less: { if (Left->As()->Value < Right->As()->Value) { - return Left; + return std::make_shared(true); } - break; + return std::make_shared(false); } case LexerTokenType::LessEqual: { if (Left->As()->Value <= Right->As()->Value) { - return Left; + return std::make_shared(true); } - break; + return std::make_shared(false); } default: Safety::Throw(std::format("Tried to evaluate an unknown logical operator {}!", Reflection::EnumToString(node->Operator))); diff --git a/Custom-lang/Runtime/Interpreter/Interpreter.ixx b/Horizon-Lang/Runtime/Interpreter/Interpreter.ixx similarity index 100% rename from Custom-lang/Runtime/Interpreter/Interpreter.ixx rename to Horizon-Lang/Runtime/Interpreter/Interpreter.ixx diff --git a/Custom-lang/Runtime/Interpreter/Stmts.ixx b/Horizon-Lang/Runtime/Interpreter/Stmts.ixx similarity index 100% rename from Custom-lang/Runtime/Interpreter/Stmts.ixx rename to Horizon-Lang/Runtime/Interpreter/Stmts.ixx diff --git a/Custom-lang/Runtime/Thread.ixx b/Horizon-Lang/Runtime/Thread.ixx similarity index 100% rename from Custom-lang/Runtime/Thread.ixx rename to Horizon-Lang/Runtime/Thread.ixx diff --git a/Custom-lang/Runtime/Values/ArrayValue.ixx b/Horizon-Lang/Runtime/Values/ArrayValue.ixx similarity index 100% rename from Custom-lang/Runtime/Values/ArrayValue.ixx rename to Horizon-Lang/Runtime/Values/ArrayValue.ixx diff --git a/Custom-lang/Runtime/Values/BoolValue.ixx b/Horizon-Lang/Runtime/Values/BoolValue.ixx similarity index 100% rename from Custom-lang/Runtime/Values/BoolValue.ixx rename to Horizon-Lang/Runtime/Values/BoolValue.ixx diff --git a/Custom-lang/Runtime/Values/EnumValue.ixx b/Horizon-Lang/Runtime/Values/EnumValue.ixx similarity index 100% rename from Custom-lang/Runtime/Values/EnumValue.ixx rename to Horizon-Lang/Runtime/Values/EnumValue.ixx diff --git a/Custom-lang/Runtime/Values/FloatValue.ixx b/Horizon-Lang/Runtime/Values/FloatValue.ixx similarity index 88% rename from Custom-lang/Runtime/Values/FloatValue.ixx rename to Horizon-Lang/Runtime/Values/FloatValue.ixx index 24b999b..d0e2f05 100644 --- a/Custom-lang/Runtime/Values/FloatValue.ixx +++ b/Horizon-Lang/Runtime/Values/FloatValue.ixx @@ -81,6 +81,16 @@ export return nullptr; } + Shared operator%(Shared other) override + { + if (other->Is()) + { + return std::make_shared(std::fmod(Value, other->AsUnchecked()->Value)); + } + + return nullptr; + } + String ToString() override { return std::format("{{\nType: '{}',\nValue: '{}'\n}}", Reflection::EnumToString(Type), Value); diff --git a/Custom-lang/Runtime/Values/IntValue.ixx b/Horizon-Lang/Runtime/Values/IntValue.ixx similarity index 89% rename from Custom-lang/Runtime/Values/IntValue.ixx rename to Horizon-Lang/Runtime/Values/IntValue.ixx index bbafe62..20d6158 100644 --- a/Custom-lang/Runtime/Values/IntValue.ixx +++ b/Horizon-Lang/Runtime/Values/IntValue.ixx @@ -81,6 +81,16 @@ export return nullptr; } + Shared operator%(Shared other) override + { + if (other->Is()) + { + return std::make_shared(Value % other->AsUnchecked()->Value); + } + + return nullptr; + } + String ToString() override { return std::format("{{\nType: '{}',\nValue: '{}'\n}}", Reflection::EnumToString(Type), Value); diff --git a/Custom-lang/Runtime/Values/NullValue.ixx b/Horizon-Lang/Runtime/Values/NullValue.ixx similarity index 100% rename from Custom-lang/Runtime/Values/NullValue.ixx rename to Horizon-Lang/Runtime/Values/NullValue.ixx diff --git a/Custom-lang/Runtime/Values/ObjectValue.ixx b/Horizon-Lang/Runtime/Values/ObjectValue.ixx similarity index 100% rename from Custom-lang/Runtime/Values/ObjectValue.ixx rename to Horizon-Lang/Runtime/Values/ObjectValue.ixx diff --git a/Custom-lang/Runtime/Values/RuntimeValue.ixx b/Horizon-Lang/Runtime/Values/RuntimeValue.ixx similarity index 95% rename from Custom-lang/Runtime/Values/RuntimeValue.ixx rename to Horizon-Lang/Runtime/Values/RuntimeValue.ixx index d7cd412..0a49c03 100644 --- a/Custom-lang/Runtime/Values/RuntimeValue.ixx +++ b/Horizon-Lang/Runtime/Values/RuntimeValue.ixx @@ -65,7 +65,11 @@ export return nullptr; } - // virtual Shared operator%(Shared other) = 0; + virtual Shared operator%(Shared other) + { + return nullptr; + } + // virtual Shared operator^(Shared other) = 0; // virtual Shared operator!() = 0; // virtual Shared operator-() = 0; diff --git a/Custom-lang/Runtime/Values/StringValue.ixx b/Horizon-Lang/Runtime/Values/StringValue.ixx similarity index 100% rename from Custom-lang/Runtime/Values/StringValue.ixx rename to Horizon-Lang/Runtime/Values/StringValue.ixx diff --git a/Custom-lang/Safety.ixx b/Horizon-Lang/Safety.ixx similarity index 100% rename from Custom-lang/Safety.ixx rename to Horizon-Lang/Safety.ixx diff --git a/Custom-lang/Types/ConstexprString.ixx b/Horizon-Lang/Types/ConstexprString.ixx similarity index 100% rename from Custom-lang/Types/ConstexprString.ixx rename to Horizon-Lang/Types/ConstexprString.ixx diff --git a/Custom-lang/Types/Extensions/String.ixx b/Horizon-Lang/Types/Extensions/String.ixx similarity index 100% rename from Custom-lang/Types/Extensions/String.ixx rename to Horizon-Lang/Types/Extensions/String.ixx diff --git a/Custom-lang/Types/Extensions/Vector.ixx b/Horizon-Lang/Types/Extensions/Vector.ixx similarity index 100% rename from Custom-lang/Types/Extensions/Vector.ixx rename to Horizon-Lang/Types/Extensions/Vector.ixx diff --git a/Custom-lang/Types/FlatMap.ixx b/Horizon-Lang/Types/FlatMap.ixx similarity index 100% rename from Custom-lang/Types/FlatMap.ixx rename to Horizon-Lang/Types/FlatMap.ixx diff --git a/Custom-lang/Types/Reflection.ixx b/Horizon-Lang/Types/Reflection.ixx similarity index 100% rename from Custom-lang/Types/Reflection.ixx rename to Horizon-Lang/Types/Reflection.ixx diff --git a/Custom-lang/Types/Types.ixx b/Horizon-Lang/Types/Types.ixx similarity index 100% rename from Custom-lang/Types/Types.ixx rename to Horizon-Lang/Types/Types.ixx diff --git a/Horizon-Lang/test.hz b/Horizon-Lang/test.hz new file mode 100644 index 0000000..45b4f3f --- /dev/null +++ b/Horizon-Lang/test.hz @@ -0,0 +1,11 @@ +function fib(n: Int): Int +{ + if (n <= 1) + { + return n; + } + + return fib(n - 1) + fib(n - 2); +} + +print("fib(10) = {}", fib(10)); \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..64edf29 --- /dev/null +++ b/README.MD @@ -0,0 +1,95 @@ +# Horizon programming language + +This repo contains the source code for the experimental Horizon programming language's interpreter and base compiler. + +## Disclaimer + +This is a hobby project for educational purposes, and is not intended for production use. It is not feature complete, and is not guaranteed to be bug free. It is not intended to be a replacement for any other programming language, and is not intended to be used for any purpose other than for fun and learning. + +## Features + +- Statically typed +- Interpreted +- Javascript like syntax +- Fast execution speed + +For a more detailed list of features, see features [document](FEATURES.MD) + +## Examples + +### Hello world + +```haxe +print("Hello {}", "World"); +``` + +### Fibonacci + +```haxe +function fib(n: Int): Int +{ + if (n <= 1) + { + return n; + } + + return fib(n - 1) + fib(n - 2); +} + +print("fib(10) = {}", fib(10)); +``` + +### FizzBuzz + +```haxe +let i: Int = 1; +loop (99) +{ + if (i % 15 == 0) + { + print("FizzBuzz"); + } + else if (i % 3 == 0) + { + print("Fizz"); + } + else if (i % 5 == 0) + { + print("Buzz"); + } + else + { + print("{}", i); + } + + i = i + 1; +} +``` + +## Building + +- Prerequisite + - Latest Visual Studio 2022, with C++ platform toolset v143 + - LLVM 14.0.4 + +**Note: This project makes heavy use of C++23 features, and will not build with older versions of Visual Studio.** + +**As of the current date (2/10/2023) intellisense is extremely broken on this project due to the use of c++ modules. This is not a problem with the project, but with Visual Studio itself, I personally use resharper++, it's broken aswell just more useable.** + +## License + +This project is licensed under the MIT license. See [LICENSE](LICENSE) for more details. + +## Contributing + +Contributions are welcome, but please open an issue first to discuss the change you wish to make. + +## Acknowledgements + +- [Tyler Laceby](https://www.youtube.com/@tylerlaceby) for his [Build a Custom Scripting](https://youtube.com/playlist?list=PL_2VhOvlMk4UHGqYCLWc6GO8FaPl8fQTh) series + +- [Crafting Interpreters](https://craftinginterpreters.com/) for their fantastic book on writing interpreters + +- [The LLVM Project](https://llvm.org/) for their C++ compiler framework + +- [The Haxe Foundation](https://haxe.org/) for inspiration for the syntax