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
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

<img src="SpliceLogo.png">
<img src="SpliceLogo.png" class="width;1">

<tr>
<td>
Expand Down
Binary file modified bin/Splice
Binary file not shown.
Binary file modified bin/spbuild
Binary file not shown.
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ echo "Proceeding with build on $OS/$ARCH..."
echo "Building Splice runtime and native module..."

# Compile Splice runtime (with SDK globals)
gcc -DSDK_IMPLEMENTATION -Isrc -Wall -Wextra -c src/splice.c -o "$BIN_DIR/Splice.o"
gcc -DSDK_IMPLEMENTATION -Isrc -Wall -Wextra -c -DNDEBUG -O3 -flto src/splice.c -o "$BIN_DIR/Splice.o"

# Compile native module without SDK_IMPLEMENTATION
gcc -Isrc -Wall -Wextra -c src/module_stubs.c -o "$BIN_DIR/module_stubs.o"
gcc -Isrc -Wall -Wextra -c -DNDEBUG -O3 -flto src/module_stubs.c -o "$BIN_DIR/module_stubs.o"

# Link executable (local binary: Splice)
gcc "$BIN_DIR/Splice.o" "$BIN_DIR/module_stubs.o" -o "$BIN_DIR/Splice"

echo "Building spbuild (bytecode compiler)..."
gcc -Isrc -Wall -Wextra src/build.c -o "$BIN_DIR/spbuild"
gcc -Isrc -Wall -Wextra -DNDEBUG -O3 -flto src/build.c -o "$BIN_DIR/spbuild"

# --- Install section ---
INSTALL_DIR=""
Expand Down
265 changes: 260 additions & 5 deletions docs.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,266 @@
# How to code in Splice
# How to Code in Splice

Splice is a very basic language and some of the syntax is derived from Lua, Python and a bit of it's own syntax.
Splice is a lightweight and embeddable programming language.
Its syntax is inspired by Lua and Python, with additional custom syntax
designed to keep the language simple and predictable.

## Print
Splice programs are executed from top to bottom.

Printing in Splice is written using
---

``` Splice
## Program Structure

A basic Splice program consists of statements separated by semicolons.

```splice
print("Hello, Splice");
```

---

## Comments

Splice supports single-line comments using `//`.

```splice
// This is a comment
print("This line will execute");
```

---

## Printing Output

Printing output is done using the `print` keyword.

```splice
print("Hi");
```

### Printing Variables

```splice
let x = 10;
print(x);
```

---

## Variables

Variables are declared using the `let` keyword.

```splice
let number = 42;
let name = "Splice";
let pi = 3.14;
```

Splice is dynamically typed, meaning the type is determined at runtime.

---

## Arithmetic Operations

Splice supports basic arithmetic operations.

```splice
let a = 10;
let b = 5;

print(a + b);
print(a - b);
print(a * b);
print(a / b);
```

---

## Comparison Operators

Splice supports standard comparison operators.

```splice
let x = 10;

print(x == 10);
print(x != 5);
print(x > 5);
print(x < 20);
```

---

## If Statements

Conditional execution is done using `if`.

```splice
let age = 18;

if (age >= 18) {
print("You are an adult");
}
```

---

## If-Else Statements

```splice
let score = 40;

if (score >= 50) {
print("Pass");
} else {
print("Fail");
}
```

---

## While Loops

The `while` loop executes as long as the condition is true.

```splice
let i = 0;

while (i < 5) {
print(i);
i = i + 1;
}
```

---

## For Loops

Splice supports `for` loops with a counter variable.

```splice
for (let i = 0; i < 5; i = i + 1) {
print(i);
}
```

---

## Functions

Functions are declared using the `func` keyword.

```splice
func add(a, b) {
return a + b;
}
```

### Calling Functions

```splice
let result = add(10, 20);
print(result);
```

---

## Return Statement

Functions return values using `return`.

```splice
func square(x) {
return x * x;
}

print(square(5));
```

---

## User Input

Splice supports input using the `input` keyword.

```splice
let name = input("Enter your name: ");
print(name);
```

---

## Error Handling

Splice provides basic error reporting at runtime.
Errors include:

- Undefined variables
- Invalid operations
- Syntax errors

---

## Execution Model (High Level)

Splice executes programs by walking an Abstract Syntax Tree (AST).
Each node represents a language construct such as variables, function calls,
loops, or expressions.

This design allows:

- Easy embedding in C programs
- Simpler debugging
- Low memory overhead

---

## Embedding Splice in C

Splice is designed to be embedded in C applications.

```c
#include <Arduino.h>

#define ARDUINO
#define SPLICE_EMBED 1

#include "splice.h"

/*
Splice source (compiled beforehand):

print("Hello from Splice");
*/

const unsigned char program[] = {
'S','P','C',0x00, // magic
0x01, // version

AST_PRINT,
AST_STRING,
0x00, 0x11,
'H','e','l','l','o',' ',
'f','r','o','m',' ',
'S','p','l','i','c','e'
};

void setup() {
Serial.begin(115200);
while (!Serial);

ASTNode *root = read_ast_from_spc_mem(
program,
sizeof(program)
);

interpret(root);
}

void loop() {}

```

---


Binary file added examples/.DS_Store
Binary file not shown.
Binary file removed examples/array/array.spc
Binary file not shown.
11 changes: 6 additions & 5 deletions examples/calculator/calc_test.spl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
func calculator(num1, num2, op) {
if (op == "+") {
print(num1 + num2)
} else {
print("Invalid operator: " + op)
print(num1 + num2);
}
if (op == "-") {
print(num1 - num2);
}
}

calculator(5, 3, "+") // prints 8
calculator(5, 3, "%") // prints "Invalid operator: %"
calculator(5, 3, "+");
calculator(5, 3, "-");
Binary file added examples/calculator/hello.spc
Binary file not shown.
Binary file added examples/forloops/for.spc
Binary file not shown.
Binary file modified examples/helloworld/hello.spc
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/helloworld/helloworld.spl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print("Hello world")
print("Hello world");
5 changes: 3 additions & 2 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Release notes

Current Version: 1.0
Current Version: 1.1 Beta

## Overview

This Version of Splice Made it so now the ast Dce and all of the building is done in spbuild so vm can be use in a esp32
* Major bug fixes
* Added MAX_FUNCS **(Set 16 for embedded and 32 for Normal PC as functions excedding MAX_FUNCS cause Segmentation fault)**
Loading