Add all the A tasks

This commit is contained in:
Ingy döt Net 2013-04-10 14:58:50 -07:00
parent 2dd7375f96
commit 051504d65b
1608 changed files with 18584 additions and 0 deletions

View file

@ -0,0 +1 @@
{{basic data operation}}Demonstrate how to get the address of a variable and how to set the address of a variable.

View file

@ -0,0 +1,2 @@
---
note: Basic Data Operations

View file

@ -0,0 +1,4 @@
[4]INT test := (222,444,666,888);
REF INT reference := test[3];
REF INT(reference) := reference + 111;
print(("test value is now: ",test))

View file

@ -0,0 +1 @@
PROC establish = (REF FILE file, STRING idf, CHANNEL chan, INT p, l, c) INT: ~

View file

@ -0,0 +1,3 @@
The_Address : System.Address;
I : Integer;
The_Address := I'Address;

View file

@ -0,0 +1,2 @@
I : Integer;
for I'Address use 16#A100#;

View file

@ -0,0 +1,3 @@
I : Integer;
J : Integer;
for I'Address use J'Address;

View file

@ -0,0 +1,6 @@
use std, array (: array.arg also defines pointer operators :)
let var = 42
let ptr = &var (: value of ptr is address of var :)
print var (: prints 42 :)
(*ptr)++ (: increments value pointed by ptr :)
print var (: prints 43 :)

View file

@ -0,0 +1,3 @@
use std, array
=:mac:= -> int& { * (0x400000 as int*) }
printf "%x\n" mac (: may crash depending on operating system :)

View file

@ -0,0 +1 @@
msgbox % &var

View file

@ -0,0 +1,8 @@
'get a variable's address:
DIM x AS INTEGER, y AS LONG
y = VARPTR(x)
'can't set the address, but can access a given memory location... 1 byte at a time
DIM z AS INTEGER
z = PEEK(y)
z = z + (PEEK(y) * 256)

View file

@ -0,0 +1,10 @@
program test_loc
implicit none
integer :: i
real :: r
i = loc (r)
write (*, '(i0)') i
end program test_loc

View file

@ -0,0 +1,16 @@
package main
import (
"fmt"
"unsafe"
)
func main() {
myVar := 3.14
myPointer := &myVar
fmt.Println(myPointer)
fmt.Printf("%p\n", myPointer)
addr := int64(uintptr(unsafe.Pointer(myPointer)))
fmt.Printf("0x%x\n", addr)
}

View file

@ -0,0 +1,29 @@
== Get ==
There are at least three ways to get the address of a variable in IWBASIC. The first is to use the address of operator:
DEF X:INT
PRINT &X
'This will print in the console window (after OPENCONSOLE is issued.)
'To Print in an open window the appropriate Window variable is specified, e.g., PRINT Win,&X.
The second is to use a pointer:
DEF X:INT
DEF pPointer:POINTER
pPointer=X
The third is to use the Windows API function Lstrcpy. That is done in the same way as the Creative Basic example;
however, the function would be declared as follows: DECLARE IMPORT,Lstrcpy(P1:POINTER,P2:POINTER),INT.
== Set ==
It appears to the author that the closest one can come to being able to assign an address to a variable is to set
which bytes will be used to store a variable in a block of reserved memory:
DEF pMem as POINTER
pMem = NEW(CHAR,1000) : 'Get 1000 bytes to play with
#<STRING>pMem = "Copy a string into memory"
pMem += 100
#<UINT>pMem = 34234: 'Use bytes 100-103 to store a UINT
DELETE pMem

View file

@ -0,0 +1,3 @@
var =: 52 NB. Any variable (including data, functions, operators etc)
var_addr =: 15!:6<'var' NB. Get address
new_var =: 15!:7 var_addr NB. Set address

View file

@ -0,0 +1,2 @@
use Scalar::Util qw(refaddr);
print refaddr(\my $v), "\n"; # 135691508

View file

@ -0,0 +1,4 @@
my $a = 12;
my $b = \$a; # get reference
$$b = $$b + 30; # access referenced value
print $a; # prints 42

View file

@ -0,0 +1,6 @@
my $a = 12;
our $b; # you can overlay only global variables (this line is only for strictness)
*b = \$a;
print $b; # prints 12
$b++;
print $a; # prints 13

View file

@ -0,0 +1,14 @@
: (setq X 7)
-> 7
: (adr 'X)
-> -2985527269106
: (val (adr -2985527269106))
-> 7
: (set (adr -2985527269106) '(a b c))
-> (a b c)
: X
-> (a b c)

View file

@ -0,0 +1,2 @@
foo = object() # Create (instantiate) an empty object
address = id(foo)

View file

@ -0,0 +1 @@
zzz=storage(xxx)

View file

@ -0,0 +1,6 @@
#lang racket
(require ffi/unsafe)
(define (madness v) ; i'm so sorry
(cast v _racket _gcpointer))

View file

@ -0,0 +1,6 @@
(ptr-ref (madness +) _short)
(ptr-ref (madness (/ 4 3)) _short)
(ptr-ref (madness 3.2) _short)
(ptr-ref (madness (sqrt -2)) _short)
(ptr-ref (madness #\a) _short)
(ptr-ref (madness 'foo) _short)

View file

@ -0,0 +1,3 @@
>foo = Object.new # => #<Object:0x10ae32000>
>id = foo.object_id # => 2238812160
>"%x" % (id << 1) # => "10ae32000"

View file

@ -0,0 +1,5 @@
|p|
p := Point x:10 y:20.
ObjectMemory addressOf:p.
ObjectMemory collectGarbage.
ObjectMemory addressOf:p

View file

@ -0,0 +1,4 @@
|ptr|
ptr := ExternalBytes new:10.
ptr address.
ptr byteAt:1 put: 16rFF.

View file

@ -0,0 +1,21 @@
package require critcl
# This code assumes an ILP32 architecture, like classic x86 or VAX.
critcl::cproc peek {int addr} int {
union {
int i;
int *a;
} u;
u.i = addr;
return *u.a;
}
critcl::cproc poke {int addr int value} void {
union {
int i;
int *a;
} u;
u.i = addr;
*u.a = value;
}
package provide poker 1.0

View file

@ -0,0 +1,7 @@
package require poker
# Increment a memory location; this will probably crash if you try for real.
# We don't define how to get a good address, but it's not usually a problem
# for embedded programming...
set where 0x12340
poke $where [expr {[peek $where] + 1}]