Compare commits

...

10 Commits
v0.5.0 ... main

8 changed files with 60 additions and 10 deletions

View File

@ -19,9 +19,11 @@ This language is designed for:
- Compiler must avoid generating logic that the user does not write
## Installation
You can install the compiler by running:
Before installing the compiler with `go install`, you will need to install the
[Go programming language](https://go.dev/) on your system. Afterwards, you can
install the compiler and associated tooling by running:
`go install ./cmd/fsplc`
`go install ./cmd/*`
The `fsplc` program depends on the LLVM IR compiler (`llc`). If it is not found,
it will attempt to use `clang` instead but with some features disabled. Please
@ -116,3 +118,24 @@ Q3 2024
At the beginning of Q4 2024, a 1.0 version of the language will be released.
## FAQ
I have either been asked these questions, or expect to be at some point.
### What happened to ARF?
A couple of years ago, I attempted to create a programming language under the
name ARF, with the goal of trying out some new and interesting syntax I'd come
up with. I made several attempts to build a working compiler for it, but never
quite succeeded. When I entered my senior year at university, I decided to have
another crack at it as my senior project. By then, the ideas I had for the
language had changed so much, it was basically a Ship of Theseus situation and
it really just needed a new name altogether. Plus, ARF never really stood for
anything in the first place.
### Why Go?
Out of all the languages I know, I probably know Go the best. It was an obvious
choice for making something this complex. However, I'd like to self-host the
compiler eventually.
### I know you as X name from Y place, why is your name here Sasha Koshka?
I consider it a bad idea to share your real name over the internet.

View File

@ -103,7 +103,7 @@ U: (| Int F64 UInt)
func TestSwitch (test *testing.T) {
testString (test,
`
[switch x:Int]:Int = switch x
[f x:Int]:Int = switch x
| 0 5
| 1 4
| 2 3
@ -134,7 +134,7 @@ func TestSwitchErrBadLiteral (test *testing.T) {
testStringErr (test,
"cannot use array literal as Int", 4, 4,
`
[switch x:Int]:Int = switch x
[f x:Int]:Int = switch x
| 0 5
| (1) 4
| 2 3
@ -146,7 +146,7 @@ func TestSwitchErrNotConstant (test *testing.T) {
testStringErr (test,
"y cannot represent a constant integer", 7, 4,
`
[switch x:Int]:Int = {
[f x:Int]:Int = {
y:Int = 1
switch x
@ -162,7 +162,7 @@ func TestSwitchErrDuplicate (test *testing.T) {
testStringErr (test,
"65 already listed in match at stream0.fspl:6:2", 7, 4,
`
[switch x:I8]:Int = switch x
[f x:I8]:Int = switch x
| 0 5
| 1 4
| 2 3

View File

@ -3,6 +3,7 @@ package analyzer
import "fmt"
import "git.tebibyte.media/fspl/fspl/errors"
import "git.tebibyte.media/fspl/fspl/entity"
import "git.tebibyte.media/fspl/fspl/parser/fspl"
// All expression analysis routines must take in the type they are being
// assigned to and return an error if they can't be assigned to it. if the type
@ -62,6 +63,13 @@ func (this *Tree) analyzeDeclaration (
entity.Expression,
error,
) {
if fsplParser.IsReserved(declaration.Name) {
return nil, errors.Errorf (
declaration.Position(),
"cannot shadow reserved identifier %s",
declaration.Name)
}
scope, _ := this.topScope()
existing := scope.Variable(declaration.Name)
if existing != nil {

View File

@ -76,6 +76,11 @@ func (this *Tree) assembleRawMaps () error {
}
func (this *Tree) topLevelNameAvailable (currentPos errors.Position, key entity.Key) error {
if fsplParser.IsReserved(key.Name) {
return errors.Errorf (
currentPos, "cannot shadow reserved identifier %s",
key.Name)
}
if _, isPrimitive := primitiveTypes[key.Name]; isPrimitive {
return errors.Errorf (
currentPos, "cannot shadow primitive %s",

View File

@ -38,7 +38,7 @@ in order of preference:
- `/usr/src/fspl`
- `/usr/include/fspl`
On windows, these are used instead:
On Windows, these are used instead:
- `%LOCALAPPDATA%\fspl\src`
- `%LOCALAPPDATA%\fspl\include`
- `%ALLUSERSPROFILE%\fspl\src`

View File

@ -8,9 +8,9 @@ IR module tree.
## Organization
Generator defines the Target type, which contains information about the system
that the program is being compiled for. The native sub-package uses Go's
conditional compilation directives to provide a default Target that matches the
system the compiler has been natively built for.
that the program is being compiled for. The native sub-package uses GOOS and
GOARCH to provide a default Target that matches the system the compiler has been
natively built for.
The entry point for all logic defined in this package is Target.Generate(). This
method creates a new generator, and uses it to recursively generate and return an

View File

@ -72,6 +72,7 @@ expression, the parser follows this decision tree to determine what to parse:
| | 'match' =Match
| | 'switch' =Switch
| | 'loop' =Loop
| | 'for' =For
| | +Colon =Declaration
| | +DoubleColon =Call
|

13
parser/fspl/reserved.go Normal file
View File

@ -0,0 +1,13 @@
package fsplParser
func IsReserved (identifier string) bool {
switch identifier {
case "true", "false", "nil",
"if", "match", "switch",
"loop", "for",
"then", "in",
"break", "return":
return true
default: return false
}
}