Skip to content

Commit

Permalink
Initial code found from my very old backups.
Browse files Browse the repository at this point in the history
  • Loading branch information
brosner committed May 9, 2008
0 parents commit 01cb544
Show file tree
Hide file tree
Showing 43 changed files with 6,473 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added bin/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions bin/hello.dpl
@@ -0,0 +1,3 @@

string a[];
a[0] = "hello";
7 changes: 7 additions & 0 deletions bin/test.dpl
@@ -0,0 +1,7 @@

file fp = @/home/brian/dpl2/test;
print fp;
print @fp;
print fp;
print fp;
print @fp;
18 changes: 18 additions & 0 deletions content.py
@@ -0,0 +1,18 @@
#!/usr/bin/env python

# for cf.net

import time, random

list = [x for x in range(1000000)]
begin = time.time()
for index in range(1000000):
x = random.randrange(1000000)
temp = list[x]
list[x] = list[index]
list[index] = temp
end = time.time()
for i in range(100):
print list[i],
total = end - begin
print "\nRandomization took %d seconds." % total
24 changes: 24 additions & 0 deletions contest.php
@@ -0,0 +1,24 @@
<?php

function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

$size = 999999;
$range = range(0,$size);

$start = time();
for($i = 0; $i < $size; $i++) {
$index = rand(0,$size);
$new[] = $range[$index];
}
$end = time();

for($i = 0; $i < 100; $i++) {
printf("%d ",$new[$i]);
}

printf("\n\nTook %d seconds to randomize\n",$end - $start);

?>
41 changes: 41 additions & 0 deletions makefile
@@ -0,0 +1,41 @@

# define building tools
CC = gcc
LEXER = flex
YACC = bison

# define paths
ROOT = /home/brian/dpl2
BIN = $(ROOT)/bin
SRC = $(ROOT)/src
EXT = $(SRC)/ext

# define program specifics
PROG = $(BIN)/dpl

LEXFILE = $(SRC)/dpl_scanner.l
YACCFILE = $(SRC)/dpl_parser.y
LEXOUT = $(SRC)/dpl_scanner.c
YACCOUT = $(SRC)/dpl_parser.c

SRCS = $(LEXOUT) $(YACCOUT) main.c variables.c

OBJS = hash.o stack.o dpl_api.o dpl_scanner.o dpl_parser.o main.o variables.o arrays.o functions.o operators.o control_structs.o file.o
EXT_OBJS = string.o math.o array.o

all: dpl clean

dpl:
$(LEXER) -o$(LEXOUT) $(LEXFILE)
$(YACC) -y -d -o $(YACCOUT) $(YACCFILE)

# compile core source
$(CC) -ggdb -c $(SRC)/*.c

# compile ext source
$(CC) -c -I$(SRC) $(EXT)/*.c

$(CC) -ggdb -o $(PROG) $(OBJS) $(EXT_OBJS)

clean:
rm -f ./*.o
214 changes: 214 additions & 0 deletions src/arrays.c
@@ -0,0 +1,214 @@
/*
+----------------------------------------------+
| DPL Programming Language v1.1 |
+----------------------------------------------+
| The DPL langauge was developed for a school |
| project at ThunderRidge High School. |
| |
| Development of the language after its |
| completion is reserved to Brian Rosner. |
+----------------------------------------------+
| Author: Brian Rosner <br@brosner.com> |
+----------------------------------------------+
*/

#include <stdio.h>
#include <string.h>

#include "dpl.h"
#include "arrays.h"
#include "variables.h"

void arrayInit(dplVal *type,dplVal *name) {
dplVal array;

/* set array specific data and pass thru type */
array.type = type->type;
array.isArray = TRUE;

#ifdef DEBUG
printf("init array (type = %d,name = %s)\n",type->type,name->value.str.val);
#endif

/* init the variable */
variableInit(&array,name);
}

void arrayCreate(dplVal *type,dplVal *name,dplVal *value) {
#ifdef DEBUG
printf("creating array (type = %d,name = %s)\n",type->type,name->value.str.val);
#endif

/* validate the value being assigned MUST BE AN ARRAY */
if(value->isArray != TRUE ) {
dplError(DPL_WARNINGL,"value being assigned to array must be an array");
return;
}
else {
int elementCount;
dplVal i, *ivalue;

/* initialize array */
arrayInit(type,name);

/* cache element count and set the type for i to int */
elementCount = value->value.array.elements->numElements;
i.type = IS_INT;

/* assign in the values passed by the array */
for(i.value.ival = 0; i.value.ival < elementCount; i.value.ival++) {
/* fetch the element value from ht */
if(dplHashIndexFind(value->value.array.elements,i.value.ival,(void **) &ivalue) == FAILURE) {
dplError(DPL_CORE,"error extracting element %d from ht",i.value.ival);
break;
}

/* assign to right index */
arrayAssign(name,&i,ivalue);
}
}
}

void arrayAssign(dplVal *name,dplVal *element,dplVal *value) {
#ifdef DEBUG
printf("assigning array (name = %s,element = %d)\n",name->value.str.val,element->value.ival);
#endif

dplVal array;

/* fetch the array */
if(variableFetch(&array,name) == FAILURE) {
dplError(DPL_WARNINGL,"array was not initialized.");
return;
}

#ifdef DEBUG
printf("array check (init = %d,ce = %d)\n",array.value.array.elements->isInit,array.value.array.currentElement);
#endif

/* check if element exists */
if(arrayElementExists(&array,element) == TRUE) {
#ifdef DEBUG
printf("element %d in array %s exists...updating\n",element->value.ival,name->value.str.val);
#endif
/* perform a hash update */
if(dplHashUpdateIndexElement(array.value.array.elements,element->value.ival,value,sizeof(dplVal)) == FAILURE) {
dplError(DPL_CORE,"failed updating index %d in %s",element->value.ival,name->value.str.val);
return;
}
else {
#ifdef DEBUG
printf("updated array element %d successfully\n",element->value.ival);
#endif
}
}
else {
#ifdef DEBUG
printf("element %d in array %s does not exist...adding\n",element->value.ival,name->value.str.val);
#endif

/* perform a hash add */
if(dplHashAddIndexElement(array.value.array.elements,element->value.ival,value,sizeof(dplVal)) == FAILURE) {
dplError(DPL_CORE,"failed adding index %d in %s",element->value.ival,name->value.str.val);
return;
}
else {
#ifdef DEBUG
printf("added array element %d successfully\n",element->value.ival);
#endif
}

/* commit the changes of the array back */
if(dplHashUpdateElement(&_global(vst),name->value.str.val,name->value.str.len + 1,&array,sizeof(dplVal)) == FAILURE) {
dplError(DPL_CORE,"failed udpating the array %s",name->value.str.val);
}
else {
#ifdef DEBUG
printf("commited the array back successfully\n");
#endif
}
}

}

void passArrayValue(dplVal *result,dplVal *value,int init) {
static int elementCount = 0;

if(init == 1) {
result->isArray = TRUE;
result->value.array.elements = (HashTable *) malloc(sizeof(HashTable));

if(dplHashInit(result->value.array.elements,20,NULL) == FAILURE) {
dplError(DPL_CORE,"array pass hash tbl failed init");
}
}

if(dplHashAddIndexElement(result->value.array.elements,elementCount,value,sizeof(dplVal)) == FAILURE) {
dplError(DPL_CORE,"failed adding elements");
}

elementCount++;
}

int arrayElementExists(dplVal *array,dplVal *element) {
dplVal *tmp;

if(dplHashIndexFind(array->value.array.elements,element->value.ival,(void **) &tmp) == FAILURE) {
return FALSE;
}
else {
return TRUE;
}
}

void arrayElementFetch(dplVal *result,dplVal *_array,dplVal *element) {
dplVal array, *elementData;


/* check to see if we need to fetch the array */
if(_array->isArray != TRUE) {
if(variableFetch(&array,_array) == FAILURE) {
dplError(DPL_CORE,"failed fetching array %s in arrayElementFetch",_array->value.str.val);
return;
}
}
else {
arrayValueCopy(&array,_array);
}

#ifdef DEBUG
printf("arrayElementFetch array check (init = %d,ce = %d,elements = %d)\n",array.value.array.elements->isInit,array.value.array.currentElement,array.value.array.elements->numElements);
#endif

/* fetch the element data */
if(dplHashIndexFind(array.value.array.elements,element->value.ival,(void **) &elementData) == FAILURE) {
dplError(DPL_WARNINGL,"cannot fetch element %d of array %s",element->value.ival,_array->value.str.val);
result->isNull = TRUE;
return;
}
else {
#ifdef DEBUG
printf("fetched element %d from array %s successfully\n",element->value.ival,_array->value.str.val);
#endif
}

/* result */
if(elementData->isArray == TRUE) {
arrayValueCopy(result,elementData);
}
else {
valueCopy(result,elementData);
}
}

void arrayElementDump(dplVal *arrayName) {
dplVal array;

/* fetch array */
if(variableFetch(&array,arrayName) == FAILURE) {
dplError(DPL_CORE,"failed fetching array");
}

/* preform dump - make sure a stderr redirect is ineffect to make easier reading */
dplHashIndexDump(array.value.array.elements,FALSE);
}
29 changes: 29 additions & 0 deletions src/arrays.h
@@ -0,0 +1,29 @@
/*
+----------------------------------------------+
| DPL Programming Language v1.1 |
+----------------------------------------------+
| The DPL langauge was developed for a school |
| project at ThunderRidge High School. |
| |
| Development of the language after its |
| completion is reserved to Brian Rosner. |
+----------------------------------------------+
| Author: Brian Rosner <br@brosner.com> |
+----------------------------------------------+
*/

#ifndef _DPL_ARRAYS_H
#define _DPL_ARRAYS_H

extern void arrayInit(dplVal *type,dplVal *name);
extern void arrayCreate(dplVal *type,dplVal *name,dplVal *value);
extern void arrayAssign(dplVal *name,dplVal *element,dplVal *value);

extern void passArrayValue(dplVal *result,dplVal *value,int init);

extern int arrayElementExists(dplVal *array,dplVal *element);
extern void arrayElementFetch(dplVal *result,dplVal *_array,dplVal *element);

extern void arrayElementDump(dplVal *arrayName);

#endif
52 changes: 52 additions & 0 deletions src/control_structs.c
@@ -0,0 +1,52 @@
/*
+----------------------------------------------+
| DPL Programming Language v1.1 |
+----------------------------------------------+
| The DPL langauge was developed for a school |
| project at ThunderRidge High School. |
| |
| Development of the language after its |
| completion is reserved to Brian Rosner. |
+----------------------------------------------+
| Author: Brian Rosner <br@brosner.com> |
+----------------------------------------------+
*/

#include <stdio.h>

#include "dpl.h"
#include "control_structs.h"
#include "stack.h"
#include "operators.h"

void csIfStart(dplVal *expr) {
/* push current state on to css stack */
stackPush(&_global(css),&_global(execute),sizeof(int));

/* should this if execute? */
if(_global(execute)) {
/* test the expression */
if(dplValExprTrue(expr) == TRUE) {
_global(execute) = TRUE;
}
else {
_global(execute) = FALSE;
}
}
else {
_global(execute) = FALSE;
}
}

void csIfEnd() {
int *execFlag;

/* restore last state and jump back */
stackPop(&_global(css),(void **) &execFlag);
_global(execute) = *execFlag;
}

void csElseStart() {
if(_global(execute) == TRUE) _global(execute) = FALSE;
else _global(execute) = TRUE;
}

0 comments on commit 01cb544

Please sign in to comment.