Page 1 of 3

nSquirrel on Ti-Nspire

Unread postPosted: 07 Apr 2016, 00:34
by Eiyeron
nSquirrel
Squirrel on Ti-Nspire

Last release version (v1.0.1) : https://github.com/Eiyeron/squirrel/rel ... rrel_1.0.1
Project repository : https://github.com/Eiyeron/squirrel/

nSquirrel (interpreter + n2SDLib) branch : https://github.com/Eiyeron/squirrel/tree/nSquirrel

"Squirrel is a high level imperative, object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games."

Although Squirrel offers a wide range of features like:
  • Open Source MIT licence
  • dynamic typing
  • delegation
  • classes & inheritance
  • higher order functions
  • lexical scoping
  • generators
  • cooperative threads (coroutines)
  • tail recursion
  • exception handling
  • automatic memory management (CPU bursts free; mixed approach ref counting/GC)
  • both compiler and virtual machine fit together in about 7k lines of C++ code and add only around 100kb-150kb the executable size
  • optional 16bits characters strings
  • powerful embedding api
  • eg. function/classes can be defined by scripts or in C
    • eg. objects can fully exist in the VM or be bound to native code
    • eg. classes created in C can be extended by scripts or vice-versa
    • and more

nSquirrel is a fork of this language destined for Ti-Nspires. The core language will be easily embeddable into Ndless projects as the project offers libraries and API to mess with it. Thus, it's included with bindings to n2DLib to allow playing with the screen and the keyboard.

nSquirrel

Instructions :
- Download the archive containing the program (sq.tns) and if wanted, the example scripts.
- Install your sq.tns on your calc's nspire folder
- Now you can launch the interpreter for an interactive session ( quit() to exit it) or launch a .nut script (only after running the exectuable once). NOte that thanks to nspireio, you have to press twice Enter to validate your input.
- The interpreter registering itself to open .nut files, to execute such scripts, you will just have to click on them.

Notes
- For further versions, I'll probably provide two versions of the binaries, ones to compile nSquirrel's interpreter (which uses Nspire-IO) and one to be included in projects.

Example script
Image

Squirrel sur Ti-Nspire

Dernière version (v.1.0.1) : https://github.com/Eiyeron/squirrel/rel ... rrel_1.0.1
Source du projet : https://github.com/Eiyeron/squirrel/

Branche avec interpréteur nSquirrel (+n2DLib) : https://github.com/Eiyeron/squirrel/tree/nSquirrel

"Squirrel est un langage de programmation impératif de haut niveau et orienté objet, conçu pour être un langage de script léger qui rentre les conditions de taille, mémoire et resosurces de temps réels dans des applications comme des jeux vidéos."

(Autrement dit : C'est un langage de programmation destiné à être embarqué comme le lua)

Même si Squirrel offre un large panel de fonctionnalités :
  • Licence MIT Open Source
  • typage dynamique
  • délégation
  • classes et héritage
  • fonctions de haut niveau
  • encapsulation lexicale
  • générateurs
  • threads coopératifs (coroutines)
  • simplification automatique de récursion terminale
  • gestion des exceptions
  • Gestion automatique de la mémoire (sans pic d'utilisation du CPU; approche mixte de collection de déchets et de comptage de références)
  • Le compilateur et la VM tiennent sur environ 7000 lignes de C++ et n'ajoutent qu'à peu près 100-150kb de données sur l'exécutable.
  • en option, chaînes de caractères 16-bits
  • puissante API embarquée
  • exemples avec des classes et fonctions définissables par script ou en C
    • Ex : les objets peuvent n'exister que dans la VM ou être lié à du code natif
    • Les classes définies en C peuvent être étendues par des scripts et vice versa
    • Et plus!

nSquirrel est un dérivé de ce langage destiné aux calculatrices Ti-Nspire. Le cœur du programme sera facilement intégrable dans des projets Ndless car le projet offre des librairies et une API pour intéragir avec. Ainsi, le programme est inclus à la librarie n2DLib pour permettre de jouer avec l'écran et le clavier.

nSquirrel

Instructions d'installation :

  • Téléchargez l'archive contenant l'interpréteur (sq.tns) et si voulus, les scripts d'exemple
  • Installez sq.tns dans le dossier "ndless" de votre calculatrice
  • À présent, vous pouvez soit lancer l'interpréteur (quit() pour quitter) ou vous pouvez lancer un fichier .nut.tns (après avoir au moins lancé une fois l'interpréteur). Notez qu'à cause d'nspire-io, vous avez à appuyer deux fois sur Enter pour valider.
  • L'interpréteur s'enregistre automatiquement pour ouvrir les fichiers .nut à leur exécution.

Notes
Pour les versions futures, je fournirai 2 versions des fichiers binaires : l'une pour compiler l'interpréteur nSquirrel (qui utilise Nspire-IO) et l'autre pour être incluse dans des projets

Exemple de script :
Image

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 07:52
by Adriweb
This is definitely very cool - Yet another third-party language on the Nspire platform :D
The demo is pretty nice, too.

Regarding n2DLib, I think that one will have to be recompiled/adapted to work with the latest Nspire CX revisions (rev. W ("CR 4")) with their new LCDs, and maybe nSquirrel as well

(And thanks for crossposting!)

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 10:07
by Eiyeron
Concerning the newer revision, indeed, that must be something to be added, but on n2DLib's side. I should add another issue ticket to Matref's repository. As soon as this will be fixed or loadPNG, I'll update nSq to accept these changes.

I also am a bit busy right now but the french translation will come later. You're welcome for the crosspost, thanks Streetwalrus to have suggested me to post it here. What should be next? Should I post to the archive or should I keep it here for now?

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 12:34
by Ti64CLi++
Very good Eiyeron. :bj:
For a member of Planète Casio and a Casio adept, very good. ;)

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 14:32
by Eiyeron
I find this a bit reducing me, summing me as "a Casio-ist". I mean, it's already been years that I registered to Omnimaga because I was programming also on Ti (like Snak'11, HBE, a stupid experiment with my own (a bit of Street's too) game engine in the works.

I don't hold any ressentment or grudges, don't worry though. :p I switched for the Nspire only because of the better support of C/C++ and the better power and memory.

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 15:38
by Ti64CLi++
Excuse me, but I just know you on Planète-Casio. Sorry :?

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 20:38
by Eiyeron
Again, no problem. That aside, I wonder how much people will be interested in this thing. I should provide some better examples, shouldn't I?

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 20:43
by Adriweb
I didn't know the language, at first, but looking at the example scripts, it's pretty damn impressive \o/
Looks like a Lua on steroids (especially with the bindings to Nspire-specific stuff) :)

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 07 Apr 2016, 20:45
by Lionel Debroux
Good to see another "standard", alternative language on the Nspire, showcasing once more what one can do with access to native code :)

Another "standard" language for which an embeddable implementation exists is TCL, with libjim, which provides welcome extensions to old-style TCL (which is not usually considered high quality / maintainability, and is not high performance either, but is portable).

More / better examples are seldom a bad thing.

This is newsworthy, but we're a bit busy today...

Re: nSquirrel : Squirrel Programming on Ti-Nspire

Unread postPosted: 08 Apr 2016, 01:27
by Eiyeron
An example with lots of comments will come a little later, with a bugfix about some things that I overlooked (like a wrong argument usage on drawSpritePart and wrong key names setting).

Lionel Debroux wrote:Good to see another "standard", alternative language on the Nspire, showcasing once more what one can do with access to native code :)


Yeah, that's what I wanted to show with this calc, that it's something that we usually overlook its true power and that it deserves some better solutions to allow people program on it.

Lionel Debroux wrote:Another "standard" language for which an embeddable implementation exists is TCL, with libjim, which provides welcome extensions to old-style TCL (which is not usually considered high quality / maintainability, and is not high performance either, but is portable).

There are actually quite a number of embeddable script languages. I chose this one because it had a good C-like syntax (a bit quirky on some things but I still like it) and that it would offer similar performances to Lua (if not a small slower on some things but more stable performance-wise and being a small faster on some bits).