flat assembler
Message board for the users of flat assembler.

Index > Programming Language Design > Plain English Programming

Goto page Previous  1, 2, 3, 4, 5
Author
Thread Post new topic Reply to topic
codestar



Joined: 25 Dec 2014
Posts: 254
codestar 04 May 2015, 23:44
Quote:
The problem I have with typeless languages is that it forces us to give names to things that we would normally identify by type (a box, the screen, some pixels).
For Plain English, it seems appropriate to omit names, but in Abakis, there are advantages in using names and aliases.
Code:
; bmi.xpm=0 ; compare this to...

put 0 into the BITMAPFILEINFO's xPixelsPerMeter    
What about macros and constants?
Code:
x=0
put 0 into the numeric constant named x    
How could this macro be written in English and not cause conflict with the runtime language? Returns sum in constant a=. Macro parameters are local names only and the usage determines what they are (numeric or symbolic constant, runtime variable, etc).
Code:
macro c.add a, b { a=a+b }

x=1        ; example...
y=2
c.add x, y ; result: x=3    
Quote:
... it forces us to give names to things that we would normally identify by type (a box, the screen, some pixels...

draw_rectangle(r);
draw_circle(c);
We could say: "draw box r" or "draw r which is a box".
Code:
; draw(box b, style s)

; "draw box b with style s"

; "draw a box named b with
;    the style named s"

box b
style s
; ...
draw_box b, s    
Quote:
("I want to improve Lisp, or C, or whatever") is the problem
Agree. Abakis was designed with no reference and no thought that it should be an "improvement of X". Only uses standard names - function, byte, int, etc - recognized by most programmers and the pointer notation in C and M68K ASM - which were afterthoughts. Unique semantics. Example:
Code:
function test.file
  locals n
  get n=text.n t
  try create f
  write t, n
  close
  try open f
  read s, n
  say s
  close
  execute f
endf 1

while c, c=*p++, endw, p-s, p--

. p=a, q=b, n>>>2
loop n, (u32) *p++=*q++, endl

while s<e, c=*s, *s++=*e, *e--=c, endw

if n=0, *p++='0', *p=0
  return s
end

loop n, c=*s++, *p++=c
  if c=0, break, end
endl, p--

while c, c=*s++, *p++=c, endw, p--

while c=d, c=*p++, d=*s++
  if c=0, break, end
  if d=0, break, end
endw, p=c, p-d

while n, x=n, x&1, x+'0'
  . *p++=x, n>>>1
endw, *p=0

forever, c=*p++
  if c=0, return n, end
  . x=n, x<<2, n+x, n+n
  . n-'0', n+c
endfv    
Recently, I've been working on C-ish style macro languages in FASMG for many reasons; To help/teach FASMG; No one else here can/will do this; More programmers know C = more users; Easy conversions to/from C; It can be "portable" (multi-CPU, multi OS); To offer an alternative to C (some programmers have no choice but to use C/C++ for work or Android); Never seen a good "improvement of C" with redesigned syntaxes, only additions to C (ie, start with C then add to it); Smaller than TinyCC; It makes Abakis look better in comparison.
Quote:
It's not a matter of intelligence; it's a matter of "unlearning" artificial ways of thinking. It's a matter of "getting back to one's roots".

... It's as if a small child was trying to think about nouns and verbs and adjectives when first learning to speak. The problem isn't that that you're "not bright enough" -- it's that you know too much...

Unlearning is a hard thing to do. I've been practising it for the most of my adult life and it still feels as difficult as it probably was in the beginning.
Quote:
How to be original? My rules to myself:

* Unplug internet, too many distractions
* Forget everything you've learned
* Ignore everyone, especially their thoughts and ideas on programming
* Don't use references unless you absolutely have to
* Think "unique", "what's needed". Avoid looking at your own previous creations. Buddha: "I never see what has been done; I only see what remains to be done"
* Do whatever you need to relax; example: hot bath, coffee, Nesquick, real wine (Gallo, Sutter Home), natural medicine. Make yourself comfortable, concentrate
Post 04 May 2015, 23:44
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 06 May 2015, 10:25
I find some of the discussions happening in this thread really interesting and I'm considering creating a new sub-forum for this kind of topics, so they would not become lost inside the "heap" - perhaps a forum dedicated to the design of programming languages and compilers (the design of fasm and my new engine could also be discussed there).
Post 06 May 2015, 10:25
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 06 May 2015, 12:36
Tomasz Grysztar wrote:
I find some of the discussions happening in this thread really interesting and I'm considering creating a new sub-forum for this kind of topics, so they would not become lost inside the "heap" - perhaps a forum dedicated to the design of programming languages and compilers (the design of fasm and my new engine could also be discussed there).
You should have created it long time ago considering your natural talent is more towards compiler & language design. Should be attractive to other compiler writers out there that have no common forum to discuss these sort of things. Go with it.
Post 06 May 2015, 12:36
View user's profile Send private message Visit poster's website Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 23 Dec 2017, 21:02
The current Plain English compiler produces only x86 (32 bit) Windows executables. It uses calls to short assembly
language (machine code) subroutines as primitives. While not significant short comings, optimized x64 (64 bit)
code would be a nice feature.
Here I've coded one of the longer machine code primitives in Plain English and then hand translated that to C.
I then cleaned up the gcc asm output and commented it with the original Plain English code line by line.
Plain English:
Code:
To compare a string to another string given a length and another length (equal only):
Privatize the length.
If the length is not the other length; say no.
If the length is 0; say yes.
Put the string's first into a pointer.
Put the other string's first into another pointer.
Loop.
Put the pointer's target into a byte.
Put the other pointer's target into another byte.
Uppercase the byte.
Uppercase the other byte.
If the byte is not the other byte; say no.
Add 1 to the pointer.
Add 1 to the other pointer.
Subtract 1 from the length.
If the length is 0; say yes.
Repeat.    
C:
Code:
#define BYTE unsigned char
#define WYRD short
#define DWORD long
#define QWORD unsigned long long
#define NUMBER long long
#define LENGTH NUMBER
#define BOOL NUMBER
#define POINTER NUMBER


typedef struct{
  BYTE a[16];
} STRING;


#define privatize(type, pointer) type private_##pointer = *pointer
#define private(pointer) &private_##pointer
#define cmpEq(variable, anotherVariable) *variable == *anotherVariable? 1: 0
#define cmpLt(variable, anotherVariable) *variable < *anotherVariable? 1: 0
#define cmpGt(variable, anotherVariable) *variable > *anotherVariable? 1: 0
#define mov(variable, anotherVariable) *variable = *anotherVariable
#define add(variable, anotherVariable) *variable += *anotherVariable
#define sub(variable, anotherVariable) *variable -= *anotherVariable

#define mov_IndirectBytePtr(pointer, anotherPointer, offset) \
  *pointer = (BYTE *)(QWORD)(*(QWORD *)(anotherPointer + offset))

static NUMBER zero = 0;
static NUMBER one = 1;
static NUMBER little2DA = 97;
static NUMBER little2DZ = 122;
static NUMBER space2DKey = 32;

// To uppercase a byte:
static void UppercaseAByte (
  BYTE *byte
){
  if (cmpLt(byte, &little2DA)) return;
  if (cmpGt(byte, &little2DZ)) return;
  sub(byte, &space2DKey);
}

// To compare a string to another string given a length and another length (equal only):
NUMBER CompareAStringToAnotherStringGivenALengthAndAnotherLength28EqualOnly29 (
  STRING *string,
  STRING *anotherString,
  LENGTH *length,
  LENGTH *anotherLength
){
  NUMBER result;
  BYTE *pointer, *anotherPointer;
  privatize(LENGTH, length);
  BYTE byte, anotherByte;
  while (1){
    if (!(cmpEq(length, anotherLength))) {result = zero; goto exit;}
    mov_IndirectBytePtr(&pointer, string, 0);
    mov_IndirectBytePtr(&anotherPointer, anotherString, 0);
    while (1){
      if (cmpEq(&private_length, &zero)) {result = one; goto exit;}
      mov(&byte, pointer);
      mov(&anotherByte, anotherPointer);
      UppercaseAByte(&byte);
      UppercaseAByte(&anotherByte);
      if (!(cmpEq(&byte, &anotherByte))) {result = zero; goto exit;}
      add(&pointer, &one);
      add(&anotherPointer, &one);
      sub(&private_length, &one);
    }
  }
  exit:
  return result;
}    
FASM:
Code:
use64
CompareAStringToAnotherStringGivenALengthAndAnotherLength28EqualOnly29:
  mov r10, QWORD [r8]           ; Privatize the length.
  xor eax, eax
  cmp r10, QWORD [r9]
  je .L13
.L5:
  rep ret                       ; If the length is not the other length; say no.
  align 16
.L13:
  test r10, r10                 ; If the length is 0; say yes.
  mov rcx, QWORD [rcx]          ; Put the string's first into a pointer.
  mov r11, QWORD [rdx]          ; Put the other string's first into another pointer.
  je .L10
  sub r11, rcx
  jmp .L8
  align 16
.L14:                           ; Loop.
  add rcx, 1                    ; Add 1 to the pointer.
                                ; Add 1 to the other pointer.
  sub r10, 1                    ; Subtract 1 from the length.
  je .L10                       ; If the length is 0; say yes.
.L8:
  movzx r8d, BYTE [rcx]         ; Put the pointer's target into a byte.
  movzx edx, BYTE [rcx + r11]   ; Put the other pointer's target into another byte.
  mov rax, r8                   ; Uppercase the byte.
  sub r8, 97
  lea r9d, [rax - 32]
  cmp r8, 25
  movzx r8d, dl                 ; Uppercase the other byte.
  cmovbe eax, r9d
  sub r8, 97
  lea r9d, [rdx - 32]
  cmp r8, 25
  cmovbe edx, r9d
  cmp dl, al                    ; If the byte is not the other byte; say no.
  je .L14                       ; Repeat.
  xor eax, eax
  ret
  align 16
.L10:
  mov eax, 1
  ret    

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 23 Dec 2017, 21:02
View user's profile Send private message Visit poster's website Reply with quote
bazizmix



Joined: 15 Jan 2016
Posts: 51
bazizmix 24 Dec 2017, 17:07
Quote:
.L5:
rep ret

Who can explain the meaning of this instruction?
Post 24 Dec 2017, 17:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 24 Dec 2017, 17:19
bazizmix wrote:
Quote:
.L5:
rep ret

Who can explain the meaning of this instruction?
Hehe, yeah.

http://repzret.org/p/repzret/

Mike Gonta: When i read "say no" I don't get the feeling that it should also implicitly quit. Perhaps something like "say no; and finish".
Post 24 Dec 2017, 17:19
View user's profile Send private message Visit poster's website Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 24 Dec 2017, 17:59
revolution wrote:
Mike Gonta: When i read "say no" I don't get the feeling that it should also implicitly quit. Perhaps something like "say no; and finish".
Syntactically, say yes/no is return TRUE/FALSE so exiting is implied (and part of the language specification). However,
the compiler may insert some cleanup code before the function exits, which is why I used goto exit instead of break.
You will also notice that the entire function is enclosed in a while (1) {} (also part of the spec). This is so a Loop can
start at the beginning of the function (actually after any compiler inserted init code), without actually requiring the Loop keyword.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 24 Dec 2017, 17:59
View user's profile Send private message Visit poster's website Reply with quote
porky11



Joined: 12 Feb 2019
Posts: 4
porky11 12 Feb 2019, 13:04
I also had an idea for a similar language, but I don't think, forcing a programming langauge to sound too much like a natural language is a good idea.
I prefer taking the good ideas from natural languages and use them in programming languages without making it more complicated.

I just found some document I wrote some months ago and just continued writing it a bit.

Here is what I wrote down: https://gist.github.com/porky11/3a3113e8aac98070f80182275577ccfe

I really would like to add some of these ideas into a programming language. But I'll open a new thread about my programming language anyway.
Post 12 Feb 2019, 13:04
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.