Skip to content

Instantly share code, notes, and snippets.

@AbePralle
AbePralle / 1 - VectorWrapper.rogue
Last active March 2, 2016 06:20
Simple example of wrapping a C++ vector in Rogue
#==================================================================
# VectorWrapper.rogue
#
# v2.1
#
# March 1, 2016 by Abe Pralle
#
# Compile with RogueC v1.0.6+ from
# https://github.com/AbePralle/Rogue
#
@AbePralle
AbePralle / 1 - SelectDemo.rogue
Last active March 4, 2016 03:25
Demonstrates the 'select' operator, Rogue's alternative to the decision (aka ternary) operator.
# SelectDemo.rogue
#
# March 3, 2016 by Abe Pralle
println "Settings A"
forEach (setting in [false,true])
println setting + " means " + select{ setting:"ON", "OFF" }
endForEach
println
println "Settings B"
@AbePralle
AbePralle / Test.rogue
Last active January 5, 2017 08:44
Rogue greeting + generator
# Statements outside of any class definition are run at launch.
# You can write your program here or instantiate a class to handle
# the rest:
Greeting() # Create a Greeting object - Rogue does not use the "new" keyword
# Creating a Greeting object prints out:
# Entering main
# 0
# [Greeting.init() Test.rogue:23] foo:0
# numbers:[0,1,1,2,3,5,8,13,21,34]
@AbePralle
AbePralle / FilterFunction.rogue
Last active January 5, 2017 17:46
Rogue Filter Function
routine filter( range: Range<<Int32>>, pred:Function(Int32)->(Logical) ) -> Int32[]
local result = Int32[]
forEach i in range
if pred(i)
result.add(i)
endIf
endForEach
return result
endRoutine
This file has been truncated, but you can view the full file.
/* Generated by Cython 0.25.2 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
#error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
#error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_25_2"
#include <stdio.h>
namespace std {}
using namespace std;
#include "HelloRogue.h"
//=============================================================================
// NativeCPP.cpp
//
// Rogue runtime routines.
//=============================================================================
This file has been truncated, but you can view the full file.
#!python
#cython: optimize.unpack_method_calls=False
# Generated by the Rogue compiler
import sys
from cpython cimport PyObject, Py_XINCREF, Py_XDECREF
from libcpp cimport bool
from libc.stdlib cimport malloc, free
from libc.stdint cimport intptr_t, uint32_t
cdef object Int32
class Int32:
@AbePralle
AbePralle / Build.rogue
Last active January 17, 2018 03:43
Introspective Build.rogue for Rogo
#$ ROGUEC_OPTIONS = --api
module Build
global method_prefix = "Build::on_"
routine on_random( low:Int32, high:Int32 )
println Random.int32( low, high )
endRoutine
routine on_random
@AbePralle
AbePralle / RogueModuleHandling.rouge
Last active February 23, 2018 19:43
Rogue module handling
Tokenizer accepts '::' as part of identifers.
https://github.com/AbePralle/Rogue/blob/495abaffc05785a9f661eb05e960ff13c03f1260/Source/RogueC/Tokenizer.rogue#L605
https://github.com/AbePralle/Rogue/blob/495abaffc05785a9f661eb05e960ff13c03f1260/Source/RogueC/Tokenizer.rogue#L432
When RogueC include_source()'s a new file, it creates a Parser object which tokenizes the content using a Preprocessor.
https://github.com/AbePralle/Rogue/blob/495abaffc05785a9f661eb05e960ff13c03f1260/Source/RogueC/RogueC.rogue#L443
The Preprocessor looks for 'directive_module' and updates the 'cur_module' string.
https://github.com/AbePralle/Rogue/blob/495abaffc05785a9f661eb05e960ff13c03f1260/Source/RogueC/Preprocessor.rogue#L159
==7115== Memcheck, a memory error detector
==7115== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==7115== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==7115== Command: Programs/RogueC/Rogo-Linux
==7115==
==7115==
==7115== Process terminating with default action of signal 7 (SIGBUS)
==7115== Non-existent physical address at address 0x33B008
==7115== at 0x400D2F6: elf_machine_rela_relative (dl-machine.h:541)
==7115== by 0x400D2F6: elf_dynamic_do_Rela (do-rel.h:112)