frendsick / torth Goto Github PK
View Code? Open in Web Editor NEWStack based programming language
License: MIT License
Stack based programming language
License: MIT License
Describe the bug
The compiler gives ambiguous error messages when the file given to the compiler as code_file parameter does not exist. The error message indicates that the file could not be included, which is kinda true, but it would be better just to tell the user that the file does not exist.
To Reproduce
Steps to reproduce the behavior:
./torth nonexistent.txt
Compiler Error UNSUPPORTED_FILE_EXTENSION:
File 'nonexistent.txt' has unsupported file extension
Only .torth files are supported
./torth nonexistent.torth
Compiler Error INCLUDE_ERROR:
File 'nonexistent.torth' cannot be included.
Expected behavior
In both above cases, the compiler should indicate that compiling the file fails because the file is not found. The error message could be something like the following:
Compiler Error FILE_NOT_FOUND:
File 'nonexistent.txt' is not found
Document at least the following information from libraries:
Describe the bug
The Torth compiler cannot compile itself with the compiler version merged in PR #58, which enabled using recursion by introducing proper local variables to functions. The compiler version can compile any other known programs but itself correctly.
To Reproduce
Steps to reproduce the behavior:
make
./torth torth.torth
./torth torth.torth
torth
executable is unable to compile any other programs due to segfaultExpected behavior
The Torth compiler should be able to compile itself again and again.
Additional context
This issue was introduced when function recursion was implemented in PR #58
At the moment the language does not care about the function parameter and return types or even how many of them are there. Implement type checking for function signatures to ensure the function takes and returns the expected types.
Describe the bug
Function parameter and variable values are shared between recursive function calls. This is a problem, at least if the function has multiple recursive calls to itself. This happens because each function's function parameters and variables are statically named memory locations.
To Reproduce
Steps to reproduce the behavior:
./torth -r fibonacci.torth
num
and the variable variable
include "std"
function Fib num:int -> int :
NULL take variable in
if num 1 <= do num return endif
num 1 - Fib
1337 variable =
num 2 - Fib +
// Expected variable value: 1337
// Got: NULL
"Variable value is: " puts
variable print "\n" puts
end
function main :
// Expected: 55
// Got: 18446744073709551536
10 Fib print
end
Expected behavior
Variables and function parameters should be separate for each recursive function call.
Screenshots
The output of the example program
The function parameters and variables are statically named memory locations in Assembly.
Additional context
We would need a way to have parameters that are not statically named in the assembly. For example, in C, this is done by pushing each variable to the stack, but I am not sure if that is feasible in the already stack-based language. Maybe?
Type checking of sorts were implemented in compiler/program.py inside function type_check_program using compile-time virtual stack. That stack however were not enough to provide accurate enough type checking for programs with different kinds of control clauses (IF, WHILE) or functions. Type checking should be re-implemented so that it takes code branching properly into account.
Make it possible to call a macro from within another macro
Document at least this information from intrinsics:
Add documentation on how to use the CLASS keyword and create objects.
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.