//mgoovl.bcpl	machine-independent code for Call (in overlay) 23 June 1983

get "mcommon.d"
get "mdecl.d"

external [
// OS
	Zero

// MASM
	@MBlock

// MDATA
	CallAVec

// MSYM
	ChkToken; EvalAText

// MIOC
	SimpleTexttoDVec

// MTXTBUF
	InputTextBuffer

// MCMD
	StartCmdOverlay; ErrorAbort

// Machine dependent
	DefaultGoMemory

// Defined here for ACTIONS
	StartWithArgs
]


//Used in the action table to call CallM (D1)
let StartWithArgs(lvProc,MBunion,nil) be
[	let AV,Count = vec 5*ValSize,0
	let AVal,X,TSize = vec size AVal/16,1,nil
	Zero(AV,5*ValSize)
	if X > InputTextBuffer!0 then ErrorAbort()
//EvalAText consumes the "(" delimiter
	unless EvalAText(InputTextBuffer,lv X,AVal,true,
		DefaultGoMemory()) do
	if AVal>>AVal.TypeStorage ne MemTypeStorage then ErrorAbort()
//Leave address and MemX in permanent storage for printout on return
//from call
	MBlock(CallAVec,lv AVal>>AVal.Addr,2); CallAVec!2 = AVal>>AVal.X
	let TV = vec 80
	for I = 0 to 4*ValSize by ValSize do
	[ TV!0 = 0
	  let Kind = nil
	  while true do
	  [ Kind = ChkToken(InputTextBuffer,lv X,lv TSize)
	    switchon Kind into
	    [
case LimitToken:
case RParToken:
case CommaToken:
	      X = X+1; if TV!0 eq 0 then break
//**Would like this to be SimpleTexttoDVec(TV,16*ValSize,AV+I)
//**but SimpleTexttoDVec doesn't work for more than 32 bits
	      SimpleTexttoDVec(TV,32,AV+I); Count = Count+1
	      break
default:      MBlock(TV+TV!0+1,InputTextBuffer+X,TSize)
	      X = X+TSize; TV!0 = TV!0+TSize; loop
	    ]
	  ]
	  if Kind ne CommaToken then break
	]
	StartCmdOverlay(lvProc,MBunion,AV,Count)
]