From 39a17b5764c4533717325011054cc3f55df83f2a Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sat, 10 Oct 2026 08:29:20 +0000 Subject: [PATCH] Step 7: multiple results, errors, INC and DEC Several results are a record, returned through the hidden pointer; a code procedure returns two in rax and rdx. a, b := f(x) keeps each variable's address in a frame slot while the call runs, then assigns in order. An ERROR constant is the address of its length and message; errors compare by that address, and MSG reads the message. INC and DEC evaluate their variable once. --- diff --git a/PLAN.md b/PLAN.md index d9cfd6b..a80e167 100644 --- a/PLAN.md +++ b/PLAN.md @@ -92,7 +92,7 @@ Stage 2: the rest of the language -- [ ] 7. Multiple results and errors. +- [x] 7. Multiple results and errors; `INC` and `DEC`. - [ ] 8. Enumerations and sets, record literals, `defer`; examples. - [ ] 9. `NEW`; `lib/Mem.jed`, `lib/Arena.jed`, `lib/Heap.jed`. - [ ] 10. Generic modules, with type and procedure arguments; diff --git a/doc/jed.md b/doc/jed.md index 247375a..a285a7a 100644 --- a/doc/jed.md +++ b/doc/jed.md @@ -507,6 +507,8 @@ | `NEW(p, a)` | sets `p: ^T` to a fresh, zeroed `T` from the allocator `a: ^Mem.Allocator`, or to `nil` if `a` has no room | | `MSG(e)` | the message of the error `e`, a `[]U8` | | `SYSCALL(n, x1, ..., x6)` | Linux system call `n` with up to six integer or pointer arguments; the raw result, an `I64` (a negative number is `-errno`) | +| `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` | +| `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` | | `FENCE` | a full memory barrier | | `CAS(p, old, new)` | if `p^ = old`, sets `p^ := new` and returns `true`; atomically | | `XCHG(p, x)` | sets `p^ := x` and returns the value before, atomically | @@ -517,6 +519,10 @@ `SYSCALL` exists only on Linux targets. Other systems have no stable system call interface, and their modules call the C library instead (section 9). + +`INC` and `DEC` evaluate `v` once, so `INC(a[f(i)])` calls `f` once. They +read `v` and then write it: two accesses, even through a `^VOLATILE` +pointer, and not atomic; `XADD` is the atomic one. For `CAS`, `XCHG` and `XADD`, `p` is a `^T` or `^VOLATILE T` where `T` is an 8-byte integer or pointer type (an integer type for `XADD`). They diff --git a/src/gen.pas b/src/gen.pas index 1e59770..521bd01 100644 --- a/src/gen.pas +++ b/src/gen.pas @@ -31,7 +31,7 @@ type TMode = (mConst, mVar, mReg, mStack, mProc, mType, mStr, mBuiltin, mCase, mNone); - TBase = (bFrame, bGlobal, bReg, bStack); + TBase = (bFrame, bGlobal, bReg, bStack, bSlot); { bSlot: address in a frame slot, chunk } TItem = record mode: TMode; @@ -53,6 +53,7 @@ n: longint; target: int64; { the frame slot of a procedure value, if any } chunk: longint; { else the procedure's chunk } + code: boolean; { a code procedure: two results come in rax and rdx } end; var @@ -110,7 +111,13 @@ procedure BeginProc(sig: PType; params: PObj); procedure EnterBody(c: longint); procedure ReturnValue(var x: TItem); +procedure ReturnField(f: PObj; var x: TItem); +procedure ReturnJump; procedure ReturnNone; +procedure Pin(var x: TItem); +procedure IncDec(var v, k: TItem; dec: boolean); +procedure Msg(var x: TItem); +function ErrorChunk(var x: TItem; module, name: longint): longint; procedure EndProc(c: longint); procedure CmpI(r: longint; v: int64); procedure PushRax; @@ -217,6 +224,13 @@ else begin MovRI(R11, v); Alu(aluCmp, r, R11) end; end; +{ A constant into r: an error constant is the address of its chunk. } +procedure ConstTo(r: longint; const x: TItem); +begin + if (x.typ^.form = fError) and (x.val > 0) then Lea(r, MemRip(x.val - 1, 0)) + else MovRI(r, x.val); +end; + function MemOf(var x: TItem; r: longint): TMem; begin case x.base of @@ -227,6 +241,11 @@ x.base := bReg; x.reg := r; MemOf := Mem(r, x.off); end; + bSlot: begin + Load(r, Mem(RBP, x.chunk), 8, false); + x.base := bReg; x.reg := r; + MemOf := Mem(r, x.off); + end; else MemOf := Mem(x.reg, x.off); end; end; @@ -258,7 +277,7 @@ var m: TMem; begin case x.mode of - mConst: MovRI(RAX, x.val); + mConst: ConstTo(RAX, x); mVar: begin if not IsScalar(x.typ) then Mark('not a single value'); m := MemOf(x, RAX); @@ -266,7 +285,11 @@ end; mReg: ; mStack: PopR(RAX); - mProc: Lea(RAX, MemRip(x.obj^.chunk, 0)); + mProc: begin + if x.obj^.isCode and (x.obj^.typ^.base <> nil) and x.obj^.typ^.base^.tuple then + Mark('a code procedure with two results can only be called'); + Lea(RAX, MemRip(x.obj^.chunk, 0)); + end; else Mark('not a value'); end; x.mode := mReg; @@ -391,7 +414,7 @@ if (s^.form = fConst) and (t^.form = fInt) then begin if (x.mode = mConst) and not Fits(x.val, t) then Mark('constant doesn''t fit ' + TypeName(t)); x.typ := t; - end else if (s^.form = fNil) and (t^.form in [fPtr, fProc]) then + end else if (s^.form = fNil) and (t^.form in [fPtr, fProc, fError]) then x.typ := t else if (s^.form = fPtr) and (t^.form = fPtr) and t^.vol and not s^.vol and Same(s^.base, t^.base) then @@ -752,10 +775,10 @@ end else if (xt^.form = fPtr) and (yt^.form = fPtr) and (op = sMinus) then begin if not Same(xt, yt) then Mark('different pointer types'); t := tI64; scale := xt^.base^.size; isPtr := true; - end else if (xt^.form in [fPtr, fProc, fNil]) and (yt^.form in [fPtr, fProc, fNil]) then begin + end else if (xt^.form in [fPtr, fProc, fNil, fError]) and (yt^.form in [fPtr, fProc, fNil, fError]) then begin if not (op in Rel) then Mark('not a pointer operator'); - if (xt^.form = fProc) or (yt^.form = fProc) then - if not (op in [sEql, sNeq]) then Mark('procedures compare only with = and #'); + if (xt^.form in [fProc, fError]) or (yt^.form in [fProc, fError]) then + if not (op in [sEql, sNeq]) then Mark('procedures and errors compare only with = and #'); if (xt^.form <> fNil) and (yt^.form <> fNil) and not Same(xt, yt) then if not ((xt^.form = fPtr) and (yt^.form = fPtr) and Same(xt^.base, yt^.base)) then Mark('different pointer types'); @@ -779,11 +802,11 @@ { x into rax, y into rcx } if y.mode = mConst then begin if x.mode = mStack then PopR(RAX) else Value(x); - MovRI(RCX, y.val); + ConstTo(RCX, y); end else begin Value(y); MovRR(RCX, RAX); - if x.mode = mConst then MovRI(RAX, x.val) else PopR(RAX); + if x.mode = mConst then ConstTo(RAX, x) else PopR(RAX); end; if t^.form = fReal then begin @@ -893,8 +916,10 @@ procedure BeginCall(var c: TCall; var x: TItem); begin if x.mode = mProc then begin - c.sig := x.obj^.typ; c.chunk := x.obj^.chunk; c.target := 0 + c.sig := x.obj^.typ; c.chunk := x.obj^.chunk; c.target := 0; + c.code := x.obj^.isCode; end else begin + c.code := false; if x.typ^.form <> fProc then Mark('not a procedure'); c.sig := x.typ; c.chunk := -1; c.target := ToSlot(x); @@ -942,7 +967,7 @@ ni := 0; nf := 0; if (res <> nil) and IsAggregate(res) then begin ret := AllocTemp(res^.size, res^.align); - ni := 1; + if not c.code then ni := 1; end; { the System V classes: each argument in the next free register of its kind, or else on the stack } @@ -963,7 +988,7 @@ Push(RAX); end; ni := 0; nf := 0; - if ret <> 0 then begin Lea(RDI, Mem(RBP, ret)); ni := 1 end; + if (ret <> 0) and not c.code then begin Lea(RDI, Mem(RBP, ret)); ni := 1 end; for i := 0 to c.n - 1 do if not onStack[i] then if isF[i] then begin MovsdXM(nf, Mem(RBP, c.slots[i])); inc(nf) end @@ -974,6 +999,10 @@ CallR(R11); end; if k + pad > 0 then AluI(aluAdd, RSP, 8 * (k + pad)); + if (ret <> 0) and c.code then begin + Store(Mem(RBP, ret), RAX, 8); + Store(Mem(RBP, ret + 8), RDX, 8); + end; FillChar(x, SizeOf(x), 0); if res = nil then begin x.mode := mNone; x.typ := tNone @@ -1136,11 +1165,91 @@ Load(RDI, Mem(RBP, retSlot), 8, false); Copy(result^.size); Load(RAX, Mem(RBP, retSlot), 8, false); + end else Value(x); +end; + +{ One of several results, into its place behind the hidden pointer. } +procedure ReturnField(f: PObj; var x: TItem); +begin + Coerce(x, f^.typ); + if IsScalar(f^.typ) then begin + Value(x); + Load(RCX, Mem(RBP, retSlot), 8, false); + Store(Mem(RCX, f^.val), RAX, ScalarSize(f^.typ)); end else begin - Value(x); - if result^.form = fReal then MovqXR(0, RAX); + if x.vol then Mark('can''t copy through a volatile pointer'); + Address(x, RSI); + Load(RDI, Mem(RBP, retSlot), 8, false); + Lea(RDI, Mem(RDI, f^.val)); + Copy(f^.typ^.size); end; +end; + +{ With the result in rax, as ReturnValue left it. } +procedure ReturnJump; +begin + if IsAggregate(result) then Load(RAX, Mem(RBP, retSlot), 8, false) + else if result^.form = fReal then MovqXR(0, RAX); Jmp(exitL); +end; + +{ Keeps a variable's address in a frame slot, rather than in a register + or on the stack, while other code runs. } +procedure Pin(var x: TItem); +var s: int64; +begin + if (x.mode = mVar) and (x.base in [bReg, bStack]) then begin + Address(x, RAX); + s := AllocTemp(8, 8); + Store(Mem(RBP, s), RAX, 8); + x.base := bSlot; + x.chunk := s; + end; +end; + +procedure IncDec(var v, k: TItem; dec: boolean); +var n: longint; +begin + Coerce(k, v.typ); + Value(k); + MovRR(RCX, RAX); + Address(v, RDX); + n := ScalarSize(v.typ); + Load(RAX, Mem(RDX, 0), n, v.typ^.signed); + if dec then Alu(aluSub, RAX, RCX) else Alu(aluAdd, RAX, RCX); + Store(Mem(RDX, 0), RAX, n); +end; + +{ An error is the address of its length, followed by its message. } +function ErrorChunk(var x: TItem; module, name: longint): longint; +var c: longint; p: PBytes; +begin + if x.mode <> mStr then Mark('an error is made from a string'); + p := GetMem(x.val + 8); + PInt64(p)^ := x.val; + Move(rodata^[chunks^[x.chunk].start], p^[8], x.val); + c := NewChunk(secRodata, module, name); + SetData(c, p, x.val + 8, 8); + FreeMem(p); + ErrorChunk := c; +end; + +procedure Msg(var x: TItem); +var L: longint; s: int64; +begin + Coerce(x, tError); + Value(x); + s := AllocTemp(16, 8); + MovRI(RCX, 0); + L := NoLabel; + TestRR(RAX, RAX); + Jcc(ccE, L); + Load(RCX, Mem(RAX, 0), 8, false); + Lea(RAX, Mem(RAX, 8)); + FixLink(L); + Store(Mem(RBP, s), RAX, 8); + Store(Mem(RBP, s + 8), RCX, 8); + TempItem(x, tBytes, s); end; procedure ReturnNone; diff --git a/src/parse.pas b/src/parse.pas index d452264..19bb4ec 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -11,7 +11,7 @@ are read for their declarations only, and must export the same interface. - Depends on: scan, tok, x64, gen. + Depends on: scan, sym, x64, gen. Leaves out (for later stages): multiple results, errors, enumerations and sets, record literals, defer, NEW, generic modules, extern. } @@ -234,6 +234,33 @@ VariantType := t; end; +{ Several results: a record of them, laid out as C would, and + returned through a hidden pointer. } +function Results: PType; +var t, ft: PType; f, last: PObj; off: int64; +begin + Next; + t := NewType(fRecord, 0, 1); + t^.tuple := true; + off := 0; last := nil; + repeat + ft := ParseType; + off := AlignUp(off, ft^.align); + f := NewObj(oField, -1, ft); + f^.val := off; + off := off + ft^.size; + if ft^.align > t^.align then t^.align := ft^.align; + if last = nil then t^.fields := f else last^.next := f; + last := f; + inc(t^.len); + if tok <> sComma then break; + Next; + until false; + Expect(sRparen, ')'); + t^.size := AlignUp(off, t^.align); + if t^.len = 1 then Results := t^.fields^.typ else Results := t; +end; + function Signature: PType; var t, pt: PType; p, first, last: PObj; isVar: boolean; n: longint; @@ -274,8 +301,7 @@ t^.len := n; if tok = sColon then begin Next; - if tok = sLparen then Mark('several results come in stage 2'); - t^.base := ParseType; + if tok = sLparen then t^.base := Results else t^.base := ParseType; end; Signature := t; end; @@ -450,7 +476,21 @@ x.mode := mReg; end; bCas, bXchg, bXadd: Atomic(x, which); - bNew, bMsg: Mark('NEW and MSG come in stage 2'); + bMsg: begin Expression(x, tError); Msg(x) end; + bInc, bDec: begin + Expression(x, nil); + if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fInt) then + Mark('INC and DEC need an integer variable'); + Save(x); + if tok = sComma then begin + Next; + Expression(y, x.typ); + end else MakeConst(y, x.typ, 1); + IncDec(x, y, which = bDec); + MakeConst(x, tNone, 0); + x.mode := mNone; + end; + bNew: Mark('NEW comes in step 9'); end; Expect(sRparen, ')'); end; @@ -600,6 +640,7 @@ sIdent: begin Designator(x, called); if x.mode = mNone then Mark('this procedure returns nothing'); + if x.typ^.tuple then Mark('several results go only to a, b := ...'); end; sLparen: begin Next; Expression(x, want); Expect(sRparen, ')') end; sNot: begin Next; Factor(x, nil); NotOp(x) end; @@ -853,6 +894,47 @@ FixLink(endL); end; +{ a, b := f(x): the variables first, left to right, then the call; + then each result to its variable, in order. } +procedure MultiAssign(var x: TItem); +var d: array[0..15] of TItem; y, z: TItem; n, i: longint; called: boolean; f: PObj; +begin + n := 0; + d[0] := x; + repeat + if (d[n].mode <> mVar) or not d[n].isVar then Mark('can''t assign to this'); + Pin(d[n]); + inc(n); + if tok <> sComma then break; + if n > High(d) then Mark('too many variables'); + Next; + Designator(d[n], called); + until false; + Expect(sBecomes, ':='); + Designator(y, called); + if not called or not y.typ^.tuple or (y.typ^.len <> n) then + Mark('needs a call with as many results as variables'); + f := y.typ^.fields; + for i := 0 to n - 1 do begin + z := y; + Field(z, f); + Assign(d[i], z); + f := f^.next; + end; +end; + +procedure ReturnResults; +var f: PObj; x: TItem; +begin + f := curResult^.fields; + while f <> nil do begin + Expression(x, f^.typ); + ReturnField(f, x); + f := f^.next; + if f <> nil then Expect(sComma, ','); + end; +end; + procedure Statement; var x, y: TItem; called: boolean; m: int64; c: TCall; begin @@ -867,7 +949,7 @@ Expression(y, x.typ); Assign(x, y); end else if tok = sComma then - Mark('several results come in stage 2') + MultiAssign(x) else if not called then begin if (x.mode = mProc) or ((x.mode in [mVar, mReg]) and (x.typ^.form = fProc)) then begin BeginCall(c, x); @@ -884,8 +966,12 @@ Next; if tok = sSemicolon then ReturnNone else begin - Expression(x, curResult); - ReturnValue(x); + if (curResult <> nil) and curResult^.tuple then ReturnResults + else begin + Expression(x, curResult); + ReturnValue(x); + end; + ReturnJump; end; end; sBreak: begin @@ -977,7 +1063,14 @@ q := q^.next; end; if (ni > 6) or (nf > 8) or sig^.variadic then Mark('too many parameters for a code procedure'); - if (sig^.base <> nil) and not IsScalar(sig^.base) then Mark('a code procedure returns a single value'); + if sig^.base <> nil then + if sig^.base^.tuple then begin + q := sig^.base^.fields; + if (sig^.base^.len <> 2) or (q^.typ^.size <> 8) or (q^.next^.typ^.size <> 8) + or not IsScalar(q^.typ) or not IsScalar(q^.next^.typ) + or (q^.typ^.form = fReal) or (q^.next^.typ^.form = fReal) then + Mark('a code procedure returns two results only in rax and rdx'); + end else if not IsScalar(sig^.base) then Mark('a code procedure returns a single value'); BeginChunk(p^.chunk); repeat v := ConstExpr; @@ -1039,12 +1132,20 @@ Next; while tok = sIdent do begin IdentDef(n, exp); - if tok = sColon then Mark('errors come in stage 2'); + t := nil; + if tok = sColon then begin + Next; + t := ParseType; + if t <> tError then Mark('only an ERROR constant has a type'); + end; Expect(sEql, '='); Expression(x, nil); o := NewObj(oConst, n, x.typ); o^.exported := exp and top; - if x.mode = mStr then begin o^.val := x.val; o^.chunk := x.chunk end + if t = tError then begin + o^.typ := tError; + o^.val := ErrorChunk(x, curModule^.name, n) + 1; + end else if x.mode = mStr then begin o^.val := x.val; o^.chunk := x.chunk end else o^.val := ConstValue(x); Declare(o); Expect(sSemicolon, ';'); diff --git a/src/sym.pas b/src/sym.pas index e7d044c..473113e 100644 --- a/src/sym.pas +++ b/src/sym.pas @@ -39,6 +39,7 @@ vol: boolean; { fPtr: ^VOLATILE } packd: boolean; { fRecord } variadic: boolean; { fProc: ends in ... } + tuple: boolean; { fRecord: the results of a procedure that has several } base: PType; { fPtr, fArray, fSlice: what it holds; fProc: result } len: int64; { fArray: elements; fProc: parameters; fVariant: cases } fields: PObj; { fRecord: fields; fVariant: cases; fProc: parameters } @@ -91,12 +92,13 @@ { built-in procedures } bSize = 0; bAdr = 1; bLen = 2; bNew = 3; bMsg = 4; bSyscall = 5; bFence = 6; bCas = 7; bXchg = 8; bXadd = 9; bArgc = 10; bArgv = 11; + bInc = 12; bDec = 13; MaxDepth = 64; { scopes open at once } var tI8, tI16, tI32, tI64, tU8, tU16, tU32, tU64: PType; - tBool, tReal, tConst, tNil, tStr, tNone, tPtrU8: PType; + tBool, tReal, tError, tConst, tNil, tStr, tNone, tPtrU8, tBytes: PType; curModule: PModule; function NewType(form: TForm; size, align: int64): PType; @@ -312,7 +314,9 @@ fPtr: Alike := (a^.vol = b^.vol) and Same(a^.base, b^.base); fArray: Alike := (a^.len = b^.len) and Same(a^.base, b^.base); fSlice: Alike := Same(a^.base, b^.base); - fProc: begin + fProc, fRecord: begin + { a record is the same only as itself, but for several results } + if (a^.form = fRecord) and not (a^.tuple and b^.tuple) then exit(false); if (a^.len <> b^.len) or (a^.variadic <> b^.variadic) then exit(false); if (a^.base = nil) <> (b^.base = nil) then exit(false); if (a^.base <> nil) and not Same(a^.base, b^.base) then exit(false); @@ -448,6 +452,7 @@ tU64 := Basic('U64', fInt, 8, false); tBool := Basic('BOOL', fBool, 1, false); tReal := Basic('F64', fReal, 8, false); + tError := Basic('ERROR', fError, 8, false); tConst := NewType(fConst, 8, 8); tConst^.signed := true; tNil := NewType(fNil, 8, 8); @@ -455,6 +460,8 @@ tNone := NewType(fNone, 0, 1); tPtrU8 := NewType(fPtr, 8, 8); tPtrU8^.base := tU8; + tBytes := NewType(fSlice, 16, 8); + tBytes^.base := tU8; Enter('true', oConst, tBool, 1); Enter('false', oConst, tBool, 0); Enter('nil', oConst, tNil, 0); @@ -470,4 +477,6 @@ Enter('XADD', oBuiltin, nil, bXadd); Enter('ARGC', oBuiltin, nil, bArgc); Enter('ARGV', oBuiltin, nil, bArgv); + Enter('INC', oBuiltin, nil, bInc); + Enter('DEC', oBuiltin, nil, bDec); end. diff --git a/test/err/ErrOrder.err b/test/err/ErrOrder.err new file mode 100644 index 0000000..2913f0c --- /dev/null +++ b/test/err/ErrOrder.err @@ -0,0 +1 @@ +compare only with = and # diff --git a/test/err/ErrOrder.jed b/test/err/ErrOrder.jed new file mode 100644 index 0000000..f2fef84 --- /dev/null +++ b/test/err/ErrOrder.jed @@ -0,0 +1,7 @@ +module ErrOrder; +const A: ERROR = "a"; B: ERROR = "b"; +proc main*; +begin + if A < B then end; +end; +end ErrOrder. diff --git a/test/err/Tuple.err b/test/err/Tuple.err new file mode 100644 index 0000000..252c0bc --- /dev/null +++ b/test/err/Tuple.err @@ -0,0 +1 @@ +several results go only to a, b := ... diff --git a/test/err/Tuple.jed b/test/err/Tuple.jed new file mode 100644 index 0000000..2a077eb --- /dev/null +++ b/test/err/Tuple.jed @@ -0,0 +1,8 @@ +module Tuple; +proc two: (I64, I64); begin return 1, 2; end; +proc main*; +var a: I64; +begin + a := two() + 1; +end; +end Tuple. diff --git a/test/run/Results b/test/run/Results new file mode 100755 index 0000000..6ef27b5 Binary files /dev/null and b/test/run/Results differ diff --git a/test/run/Results.expect b/test/run/Results.expect new file mode 100644 index 0000000..3ad58e7 --- /dev/null +++ b/test/run/Results.expect @@ -0,0 +1,9 @@ +3 2 +2 nil +-1 not found is NotFound, not Other, not Empty +[] +30 two 2 ok +2 1 +39 +0 zero +14 6 0 diff --git a/test/run/Results.jed b/test/run/Results.jed new file mode 100644 index 0000000..ad3b514 --- /dev/null +++ b/test/run/Results.jed @@ -0,0 +1,79 @@ +module Results; +import Out; + +const + NotFound*: ERROR = "not found"; + Empty: ERROR = "empty"; + Other: ERROR = "not found"; + +type Pair = record a, b: I64; end; + +var table: [4]I64; g: Pair; + +proc divmod(a, b: I64): (I64, I64); +begin + return a div b, a mod b; +end; + +proc find(key: I64): (I64, ERROR); +var i: I64; +begin + for i := 0 to 3 do + if table[i] = key then return i, nil; end; + end; + return -1, NotFound; +end; + +proc mixed(x: F64): (F64, []U8, Pair, BOOL); +var p: Pair; +begin + p.a := 1; p.b := 2; + return x * 2.0, "two", p, true; +end; + +proc minmax(a, b: I64): (I64, I64); +code 48H, 89H, 0F8H, (* mov rax, rdi *) + 48H, 89H, 0F2H, (* mov rdx, rsi *) + 48H, 39H, 0F7H, (* cmp rdi, rsi *) + 7EH, 06H, (* jle +6 *) + 48H, 89H, 0F0H, (* mov rax, rsi *) + 48H, 89H, 0FAH, (* mov rdx, rdi *) + 0C3H; + +proc nothing: (I64, ERROR); +begin +end; + +proc main*; +var q, r, i: I64; e: ERROR; x: F64; s: []U8; p: Pair; ok: BOOL; a: [3]I64; u: U8; +begin + q, r := divmod(17, 5); + Out.int(q); Out.str(" "); Out.int(r); Out.ln; + table := [10, 20, 30, 40]; + i, e := find(30); + Out.int(i); if e = nil then Out.str(" nil"); end; Out.ln; + i, e := find(7); + Out.int(i); Out.str(" "); Out.str(MSG(e)); + if e = NotFound then Out.str(" is NotFound"); end; + if e # Other then Out.str(", not Other"); end; + if e # Empty then Out.str(", not Empty"); end; + Out.ln; + Out.str("["); Out.str(MSG(nil)); Out.str("]"); Out.ln; + x, s, p, ok := mixed(1.5); + Out.int(I64(x * 10.0)); Out.str(" "); Out.str(s); Out.str(" "); Out.int(p.b); + if ok then Out.str(" ok"); end; Out.ln; + a[1], g.b := divmod(9, 4); + Out.int(a[1]); Out.str(" "); Out.int(g.b); Out.ln; + q, r := minmax(9, 3); + Out.int(q); Out.int(r); Out.ln; + divmod(1, 1); + i, e := nothing(); + Out.int(i); if e = nil then Out.str(" zero"); end; Out.ln; + i := 5; + INC(i); INC(i, 10); DEC(i, 2); + a[2] := 7; DEC(a[2]); + u := 255; INC(u); + Out.int(i); Out.str(" "); Out.int(a[2]); Out.str(" "); Out.int(I64(u)); Out.ln; +end; + +end Results.