Skip to content
Closed
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
matrix:
configuration: ["Debug", "Release"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.11.1
- uses: actions/setup-dotnet@v1.7.2
node-version: 18
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 2.1.816
dotnet-version: '8.0.x'
- run: yarn --ci
working-directory: ./Source/SmallBasic.Client
- run: dotnet restore
Expand Down
106 changes: 53 additions & 53 deletions .github/workflows/master_smallbasic-publicwebsite-code.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy to Caseysc`s Azure Web App - smallbasic-publicwebsite-code
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16.11.1
- uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: 2.1.816
- run: yarn --ci
working-directory: ./Source/SmallBasic.Client
- run: dotnet restore
- run: dotnet build ./SmallBasic.sln /p:TreatWarningsAsErrors=True /p:Configuration=Release
- run: dotnet publish ./Source/SmallBasic.Editor/SmallBasic.Editor.csproj --no-build /p:TreatWarningsAsErrors=True /p:Configuration=Release
- uses: actions/upload-artifact@v3.1.0
with:
path: /home/runner/work/smallbasic-editor/smallbasic-editor/Source/SmallBasic.Editor/bin/Release/netstandard2.0/publish/
if-no-files-found: error
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: artifact
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'smallbasic-publicwebsite-code'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_CC78D407C64043A1978FBF8A5FEDA312 }}
package: .
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy to Caseysc`s Azure Web App - smallbasic-publicwebsite-code

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- run: yarn --ci
working-directory: ./Source/SmallBasic.Client
- run: dotnet restore
- run: dotnet build ./SmallBasic.sln /p:TreatWarningsAsErrors=True /p:Configuration=Release
- run: dotnet publish ./Source/SmallBasic.Editor/SmallBasic.Editor.csproj --no-build /p:TreatWarningsAsErrors=True /p:Configuration=Release
- uses: actions/upload-artifact@v3.1.0
with:
path: /home/runner/work/smallbasic-editor/smallbasic-editor/Source/SmallBasic.Editor/bin/Release/netstandard2.0/publish/
if-no-files-found: error

deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: artifact

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'smallbasic-publicwebsite-code'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_CC78D407C64043A1978FBF8A5FEDA312 }}
package: .
67 changes: 67 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Release Standalone Binaries and IDE

on:
release:
types: [published, created]
push:
tags:
- '*'
- 'v*'
workflow_dispatch:

jobs:
build-release:
name: Build Standalone Release (${{ matrix.target.os }})
runs-on: ${{ matrix.target.runner }}
strategy:
matrix:
target:
- os: win-x64
runner: windows-latest
asset: smallbasic-win-x64.zip
- os: linux-x64
runner: ubuntu-latest
asset: smallbasic-linux-x64.tar.gz
- os: osx-x64
runner: macos-latest
asset: smallbasic-macos-x64.tar.gz

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- name: Setup .NET 8 SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

- name: Restore Node Packages for Webpack
run: yarn --ci
working-directory: ./Source/SmallBasic.Client

- name: Publish Self-Contained CLI / Compiler
run: dotnet publish Source/SmallBasic.Cli/SmallBasic.Cli.csproj -c Release -r ${{ matrix.target.os }} --self-contained true /p:PublishSingleFile=true -o dist/${{ matrix.target.os }}

- name: Publish Editor / IDE
run: dotnet publish Source/SmallBasic.Editor/SmallBasic.Editor.csproj -c Release -o dist/${{ matrix.target.os }}/editor

- name: Package Release Assets (Windows)
if: matrix.target.runner == 'windows-latest'
run: Compress-Archive -Path dist/${{ matrix.target.os }}/* -DestinationPath ${{ matrix.target.asset }}

- name: Package Release Assets (Unix)
if: matrix.target.runner != 'windows-latest'
run: tar -czvf ${{ matrix.target.asset }} -C dist/${{ matrix.target.os }} .

- name: Attach Assets to GitHub Release
uses: softprops/action-gh-release@v1
with:
files: ${{ matrix.target.asset }}
tag_name: ${{ github.event.release.tag_name || github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
# Output files
bin
obj
dist/
node_modules
wwwroot
*.exe
*.dll
*.pdb
*.runtimeconfig.json
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<NuGetAudit>false</NuGetAudit>
<NuGetAuditLevel>none</NuGetAuditLevel>
<NuGetAuditMode>direct</NuGetAuditMode>
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904;NETSDK1138</WarningsNotAsErrors>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<NuGetAudit>false</NuGetAudit>
<NuGetAuditLevel>none</NuGetAuditLevel>
<NuGetAuditMode>direct</NuGetAuditMode>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904;NETSDK1138</WarningsNotAsErrors>
<NoWarn>$(NoWarn);NU1901;NU1902;NU1903;NU1904;NETSDK1138</NoWarn>
</PropertyGroup>

<Target Name="DisableNuGetAuditWarningsAsErrors" BeforeTargets="Restore;BeforeBuild;CoreCompile">
<PropertyGroup>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904;NETSDK1138</WarningsNotAsErrors>
<NoWarn>$(NoWarn);NU1901;NU1902;NU1903;NU1904;NETSDK1138</NoWarn>
</PropertyGroup>
</Target>
</Project>
128 changes: 128 additions & 0 deletions LANGUAGE_EXTENSIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Small Basic Language Extensions Documentation

This repository contains modern, powerful extensions to the Small Basic compiler and runtime. Below is a comprehensive guide to all newly added language features, control flow constructs, file module imports, and .NET interop libraries.

---

## 1. Functions with Parameters and Return Statements

Small Basic now supports standard parameter-passing subroutines and functions with return values.

### Keywords
- `Function` or `Fn`
- `EndFunction` or `EndFn`
- `Return`

### Syntax & Examples

```smallbasic
Function Add(a, b)
Return a + b
EndFunction

sum = Add(15, 25) ' sum = 40
```

Recursive functions are fully supported:

```smallbasic
Fn Factorial(n)
If n <= 1 Then
Return 1
EndIf
Return n * Factorial(n - 1)
EndFn

result = Factorial(5) ' result = 120
```

---

## 2. File Module Import System (`Import`)

Organize Small Basic code into modular files using relative or absolute path imports.

### Syntax
```smallbasic
Import "helpers/math_utils.sb"

res = Square(6)
```

Imports are recursively resolved relative to the current file's directory path. Cyclic imports are automatically detected and safely skipped.

---

## 3. Control Flow Constructs

### A. `Select Case` Statements
Replace long `If/ElseIf` chains with clean pattern matching:

```smallbasic
val = 2

Select Case val
Case 1
TextWindow.WriteLine("One")
Case 2
TextWindow.WriteLine("Two")
Else
TextWindow.WriteLine("Other")
EndSelect
```

### B. `Try / Catch / Finally` Error Handling
Handle errors gracefully without terminating execution:

```smallbasic
Try
res = File.ReadContents("data.txt")
Catch ex
res = "Default Content"
Finally
TextWindow.WriteLine("Completed read attempt.")
EndTry
```

### C. `ForEach` Loops
Iterate over collections easily:

```smallbasic
ForEach item In list
TextWindow.WriteLine(item)
EndFor
```

---

## 4. .NET / C# Reflection Interop (`System` Library)

Directly invoke static methods and read static properties from any available .NET type directly in Small Basic code.

### Methods
- `System.Call(typeName, methodName, argument)`
- `System.GetProperty(typeName, propertyName)`
- `System.Exists(filePath)`

### Example Usage

```smallbasic
' Call System.Math.Abs
absVal = System.Call("System.Math", "Abs", -42) ' returns 42

' Access .NET System.Environment property
os = System.GetProperty("System.Environment", "OSVersion")
```

---

## 5. Extended Math Utilities (`Math` Library)

- `Math.Clamp(value, min, max)`: Clamps `value` between `min` and `max`.
- `Math.Lerp(start, end, amount)`: Performs linear interpolation between `start` and `end`.
- `Math.Atan2(y, x)`: Returns the 2-argument arctangent of `y` and `x`.

---

## Summary of All Added Keywords
`Function`, `Fn`, `EndFunction`, `EndFn`, `Return`, `Import`, `Select`, `Case`, `EndSelect`, `Try`, `Catch`, `Finally`, `EndTry`, `ForEach`, `In`.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This is home to the new SmallBasic editor. It has the following projects:
* **SmallBasic.Tests**: C# unit tests to test the compiler/engine.
* **SmallBasic.Utilities**: helper utilities shared between different projects.

#### Language Extensions & New Features
For complete details and code examples of newly added compiler features (Functions with parameters/returns, relative module `Import`, `Select Case`, `Try/Catch/Finally`, `ForEach`, `Math` extensions, and `System.Call` .NET reflection interop), see [LANGUAGE_EXTENSIONS.md](LANGUAGE_EXTENSIONS.md).

#### Developer Workflow

1. Open **SmallBasic.sln** in Visual Studio 2017.
Expand Down
1 change: 1 addition & 0 deletions Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<DisabledWarnings Include="CA1710" Comment="Rename '{0}' to end in '{1}' (for IReadOnly collections)." />
<DisabledWarnings Include="CA1716" Comment="Rename type '{0}' so that it no longer conflicts with the reserved language keyword '{0}'. Using a reserved keyword as the name of a type makes it harder for consumers in other languages to use the type." />
<DisabledWarnings Include="CA1812" Comment="'{0}' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (blazor components)." />
<DisabledWarnings Include="CA1825" Comment="Avoid unnecessary zero-length array allocations." />
<DisabledWarnings Include="CA2225" Comment="Operator overloads have named alternates." />
<DisabledWarnings Include="CA2227" Comment="Collection properties should be read only (required for XML deserialization)." />

Expand Down
Loading