Author Topic: Gosub.02bas error  (Read 3615 times)

0 Members and 2 Guests are viewing this topic.

José Roca

  • Guest
Gosub.02bas error
« on: September 29, 2018, 07:16:06 AM »
This example fails with an error: "Unidentified instruction when".

Code: [Select]
'% filename "t.exe"
'uses rtl64


function f()
  int a=42
  int b

  'gosub g
  gosub g when a>0
  print b
  return
  '
  g:
  b=a/2
  ret
  '
end function

f

Aurel

  • Guest
Re: Gosub.02bas error
« Reply #1 on: September 29, 2018, 07:37:32 AM »
Jose
as you know GOSUB is keyword so there is no WHEN

gosub to g... ?
g - should be SUBROUTINE or FUNCTION... ok  ;)

José Roca

  • Guest
Re: Gosub.02bas error
« Reply #2 on: September 29, 2018, 08:33:59 AM »
The program is not mine. It is one of the examples that comes with the compiler and I'm just pointing that it fails.

> gosub to g... ?
> g - should be SUBROUTINE or FUNCTION... ok  ;)

No, it should be a label.

Charles Pegge

  • Guest
Re: Gosub.02bas error
« Reply #3 on: September 29, 2018, 08:37:18 AM »
Will be fixed.

if, when, while, until are  currently supported for goto and gosub.

José Roca

  • Guest
Re: Gosub.02bas error
« Reply #4 on: September 29, 2018, 08:48:16 AM »
> if, when, while, until are  currently supported for goto and gosub.

What do you mean?

Charles Pegge

  • Guest
Re: Gosub.02bas error
« Reply #5 on: September 29, 2018, 08:54:49 AM »
In this context, when and while are the same as if.

Until is the same as if not ...

This is experimental syntax :)

Aurel

  • Guest
Re: Gosub.02bas error
« Reply #6 on: September 29, 2018, 10:09:34 AM »
Well ... i don't know that we have WHEN in o2  ::)
and i never use gosub to jump to label only to call function
also i never use until too

José Roca

  • Guest
Re: Gosub.02bas error
« Reply #7 on: September 29, 2018, 10:21:10 AM »
Do you use Gosub  to call a Function? How?

JRS

  • Guest
Re: Gosub.02bas error
« Reply #8 on: September 29, 2018, 10:32:55 AM »
SB allows doing a GOSUB within a FUNCTION/SUB to a LABEL but using GOSUB/GOTO to reference a function sounds non-BASIC to me.

Charles Pegge

  • Guest
Re: Gosub.02bas error
« Reply #9 on: September 29, 2018, 11:27:02 AM »
Yes, it is possible to use gosub to call a function that has no parameters, though you would not normally do this.

Aurel

  • Guest
Re: Gosub.02bas error
« Reply #10 on: September 29, 2018, 01:23:55 PM »
Yes ..like this:

'gosub calls
declare sub hey()

gosub hey

sub hey
print "Hey Oxygen"
return
end sub


Of course I use it very rare

José Roca

  • Guest
Re: Gosub.02bas error
« Reply #11 on: September 29, 2018, 01:40:07 PM »
Doesn't look worthwile.

JRS

  • Guest
Re: Gosub.02bas error
« Reply #12 on: September 29, 2018, 02:14:05 PM »
Quote
Doesn't look worthwile.

+1

BASIC is diluted enough. We don't need core syntax doing tricks.

Mike Lobanovsky

  • Guest
Re: Gosub.02bas error
« Reply #13 on: September 29, 2018, 02:28:46 PM »
I'm almost sure that's kind of an (almost) unnoticed side effect left over from the early stages of syntax experimentation; a transition from gosub to genuine subprocedures. Used to have some such in FBSL BASIC myself. :D

Charles Pegge

  • Guest
Re: Gosub.02bas error
« Reply #14 on: September 29, 2018, 09:31:30 PM »
But There is a problem in 64bit mode. You will lose 16byte stack pointer alignment when making a gosub to a procedure. Therefore gosubs should only be used to call a subroutine, or piece of asm.

PS:

I can remove this vulnerability to stack-pointer misalignment by adding one instruction to the procedure's internal prolog. It rounds the stack pointer down to the nearest 16-byte boundary:

and rsp, -16

This will cost about half a nanosecond per call :)
« Last Edit: September 30, 2018, 01:39:41 AM by Charles Pegge »