Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpiler #14

Merged
merged 2 commits into from
Oct 9, 2024
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ docker compose up -d
- Open [Google Chrome browser](https://www.google.com/chrome/) and access [http://localhost:3000/](http://localhost:3000/).
- You can see BlueScript REPL page on the browser.

- You can also run a REPL that executes a program on a PC. You can use this REPL without a microcontroller connected to your PC.
```
docker exec -it bluescript_server npm run shell
```

### Build and Flash the BlueScript Runtime

1. Build the BlueScript runtime:
Expand Down
22 changes: 14 additions & 8 deletions microcontroller/core/src/c-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ pointer_t gc_heap_pointer(pointer_t ptr) {

#ifdef TEST64

#define ATOMIC_ENTER_CRITICAL
#define ATOMIC_EXIT_CRITICAL
#define GC_ENTER_CRITICAL(m)
#define GC_EXIT_CRITICAL(m)

#else

#include <FreeRTOS.h>
#include <atomic.h>
#include <freertos/FreeRTOS.h>

#define GC_ENTER_CRITICAL(m) portENTER_CRITICAL(&(m))
#define GC_EXIT_CRITICAL(m) portEXIT_CRITICAL(&(m))

#endif

Expand Down Expand Up @@ -1208,21 +1210,25 @@ static void push_object_to_stack(pointer_t obj, uint32_t mark) {
gc_stack_overflowed = true;
}

#ifndef TEST64
static portMUX_TYPE gc_mux = portMUX_INITIALIZER_UNLOCKED;
#endif

void gc_write_barrier(pointer_t obj, value_t value) {
if (nested_interrupt_handler > 0 && gc_is_running) {
if (is_ptr_value(value)) {
uint32_t mark = current_no_mark ? 0 : 1;
pointer_t ptr = value_to_ptr(value);
if (IS_WHITE(ptr, mark) && (obj == NULL || IS_BLACK(obj, mark))) {
ATOMIC_ENTER_CRITICAL
GC_ENTER_CRITICAL(gc_mux);
if (gc_intr_stack_top < ISTACK_SIZE)
gc_intr_stack[gc_intr_stack_top++] = ptr;
else {
WRITE_MARK_BIT(ptr, mark);
SET_GRAY_BIT(ptr);
gc_stack_overflowed = true;
}
ATOMIC_EXIT_CRITICAL
GC_EXIT_CRITICAL(gc_mux);
}
}
}
Expand All @@ -1236,7 +1242,7 @@ static void copy_from_intr_stack(uint32_t mark) {
while (i < num)
push_object_to_stack(gc_intr_stack[i++], mark);

ATOMIC_ENTER_CRITICAL
GC_ENTER_CRITICAL(gc_mux);
if (num == gc_intr_stack_top) {
failure = 0;
gc_intr_stack_top = 0;
Expand All @@ -1245,7 +1251,7 @@ static void copy_from_intr_stack(uint32_t mark) {
num = gc_intr_stack_top;
failure = 1;
}
ATOMIC_EXIT_CRITICAL
GC_EXIT_CRITICAL(gc_mux);
} while (failure);
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/transpiler/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function buildShell() {
const srcdir = 'src/transpiler'
console.log(execSync("pwd").toString())
execSync(`cc -DTEST64 -O2 -shared -fPIC -o ${dir}/c-runtime.so ${cRuntimeC} ${srcdir}/shell-builtins.c`)
execSync(`cc -DTEST64 -O2 -o ${dir}/shell ${srcdir}/shell.c ${dir}/c-runtime.so`)
execSync(`cc -DTEST64 -O2 -o ${dir}/shell ${srcdir}/shell.c ${dir}/c-runtime.so -ldl`)
}

function makeShell(closer: (code: number) => void) {
Expand Down