-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the Mark() and Release() procedures from the Pascal compiler and
standard library, because they never worked and come from an achingly old version of the Pascal specification. Fix the implementations of New() and Dispose() to use the standard C memory allocator rather than rolling their own (also in C). Write test!
- Loading branch information
1 parent
899f1ea
commit c084f9f
Showing
10 changed files
with
95 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,51 @@ | ||
/* REQUIRED PROCEDURES AND FUNCTIONS */ | ||
|
||
/* PROCEDURES */ | ||
/* FILE HANDLING */ | ||
#define R_REWRITE 1 | ||
#define R_PUT 2 | ||
#define R_RESET 3 | ||
#define R_GET 4 | ||
#define R_PAGE 5 | ||
|
||
/* DYNAMIC ALLOCATION */ | ||
#define R_NEW 6 | ||
#define R_DISPOSE 7 | ||
#define R_MARK 8 | ||
#define R_RELEASE 9 | ||
|
||
/* MISCELLANEOUS PROCEDURE(S) */ | ||
#define R_HALT 10 | ||
|
||
/* TRANSFER */ | ||
#define R_PACK 11 | ||
#define R_UNPACK 12 | ||
|
||
/* FUNCTIONS */ | ||
/* ARITHMETIC */ | ||
#define R_ABS 13 | ||
#define R_SQR 14 | ||
#define R_SIN 15 | ||
#define R_COS 16 | ||
#define R_EXP 17 | ||
#define R_LN 18 | ||
#define R_SQRT 19 | ||
#define R_ARCTAN 20 | ||
|
||
/* TRANSFER */ | ||
#define R_TRUNC 21 | ||
#define R_ROUND 22 | ||
|
||
/* ORDINAL */ | ||
#define R_ORD 23 | ||
#define R_CHR 24 | ||
#define R_SUCC 25 | ||
#define R_PRED 26 | ||
|
||
/* BOOLEAN */ | ||
#define R_ODD 27 | ||
#define R_EOF 28 | ||
#define R_EOLN 29 | ||
enum | ||
{ | ||
R__UNUSED = 0, | ||
|
||
/* PROCEDURES */ | ||
/* FILE HANDLING */ | ||
R_REWRITE, | ||
R_PUT, | ||
R_RESET, | ||
R_GET, | ||
R_PAGE, | ||
|
||
/* DYNAMIC ALLOCATION */ | ||
R_NEW, | ||
R_DISPOSE, | ||
|
||
/* MISCELLANEOUS PROCEDURE(S) */ | ||
R_HALT, | ||
|
||
/* TRANSFER */ | ||
R_PACK, | ||
R_UNPACK, | ||
|
||
/* FUNCTIONS */ | ||
/* ARITHMETIC */ | ||
R_ABS, | ||
R_SQR, | ||
R_SIN, | ||
R_COS, | ||
R_EXP, | ||
R_LN, | ||
R_SQRT, | ||
R_ARCTAN, | ||
|
||
/* TRANSFER */ | ||
R_TRUNC, | ||
R_ROUND, | ||
|
||
/* ORDINAL */ | ||
R_ORD, | ||
R_CHR, | ||
R_SUCC, | ||
R_PRED, | ||
|
||
/* BOOLEAN */ | ||
R_ODD, | ||
R_EOF, | ||
R_EOLN, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,20 @@ | ||
/* | ||
* File: - new.c | ||
* | ||
* new() built in standard procedure in Pascal (6.6.5.3) | ||
* | ||
* Re-implementation of storage allocator for Ack Pascal compiler | ||
* under Linux, and other UNIX-like systems. | ||
* | ||
* Written by Erik Backerud, 2010-10-01 | ||
* | ||
* Original copyright and author info below: | ||
*/ | ||
/* $Id$ */ | ||
/* | ||
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. | ||
* | ||
* This product is part of the Amsterdam Compiler Kit. | ||
* | ||
* Permission to use, sell, duplicate or disclose this software must be | ||
* obtained in writing. Requests for such permissions may be sent to | ||
* | ||
* Dr. Andrew S. Tanenbaum | ||
* Wiskundig Seminarium | ||
* Vrije Universiteit | ||
* Postbox 7161 | ||
* 1007 MC Amsterdam | ||
* The Netherlands | ||
* | ||
*/ | ||
|
||
/* Author: J.W. Stevenson */ | ||
#include <stdlib.h> | ||
#include <em_abs.h> | ||
#include <pc_err.h> | ||
|
||
#define assert(x) /* nothing */ | ||
#define UNDEF 0x8000 | ||
#define NALLOC (1024) /* request this many units from OS */ | ||
|
||
|
||
/* | ||
* use a singly linked list of free blocks. | ||
*/ | ||
struct adm { | ||
struct adm *next; | ||
int size; | ||
}; | ||
|
||
extern struct adm *freep; | ||
|
||
extern void _trp(int); /* called on error */ | ||
|
||
extern void _dis(int, struct adm **); | ||
|
||
|
||
/* | ||
* Helper function to request 'nu' units of memory from the OS. | ||
* A storage unit is sizeof(struct adm). Typically 8 bytes | ||
* on a 32-bit machine like i386 etc. | ||
*/ | ||
static struct adm * | ||
morecore(unsigned nu) | ||
void _new(int n, void** ptr) | ||
{ | ||
char *cp, *sbrk(int); | ||
struct adm *up; | ||
void* p = malloc(n); | ||
if (!p) | ||
_trp(EHEAP); | ||
|
||
if (nu < NALLOC) | ||
nu = NALLOC; | ||
cp = sbrk(nu * sizeof(struct adm)); | ||
if (cp == (char *) -1) /* no space at all */ | ||
return 0; | ||
up = (struct adm*) cp; | ||
up->size = nu; | ||
up = up + 1; | ||
_dis((nu - 1) * sizeof(struct adm), &up); | ||
return freep; | ||
} /* morecore */ | ||
*ptr = p; | ||
} | ||
|
||
/* | ||
* Dispose | ||
* Called with two arguments: | ||
* n the size of the block to be freed, in bytes, | ||
* pp address of pointer to data. | ||
*/ | ||
void | ||
_new(int n, struct adm **pp) | ||
void _dis(int n, void** ptr) | ||
{ | ||
int nunits; /* the unit of storage is sizeof(struct adm) */ | ||
struct adm *p,*q; | ||
|
||
/* round up size of request */ | ||
nunits = (n + sizeof(struct adm) - 1) / sizeof(struct adm) + 1; | ||
|
||
q = 0; | ||
for (p = freep; ; p = p->next) { | ||
if (p == 0) { | ||
p = morecore(nunits); | ||
if (p == 0) | ||
_trp(EHEAP); | ||
q = 0; | ||
} | ||
if (p->size >= nunits) { | ||
if (p->size == nunits) { /* exact fit */ | ||
if (q == 0) { /* first element on free list. */ | ||
freep = p->next; | ||
} else { | ||
q->next = p->next; | ||
} | ||
} else { /* allocate tail end */ | ||
q = p; | ||
q->size = q->size - nunits; | ||
p = q + q->size; | ||
p->next = 0; | ||
p->size = nunits; | ||
} | ||
break; | ||
} | ||
q = p; | ||
} | ||
*pp = p + 1; | ||
} /* _new */ | ||
free(*ptr); | ||
*ptr = NULL; | ||
} |
Oops, something went wrong.