Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ jobs:
with:
global-json-file: global.json

- name: Clean
run: make clean

- name: Generate
run: make generate
- name: Setup
run: make setup

- name: Build
run: make
Expand Down
8 changes: 1 addition & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
"preLaunchTask": "build compiler debug",
"program": "${workspaceFolder}/src/Buckle/CommandLine/bin/Debug/net9.0/CommandLine.dll",
"args": [
// "-r"
"--execute",
"samples/Temp",
// "samples/Pong",
// "samples/Platformer",
"--type=graphics",
// "--verbose",
"-r"
],
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ SINGLE_FILE_FLAGS:=-p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExt
FLAGS:=$(PUBLISH_FLAGS) $(SINGLE_FILE_FLAGS)

ifeq ($(OS), Windows_NT)
RM:=powershell -Command "Remove-Item -Recurse -Force -ErrorAction SilentlyContinue"
CP:=powershell -Command "Copy-Item -Recurse"
MV:=powershell -Command "Move-Item -Force"
MKDIR:= powershell -Command "New-Item -ItemType Directory -Force"
RM:=powershell -Command "Remove-Item -Recurse -Force -ErrorAction SilentlyContinue > \$null"
CP:=powershell -Command "Copy-Item -Recurse > \$null"
MV:=powershell -Command "Move-Item -Force > \$null"
MKDIR:= powershell -Command "New-Item -ItemType Directory -Force > \$null"
else
RM:=rm -rf
CP:=cp
Expand All @@ -40,7 +40,7 @@ release: prebuild copydlls build postbuild
portable: prebuild buildportable postbuildportable
debug: prebuild builddebug postbuilddebug
linux: prebuild buildlinux postbuildlinux
setup: prebuild generate
setup: prebuild generate libs

.PHONY: test

Expand Down
110 changes: 73 additions & 37 deletions docs/Repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The Repl provides many commands usefully for debug snippets or code.
| Command Name | Usage | Description |
|-|-|-|
| [Clear](#clear-command) | `#clear` | Clear the screen |
| [Dump](#dump-command-no-arguments) | `#dump` | Locate a symbol to show the contents of |
| [Dump](#dump-command) | `#dump <signature>` | Show contents of symbol \<signature> |
| [Exit](#exit-command) | `#exit` | Exit the Repl |
| [Help](#help-command) | `#help` | Show this document |
Expand All @@ -48,6 +49,7 @@ The Repl provides many commands usefully for debug snippets or code.
| [Reset](#reset-command) | `#reset` | Clear previous submissions |
| [Save to File](#save-to-file-command) | `#saveToFile <path> <count=1>` | Save previous \<count> submissions to \<path> |
| [Settings](#settings-command) | `#settings` | Open settings page |
| [Show CS](#show-c-command) | `#showCS` | Toggle display of C# code |
| [Show IL](#show-il-command) | `#showIL` | Toggle display of IL code |
| [Show Program](#show-program-command) | `#showProgram` | Toggle display of the intermediate representation |
| [Show Time](#show-time-command) | `#showTime` | Toggle display of submission execution time |
Expand All @@ -56,40 +58,90 @@ The Repl provides many commands usefully for debug snippets or code.
| [Show Warnings](#show-warnings-command) | `#showWarnings` | Toggle display of warnings |
| [State](#state-command) | `#state` | Dump the current state of the Repl |

<!-- | [Show C#](#show-c-command) | `#showCS` | Toggle display of C# code | -->

### Clear Command

Usage: `#clear`

The clear command will clear the entire terminal of any past submissions, and then you can continue coding snippets.
This command does not affect any of the Repl state like the reset command, it only clears the terminal buffer.

### Dump Command (no arguments)

Usage: `#dump`

Using the dump command without providing a symbol signature as an argument will invoke the dump locator screen where
the user can use up and down arrow keys to dig into symbols and display them. Unlike the `#list` command, the dump
locator can be used to dig into natively written library types.

```belte
» class MyClass {
· public int Add(int a, int b) {
· return a + b;
· }
· }
» #dump
```

Moves to dump locator screen:

```
#dump [none]

Exit
MyClass
public Object
...
```

Example screen:

```
#dump global::MyClass

Exit
..
Select Current Symbol
public Nullable<int> MyClass.Add(Nullable<int> a, Nullable<int> b)
public void MyClass..ctor()
```

Example result:

```
#dump global::MyClass.Add
public Nullable<int> MyClass.Add(Nullable<int> a, Nullable<int> b) {
return ((a.get_HasValue() && b.get_HasValue()) ? new Nullable<int>((a.get_Value() + b.get_Value())) : null)
}
»
```

### Dump Command

Usage: `#dump <signature>`

The dump command will display information about any symbol defined in any scope. Currently, this information is only
declaration information and not the current state of any symbol (like a variable's value). It will show member
declarations and bodies.
The dump command will display the declaration of any symbol defined in any scope. If the given symbol is a local, the
current state of the local will be displayed in addition to the declaration.

Examples:

```belte
» int myInt = 3;
» #dump myInt
int myInt
Nullable<int> myInt = 3
```

```belte
» struct MyStruct {
· int field1;
» class MyClass {
· public int field1;
· string! field2;
· }
» #dump MyStruct
struct MyStruct {
int field1
string! field2
class MyClass extends Object {
public Nullable<int> MyClass.field1

private string MyClass.field2

public void MyClass..ctor()
}
```

Expand Down Expand Up @@ -163,32 +215,15 @@ The Repl:

Usage: `#list`

The list command lists all currently declared symbols, including built-in ones.
The list command lists all user-declared symbols.

For example:

```belte
» int myInt = 3;
» #ls
int myInt
int! Ascii(string! char)
string! Char(int! ascii)
bool! HasValue(any value)
bool! HasValue(bool value)
bool! HasValue(decimal value)
bool! HasValue(int value)
bool! HasValue(string value)
string! Hex(int! value, bool! prefix)
string! Input()
void Print(any text)
void PrintLine(any text)
void PrintLine()
int! RandInt(int max)
any! Value(any value)
bool! Value(bool value)
decimal! Value(decimal value)
int! Value(int value)
string! Value(string value)
» #list
Global symbols:
Nullable<int> myInt
```

### Reset Command
Expand Down Expand Up @@ -256,9 +291,8 @@ All Repl settings:

| Setting Name | Options | Default | Description |
|-|-|-|-|
| Theme | Dark, Light, Green | Dark | The color theme of the Repl; each contributor gets their own color theme! |
| Theme | Dark, Light, Green, Purpura, TrafficStop | Dark | The color theme of the Repl; each contributor gets their own color theme! |

<!--
### Show C# Command

Usage: `#showCS`
Expand All @@ -285,7 +319,6 @@ public static class Program {

}
```
-->

### Show IL Command

Expand Down Expand Up @@ -418,14 +451,17 @@ use outside of development.

```belte
» #state
showTokens False
showTree False
showProgram False
showWarnings True
showIL False
showCS False
showWarnings False
loadingSubmissions False
colorTheme Repl.Themes.DarkTheme
currentPage Repl
previous Buckle.CodeAnalysis.Compilation
baseCompilation Buckle.CodeAnalysis.Compilation
tree #state
variables System.Collections.Generic.Dictionary`2[Buckle.CodeAnalysis.Symbols.IVariableSymbol,Buckle.CodeAnalysis.Evaluating.IEvaluatorObject]
variables EvaluatorContext [ Tracking 2 symbols ]
```
4 changes: 4 additions & 0 deletions src/Belte/Native/Standard/String.blt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

public static class String {
public static string[]! Split(string! text, string! separator);

public static int Ascii(string! chr);

public static string! Char(int! ascii);
}
39 changes: 35 additions & 4 deletions src/Buckle/CommandLine/BuckleCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ private static CompilerState DecodeOptions(
var specifyStage = false;
var specifyOut = false;
var specifyModule = false;
var specifyBuildMode = false;
var specifyWarningLevel = false;

var tempDialogs = new ShowDialogs {
Expand All @@ -481,11 +482,11 @@ private static CompilerState DecodeOptions(
state.buildMode = BuildMode.AutoRun;
state.finishStage = CompilerStage.Finished;
state.outputFilename = "a.exe";
state.moduleName = "defaultModuleName";
state.moduleName = "a";
state.noOut = false;
state.warningLevel = 1;
state.severity = DiagnosticSeverity.Warning;
state.projectType = OutputKind.Console;
state.projectType = OutputKind.ConsoleApplication;
state.verboseMode = false;

void DecodeSimpleOption(string arg) {
Expand All @@ -500,29 +501,37 @@ void DecodeSimpleOption(string arg) {
break;
case "-r":
case "--repl":
specifyBuildMode = true;
state.buildMode = BuildMode.Repl;
break;
case "-n":
specifyBuildMode = true;
state.buildMode = BuildMode.Independent;
break;
case "-i":
specifyBuildMode = true;
state.buildMode = BuildMode.AutoRun;
break;
case "--script":
specifyBuildMode = true;
state.buildMode = BuildMode.Interpret;
break;
case "--evaluate":
specifyBuildMode = true;
state.buildMode = BuildMode.Evaluate;
break;
case "--execute":
specifyBuildMode = true;
state.buildMode = BuildMode.Execute;
break;
case "-t":
case "--transpile":
specifyBuildMode = true;
state.buildMode = BuildMode.CSharpTranspile;
break;
case "-d":
case "--dotnet":
specifyBuildMode = true;
state.buildMode = BuildMode.Dotnet;
break;
case "-h":
Expand Down Expand Up @@ -648,9 +657,11 @@ void DecodeSimpleOption(string arg) {
var type = arg.Substring(7).ToLower();

if (type == "console")
state.projectType = OutputKind.Console;
state.projectType = OutputKind.ConsoleApplication;
else if (type == "graphics")
state.projectType = OutputKind.Graphics;
state.projectType = OutputKind.GraphicsApplication;
else if (type == "dll")
state.projectType = OutputKind.DynamicallyLinkedLibrary;
else
diagnostics.Push(Belte.Diagnostics.Error.UnrecognizedType(type));
} else if (arg == "--") {
Expand All @@ -675,6 +686,17 @@ void DecodeSimpleOption(string arg) {
state.includeWarnings = includeWarnings.ToArray();
state.excludeWarnings = excludeWarnings.ToArray();

if (state.projectType == OutputKind.DynamicallyLinkedLibrary) {
if (!specifyBuildMode)
state.buildMode = BuildMode.Dotnet;

if (state.buildMode != BuildMode.Dotnet)
diagnostics.Push(Belte.Diagnostics.Fatal.DLLWithWrongBuildMode());

if (!specifyOut)
state.outputFilename = "a.dll";
}

if (!specifyWarningLevel &&
state.buildMode is BuildMode.AutoRun or BuildMode.Interpret or BuildMode.Evaluate or BuildMode.Execute) {
state.warningLevel = 0;
Expand Down Expand Up @@ -711,6 +733,15 @@ void DecodeSimpleOption(string arg) {
if (state.tasks.Length == 0 && !(state.buildMode == BuildMode.Repl))
diagnostics.Push(Belte.Diagnostics.Fatal.NoInputFiles());

if (state.projectType == OutputKind.DynamicallyLinkedLibrary) {
if (specifyOut && specifyModule)
diagnostics.Push(Belte.Diagnostics.Fatal.CannotSpecifyOutAndModuleWithDll());
else if (!specifyOut)
state.outputFilename = state.moduleName + ".dll";
else if (!specifyModule)
state.moduleName = Path.GetFileNameWithoutExtension(state.outputFilename);
}

state.outputFilename = state.outputFilename.Trim();

if (state.verboseMode)
Expand Down
2 changes: 2 additions & 0 deletions src/Buckle/CommandLine/Diagnostics/DiagnosticCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public enum DiagnosticCode : ushort {
ERR_CodeIsNotWarning = 28,
ERR_MissingType = 29,
ERR_UnrecognizedType = 30,
FTL_DLLWithWrongBuildMode = 31,
FTL_CannotSpecifyOutAndModuleWithDll = 32,
}
Loading