brendanator / jsforth Goto Github PK
View Code? Open in Web Editor NEWForth implemented in js
Forth implemented in js
I am attempting to figure out how to convert a counted string (such as from using s" in a definition) into a JavaScript string so that I can call external JavaScript functions that require strings as input. However, I cannot seem to get it working. Here is what I am trying to do:
: test123 s" statusTarget" ;
statusTarget is the ID of an element on the DOM in my test page
test123
Two numbers are now on the stack, representing the counted string
js /document.getElementById{2}
This pops TOS and NOS, but only returns null (where it should have returned something relating to the found element).
I have checked that document.getElementById('statusText') works in the console, however I cannot manage to get the JS interop code to do the same thing. Browsing through js-interop.js seems to indicate that there isn't currently a function to do this conversion, as there are no examples of how to this in the comments at the top. Other JS functions seem to work as long as they only take numbers as input.
I would have attempted to implement this myself, but I cannot yet figure out how strings are stored in Forth's virtual memory, so I am a bit lost (the address on the stack is always some large negative number). Am I overlooking something or is this not yet implemented?
P.S. Great code by the way! jsForth works really well otherwise.
It would be nice if the ".s" command was supported in the browser interpreter so that we could look at the stuff in the stack without deleting it.
Hey @brendanator
First off - your Forth rocks! ๐ I've played with building Forths for numerous platforms, and I've enjoyed playing with a lot of pre-existing Forths too. For people like me who don't get how the whole "threading" thing works, creating a full ANS Forth is nothing short of incredible. Very, very cool!
Having said that, I've kinda got two issues in one here:
S"
doesn't put the pointer and length on the stack... at least, not in the demo page. For example, if I'm in Gforth, and I type s" Forth" .s
, I'll get output like 1234567 5
(the 5 being the length of the word "Forth" and the other number being a pointer to the string in memory). That's not happening here.s" Message here" /js alert{1}
and it would show an alert("Message here"). If you need some tutorials, I'd be happy to contribute those once I know what the heck I'm doing. ๐Anyway, thanks again for the awesome #Forth ! I can't wait to wire this up to something like xterm.js, build a nice little API of words around a canvas, and doo all kinds of crazy fun stuff with this thing. ๐
On success, refill
doesn't return -1, but something like 1. When true flag should be -1 for all the standard words.
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.