Comments (31)
Yes it is desired (stdlib/term.cpp), it would be awesome if you could work on that 😁
from ethereal.
Only thing I don't get is adding funcs to the VM?
I see things like:
vm.funcs.add( { "colorize", 1, 1, { "str" }, FnType::MODULE, { .modfn = colorize }, true } );
But don't get what some of the parameters mean?
from ethereal.
Currently have this:
#ifdef linux // For getting terminal size on Linux
#include <sys/ioctl.h>
#include <unistd.h>
#endif
...
var_base_t * term_width( vm_state_t & vm, func_call_data_t & fcd )
{
#if linux
struct winsize size;
ioctl( STDOUT_FILENO, TIOCGWINSZ, &size );
return new var_int_t(size.ws_row, fcd.args[ 0 ]->parse_ctr() );
#endif
}
...
vm.funcs.add( { "term_width", 0, 0, {}, FnType::MODULE, { .modfn = term_width }, true } );
from ethereal.
see line 41 src/VM/Functions.hpp
the function_t
struct. Ask up if something is not understood 😁
Also, if you are going to create a new object and return it, u should set the last field (manual_res_free
) of the struct to be true
, and to false
if you are returning an already existing object.
vm.nil
is an exception here because the interpreter treats it specially. So, even if you return newly created objects, you can still return nil without having to set the last struct field to be false (since nil already exists).
from ethereal.
With returning variables do I need to:
return new var_int_t(size.ws_row, fcd.args[ 0 ]->parse_ctr() );
Or can I just do:
return size.ws_row;
Looking through the other modules it would seem you need to do the earlier.
from ethereal.
Just built it, built fine and all tests passed. Will actually try it out now.
from ethereal.
Need to add Windows support after anyways.
from ethereal.
Seems to not work, when adding this line to the mod_term.et
test, I get a segfault:
println( term_width() );
from ethereal.
Still get a segfault if in the term module I have this:
return new var_int_t(size.ws_row, 0 );
from ethereal.
well, windows support is not built into the language right now anyway, so u can skip that part if you desire.
Also, tests do not include the feature you built so use your feature first. Only then will you know if it works or not.
Finally, for returning, you will have to do the return new
thing since it is a new variable in the perspective of the language.
from ethereal.
What do you mean about that thing about testing?
After changing the code of Ethereal and then the test, I run ./bootstrap.sh
, then ./perform_tests.et
. Surely that would work fine?
from ethereal.
that would work,yes, assuming u added ur function in one of the files in tests/ directory.
from ethereal.
Right now I get a seg fault whenever I run the function (below):
var_base_t * term_width( vm_state_t & vm, func_call_data_t & fcd )
{
#if linux
struct winsize size;
ioctl( STDOUT_FILENO, TIOCGWINSZ, &size );
return new var_int_t( size.ws_row, fcd.args[ 0 ]->parse_ctr() );
#endif
}
from ethereal.
Registration code (at the bottom of REGISTER_MODULE ( term )
:
vm.funcs.add( { "term_width", 0, 0, {}, FnType::MODULE, { .modfn = term_width }, true } );
from ethereal.
fcd.args is available when the function u fired gets some arguments, otherwise it is empty. So, u accessing args[0] will fail
from ethereal.
Should I just pass 0
or something as the 2nd var?
from ethereal.
I think it was because:
#if linux
would never run the code inside it, it needed to be #if __linux__
from ethereal.
I got it working!
from ethereal.
Is now accessible via term.width
from ethereal.
I'm going to add term.height
now, and probably term.size
which contains both as well.
from ethereal.
How do you properly make a var_tuple_t
? Is there any way to produce it from a proper / real tuple?
from ethereal.
I've given up on size (term.size
) for now. term.width
(plus term_width()
) and term.height
(plus term_height()
are fully functional.
from ethereal.
for tuple,
import tuple;
tup = make_tuple( /* all tuple elements */ );
println( 'first element: ', tup.0 );
from ethereal.
i will work on term.size when i reach home 😃
from ethereal.
Okay, I have updated the code base so fcd.args[..]->parse_ctr()
will no longer be required as an argument for creating new variables. And by the way, for your code, term width should use ws_col
struct member shouldn't it?
from ethereal.
Where are u performing all these additions? When you are done please do share them :)
Also, what exactly do you mean by term size? I seem to have that confused haha.
from ethereal.
Sorry, didn't see. Added in stdlib/term.cpp
and include/ethereal/term.et
, I also added some println
of the size in tests/mod_term.et
.
By size I mean probably a tuple.
I'll push ASAP.
from ethereal.
Oh, alright. Also, you cannot simply push to this repository. You will have to fork it, modify there, and then create a pull request for me to merge :)
from ethereal.
and, for using a tuple, you can create a vector of var_base_t *
and push the row and column in it. Then create a var_tuple_t
with that vector and return that.
But then you will have to access the row and column using size.0
and size.1
from ethereal.
Another way would be to create a struct in include/ethereal/term.et
and return that struct from a term_size()
function. Then you can use size.row
and size.col
struct members
from ethereal.
I wrote the terminal size functions/structs (thanks to you). You can see the commit if you want :)
Reopen if you need to.
from ethereal.
Related Issues (11)
- More test programs/scripts
- Add benchmarks HOT 3
- Add complex library (std.complex) HOT 1
- Fix / update README.md in VSCode extension HOT 3
- Can't add / '+' a string and an int HOT 15
- `tests/mem_funcs.et` test has two `#!./buildfiles/et`'s
- Compile Ethereal VM to wasm HOT 1
- Create a CMake/Make build script HOT 3
- How do you deal with circular references? HOT 1
- Add Windows support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ethereal.