September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,59 @@
/* ARM assembly Raspberry PI */
/* program variable.s */
/************************************/
/* Constantes Définition */
/************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*********************************/
/* Initialized data */
/*********************************/
.data
szString: .asciz "String définition"
sArea1: .fill 11, 1, ' ' @ 11 spaces
@ or
sArea2: .space 11,' ' @ 11 spaces
cCharac: .byte '\n' @ character
cByte1: .byte 0b10101 @ 1 byte binary value
hHalfWord1: .hword 0xFF @ 2 bytes value hexa
.align 4
iInteger1: .int 123456 @ 4 bytes value decimal
iInteger3: .short 0500 @ 4 bytes value octal
iPointer1: .int 0x4000 @ 4 bytes value hexa
@ or
iPointer2: .word 0x4000 @ 4 bytes value hexa
iPointer3: .int 04000 @ 4 bytes value octal
TabInteger4: .int 5,4,3,2 @ Area of 4 integers = 4 * 4 = 16 bytes
iDoubleInt1: .quad 0xFFFFFFFFFFFFFFFF @ 8 bytes
dfFLOAT1: .double 0f-31415926535897932384626433832795028841971.693993751E-40 @ Float 8 bytes
sfFLOAT2: .float 0f-31415926535897932384626433832795028841971.693993751E-40 @ Float 4 bytes (or use .single)
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sBuffer: .skip 500 @ 500 bytes values zero
iInteger2: .skip 4 @ 4 bytes value zero
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
ldr r0,iAdriInteger2 @ load variable address
mov r1,#100
str r1,[r0] @ init variable iInteger2
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdriInteger2: .int iInteger2 @ variable address iInteger2

View file

@ -5,7 +5,7 @@ Name: declare -- a local declaration block has an optional name
Z : Integer renames Y: -- Rename Y (creates a view)
function F (X: Integer) return Integer is
-- Inside, all declarations outside are visible when not hidden: X, Y, Z are global with respect to F.
X: Integer := Z; -- hides the outer X which however can be refered to by Name.X
X: Integer := Z; -- hides the outer X which however can be referred to by Name.X
begin
...
end F; -- locally declared variables stop to exist here

View file

@ -0,0 +1,3 @@
(defun frobnicate (x)
(declare (type fixnum x))
(the fixnum (+ x 128)))

View file

@ -1,4 +1,2 @@
(declaim (ftype (function (fixnum) fixnum) frobnicate))
(defun frobnicate (x)
(declare (type fixnum x))
(the fixnum (+ x 128)))
(setf *x* 42 *y* (1+ *x*))
=>43

View file

@ -0,0 +1,3 @@
(setf *x* 625)
(psetf *x* 42 *y* (1+ *x*)
=>NIL

View file

@ -0,0 +1,3 @@
(declaim (ftype (function (fixnum) fixnum) frobnicate))
(defun frobnicate (x)
(+ x 42))

View file

@ -1,8 +1,10 @@
program =
[
var c := $nil. // declaring variable.
var a := 3. // declaring and initializing variables
var b := "my string" length.
public program
{
var c := nil; // declaring variable.
var a := 3; // declaring and initializing variables
var b := "my string".Length;
long l := 200l; // declaring strongly typed variable
auto l := new List<int>();
c := b + a. // assigning variable
].
c := b + a; // assigning variable
}

View file

@ -0,0 +1,5 @@
:- func name = string.
name = Name :-
Name = Title ++ " " ++ Given,
Title = "Dr.",
Given = "Bob".

View file

@ -0,0 +1,4 @@
:- pred greet(string::in, io::di, io::uo) is det.
greet(Who, !IO) :-
io.write_string("Hello", !IO),
io.format(", %s!\n", [s(Who)], !IO).

View file

@ -0,0 +1,4 @@
:- pred greet(string::in, io::di, io::uo) is det.
greet(Who, !.IO, !:IO) :-
io.write_string("Hello", !.IO, !:IO),
io.format(", %s!\n", [s(Who)], !.IO, !:IO).

View file

@ -0,0 +1,4 @@
:- pred greet(string::in, io::di, io::uo) is det.
greet(Who, IO0, IO) :-
io.write_string("Hello", IO0, IO1),
io.format(", %s!\n", [s(Who)], IO1, IO).

View file

@ -0,0 +1,9 @@
:- func dr(string) = string.
dr(Name) = Titled :-
some [!SB] (
!:SB = string.builder.init,
put_char(handle, 'D', !SB),
put_char(handle, 'r', !SB),
format(handle, " %s", [s(Name)], !SB),
Titled = to_string(!.SB)
).

View file

@ -0,0 +1,6 @@
% all_under(N, L)
% True if every member of L is less than N
%
:- pred all_under(int::in, list(int)::in) is semidet.
all_under(Limit, L) :-
all [N] (member(N, L) => N < Limit).

View file

@ -0,0 +1,23 @@
:- type accumulator == (pred(int, int, io, io)).
:- inst accumulator == (pred(in, out, di, uo) is det).
:- func accumulator >> accumulator = accumulator.
:- mode in(accumulator) >> in(accumulator) = out(accumulator).
A >> B = C :-
C = (pred(!.N::in, !:N::out, !.IO::di, !:IO::uo) is det :-
A(!N, !IO),
B(!N, !IO)).
:- pred add(int::in, int::in, int::out, io::di, io::uo) is det.
add(N, !Acc, !IO) :-
io.format("adding %d to accumulator (current value: %d)\n",
[i(N), i(!.Acc)], !IO),
!:Acc = !.Acc + N.
:- pred example2(io::di, io::uo) is det.
example2(!IO) :-
F = add(5)
>> add(5)
>> add(-10),
F(0, X, !IO),
io.print_line(X, !IO).

View file

@ -0,0 +1,39 @@
:- module evenodd.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module list, string.
:- type coin
---> heads
; tails.
:- inst heads for coin/0
---> heads.
:- inst tails for coin/0
---> tails.
main(!IO) :-
(if heads(heads, N) then
print_heads(N, !IO)
else true).
:- pred print_heads(coin::in(heads), io::di, io::uo) is det.
print_heads(_, !IO) :-
io.write_string("heads\n", !IO).
:- pred print_tails(coin::in(tails), io::di, io::uo) is det.
print_tails(_, !IO) :-
io.write_string("tails\n", !IO).
:- pragma foreign_export_enum("C", coin/0, [prefix("COIN_"), uppercase]).
:- pred heads(coin::in, coin::out(heads)) is semidet.
:- pragma foreign_proc("C",
heads(N::in, M::out(heads)),
[promise_pure, will_not_call_mercury],
"
M = N;
SUCCESS_INDICATOR = N == COIN_HEADS;
").

View file

@ -0,0 +1,2 @@
Dim variable As datatype
Dim var1,var2,... As datatype

View file

@ -0,0 +1,4 @@
Dim n1,n2 as Integer
Dim x as Double
Dim isRaining as Boolean
Dim greeting as String

View file

@ -0,0 +1,2 @@
Dim variable As datatype = value
Dim var1,var2,... As datatype

View file

@ -0,0 +1,6 @@
Dim wholeNumber1,wholeNumber2 as Integer = 3
Dim realNumber as Double = 3.0
Dim isRaining as Boolean = False
Dim greeting as String = "Hello, this is World speaking."
Dim longArray() As Long = {0, 1, 2, 3}
Dim twoDimensions(,) As Integer = {{0, 1, 2}, {10, 11, 12}}

View file

@ -0,0 +1 @@
variable = expression

View file

@ -0,0 +1,3 @@
v = a
d = b^2 - 4*a*c
s3 = s1 & mid(s2,3,2)

View file

@ -0,0 +1 @@
variable <operator>= expression2

View file

@ -0,0 +1,8 @@
c += a
c -= a
c *= a
c /= a
c ^= a
c <<= n
c >>= n
c &= a

View file

@ -1,4 +0,0 @@
Dim wholeNumber as Integer = 3
Dim realNumber as Double = 3.0
Dim isRaining as Boolean = False
Dim greeting as String = "Hello, this is World speaking."