-
Notifications
You must be signed in to change notification settings - Fork 7
First Program
We will see in different ways how to write and compile a small program that displays "Hi profanOS!" on the screen.
For reasons of simplicity we will note LINUX$
the host shell
prompt which allows you to compile profanOS and PROFAN>
the Olivine shell of profanOS.
- Writing and compiling in Linux
- Writing in Linux, Compiling in profanOS
- Writing and compiling in profanOS
In this first approach we will use linux to write and compile the program and we will only execute it in profan.
All file in directory zapps/
are compiled when the disk image
is created. So we will create a file zapps/cmd/hi.c
and write
the following code with your favorite text editor:
#include <stdio.h>
int main(void) {
printf("Hi profanOS!\n");
return 0;
}
# Just compile the disk image
LINUX$ make disk
# And run profanOS
LINUX$ make run
During disk creation, the program was compiled in /bin/cmd
we
can run it manually or just write its name (See Olivine).
# Full path
PROFAN> . /bin/cmd/hi.elf
# Using the env:PATH
PROFAN> hi
In this second approach we will use linux to write the program
and we will compile it in profanOS using tcc
.
All file in directory sys_dir/user/
are moved to the profanOS
file system when the disk image is created. So we will create a
file sys_dir/user/hi.c
and write the program in it.
#include <stdio.h>
int main(void) {
printf("Hi profanOS!\n");
return 0;
}
Heavy profanOS programs are not directly in the main repo, but you can easily retrieve them.
# We can use the gui addons manager and scroll
# down to select tcc and download it.
LINUX$ make gaddons
# -- OR -- cli way
LINUX$ python3 tools/addons.py tcc
# Build disk and start profanOS vm
LINUX$ make disk run
In profanOS, using tcc we can easily have an executable!
# Go to the user directory
PROFAN> cd /user
# Compile the program
PROFAN> tcc hi.c -o hi.elf
Using the .
command we can run the program like any other.
# Run the program
PROFAN> . hi.elf
Tcc also has an option that allows you to compile and execute a C program in one go:
# Compile and run the program
PROFAN> tcc -run hi.c
In this third approach we will write and compile the program directly in profanOS.
# Select tcc in the gui addons manager
LINUX$ make gaddons
# Build disk and start profanOS vm
LINUX$ make disk run
In profanOS you can use the rim
text editor with syntax highlighting
to write or edit code. To save the file press Ctrl
and to exit press
Esc
(it's simpler than in vim 🥲)
# Go to the user directory
PROFAN> cd /user
# Start the editor
PROFAN> rim hi.c
Write the program in the editor:
#include <stdio.h>
int main(void) {
printf("Hi profanOS!\n");
return 0;
}
Compile the C program like last time
# Compile the program
PROFAN> tcc hi.c -o hi.elf
PROFAN> . hi.elf
# -- OR -- compile and run in one go
PROFAN> tcc -run hi.c
If you want to recover your program in linux, you cat it in the serial console.
# Cat the program and redirect the
# output to the serial port
PROFAN> cat hi.c > /dev/userial
In linux the program will be displayed in the terminal, you can copy it and paste it into a file.
You have seen three different ways to write and compile a program in profanOS. The choice of method depends on your preferences and the size of the program you want to write.
Interpreters for other languages are also available in the addons menu such as lua and sulfur 😊
-
Getting Started
- Compiling profanOS
- Running profanOS
-
User Guide
-
Development Guide
-
Library Documentation