dcraftbg / sopl Goto Github PK
View Code? Open in Web Editor NEWA compiled, low level language
License: MIT License
A compiled, low level language
License: MIT License
Mostly due to the fact that the SOPL compiler assumes that rsi is not going to be modified during the evaluation of the expression, and so when that does happen it causes unexpected behaviour
A basic example is something like this:
func foo(: int) {
RSI = 5;
return 0;
}
func main() {
let bar: [int,5];
*bar = foo();
}
The specific issue with the generated assembly are these lines:
mov rsi, qword [bar]
call foo
mov dword [rsi], eax
This is also due to the fact that SOPL assumes that no matter what, functions always don't change specific registers
This issue happens because Release doesn't take into account arguments, only sets. That means that when you call a function with a string as an argument it won't get accounted for by the compiler, meaning it will generate invalid nasm assembly.
A really simple recreation of it is Hello World:
include "libc/stdio.spl"
func main(){
printf("Hello Wold!");
}
If you try running any program with arguments like long, long, char or something its going to break. This is probably due to this part of the compiler code:
if (offset-osize)%8 > 0 {
offset-=8-(offset-osize)%8;
}
It only works for very specific cases, and even then it breaks.
The easiest recreation would be to use a library like strlib. buffers from the examples breaks because of strset
include "../libs/strlib/strlib.spl"
include "../libs/libc/stdio.spl"
func main(){
let name: [char, 500];
strset(name, 500, 0);
scanf("%s",name);
printf("Hello: %s\n",name);
}
Whilst the issue was partially fixed in the newest patches of 0.16.4A, it still doesn't work for 32 bit, and causes the program to generate invalid assembly -> result of the fact that all functions have a prefix '_' in 32 bit, however that isn't supported in the getting of result.
The name example name.spl is the simplest one as it relys on malloc as an external. But just in case I update it:
include "../libs/libc/stdio.spl"
include "../libs/libc/stdlib.spl"
include "../libs/strlib/strlib.spl"
const NAMELEN = 50l;
func main() {
let name: *char;
name = malloc(NAMELEN);
strset(name, NAMELEN, 0);
printf("What is your name? ");
gets(name);
printf("Hello %s!",name);
free(name)
}
If you are compiling for 32 bit mode, don't use longs, otherwise your whole program is going to break and it won't generate valid nasm x86 assembly.
On a windows or linux machine provide the argument -arc win_x86/linux_x86. An example program could be:
func main(){
let a: long = 5l;
let b: long = 6l;
let c: long = a+b;
}
[NOTE] If you are using longs throughout your code, try and replace them with size_t which will work on any platform you give it.
Fixing this issue will require implementation of 64 bit addition, subtraction, multiplication and division which is going to take a long time to implement by hand but is something that is planned to be added in the future (possibly).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.