Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
°A→B
|
||||
.B now contains the address of A
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
1234→A
|
||||
1→{A}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
........
|
||||
A%=100
|
||||
ADDR=VARPTR(A%)
|
||||
.......
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
PROGRAM POINTER
|
||||
BEGIN
|
||||
A%=100
|
||||
ADDR=VARPTR(A%)
|
||||
PRINT(A%) ! prints 100
|
||||
POKE(ADDR,200)
|
||||
PRINT(A%) ! prints 200
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
' FB 1.05.0 Win64
|
||||
Dim a As Integer = 3
|
||||
Dim p As Integer Ptr = @a
|
||||
Print a, p
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Var p = Cast(Integer Ptr, 1375832)
|
||||
*p = 42
|
||||
Print p, *p
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
dim as short i : i = 575
|
||||
dim as ptr j : j = NULL
|
||||
|
||||
j = @i
|
||||
|
||||
print "Adddress of i ="; j
|
||||
print "Value of i ="; [j]
|
||||
4
Task/Address-of-a-variable/Nim/address-of-a-variable.nim
Normal file
4
Task/Address-of-a-variable/Nim/address-of-a-variable.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var x = 12
|
||||
var xptr = addr(x) # Get address of variable
|
||||
echo cast[int](xptr) # and print it
|
||||
xptr = cast[ptr int](0xFFFE) # Set the address
|
||||
24
Task/Address-of-a-variable/Phix/address-of-a-variable.phix
Normal file
24
Task/Address-of-a-variable/Phix/address-of-a-variable.phix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
procedure address()
|
||||
object V
|
||||
integer addr4 -- stored /4 (assuming dword aligned, which it will be)
|
||||
#ilASM{
|
||||
[32]
|
||||
lea eax,[V]
|
||||
shr eax,2
|
||||
mov [addr4],eax
|
||||
[64]
|
||||
lea rax,[V]
|
||||
shr rax,2
|
||||
mov [addr4],rax
|
||||
[]
|
||||
}
|
||||
if machine_bits()=32 then
|
||||
poke4(addr4*4,123)
|
||||
elsif machine_bits()=64 then
|
||||
poke8(addr4*4,123)
|
||||
end if
|
||||
?V
|
||||
if getc(0) then end if
|
||||
end procedure
|
||||
|
||||
address()
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var n = 42;
|
||||
say Sys.refaddr(\n); # prints the address of the variable
|
||||
say Sys.refaddr(n); # prints the address of the object at which the variable points to
|
||||
31
Task/Address-of-a-variable/Swift/address-of-a-variable.swift
Normal file
31
Task/Address-of-a-variable/Swift/address-of-a-variable.swift
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
class MyClass {
|
||||
}
|
||||
|
||||
func printPointer<T>(ptr: UnsafePointer<T>) {
|
||||
println(ptr)
|
||||
}
|
||||
|
||||
func test() {
|
||||
var x = 42
|
||||
var y = 3.14
|
||||
var z = "foo"
|
||||
var obj = MyClass()
|
||||
|
||||
// Use a pointer to a variable on the stack and print its address
|
||||
withUnsafePointer(&x) { ptr in println(ptr) }
|
||||
withUnsafePointer(&y) { ptr in println(ptr) }
|
||||
withUnsafePointer(&z) { ptr in println(ptr) }
|
||||
withUnsafePointer(&obj) { ptr in println(ptr) }
|
||||
|
||||
// Alternately:
|
||||
printPointer(&x)
|
||||
printPointer(&y)
|
||||
printPointer(&z)
|
||||
printPointer(&obj)
|
||||
|
||||
// Printing the address of an object that an object reference points to
|
||||
// In Swift 3, unsafeAddress is removed
|
||||
println(Unmanaged.passUnretained(obj).toOpaque())
|
||||
}
|
||||
|
||||
test()
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
addr.x
|
||||
=> 27975840
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
if (addr.x = addr.y)
|
||||
..
|
||||
Loading…
Add table
Add a link
Reference in a new issue