From bc1240a7e4b9df25f0400f0a175ed3ae7b3cd25e Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sat, 10 Oct 2026 04:28:48 +0000 Subject: [PATCH] Step 6: first library, examples, check and bench lib/Rt.jed (fail, eq), lib/Sys.linux-x86_64.jed (write, exit) and lib/Out.jed. Examples: hello, args, variants and slices, volatile, a code procedure. test/run holds programs with their expected output and status, test/err programs that must not compile and what they must say. make check runs them all; make bench times the compiler on a generated program of 348,000 lines and fails below 400,000 lines a second; make loc counts the compiler's lines. --- diff --git a/Makefile b/Makefile index e8f1b11..ce34c34 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ FPCFLAGS = -O2 -Mobjfpc -Sh- -vew -FUbuild jed: src/*.pas | build - $(FPC) $(FPCFLAGS) -ojed src/jed.pas + $(FPC) $(FPCFLAGS) -FE. -ojed src/jed.pas units: src/*.pas | build for u in scan sym x64 link elf; do $(FPC) $(FPCFLAGS) src/$$u.pas || exit 1; done @@ -22,5 +22,23 @@ clean: rm -rf build jed + +# every example and test, against what it should print +check: jed + test/check.sh -.PHONY: units tests clean +# the compiler's speed, on a generated program of about 350,000 lines; +# fails below 400,000 lines a second +bench: jed | build + python3 test/genbench.py 12000 > build/Bench.jed + @lines=$$(wc -l < build/Bench.jed); \ + start=$$(date +%s%N); ./jed build/Bench.jed || exit 1; end=$$(date +%s%N); \ + rate=$$((lines * 1000000000 / (end - start))); \ + echo "$$lines lines in $$(((end - start) / 1000000)) ms: $$rate lines a second"; \ + test $$rate -ge 400000 + +# lines of the compiler: all of them, and those that aren't blank or comments +loc: + @python3 test/loc.py src/*.pas + +.PHONY: units tests check bench loc clean diff --git a/examples/Args b/examples/Args new file mode 100755 index 0000000..be0857c Binary files /dev/null and b/examples/Args differ diff --git a/examples/Args.args b/examples/Args.args new file mode 100644 index 0000000..89596af --- /dev/null +++ b/examples/Args.args @@ -0,0 +1,2 @@ +one +two words diff --git a/examples/Args.expect b/examples/Args.expect new file mode 100644 index 0000000..89596af --- /dev/null +++ b/examples/Args.expect @@ -0,0 +1,2 @@ +one +two words diff --git a/examples/Args.jed b/examples/Args.jed new file mode 100644 index 0000000..e79fb27 --- /dev/null +++ b/examples/Args.jed @@ -0,0 +1,25 @@ +(* Prints its arguments, one per line, and exits with how many. *) +module Args; +import Out; + +(* The length of a C string. *) +proc len(s: ^U8): I64; +var n: I64; +begin + n := 0; + while s[n] # 0 do n := n + 1; end; + return n; +end; + +proc main*: I64; +var i: I64; s: ^U8; +begin + for i := 1 to ARGC() - 1 do + s := ARGV()[i]; + Out.str(s[0..len(s)]); + Out.ln; + end; + return ARGC() - 1; +end; + +end Args. diff --git a/examples/Args.status b/examples/Args.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/examples/Args.status @@ -0,0 +1 @@ +2 diff --git a/examples/Cpu b/examples/Cpu new file mode 100755 index 0000000..1b36c19 Binary files /dev/null and b/examples/Cpu differ diff --git a/examples/Cpu.expect b/examples/Cpu.expect new file mode 100644 index 0000000..9bdbe6e --- /dev/null +++ b/examples/Cpu.expect @@ -0,0 +1 @@ +vendor is printable diff --git a/examples/Cpu.jed b/examples/Cpu.jed new file mode 100644 index 0000000..60b5538 --- /dev/null +++ b/examples/Cpu.jed @@ -0,0 +1,29 @@ +(* A code procedure: machine code written as bytes, called like any + other procedure. cpuid's vendor string, from leaf 0. *) +module Cpu; +import Out; + +(* cpuid leaf 0: puts the 12 bytes of the vendor in buf, rdi. *) +proc vendor(buf: ^U8); +code 53H, (* push rbx *) + 49H, 89H, 0F8H, (* mov r8, rdi *) + 31H, 0C0H, (* xor eax, eax *) + 0FH, 0A2H, (* cpuid *) + 41H, 89H, 18H, (* mov [r8], ebx *) + 41H, 89H, 50H, 04H, (* mov [r8+4], edx *) + 41H, 89H, 48H, 08H, (* mov [r8+8], ecx *) + 5BH, (* pop rbx *) + 0C3H; (* ret *) + +proc main*; +var buf: [12]U8; i: I64; ok: BOOL; +begin + vendor(ADR(buf[0])); + ok := true; + for i := 0 to 11 do + if (buf[i] < ' ') or (buf[i] > '~') then ok := false; end; + end; + if ok then Out.str("vendor is printable\n"); end; +end; + +end Cpu. diff --git a/examples/Hello b/examples/Hello new file mode 100755 index 0000000..e145faf Binary files /dev/null and b/examples/Hello differ diff --git a/examples/Hello.expect b/examples/Hello.expect new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/examples/Hello.expect @@ -0,0 +1 @@ +hello, world diff --git a/examples/Hello.jed b/examples/Hello.jed new file mode 100644 index 0000000..dede538 --- /dev/null +++ b/examples/Hello.jed @@ -0,0 +1,9 @@ +module Hello; +import Out; + +proc main*; +begin + Out.str("hello, world\n"); +end; + +end Hello. diff --git a/examples/Shapes b/examples/Shapes new file mode 100755 index 0000000..4848316 Binary files /dev/null and b/examples/Shapes differ diff --git a/examples/Shapes.expect b/examples/Shapes.expect new file mode 100644 index 0000000..1f18ec1 --- /dev/null +++ b/examples/Shapes.expect @@ -0,0 +1,3 @@ +all: 334 +last two: 2 +none: 0 diff --git a/examples/Shapes.jed b/examples/Shapes.jed new file mode 100644 index 0000000..d5e95da --- /dev/null +++ b/examples/Shapes.jed @@ -0,0 +1,39 @@ +(* Variants and slices: a list of shapes, measured. *) +module Shapes; +import Out; + +type + Shape = variant + circle(r: I64); + rect(w, h: I64); + dot; + end; + +(* Twice the area, rounded down, of a circle taken as pi = 22/7. *) +proc area(s: Shape): I64; +begin + match s of + | circle(r): return 44 * r * r div 7; + | rect(w, h): return 2 * w * h; + | dot: return 0; + end; +end; + +proc total(shapes: []Shape): I64; +var i, sum: I64; +begin + sum := 0; + for i := 0 to LEN(shapes) - 1 do sum := sum + area(shapes[i]); end; + return sum; +end; + +proc main*; +var shapes: [4]Shape; +begin + shapes := [circle(7), rect(3, 4), dot, rect(1, 1)]; + Out.str("all: "); Out.int(total(shapes)); Out.ln; + Out.str("last two: "); Out.int(total(shapes[2..4])); Out.ln; + Out.str("none: "); Out.int(total(shapes[0..0])); Out.ln; +end; + +end Shapes. diff --git a/examples/Volatile b/examples/Volatile new file mode 100755 index 0000000..a2b6f73 Binary files /dev/null and b/examples/Volatile differ diff --git a/examples/Volatile.expect b/examples/Volatile.expect new file mode 100644 index 0000000..e291ddb --- /dev/null +++ b/examples/Volatile.expect @@ -0,0 +1,2 @@ +abc +1 255 diff --git a/examples/Volatile.jed b/examples/Volatile.jed new file mode 100644 index 0000000..fe0bc9f --- /dev/null +++ b/examples/Volatile.jed @@ -0,0 +1,32 @@ +(* A record laid over memory that something else may change: here a + page of the program's own, as a device's registers would be. Every + access through the ^VOLATILE pointer is one instruction of its + size, in the order written. *) +module Volatile; +import Out; + +type + Uart = record + data: U32; + status: U32; + control: U8; + end; + +var page: [64]U8; + +proc main*; +var dev: ^VOLATILE Uart; i: I64; +begin + dev := ^VOLATILE Uart(ADR(page)); + dev^.control := 1; + dev^.status := 0FFH; + for i := 0 to 2 do + dev^.data := U32('a' + i); + Out.char(U8(dev^.data)); + end; + Out.ln; + FENCE; + Out.int(I64(page[8])); Out.str(" "); Out.int(I64(dev^.status)); Out.ln; +end; + +end Volatile. diff --git a/lib/Out.jed b/lib/Out.jed new file mode 100644 index 0000000..ef6a43f --- /dev/null +++ b/lib/Out.jed @@ -0,0 +1,57 @@ +(* Writing text and numbers to standard output. Nothing is buffered: + each call is one write. *) +module Out; +import Sys; + +proc str*(s: []U8); +begin + Sys.write(Sys.stdout, s); +end; + +proc char*(c: U8); +var b: [1]U8; +begin + b[0] := c; + Sys.write(Sys.stdout, b); +end; + +proc ln*; +begin + str("\n"); +end; + +(* n in decimal *) +proc int*(n: I64); +var buf: [20]U8; i: I64; u: U64; +begin + u := U64(n); + if n < 0 then u := 0 - u; end; + i := 20; + repeat + i := i - 1; + buf[i] := U8(u mod 10) + '0'; + u := u div 10; + until u = 0; + if n < 0 then + i := i - 1; + buf[i] := '-'; + end; + str(buf[i..20]); +end; + +(* n in hexadecimal, digits digits at least *) +proc hex*(n: U64; digits: I64); +var buf: [16]U8; i: I64; d: U8; +begin + i := 16; + repeat + i := i - 1; + d := U8(n and 15); + if d < 10 then buf[i] := d + '0'; else buf[i] := d - 10 + 'A'; end; + n := n shr 4; + digits := digits - 1; + until (n = 0) and (digits <= 0) or (i = 0); + str(buf[i..16]); +end; + +end Out. diff --git a/lib/Rt.jed b/lib/Rt.jed new file mode 100644 index 0000000..232b411 --- /dev/null +++ b/lib/Rt.jed @@ -0,0 +1,37 @@ +(* What the compiler's code calls: fail when a check fails, eq when = + or # compares two strings. The compiler finds them by these names. *) +module Rt; +import Sys; + +(* A check failed at line of file: says so on standard error and stops + the program with status 2. *) +proc fail*(file: ^U8; line: I64); +var buf: [20]U8; i, n: I64; +begin + n := 0; + while file[n] # 0 do n := n + 1; end; + Sys.write(Sys.stderr, file[0..n]); + i := 20; + repeat + i := i - 1; + buf[i] := U8(line mod 10) + '0'; + line := line div 10; + until line = 0; + i := i - 1; + buf[i] := ':'; + Sys.write(Sys.stderr, buf[i..20]); + Sys.write(Sys.stderr, ": index out of range\n"); + Sys.exit(2); +end; + +proc eq*(a, b: []U8): BOOL; +var i: I64; +begin + if LEN(a) # LEN(b) then return false; end; + for i := 0 to LEN(a) - 1 do + if a[i] # b[i] then return false; end; + end; + return true; +end; + +end Rt. diff --git a/lib/Sys.linux-x86_64.jed b/lib/Sys.linux-x86_64.jed new file mode 100644 index 0000000..367e730 --- /dev/null +++ b/lib/Sys.linux-x86_64.jed @@ -0,0 +1,24 @@ +(* System calls on Linux for x86-64. Other targets supply their own + Sys, with the same exports. *) +module Sys; + +const + stdin* = 0; + stdout* = 1; + stderr* = 2; + +(* Writes s to the file descriptor fd; the number of bytes written, or + minus an errno. *) +proc write*(fd: I64; s: []U8): I64; +begin + if LEN(s) = 0 then return 0; end; + return SYSCALL(1, fd, ADR(s[0]), LEN(s)); +end; + +(* Ends the program, at once, with status. *) +proc exit*(status: I64); +begin + SYSCALL(231, status); +end; + +end Sys. diff --git a/test/check.sh b/test/check.sh new file mode 100755 index 0000000..4a90396 --- /dev/null +++ b/test/check.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# Compiles and runs every example and test, and compares what each +# prints, and its exit status, with what is expected: +# X.jed the program +# X.expect its standard output +# X.args its arguments, one per line (optional) +# X.status its exit status (optional; 0 if missing) +# Programs in test/err must not compile, and must print X.err. + +jed=./jed +out=build/check +mkdir -p $out +pass=0 +fail=0 + +run() { # run dir name + dir=$1; name=$2 + if ! $jed -I $dir/mods -o $out/$name $dir/$name.jed 2>$out/$name.cerr; then + echo "FAIL $dir/$name: doesn't compile: $(cat $out/$name.cerr)" + fail=$((fail + 1)); return + fi + set -- + if [ -f $dir/$name.args ]; then + while IFS= read -r a; do set -- "$@" "$a"; done < $dir/$name.args + fi + $out/$name "$@" > $out/$name.out 2>/dev/null + status=$? + want=0 + [ -f $dir/$name.status ] && want=$(cat $dir/$name.status) + if ! cmp -s $out/$name.out $dir/$name.expect; then + echo "FAIL $dir/$name: output differs" + diff $out/$name.out $dir/$name.expect | head -5 + fail=$((fail + 1)) + elif [ $status != $want ]; then + echo "FAIL $dir/$name: status $status, not $want" + fail=$((fail + 1)) + else + pass=$((pass + 1)) + fi +} + +for f in examples/*.jed test/run/*.jed; do + run $(dirname $f) $(basename $f .jed) +done +for f in test/err/*.jed; do + name=$(basename $f .jed) + if $jed -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then + echo "FAIL $f: compiles" + fail=$((fail + 1)) + elif ! grep -qF "$(cat test/err/$name.err)" $out/$name.cerr; then + echo "FAIL $f: says $(cat $out/$name.cerr)" + fail=$((fail + 1)) + else + pass=$((pass + 1)) + fi +done +echo "$pass passed, $fail failed" +[ $fail = 0 ] diff --git a/test/err/Assign.err b/test/err/Assign.err new file mode 100644 index 0000000..138914e --- /dev/null +++ b/test/err/Assign.err @@ -0,0 +1 @@ +can't use I32 as I64 diff --git a/test/err/Assign.jed b/test/err/Assign.jed new file mode 100644 index 0000000..1265423 --- /dev/null +++ b/test/err/Assign.jed @@ -0,0 +1,7 @@ +module Assign; +proc main*; +var a: I64; b: I32; +begin + a := b; +end; +end Assign. diff --git a/test/err/Break.err b/test/err/Break.err new file mode 100644 index 0000000..fa5a823 --- /dev/null +++ b/test/err/Break.err @@ -0,0 +1 @@ +break outside a loop diff --git a/test/err/Break.jed b/test/err/Break.jed new file mode 100644 index 0000000..b7e0697 --- /dev/null +++ b/test/err/Break.jed @@ -0,0 +1,6 @@ +module Break; +proc main*; +begin + break; +end; +end Break. diff --git a/test/err/Cycle.err b/test/err/Cycle.err new file mode 100644 index 0000000..b81dc1f --- /dev/null +++ b/test/err/Cycle.err @@ -0,0 +1 @@ +Cycle imports itself diff --git a/test/err/Cycle.jed b/test/err/Cycle.jed new file mode 100644 index 0000000..b8be661 --- /dev/null +++ b/test/err/Cycle.jed @@ -0,0 +1,3 @@ +module Cycle; +import CycleB; +end Cycle. diff --git a/test/err/Field.err b/test/err/Field.err new file mode 100644 index 0000000..81be2a4 --- /dev/null +++ b/test/err/Field.err @@ -0,0 +1 @@ +field extra isn't exported diff --git a/test/err/Field.jed b/test/err/Field.jed new file mode 100644 index 0000000..41c9cf9 --- /dev/null +++ b/test/err/Field.jed @@ -0,0 +1,8 @@ +module Field; +import Plat; +proc main*; +var i: Plat.Info; +begin + i.extra := 1; +end; +end Field. diff --git a/test/err/Match.err b/test/err/Match.err new file mode 100644 index 0000000..f32c48a --- /dev/null +++ b/test/err/Match.err @@ -0,0 +1 @@ +no arm for c diff --git a/test/err/Match.jed b/test/err/Match.jed new file mode 100644 index 0000000..f61cc23 --- /dev/null +++ b/test/err/Match.jed @@ -0,0 +1,11 @@ +module Match; +type S = variant a; b; c; end; +proc main*; +var s: S; +begin + match s of + | a: s := b; + | b: + end; +end; +end Match. diff --git a/test/err/UsesExtra.err b/test/err/UsesExtra.err new file mode 100644 index 0000000..0fffaad --- /dev/null +++ b/test/err/UsesExtra.err @@ -0,0 +1 @@ +more isn't exported by diff --git a/test/err/UsesExtra.jed b/test/err/UsesExtra.jed new file mode 100644 index 0000000..d6482c5 --- /dev/null +++ b/test/err/UsesExtra.jed @@ -0,0 +1,3 @@ +module UsesExtra; +import Extra; +end UsesExtra. diff --git a/test/err/UsesIface.err b/test/err/UsesIface.err new file mode 100644 index 0000000..772b8ad --- /dev/null +++ b/test/err/UsesIface.err @@ -0,0 +1 @@ +f isn't exported as in diff --git a/test/err/UsesIface.jed b/test/err/UsesIface.jed new file mode 100644 index 0000000..9dd29d0 --- /dev/null +++ b/test/err/UsesIface.jed @@ -0,0 +1,3 @@ +module UsesIface; +import Iface; +end UsesIface. diff --git a/test/err/UsesRec.err b/test/err/UsesRec.err new file mode 100644 index 0000000..d7a8520 --- /dev/null +++ b/test/err/UsesRec.err @@ -0,0 +1 @@ +R isn't exported as in diff --git a/test/err/UsesRec.jed b/test/err/UsesRec.jed new file mode 100644 index 0000000..d446004 --- /dev/null +++ b/test/err/UsesRec.jed @@ -0,0 +1,3 @@ +module UsesRec; +import Rec; +end UsesRec. diff --git a/test/err/Utf.err b/test/err/Utf.err new file mode 100644 index 0000000..a24bb48 --- /dev/null +++ b/test/err/Utf.err @@ -0,0 +1 @@ +Utf.jed:2:5: text outside strings, characters and comments must be ASCII diff --git a/test/err/Utf.jed b/test/err/Utf.jed new file mode 100644 index 0000000..c604f87 --- /dev/null +++ b/test/err/Utf.jed @@ -0,0 +1,3 @@ +module Utf; +var é: I64; +end Utf. diff --git a/test/err/Volatile.err b/test/err/Volatile.err new file mode 100644 index 0000000..ed941bc --- /dev/null +++ b/test/err/Volatile.err @@ -0,0 +1 @@ +can't use ^VOLATILE I64 as ^I64 diff --git a/test/err/Volatile.jed b/test/err/Volatile.jed new file mode 100644 index 0000000..f57aa24 --- /dev/null +++ b/test/err/Volatile.jed @@ -0,0 +1,8 @@ +module Volatile; +proc main*; +var x: I64; p: ^VOLATILE I64; q: ^I64; +begin + p := ADR(x); + q := p; +end; +end Volatile. diff --git a/test/err/mods/Cycle.jed b/test/err/mods/Cycle.jed new file mode 100644 index 0000000..b8be661 --- /dev/null +++ b/test/err/mods/Cycle.jed @@ -0,0 +1,3 @@ +module Cycle; +import CycleB; +end Cycle. diff --git a/test/err/mods/CycleB.jed b/test/err/mods/CycleB.jed new file mode 100644 index 0000000..1e365e8 --- /dev/null +++ b/test/err/mods/CycleB.jed @@ -0,0 +1,3 @@ +module CycleB; +import Cycle; +end CycleB. diff --git a/test/err/mods/Extra.jed b/test/err/mods/Extra.jed new file mode 100644 index 0000000..218c10e --- /dev/null +++ b/test/err/mods/Extra.jed @@ -0,0 +1,4 @@ +module Extra; +type R* = record a*: I64; secret: [4]I64; end; +const more* = 1; +end Extra. diff --git a/test/err/mods/Extra.linux.jed b/test/err/mods/Extra.linux.jed new file mode 100644 index 0000000..fa80151 --- /dev/null +++ b/test/err/mods/Extra.linux.jed @@ -0,0 +1,3 @@ +module Extra; +type R* = record a*: I64; hidden: U8; end; +end Extra. diff --git a/test/err/mods/Iface.jed b/test/err/mods/Iface.jed new file mode 100644 index 0000000..7ecbea9 --- /dev/null +++ b/test/err/mods/Iface.jed @@ -0,0 +1,3 @@ +module Iface; +proc f*(x: I32): I64; begin return 0; end; +end Iface. diff --git a/test/err/mods/Iface.linux-x86_64.jed b/test/err/mods/Iface.linux-x86_64.jed new file mode 100644 index 0000000..52d7f0c --- /dev/null +++ b/test/err/mods/Iface.linux-x86_64.jed @@ -0,0 +1,3 @@ +module Iface; +proc f*(x: I64): I64; begin return x; end; +end Iface. diff --git a/test/err/mods/Rec.jed b/test/err/mods/Rec.jed new file mode 100644 index 0000000..3fa6ee9 --- /dev/null +++ b/test/err/mods/Rec.jed @@ -0,0 +1,4 @@ +module Rec; +type R* = record a*: I32; end; +proc f*(r: ^R); begin end; +end Rec. diff --git a/test/err/mods/Rec.linux-x86_64.jed b/test/err/mods/Rec.linux-x86_64.jed new file mode 100644 index 0000000..63611c0 --- /dev/null +++ b/test/err/mods/Rec.linux-x86_64.jed @@ -0,0 +1,4 @@ +module Rec; +type R* = record a*: I64; b: I64; end; +proc f*(r: ^R); begin end; +end Rec. diff --git a/test/genbench.py b/test/genbench.py new file mode 100644 index 0000000..6794ea7 --- /dev/null +++ b/test/genbench.py @@ -0,0 +1,61 @@ +"""Writes a large jed program to standard output, for timing the +compiler: n procedures of loops, conditions, records, slices and calls, +each calling the one before, so that none is left out.""" +import sys + +n = int(sys.argv[1]) +print("""module Bench; +import Out; + +type + Pair = record x, y: I64; end; + Shape = variant circle(r: I64); rect(w, h: I64); dot; end; + +var + g: [16]I64; + data: [64]I64; +""") +print("""proc p0(a, b: I64; s: []I64): I64; +begin + return a + b; +end; +""") +for i in range(1, n + 1): + print(f"""(* procedure {i} *) +proc p{i}(a, b: I64; s: []I64): I64; +var i, t: I64; r: Pair; sh: Shape; +begin + t := 0; + for i := 0 to LEN(s) - 1 do + if s[i] > a then + t := t + s[i] * b; + elsif s[i] = b then + t := t - 1; + else + t := t xor i; + end; + end; + r.x := t; + r.y := a + b * {i}; + while r.x > 100 do + r.x := r.x div 2; + end; + sh := rect(r.x, r.y); + match sh of + | circle(c): t := t + c; + | rect(w, h): t := t + w * h; + | dot: t := t - 1; + end; + g[a and 15] := r.x + r.y; + return p{i - 1}(t and 1023, b, s[0..LEN(s) div 2]) + r.x; +end; +""") +print(f"""proc main*; +var i: I64; +begin + for i := 0 to 63 do data[i] := i; end; + Out.int(p{n}(1, 2, data[0..4])); + Out.ln; +end; + +end Bench.""") diff --git a/test/loc.py b/test/loc.py new file mode 100644 index 0000000..c9a4cd0 --- /dev/null +++ b/test/loc.py @@ -0,0 +1,14 @@ +"""Counts the lines of the compiler's units: all of them, and the lines +of code, those that are neither blank nor only comment.""" +import re, sys + +total = code = 0 +for path in sys.argv[1:]: + text = open(path).read() + bare = re.sub(r"\{[^}]*\}|\(\*.*?\*\)", "", text, flags=re.S) + n = text.count("\n") + c = sum(1 for line in bare.split("\n") if line.strip()) + print(f"{path:18} {n:6} {c:6}") + total += n + code += c +print(f"{'total':18} {total:6} {code:6}") diff --git a/test/run/Args b/test/run/Args new file mode 100755 index 0000000..463029e Binary files /dev/null and b/test/run/Args differ diff --git a/test/run/Args.args b/test/run/Args.args new file mode 100644 index 0000000..447475b --- /dev/null +++ b/test/run/Args.args @@ -0,0 +1,3 @@ +one +two words +é diff --git a/test/run/Args.expect b/test/run/Args.expect new file mode 100644 index 0000000..447475b --- /dev/null +++ b/test/run/Args.expect @@ -0,0 +1,3 @@ +one +two words +é diff --git a/test/run/Args.jed b/test/run/Args.jed new file mode 100644 index 0000000..f069599 --- /dev/null +++ b/test/run/Args.jed @@ -0,0 +1,18 @@ +module Args; +import Out; + +proc main*: I64; +var i, n: I64; a: ^^U8; s: ^U8; +begin + a := ARGV(); + for i := 1 to ARGC() - 1 do + s := a[i]; + n := 0; + while s[n] # 0 do n := n + 1; end; + Out.str(s[0..n]); + Out.ln; + end; + return ARGC(); +end; + +end Args. diff --git a/test/run/Args.status b/test/run/Args.status new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/test/run/Args.status @@ -0,0 +1 @@ +4 diff --git a/test/run/Arith b/test/run/Arith new file mode 100755 index 0000000..0cafe1b Binary files /dev/null and b/test/run/Arith differ diff --git a/test/run/Arith.expect b/test/run/Arith.expect new file mode 100644 index 0000000..078b550 --- /dev/null +++ b/test/run/Arith.expect @@ -0,0 +1,35 @@ +M 32 +add 22 +sub 12 +mul 85 +div -3 +mod -1 +divv -3 +modv -2 +prec 14 +neg -85 +u8wrap 44 +i8wrap -128 +u32wrap 1 +u64>i 1 +i64< 1 +shl 1024 +shr -4 +ushr 15 +and 8 +or 15 +xor 6 +not -1 +real 85 +trunc -2 +nan 0 +rlt 1 +u64real 18 +bool 1 +shortcut 1 +global 42 +char 65 +utf8 233 +hexconst 255 +cut 44 +sext -1 diff --git a/test/run/Arith.jed b/test/run/Arith.jed new file mode 100644 index 0000000..8fe90cb --- /dev/null +++ b/test/run/Arith.jed @@ -0,0 +1,74 @@ +module Arith; +import Out; + +const + K = 10; + M = K * 3 + 2; + Big = 0FFFFFFFFFFFFFFFFH; + +var g: I64; + +proc show(s: []U8; n: I64); +begin + Out.str(s); Out.str(" "); Out.int(n); Out.ln; +end; + +proc showb(s: []U8; t: BOOL); +begin + if t then show(s, 1); else show(s, 0); end; +end; + +proc main*; +var a, b: I64; u: U8; i8: I8; w: U32; x: U64; r: F64; t: BOOL; +begin + show("M", M); + a := 17; b := 5; + show("add", a + b); + show("sub", a - b); + show("mul", a * b); + show("div", -7 div 2); + show("mod", -7 mod 2); + show("divv", (0 - a) div b); + show("modv", (0 - a) mod b); + show("prec", 2 + 3 * 4); + show("neg", -a * b); + u := 200; + u := u + 100; + show("u8wrap", I64(u)); + i8 := 127; + i8 := i8 + 1; + show("i8wrap", I64(i8)); + w := 0FFFFFFFFH; + w := w + 2; + show("u32wrap", I64(w)); + x := Big; + showb("u64>i", x > 5); + showb("i64<", -1 < 5); + show("shl", 1 shl 10); + show("shr", -16 shr 2); + show("ushr", I64(U64(-16) shr 60)); + show("and", 12 and 10); + show("or", 12 or 3); + show("xor", 12 xor 10); + show("not", not 0); + r := F64(a) / 2.0; + show("real", I64(r * 10.0)); + r := -2.75; + show("trunc", I64(r)); + showb("nan", 0.0 / 0.0 = 0.0 / 0.0); + showb("rlt", 1.5 < 2.5); + show("u64real", I64(F64(x) / 1.0E18)); + t := (a > 3) and (b < 3); + if not t then show("bool", 1); end; + t := (a > 3) or (g div 0 = 1); + if t then show("shortcut", 1); end; + g := 42; + show("global", g); + show("char", 'A'); + show("utf8", 'é'); + show("hexconst", 0FFH); + show("cut", I64(U8(300))); + show("sext", I64(I8(U8(255)))); +end; + +end Arith. diff --git a/test/run/Atomic b/test/run/Atomic new file mode 100755 index 0000000..9ab1b44 Binary files /dev/null and b/test/run/Atomic differ diff --git a/test/run/Atomic.expect b/test/run/Atomic.expect new file mode 100644 index 0000000..20c8519 --- /dev/null +++ b/test/run/Atomic.expect @@ -0,0 +1,6 @@ +5 7 +cas1 cas2 100 +0 9 +321 +6 +100 diff --git a/test/run/Atomic.jed b/test/run/Atomic.jed new file mode 100644 index 0000000..290df92 --- /dev/null +++ b/test/run/Atomic.jed @@ -0,0 +1,35 @@ +module Atomic; +import Out; + +var counter: I64; flag: U64; p: ^I64; + +proc add3*(a, b, c: I64): I64; +code 48H, 8DH, 04H, 37H, (* lea rax, [rdi+rsi] *) + 48H, 01H, 0D0H, (* add rax, rdx *) + 0C3H; (* ret *) + +proc main*; +var old: I64; ok: BOOL; v: ^VOLATILE I64; x: I64; +begin + old := XADD(ADR(counter), 5); + old := XADD(ADR(counter), 2); + Out.int(old); Out.str(" "); Out.int(counter); Out.ln; + ok := CAS(ADR(counter), 7, 100); + if ok then Out.str("cas1 "); end; + ok := CAS(ADR(counter), 7, 200); + if not ok then Out.str("cas2 "); end; + Out.int(counter); Out.ln; + Out.int(I64(XCHG(ADR(flag), 9))); Out.str(" "); + Out.int(I64(XCHG(ADR(flag), 3))); Out.ln; + FENCE; + FENCE(); + Out.int(add3(1, 20, 300)); Out.ln; + v := ADR(x); + v^ := 5; + v^ := v^ + 1; + Out.int(x); Out.ln; + v := ^VOLATILE I64(ADR(counter)); + Out.int(v^); Out.ln; +end; + +end Atomic. diff --git a/test/run/Bodies b/test/run/Bodies new file mode 100755 index 0000000..c207da5 Binary files /dev/null and b/test/run/Bodies differ diff --git a/test/run/Bodies.expect b/test/run/Bodies.expect new file mode 100644 index 0000000..cc8be56 --- /dev/null +++ b/test/run/Bodies.expect @@ -0,0 +1 @@ +First Second Bodies main 12 diff --git a/test/run/Bodies.jed b/test/run/Bodies.jed new file mode 100644 index 0000000..aee922d --- /dev/null +++ b/test/run/Bodies.jed @@ -0,0 +1,11 @@ +module Bodies; +import Out, A := First, Second; + +proc main*; +begin + Out.str("main "); Out.int(A.count); Out.int(Second.count); Out.ln; +end; + +begin + Out.str("Bodies "); +end Bodies. diff --git a/test/run/Bounds b/test/run/Bounds new file mode 100755 index 0000000..745e85f Binary files /dev/null and b/test/run/Bounds differ diff --git a/test/run/Bounds.expect b/test/run/Bounds.expect new file mode 100644 index 0000000..6da806d --- /dev/null +++ b/test/run/Bounds.expect @@ -0,0 +1 @@ +0123 \ No newline at end of file diff --git a/test/run/Bounds.jed b/test/run/Bounds.jed new file mode 100644 index 0000000..86210e2 --- /dev/null +++ b/test/run/Bounds.jed @@ -0,0 +1,13 @@ +module Bounds; +import Out; + +proc main*; +var a: [4]I64; i: I64; +begin + for i := 0 to 4 do + a[i] := i; + Out.int(a[i]); + end; +end; + +end Bounds. diff --git a/test/run/Bounds.status b/test/run/Bounds.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/test/run/Bounds.status @@ -0,0 +1 @@ +2 diff --git a/test/run/Control b/test/run/Control new file mode 100755 index 0000000..043ef5c Binary files /dev/null and b/test/run/Control differ diff --git a/test/run/Control.expect b/test/run/Control.expect new file mode 100644 index 0000000..bc4340a --- /dev/null +++ b/test/run/Control.expect @@ -0,0 +1,8 @@ +12345 +10 7 4 1 +0 4 8 +6 +3 +0 1 10 11 20 21 +4 +one two three many diff --git a/test/run/Control.jed b/test/run/Control.jed new file mode 100644 index 0000000..314101b --- /dev/null +++ b/test/run/Control.jed @@ -0,0 +1,42 @@ +module Control; +import Out; + +proc main*; +var i, j, n: I64; u: U8; k: I8; +begin + for i := 1 to 5 do Out.int(i); end; Out.ln; + for i := 10 to 1 by -3 do Out.int(i); Out.str(" "); end; Out.ln; + for i := 0 to 10 by 4 do Out.int(i); Out.str(" "); end; Out.ln; + for i := 5 to 1 do Out.str("never"); end; + n := 0; + for u := 250 to 255 do n := n + 1; end; + Out.int(n); Out.ln; + n := 0; + for k := 120 to 127 by 3 do n := n + 1; end; + Out.int(n); Out.ln; + i := 0; + while i < 3 do + j := 0; + while true do + if j = 2 then break; end; + Out.int(i * 10 + j); Out.str(" "); + j := j + 1; + end; + i := i + 1; + end; + Out.ln; + i := 0; + repeat i := i + 1; if i = 4 then break; end; until i = 10; + Out.int(i); Out.ln; + for i := 1 to 4 do + if i = 1 then Out.str("one"); + elsif i = 2 then Out.str("two"); + elsif i = 3 then Out.str("three"); + else Out.str("many"); + end; + Out.str(" "); + end; + Out.ln; +end; + +end Control. diff --git a/test/run/Data b/test/run/Data new file mode 100755 index 0000000..6676530 Binary files /dev/null and b/test/run/Data differ diff --git a/test/run/Data.expect b/test/run/Data.expect new file mode 100644 index 0000000..b91c93e --- /dev/null +++ b/test/run/Data.expect @@ -0,0 +1,12 @@ +2 24 11 48 16 +120 7 +30 +23 10 +500 5 300 +4 200 500 +2 300 +200 +8 +3 4 +-2 65535 +16 diff --git a/test/run/Data.jed b/test/run/Data.jed new file mode 100644 index 0000000..2eb31b4 --- /dev/null +++ b/test/run/Data.jed @@ -0,0 +1,72 @@ +module Data; +import Out; + +type + Cell = record ch: U8; attr: U8; end; + Mixed = record a: U8; b: I64; c: U16; end; + Packed = packed record a: U8; b: I64; c: U16; end; + Node = record next: ^Node; val: I64; end; + Grid = [3][4]I32; + Pair = record x, y: I64; end; + +var + nodes: [5]Node; + grid: Grid; + gp: Pair; + +proc sum(p: ^Node): I64; +var s: I64; +begin + s := 0; + while p # nil do + s := s + p^.val; + p := p^.next; + end; + return s; +end; + +proc main*; +var + c: Cell; cells: [4]Cell; m: Mixed; i, j: I64; p, q: ^I64; arr: [8]I64; + s: []I64; pp: Pair; bp: ^U8; +begin + Out.int(SIZE(Cell)); Out.str(" "); + Out.int(SIZE(Mixed)); Out.str(" "); + Out.int(SIZE(Packed)); Out.str(" "); + Out.int(SIZE(Grid)); Out.str(" "); + Out.int(SIZE([]U8)); Out.ln; + c.ch := 'x'; c.attr := 7; + cells[2] := c; + Out.int(I64(cells[2].ch)); Out.str(" "); Out.int(I64(cells[2].attr)); Out.ln; + for i := 0 to 4 do + nodes[i].val := i * i; + if i < 4 then nodes[i].next := ADR(nodes[i + 1]); end; + end; + Out.int(sum(ADR(nodes[0]))); Out.ln; + for i := 0 to 2 do + for j := 0 to 3 do grid[i][j] := I32(i * 10 + j); end; + end; + Out.int(I64(grid[2][3])); Out.str(" "); Out.int(I64(grid[1][0])); Out.ln; + for i := 0 to 7 do arr[i] := i * 100; end; + p := ADR(arr[0]); + q := p + 5; + Out.int(q^); Out.str(" "); Out.int(q - p); Out.str(" "); Out.int(p[3]); Out.ln; + s := arr[2..6]; + Out.int(LEN(s)); Out.str(" "); Out.int(s[0]); Out.str(" "); Out.int(s[3]); Out.ln; + s := s[1..3]; + Out.int(LEN(s)); Out.str(" "); Out.int(s[0]); Out.ln; + s := p[1..3]; + Out.int(s[1]); Out.ln; + s := arr; + Out.int(LEN(s)); Out.ln; + pp.x := 3; pp.y := 4; + gp := pp; + pp.x := 99; + Out.int(gp.x); Out.str(" "); Out.int(gp.y); Out.ln; + m.a := 1; m.b := -2; m.c := 65535; + Out.int(m.b); Out.str(" "); Out.int(I64(m.c)); Out.ln; + bp := ^U8(ADR(m)); + Out.int(I64(ADR(m.c)) - I64(bp)); Out.ln; +end; + +end Data. diff --git a/test/run/Edge b/test/run/Edge new file mode 100755 index 0000000..bf29355 Binary files /dev/null and b/test/run/Edge differ diff --git a/test/run/Edge.expect b/test/run/Edge.expect new file mode 100644 index 0000000..f14b18d --- /dev/null +++ b/test/run/Edge.expect @@ -0,0 +1,7 @@ +22 +20 2 +123 item +100 -1 +1338 932 +44 5 +1112 diff --git a/test/run/Edge.jed b/test/run/Edge.jed new file mode 100644 index 0000000..6870a5e --- /dev/null +++ b/test/run/Edge.jed @@ -0,0 +1,64 @@ +module Edge; +import Out; + +type + Inner = record vals: [4]I64; name: []U8; end; + Outer = record items: [3]Inner; n: I64; end; + +var g: Outer; calls: I64; + +(* rsp mod 16 at the call, as the callee sees it after its return + address: always 8 when the caller keeps the stack aligned *) +proc rspmod: I64; +code 48H, 89H, 0E0H, (* mov rax, rsp *) + 48H, 83H, 0E0H, 0FH, (* and rax, 15 *) + 0C3H; + +proc next: I64; +begin + calls := calls + 1; + return calls; +end; + +proc setall(var o: Outer; v: I64); +var i, j: I64; +begin + for i := 0 to 2 do + for j := 0 to 3 do o.items[i].vals[j] := v + i * 10 + j; end; + o.items[i].name := "item"; + end; + o.n := 3; +end; + +proc sumInner(xs: []Inner): I64; +var i, j, s: I64; +begin + s := 0; + for i := 0 to LEN(xs) - 1 do + for j := 0 to 3 do s := s + xs[i].vals[j]; end; + end; + return s; +end; + +proc main*; +var a: [5]I64; i, r: I64; o: Outer; pa: ^[5]I64; +begin + r := rspmod() + (1 + (2 + (3 + rspmod()))); + Out.int(r); Out.ln; + a[next()] := next() * 10; + Out.int(a[1]); Out.str(" "); Out.int(calls); Out.ln; + setall(g, 100); + Out.int(g.items[2].vals[3]); Out.str(" "); Out.str(g.items[1].name); Out.ln; + o := g; + o.items[0].vals[0] := -1; + Out.int(g.items[0].vals[0]); Out.str(" "); Out.int(o.items[0].vals[0]); Out.ln; + Out.int(sumInner(g.items)); Out.str(" "); Out.int(sumInner(g.items[1..3])); Out.ln; + pa := ADR(a); + pa^[4] := 44; + Out.int(a[4]); Out.str(" "); Out.int(LEN(pa^)); Out.ln; + i := 2; + g.items[i].vals[i + 1] := g.items[i - 1].vals[i] + 1000; + Out.int(g.items[2].vals[3]); Out.ln; +end; + +end Edge. diff --git a/test/run/Procs b/test/run/Procs new file mode 100755 index 0000000..de6316a Binary files /dev/null and b/test/run/Procs differ diff --git a/test/run/Procs.expect b/test/run/Procs.expect new file mode 100644 index 0000000..f661697 --- /dev/null +++ b/test/run/Procs.expect @@ -0,0 +1,13 @@ +parity ok +21 +10 11 21 +22 +7 12 +same +nil +3245 +2432902008176640000 +95 5 +0 +16 0 +15 diff --git a/test/run/Procs.jed b/test/run/Procs.jed new file mode 100644 index 0000000..a5b8313 --- /dev/null +++ b/test/run/Procs.jed @@ -0,0 +1,117 @@ +module Procs; +import Out; + +type + Pair = record x, y: I64; end; + Op = proc(a, b: I64): I64; + Big = record a: [10]I64; end; + +proc even(n: I64): BOOL; forward; + +proc odd(n: I64): BOOL; +begin + if n = 0 then return false; end; + return even(n - 1); +end; + +proc even(n: I64): BOOL; +begin + if n = 0 then return true; end; + return odd(n - 1); +end; + +proc swap(var a, b: I64); +var t: I64; +begin + t := a; a := b; b := t; +end; + +proc bump(p: Pair): Pair; +begin + p.x := p.x + 1; + p.y := p.y + 1; + return p; +end; + +proc add(a, b: I64): I64; begin return a + b; end; +proc mul(a, b: I64): I64; begin return a * b; end; + +proc apply(f: Op; a, b: I64): I64; +begin + return f(a, b); +end; + +proc many(a, b, c, d, e, f, g, h: I64; x: F64; i: I64; y: F64): I64; +begin + return a + 2 * b + 3 * c + 4 * d + 5 * e + 6 * f + 7 * g + 8 * h + I64(x) * 100 + 9 * i + I64(y) * 1000; +end; + +proc fact(n: I64): I64; +begin + if n <= 1 then return 1; end; + return n * fact(n - 1); +end; + +proc fill(var b: Big; v: I64); +var i: I64; +begin + for i := 0 to 9 do b.a[i] := v + i; end; +end; + +proc total(b: Big): I64; +var i, s: I64; +begin + s := 0; + for i := 0 to 9 do s := s + b.a[i]; end; + b.a[0] := 1000; + return s; +end; + +proc noresult(n: I64): I64; +begin + if n > 100 then return 1; end; +end; + +proc mk(n: I64): Big; +var b: Big; +begin + fill(b, n); + return b; +end; + +proc mkzero(n: I64): Big; +begin +end; + +proc fsum(a, b: F64): F64; +begin + return a + b; +end; + +proc main*: I64; +var a, b: I64; p, q: Pair; f: Op; bg: Big; +begin + if even(10) and odd(7) and not even(3) then Out.str("parity ok"); Out.ln; end; + a := 1; b := 2; + swap(a, b); + Out.int(a); Out.int(b); Out.ln; + p.x := 10; p.y := 20; + q := bump(p); + Out.int(p.x); Out.str(" "); Out.int(q.x); Out.str(" "); Out.int(q.y); Out.ln; + Out.int(bump(bump(p)).y); Out.ln; + f := add; + Out.int(apply(f, 3, 4)); Out.str(" "); Out.int(apply(mul, 3, 4)); Out.ln; + if f = add then Out.str("same"); Out.ln; end; + f := nil; + if f = nil then Out.str("nil"); Out.ln; end; + Out.int(many(1, 1, 1, 1, 1, 1, 1, 1, 2.5, 1, 3.9)); Out.ln; + Out.int(fact(20)); Out.ln; + fill(bg, 5); + Out.int(total(bg)); Out.str(" "); Out.int(bg.a[0]); Out.ln; + Out.int(noresult(5)); Out.ln; + Out.int(mk(7).a[9]); Out.str(" "); Out.int(mkzero(1).a[3]); Out.ln; + Out.int(I64(fsum(1.25, 2.5) * 4.0)); Out.ln; + return 7; +end; + +end Procs. diff --git a/test/run/Procs.status b/test/run/Procs.status new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/test/run/Procs.status @@ -0,0 +1 @@ +7 diff --git a/test/run/Shapes b/test/run/Shapes new file mode 100755 index 0000000..780a0bd Binary files /dev/null and b/test/run/Shapes differ diff --git a/test/run/Shapes.expect b/test/run/Shapes.expect new file mode 100644 index 0000000..959be60 --- /dev/null +++ b/test/run/Shapes.expect @@ -0,0 +1,7 @@ +12 +12 +24 +1 24 +3 hi12 1 3 +zero is a circle of 0 +32 diff --git a/test/run/Shapes.jed b/test/run/Shapes.jed new file mode 100644 index 0000000..e4ba610 --- /dev/null +++ b/test/run/Shapes.jed @@ -0,0 +1,63 @@ +module Shapes; +import Out; + +type + Shape* = variant + circle(r: F64); + rect(w, h: F64); + label(text: []U8; size: I64); + dot; + end; + +proc area(s: Shape): I64; +var a: F64; +begin + match s of + | circle(r): a := 3.0 * r * r; + | rect(w, h): a := w * h; + | label: a := 0.0; + | dot: a := 1.0; + end; + return I64(a); +end; + +proc grow(var s: Shape); +begin + match s of + | rect(w, h): w := w * 2.0; + | else: + end; +end; + +proc main*; +var s, t: Shape; shapes: [4]Shape; i: I64; z: Shape; +begin + s := circle(2.0); + Out.int(area(s)); Out.ln; + s := rect(3.0, 4.0); + Out.int(area(s)); Out.ln; + grow(s); + Out.int(area(s)); Out.ln; + t := s; + s := dot; + Out.int(area(s)); Out.str(" "); Out.int(area(t)); Out.ln; + shapes[0] := circle(1.0); + shapes[1] := label("hi", 12); + shapes[2] := dot; + shapes[3] := rect(1.5, 2.0); + for i := 0 to 3 do + match shapes[i] of + | label(text, size): Out.str(text); Out.int(size); + | else: Out.int(area(shapes[i])); + end; + Out.str(" "); + end; + Out.ln; + match z of + | circle(r): Out.str("zero is a circle of "); Out.int(I64(r)); Out.ln; + | else: Out.str("?"); + end; + Out.int(SIZE(Shape)); Out.ln; +end; + +end Shapes. diff --git a/test/run/Strings b/test/run/Strings new file mode 100755 index 0000000..877148f Binary files /dev/null and b/test/run/Strings differ diff --git a/test/run/Strings.expect b/test/run/Strings.expect new file mode 100644 index 0000000..70a499d --- /dev/null +++ b/test/run/Strings.expect @@ -0,0 +1,4 @@ +eq ne lit arr buf 0 5 2 +6 100 0 +threeone +é☺A diff --git a/test/run/Strings.jed b/test/run/Strings.jed new file mode 100644 index 0000000..ee9084b --- /dev/null +++ b/test/run/Strings.jed @@ -0,0 +1,39 @@ +module Strings; +import Out; + +const greeting = "hello"; + +var buf: [8]U8; + +proc count(xs: []I64): I64; +var i, s: I64; +begin + s := 0; + for i := 0 to LEN(xs) - 1 do s := s + xs[i]; end; + return s; +end; + +proc main*; +var a: []U8; b: [5]U8; c: [3]I64; d: [][]U8; +begin + a := "hello"; + if a = greeting then Out.str("eq "); end; + if a # "help" then Out.str("ne "); end; + if "abc" = "abc" then Out.str("lit "); end; + b := "hello"; + if b = a then Out.str("arr "); end; + buf := "hi"; + if buf[0..2] = "hi" then Out.str("buf "); end; + Out.int(I64(buf[5])); Out.str(" "); + Out.int(LEN(greeting)); Out.str(" "); + Out.int(LEN(a[1..3])); Out.ln; + c := [1, 2, 3]; + Out.int(count(c)); Out.str(" "); + Out.int(count([10, 20, 30, 40])); Out.str(" "); + Out.int(count([])); Out.ln; + d := ["one", "two", "three"]; + Out.str(d[2]); Out.str(d[0]); Out.ln; + Out.str("é\u{263A}\x41\n"); +end; + +end Strings. diff --git a/test/run/Target b/test/run/Target new file mode 100755 index 0000000..00ad87d Binary files /dev/null and b/test/run/Target differ diff --git a/test/run/Target.expect b/test/run/Target.expect new file mode 100644 index 0000000..126d1d5 --- /dev/null +++ b/test/run/Target.expect @@ -0,0 +1 @@ +linux42 diff --git a/test/run/Target.jed b/test/run/Target.jed new file mode 100644 index 0000000..9f8c1a8 --- /dev/null +++ b/test/run/Target.jed @@ -0,0 +1,11 @@ +module Target; +import Out, Plat; + +proc main*; +var i: Plat.Info; +begin + i.kind := 41; + Out.str(Plat.name); Out.int(Plat.id(i.kind)); Out.ln; +end; + +end Target. diff --git a/test/run/mods/First.jed b/test/run/mods/First.jed new file mode 100644 index 0000000..fa9f69f --- /dev/null +++ b/test/run/mods/First.jed @@ -0,0 +1,14 @@ +module First; +import Out; + +var count*: I64; + +proc main*; +begin + Out.str("First.main must not run"); +end; + +begin + count := 1; + Out.str("First "); +end First. diff --git a/test/run/mods/Plat.linux-x86_64.jed b/test/run/mods/Plat.linux-x86_64.jed new file mode 100644 index 0000000..95996ae --- /dev/null +++ b/test/run/mods/Plat.linux-x86_64.jed @@ -0,0 +1,5 @@ +module Plat; +const name* = "linux"; +type Info* = record kind*: I64; extra: I64; end; +proc id*(x: I64): I64; begin return x + 1; end; +end Plat. diff --git a/test/run/mods/Plat.macos-aarch64.jed b/test/run/mods/Plat.macos-aarch64.jed new file mode 100644 index 0000000..7d7c615 --- /dev/null +++ b/test/run/mods/Plat.macos-aarch64.jed @@ -0,0 +1,5 @@ +module Plat; +const name* = "macos"; +type Info* = record kind*: I64; other: U8; end; +proc id*(x: I64): I64; begin return SOMETHING_UNKNOWN_HERE(x); end; +end Plat. diff --git a/test/run/mods/Second.jed b/test/run/mods/Second.jed new file mode 100644 index 0000000..c9aecdc --- /dev/null +++ b/test/run/mods/Second.jed @@ -0,0 +1,11 @@ +module Second; +import Out, First; + +var count*: I64; + +begin + count := First.count + 1; + Out.str("Second "); + if count = 2 then return; end; + Out.str("not reached"); +end Second.