forth

Writing a text file into an array on Forth

泪湿孤枕 提交于 2021-02-10 14:21:48
问题 I have a text file, containing an array of numbers such as: 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 I have opened the text file with the following code: variable file-id : open_file ( -- ) \ Opens the text file s" c:\etc\textfile.txt" r/w open-file throw file-id ! ; I have also created an array to store this data: create an_array 25 chars allot \ Create the array : reset_array ( -- ) big_array 25 0 fill ; reset_array \ Set all elements to 0 Is there a way to write the contents of

Writing a text file into an array on Forth

╄→гoц情女王★ 提交于 2021-02-10 14:20:18
问题 I have a text file, containing an array of numbers such as: 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 I have opened the text file with the following code: variable file-id : open_file ( -- ) \ Opens the text file s" c:\etc\textfile.txt" r/w open-file throw file-id ! ; I have also created an array to store this data: create an_array 25 chars allot \ Create the array : reset_array ( -- ) big_array 25 0 fill ; reset_array \ Set all elements to 0 Is there a way to write the contents of

How do I create an array in Forth?

孤街醉人 提交于 2021-01-28 03:56:07
问题 I know, the question was often asked in the past and perhaps the information are given in previous Stack Overflow postings. But learning Forth is a very complicated task and repetition helps to understand the advantages of a concatenative programming language over alternative languages like C. What I have learned from Forth tutorials is that Forth doesn't provide commands for creating a 2D array, but the user has to realize everything from scratch in the program. I've found two options in

self-modifying code on MacOS Catalina / x64

孤者浪人 提交于 2020-07-10 10:28:39
问题 As part as porting a forth compiler, I'm trying to create a binary that allows for self modifying code. Gory details at https://github.com/klapauciusisgreat/jonesforth-MacOS-x64 Ideally, I create a bunch of pages for user definitions and call mprotect like so: #define __NR_exit 0x2000001 #define __NR_open 0x2000005 #define __NR_close 0x2000006 #define __NR_read 0x2000003 #define __NR_write 0x2000004 #define __NR_mprotect 0x200004a #define PROT_READ 0x01 #define PROT_WRITE 0x02 #define PROT

self-modifying code on MacOS Catalina / x64

Deadly 提交于 2020-07-10 10:28:00
问题 As part as porting a forth compiler, I'm trying to create a binary that allows for self modifying code. Gory details at https://github.com/klapauciusisgreat/jonesforth-MacOS-x64 Ideally, I create a bunch of pages for user definitions and call mprotect like so: #define __NR_exit 0x2000001 #define __NR_open 0x2000005 #define __NR_close 0x2000006 #define __NR_read 0x2000003 #define __NR_write 0x2000004 #define __NR_mprotect 0x200004a #define PROT_READ 0x01 #define PROT_WRITE 0x02 #define PROT

Building Jonesforth - asm/unistd.h: No such file or directory

前提是你 提交于 2020-07-09 03:23:12
问题 When attempting to build Jonesforth (32-bit GNU Assembler program) on Ubuntu 16.04.4 64-bit (Xenial Xerus), I'm seeing the following: ~/src/jonesforth $ make gcc -m32 -nostdlib -static -o jonesforth jonesforth.S jonesforth.S:1154:24: fatal error: asm/unistd.h: No such file or directory compilation terminated. Makefile:11: recipe for target 'jonesforth' failed Looking in the file jonesforth.S , I noticed the following lines: //#include <asm-i386/unistd.h> // You might need this instead

Word redefinition in Forth

你离开我真会死。 提交于 2020-04-13 06:44:18
问题 In Forth, in case of re-definition of word, what is the expected behavior of another word that uses the re-defined one? For e.g. if x calls y : : Y ." Old Y " CR ; : X 10 0 DO Y LOOP ; \ ... : Y ." New Y " ; then after the re-definition of Y , what should be the output of X , Old Y or New Y ? 回答1: The short answer: X will output Old Y , see also your example in online test. At the time when Y is defined in the second time, the X is already compiled. In Forth, redefinition is just shadowing:

Can a Forth-like language be implemented with just one stack?

那年仲夏 提交于 2020-01-24 13:04:25
问题 Forth has a stack and a return-stack. As far as I understand, the point of the return-stack is to store the previous values of the program counter. C programs put the previous value of program counter on the stack, and use no return stack. Does Forth only need a return-stack because it returns result(s) on the stack, and thus the previous value of the program counter could be buried? 回答1: The "Portable Assembly Language" should be close. It's a concept for a compiler for a language which is

Forth local variable assigning variables

怎甘沉沦 提交于 2020-01-15 08:08:30
问题 I have a simple local variable in Forth: : subtraction { a b } a b - ; I would like to assign the output of a b - to another variable, say c. Is this possible? 回答1: TO works for both VALUE s and local variables, so: : subtraction { a b | c -- } a b - to c ; 来源: https://stackoverflow.com/questions/49115901/forth-local-variable-assigning-variables

Gforth conditional expression with variables - only partly correct

江枫思渺然 提交于 2020-01-03 03:43:08
问题 Simple expression: variable x ok 4 x ! ok 3 x < . -1 ok 3 x > . 0 ok This seems normal and correct, however: variable x ok 3 x ! ok x 4 < . 0 ok x 4 > . -1 ok The second block of code is wrong. What is evaluating wrongly? What is the problem here? 回答1: variable x makes a new variable, but x returns the address, not the value. You need something like this: variable x 3 x ! ok x @ 4 < . x @ 4 > . 来源: https://stackoverflow.com/questions/49040227/gforth-conditional-expression-with-variables-only